author | trims |
Thu, 27 May 2010 19:08:38 -0700 | |
changeset 5547 | f4b087cbb361 |
parent 5403 | 6b0dd9c75dde |
child 7397 | 5b173b4ca846 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
2 |
* Copyright (c) 1998, 2009, 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 |
||
25 |
# include "incls/_precompiled.incl" |
|
26 |
# include "incls/_memprofiler.cpp.incl" |
|
27 |
||
28 |
#ifndef PRODUCT |
|
29 |
||
30 |
// -------------------------------------------------------- |
|
31 |
// MemProfilerTask |
|
32 |
||
33 |
class MemProfilerTask : public PeriodicTask { |
|
34 |
public: |
|
35 |
MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {} |
|
36 |
void task(); |
|
37 |
}; |
|
38 |
||
39 |
||
40 |
void MemProfilerTask::task() { |
|
41 |
// Get thread lock to provide mutual exclusion, and so we can iterate safely over the thread list. |
|
42 |
MutexLocker mu(Threads_lock); |
|
43 |
MemProfiler::do_trace(); |
|
44 |
} |
|
45 |
||
46 |
||
47 |
//---------------------------------------------------------- |
|
48 |
// Implementation of MemProfiler |
|
49 |
||
50 |
MemProfilerTask* MemProfiler::_task = NULL; |
|
51 |
FILE* MemProfiler::_log_fp = NULL; |
|
52 |
||
53 |
||
54 |
bool MemProfiler::is_active() { |
|
55 |
return _task != NULL; |
|
56 |
} |
|
57 |
||
58 |
||
59 |
void MemProfiler::engage() { |
|
60 |
const char *log_name = "mprofile.log"; |
|
61 |
if (!is_active()) { |
|
62 |
// Create log file |
|
63 |
_log_fp = fopen(log_name , "w+"); |
|
64 |
if (_log_fp == NULL) { |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
2105
diff
changeset
|
65 |
fatal(err_msg("MemProfiler: Cannot create log file: %s", log_name)); |
1 | 66 |
} |
67 |
fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n"); |
|
68 |
fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n"); |
|
69 |
fprintf(_log_fp, " used, total, used, total, total, total, total, total\n"); |
|
70 |
fprintf(_log_fp, "--------------------------------------------------------------------------\n"); |
|
71 |
||
72 |
_task = new MemProfilerTask(MemProfilingInterval); |
|
73 |
_task->enroll(); |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
||
78 |
void MemProfiler::disengage() { |
|
79 |
if (!is_active()) return; |
|
80 |
// Do one last trace at disengage time |
|
81 |
do_trace(); |
|
82 |
||
83 |
// Close logfile |
|
84 |
fprintf(_log_fp, "MemProfiler detached\n"); |
|
85 |
fclose(_log_fp); |
|
86 |
||
87 |
// remove MemProfilerTask |
|
88 |
assert(_task != NULL, "sanity check"); |
|
89 |
_task->disenroll(); |
|
90 |
delete _task; |
|
91 |
_task = NULL; |
|
92 |
} |
|
93 |
||
94 |
||
95 |
void MemProfiler::do_trace() { |
|
96 |
// Calculate thread local sizes |
|
97 |
size_t handles_memory_usage = VMThread::vm_thread()->handle_area()->size_in_bytes(); |
|
98 |
size_t resource_memory_usage = VMThread::vm_thread()->resource_area()->size_in_bytes(); |
|
99 |
JavaThread *cur = Threads::first(); |
|
100 |
while (cur != NULL) { |
|
101 |
handles_memory_usage += cur->handle_area()->size_in_bytes(); |
|
102 |
resource_memory_usage += cur->resource_area()->size_in_bytes(); |
|
103 |
cur = cur->next(); |
|
104 |
} |
|
105 |
||
106 |
// 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
|
107 |
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
|
108 |
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
|
109 |
os::elapsedTime(), |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
110 |
Threads::number_of_threads(), |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
111 |
SystemDictionary::number_of_classes(), |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
112 |
Universe::heap()->used() / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
113 |
Universe::heap()->capacity() / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
114 |
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
|
115 |
Universe::heap()->permanent_capacity() / HWperKB); |
1 | 116 |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
117 |
fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K); |
1 | 118 |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
119 |
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
|
120 |
handles_memory_usage / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
121 |
resource_memory_usage / K, |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1
diff
changeset
|
122 |
OopMapCache::memory_usage() / K); |
1 | 123 |
fflush(_log_fp); |
124 |
} |
|
125 |
||
126 |
#endif |