Mercurial > hg > truffle
annotate src/share/vm/runtime/memprofiler.cpp @ 7090:05ce1defa4f9
Common out some parts of UnsafeLoad/Store in UnsafeAccess
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 29 Nov 2012 13:24:08 +0100 |
parents | da91efe96a93 |
children | f34d701e952e |
rev | line source |
---|---|
0 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3960
diff
changeset
|
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 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/resourceArea.hpp" | |
32 #include "runtime/handles.inline.hpp" | |
33 #include "runtime/jniHandles.hpp" | |
34 #include "runtime/memprofiler.hpp" | |
35 #include "runtime/mutexLocker.hpp" | |
36 #include "runtime/os.hpp" | |
37 #include "runtime/task.hpp" | |
38 #include "runtime/vmThread.hpp" | |
39 #ifdef TARGET_OS_FAMILY_linux | |
40 # include "thread_linux.inline.hpp" | |
41 #endif | |
42 #ifdef TARGET_OS_FAMILY_solaris | |
43 # include "thread_solaris.inline.hpp" | |
44 #endif | |
45 #ifdef TARGET_OS_FAMILY_windows | |
46 # include "thread_windows.inline.hpp" | |
47 #endif | |
3960 | 48 #ifdef TARGET_OS_FAMILY_bsd |
49 # include "thread_bsd.inline.hpp" | |
50 #endif | |
0 | 51 |
52 #ifndef PRODUCT | |
53 | |
54 // -------------------------------------------------------- | |
55 // MemProfilerTask | |
56 | |
57 class MemProfilerTask : public PeriodicTask { | |
58 public: | |
59 MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {} | |
60 void task(); | |
61 }; | |
62 | |
63 | |
64 void MemProfilerTask::task() { | |
65 // Get thread lock to provide mutual exclusion, and so we can iterate safely over the thread list. | |
66 MutexLocker mu(Threads_lock); | |
67 MemProfiler::do_trace(); | |
68 } | |
69 | |
70 | |
71 //---------------------------------------------------------- | |
72 // Implementation of MemProfiler | |
73 | |
74 MemProfilerTask* MemProfiler::_task = NULL; | |
75 FILE* MemProfiler::_log_fp = NULL; | |
76 | |
77 | |
78 bool MemProfiler::is_active() { | |
79 return _task != NULL; | |
80 } | |
81 | |
82 | |
83 void MemProfiler::engage() { | |
84 const char *log_name = "mprofile.log"; | |
85 if (!is_active()) { | |
86 // Create log file | |
87 _log_fp = fopen(log_name , "w+"); | |
88 if (_log_fp == NULL) { | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
579
diff
changeset
|
89 fatal(err_msg("MemProfiler: Cannot create log file: %s", log_name)); |
0 | 90 } |
91 fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n"); | |
92 fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n"); | |
93 fprintf(_log_fp, " used, total, used, total, total, total, total, total\n"); | |
94 fprintf(_log_fp, "--------------------------------------------------------------------------\n"); | |
95 | |
96 _task = new MemProfilerTask(MemProfilingInterval); | |
97 _task->enroll(); | |
98 } | |
99 } | |
100 | |
101 | |
102 void MemProfiler::disengage() { | |
103 if (!is_active()) return; | |
104 // Do one last trace at disengage time | |
105 do_trace(); | |
106 | |
107 // Close logfile | |
108 fprintf(_log_fp, "MemProfiler detached\n"); | |
109 fclose(_log_fp); | |
110 | |
111 // remove MemProfilerTask | |
112 assert(_task != NULL, "sanity check"); | |
113 _task->disenroll(); | |
114 delete _task; | |
115 _task = NULL; | |
116 } | |
117 | |
118 | |
119 void MemProfiler::do_trace() { | |
120 // Calculate thread local sizes | |
121 size_t handles_memory_usage = VMThread::vm_thread()->handle_area()->size_in_bytes(); | |
122 size_t resource_memory_usage = VMThread::vm_thread()->resource_area()->size_in_bytes(); | |
123 JavaThread *cur = Threads::first(); | |
124 while (cur != NULL) { | |
125 handles_memory_usage += cur->handle_area()->size_in_bytes(); | |
126 resource_memory_usage += cur->resource_area()->size_in_bytes(); | |
127 cur = cur->next(); | |
128 } | |
129 | |
130 // Print trace line in log | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3960
diff
changeset
|
131 fprintf(_log_fp, "%6.1f,%5d,%5d," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",", |
513
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
132 os::elapsedTime(), |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
133 Threads::number_of_threads(), |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
134 SystemDictionary::number_of_classes(), |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
135 Universe::heap()->used() / K, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3960
diff
changeset
|
136 Universe::heap()->capacity() / K); |
0 | 137 |
513
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
138 fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K); |
0 | 139 |
513
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
140 fprintf(_log_fp, UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",%6ld\n", |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
141 handles_memory_usage / K, |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
142 resource_memory_usage / K, |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
0
diff
changeset
|
143 OopMapCache::memory_usage() / K); |
0 | 144 fflush(_log_fp); |
145 } | |
146 | |
147 #endif |