author | mgerdin |
Thu, 23 Feb 2012 14:58:35 +0100 | |
changeset 12095 | cc3d6f08a4c4 |
parent 10565 | dc90c239f4ec |
child 13728 | 882756847a04 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7397 | 2 |
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "code/codeCache.hpp" |
|
28 |
#include "gc_interface/collectedHeap.inline.hpp" |
|
29 |
#include "interpreter/oopMapCache.hpp" |
|
30 |
#include "memory/generation.hpp" |
|
31 |
#include "memory/permGen.hpp" |
|
32 |
#include "memory/resourceArea.hpp" |
|
33 |
#include "runtime/handles.inline.hpp" |
|
34 |
#include "runtime/jniHandles.hpp" |
|
35 |
#include "runtime/memprofiler.hpp" |
|
36 |
#include "runtime/mutexLocker.hpp" |
|
37 |
#include "runtime/os.hpp" |
|
38 |
#include "runtime/task.hpp" |
|
39 |
#include "runtime/vmThread.hpp" |
|
40 |
#ifdef TARGET_OS_FAMILY_linux |
|
41 |
# include "thread_linux.inline.hpp" |
|
42 |
#endif |
|
43 |
#ifdef TARGET_OS_FAMILY_solaris |
|
44 |
# include "thread_solaris.inline.hpp" |
|
45 |
#endif |
|
46 |
#ifdef TARGET_OS_FAMILY_windows |
|
47 |
# include "thread_windows.inline.hpp" |
|
48 |
#endif |
|
10565 | 49 |
#ifdef TARGET_OS_FAMILY_bsd |
50 |
# include "thread_bsd.inline.hpp" |
|
51 |
#endif |
|
1 | 52 |
|
53 |
#ifndef PRODUCT |
|
54 |
||
55 |
// -------------------------------------------------------- |
|
56 |
// MemProfilerTask |
|
57 |
||
58 |
class MemProfilerTask : public PeriodicTask { |
|
59 |
public: |
|
60 |
MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {} |
|
61 |
void task(); |
|
62 |
}; |
|
63 |
||
64 |
||
65 |
void MemProfilerTask::task() { |
|
66 |
// Get thread lock to provide mutual exclusion, and so we can iterate safely over the thread list. |
|
67 |
MutexLocker mu(Threads_lock); |
|
68 |
MemProfiler::do_trace(); |
|
69 |
} |
|
70 |
||
71 |
||
72 |
//---------------------------------------------------------- |
|
73 |
// Implementation of MemProfiler |
|
74 |
||
75 |
MemProfilerTask* MemProfiler::_task = NULL; |
|
76 |
FILE* MemProfiler::_log_fp = NULL; |
|
77 |
||
78 |
||
79 |
bool MemProfiler::is_active() { |
|
80 |
return _task != NULL; |
|
81 |
} |
|
82 |
||
83 |
||
84 |
void MemProfiler::engage() { |
|
85 |
const char *log_name = "mprofile.log"; |
|
86 |
if (!is_active()) { |
|
87 |
// Create log file |
|
88 |
_log_fp = fopen(log_name , "w+"); |
|
89 |
if (_log_fp == NULL) { |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
2105
diff
changeset
|
90 |
fatal(err_msg("MemProfiler: Cannot create log file: %s", log_name)); |
1 | 91 |
} |
92 |
fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n"); |
|
93 |
fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n"); |
|
94 |
fprintf(_log_fp, " used, total, used, total, total, total, total, total\n"); |
|
95 |
fprintf(_log_fp, "--------------------------------------------------------------------------\n"); |
|
96 |
||
97 |
_task = new MemProfilerTask(MemProfilingInterval); |
|
98 |
_task->enroll(); |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
||
103 |
void MemProfiler::disengage() { |
|
104 |
if (!is_active()) return; |
|
105 |
// Do one last trace at disengage time |
|
106 |
do_trace(); |
|
107 |
||
108 |
// Close logfile |
|
109 |
fprintf(_log_fp, "MemProfiler detached\n"); |
|
110 |
fclose(_log_fp); |
|
111 |
||
112 |
// remove MemProfilerTask |
|
113 |
assert(_task != NULL, "sanity check"); |
|
114 |
_task->disenroll(); |
|
115 |
delete _task; |
|
116 |
_task = NULL; |
|
117 |
} |
|
118 |
||
119 |
||
120 |
void MemProfiler::do_trace() { |
|
121 |
// Calculate thread local sizes |
|
122 |
size_t handles_memory_usage = VMThread::vm_thread()->handle_area()->size_in_bytes(); |
|
123 |
size_t resource_memory_usage = VMThread::vm_thread()->resource_area()->size_in_bytes(); |
|
124 |
JavaThread *cur = Threads::first(); |
|
125 |
while (cur != NULL) { |
|
126 |
handles_memory_usage += cur->handle_area()->size_in_bytes(); |
|
127 |
resource_memory_usage += cur->resource_area()->size_in_bytes(); |
|
128 |
cur = cur->next(); |
|
129 |
} |
|
130 |
||
131 |
// Print trace line in log |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
132 |
fprintf(_log_fp, "%6.1f,%5d,%5d," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) "," |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
133 |
UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",", |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
134 |
os::elapsedTime(), |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
135 |
Threads::number_of_threads(), |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
136 |
SystemDictionary::number_of_classes(), |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
137 |
Universe::heap()->used() / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
138 |
Universe::heap()->capacity() / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
139 |
Universe::heap()->permanent_used() / HWperKB, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
140 |
Universe::heap()->permanent_capacity() / HWperKB); |
1 | 141 |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
142 |
fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K); |
1 | 143 |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
144 |
fprintf(_log_fp, UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",%6ld\n", |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
145 |
handles_memory_usage / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
146 |
resource_memory_usage / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
147 |
OopMapCache::memory_usage() / K); |
1 | 148 |
fflush(_log_fp); |
149 |
} |
|
150 |
||
151 |
#endif |