annotate src/share/vm/runtime/memprofiler.cpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents f08d439fab8c
children f34d701e952e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "code/codeCache.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "gc_interface/collectedHeap.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "interpreter/oopMapCache.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "memory/generation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/handles.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "runtime/jniHandles.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "runtime/memprofiler.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #include "runtime/mutexLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 #include "runtime/task.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 #include "runtime/vmThread.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
39 #ifdef TARGET_OS_FAMILY_linux
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
40 # include "thread_linux.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
41 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
42 #ifdef TARGET_OS_FAMILY_solaris
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
43 # include "thread_solaris.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
44 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
45 #ifdef TARGET_OS_FAMILY_windows
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
46 # include "thread_windows.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
47 #endif
3960
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
48 #ifdef TARGET_OS_FAMILY_bsd
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
49 # include "thread_bsd.inline.hpp"
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 1972
diff changeset
50 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // --------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // MemProfilerTask
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 class MemProfilerTask : public PeriodicTask {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
59 MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
60 void task();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 };
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 void MemProfilerTask::task() {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Get thread lock to provide mutual exclusion, and so we can iterate safely over the thread list.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 MutexLocker mu(Threads_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 MemProfiler::do_trace();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 //----------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Implementation of MemProfiler
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 MemProfilerTask* MemProfiler::_task = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 FILE* MemProfiler::_log_fp = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 bool MemProfiler::is_active() {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 return _task != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void MemProfiler::engage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 const char *log_name = "mprofile.log";
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (!is_active()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Create log file
a61af66fc99e Initial load
duke
parents:
diff changeset
87 _log_fp = fopen(log_name , "w+");
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 fprintf(_log_fp, " used, total, used, total, total, total, total, total\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 fprintf(_log_fp, "--------------------------------------------------------------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _task = new MemProfilerTask(MemProfilingInterval);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _task->enroll();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 void MemProfiler::disengage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (!is_active()) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Do one last trace at disengage time
a61af66fc99e Initial load
duke
parents:
diff changeset
105 do_trace();
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Close logfile
a61af66fc99e Initial load
duke
parents:
diff changeset
108 fprintf(_log_fp, "MemProfiler detached\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 fclose(_log_fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // remove MemProfilerTask
a61af66fc99e Initial load
duke
parents:
diff changeset
112 assert(_task != NULL, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
113 _task->disenroll();
a61af66fc99e Initial load
duke
parents:
diff changeset
114 delete _task;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 _task = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 void MemProfiler::do_trace() {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Calculate thread local sizes
a61af66fc99e Initial load
duke
parents:
diff changeset
121 size_t handles_memory_usage = VMThread::vm_thread()->handle_area()->size_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 size_t resource_memory_usage = VMThread::vm_thread()->resource_area()->size_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 JavaThread *cur = Threads::first();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 while (cur != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 handles_memory_usage += cur->handle_area()->size_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
126 resource_memory_usage += cur->resource_area()->size_in_bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 cur = cur->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
144 fflush(_log_fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 #endif