Mercurial > hg > graal-jvmci-8
annotate src/share/vm/services/classLoadingService.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 | 436b4a3231bf |
children | fb19af007ffc |
rev | line source |
---|---|
0 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
2 * Copyright (c) 2003, 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:
1147
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1147
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:
1147
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "memory/allocation.hpp" | |
28 #include "memory/universe.hpp" | |
29 #include "oops/oop.inline.hpp" | |
30 #include "runtime/mutexLocker.hpp" | |
31 #include "services/classLoadingService.hpp" | |
32 #include "services/memoryService.hpp" | |
33 #include "utilities/dtrace.hpp" | |
0 | 34 |
35 #ifdef DTRACE_ENABLED | |
36 | |
37 // Only bother with this argument setup if dtrace is available | |
38 | |
4006 | 39 #ifndef USDT2 |
40 | |
0 | 41 HS_DTRACE_PROBE_DECL4(hotspot, class__loaded, char*, int, oop, bool); |
42 HS_DTRACE_PROBE_DECL4(hotspot, class__unloaded, char*, int, oop, bool); | |
43 | |
44 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \ | |
45 { \ | |
46 char* data = NULL; \ | |
47 int len = 0; \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
48 Symbol* name = (clss)->name(); \ |
0 | 49 if (name != NULL) { \ |
50 data = (char*)name->bytes(); \ | |
51 len = name->utf8_length(); \ | |
52 } \ | |
53 HS_DTRACE_PROBE4(hotspot, class__##type, \ | |
54 data, len, (clss)->class_loader(), (shared)); \ | |
55 } | |
56 | |
4006 | 57 #else /* USDT2 */ |
58 | |
59 #define HOTSPOT_CLASS_unloaded HOTSPOT_CLASS_UNLOADED | |
60 #define HOTSPOT_CLASS_loaded HOTSPOT_CLASS_LOADED | |
61 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared) \ | |
62 { \ | |
63 char* data = NULL; \ | |
64 int len = 0; \ | |
65 Symbol* name = (clss)->name(); \ | |
66 if (name != NULL) { \ | |
67 data = (char*)name->bytes(); \ | |
68 len = name->utf8_length(); \ | |
69 } \ | |
70 HOTSPOT_CLASS_##type( /* type = unloaded, loaded */ \ | |
71 data, len, (clss)->class_loader(), (shared)); \ | |
72 } | |
73 | |
74 #endif /* USDT2 */ | |
0 | 75 #else // ndef DTRACE_ENABLED |
76 | |
77 #define DTRACE_CLASSLOAD_PROBE(type, clss, shared) | |
78 | |
79 #endif | |
80 | |
81 // counters for classes loaded from class files | |
82 PerfCounter* ClassLoadingService::_classes_loaded_count = NULL; | |
83 PerfCounter* ClassLoadingService::_classes_unloaded_count = NULL; | |
84 PerfCounter* ClassLoadingService::_classbytes_loaded = NULL; | |
85 PerfCounter* ClassLoadingService::_classbytes_unloaded = NULL; | |
86 | |
87 // counters for classes loaded from shared archive | |
88 PerfCounter* ClassLoadingService::_shared_classes_loaded_count = NULL; | |
89 PerfCounter* ClassLoadingService::_shared_classes_unloaded_count = NULL; | |
90 PerfCounter* ClassLoadingService::_shared_classbytes_loaded = NULL; | |
91 PerfCounter* ClassLoadingService::_shared_classbytes_unloaded = NULL; | |
92 PerfVariable* ClassLoadingService::_class_methods_size = NULL; | |
93 | |
94 void ClassLoadingService::init() { | |
95 EXCEPTION_MARK; | |
96 | |
97 // These counters are for java.lang.management API support. | |
98 // They are created even if -XX:-UsePerfData is set and in | |
99 // that case, they will be allocated on C heap. | |
100 _classes_loaded_count = | |
101 PerfDataManager::create_counter(JAVA_CLS, "loadedClasses", | |
102 PerfData::U_Events, CHECK); | |
103 | |
104 _classes_unloaded_count = | |
105 PerfDataManager::create_counter(JAVA_CLS, "unloadedClasses", | |
106 PerfData::U_Events, CHECK); | |
107 | |
108 _shared_classes_loaded_count = | |
109 PerfDataManager::create_counter(JAVA_CLS, "sharedLoadedClasses", | |
110 PerfData::U_Events, CHECK); | |
111 | |
112 _shared_classes_unloaded_count = | |
113 PerfDataManager::create_counter(JAVA_CLS, "sharedUnloadedClasses", | |
114 PerfData::U_Events, CHECK); | |
115 | |
116 if (UsePerfData) { | |
117 _classbytes_loaded = | |
118 PerfDataManager::create_counter(SUN_CLS, "loadedBytes", | |
119 PerfData::U_Bytes, CHECK); | |
120 | |
121 _classbytes_unloaded = | |
122 PerfDataManager::create_counter(SUN_CLS, "unloadedBytes", | |
123 PerfData::U_Bytes, CHECK); | |
124 _shared_classbytes_loaded = | |
125 PerfDataManager::create_counter(SUN_CLS, "sharedLoadedBytes", | |
126 PerfData::U_Bytes, CHECK); | |
127 | |
128 _shared_classbytes_unloaded = | |
129 PerfDataManager::create_counter(SUN_CLS, "sharedUnloadedBytes", | |
130 PerfData::U_Bytes, CHECK); | |
131 _class_methods_size = | |
132 PerfDataManager::create_variable(SUN_CLS, "methodBytes", | |
133 PerfData::U_Bytes, CHECK); | |
134 } | |
135 } | |
136 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
137 void ClassLoadingService::notify_class_unloaded(InstanceKlass* k) { |
0 | 138 DTRACE_CLASSLOAD_PROBE(unloaded, k, false); |
139 // Classes that can be unloaded must be non-shared | |
140 _classes_unloaded_count->inc(); | |
141 | |
142 if (UsePerfData) { | |
143 // add the class size | |
144 size_t size = compute_class_size(k); | |
145 _classbytes_unloaded->inc(size); | |
146 | |
147 // Compute method size & subtract from running total. | |
148 // We are called during phase 1 of mark sweep, so it's | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
149 // still ok to iterate through Method*s here. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
150 Array<Method*>* methods = k->methods(); |
0 | 151 for (int i = 0; i < methods->length(); i++) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
152 _class_methods_size->inc(-methods->at(i)->size()); |
0 | 153 } |
154 } | |
155 | |
156 if (TraceClassUnloading) { | |
157 ResourceMark rm; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
158 tty->print_cr("[Unloading class %s " INTPTR_FORMAT "]", k->external_name(), k); |
0 | 159 } |
160 } | |
161 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
162 void ClassLoadingService::notify_class_loaded(InstanceKlass* k, bool shared_class) { |
0 | 163 DTRACE_CLASSLOAD_PROBE(loaded, k, shared_class); |
164 PerfCounter* classes_counter = (shared_class ? _shared_classes_loaded_count | |
165 : _classes_loaded_count); | |
166 // increment the count | |
167 classes_counter->inc(); | |
168 | |
169 if (UsePerfData) { | |
170 PerfCounter* classbytes_counter = (shared_class ? _shared_classbytes_loaded | |
171 : _classbytes_loaded); | |
172 // add the class size | |
173 size_t size = compute_class_size(k); | |
174 classbytes_counter->inc(size); | |
175 } | |
176 } | |
177 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
178 size_t ClassLoadingService::compute_class_size(InstanceKlass* k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
179 // lifted from ClassStatistics.do_class(Klass* k) |
0 | 180 |
181 size_t class_size = 0; | |
182 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
183 class_size += k->size(); |
0 | 184 |
185 if (k->oop_is_instance()) { | |
186 class_size += k->methods()->size(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
187 // FIXME: Need to count the contents of methods |
0 | 188 class_size += k->constants()->size(); |
189 class_size += k->local_interfaces()->size(); | |
190 class_size += k->transitive_interfaces()->size(); | |
191 // We do not have to count implementors, since we only store one! | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
192 // FIXME: How should these be accounted for, now when they have moved. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4006
diff
changeset
|
193 //class_size += k->fields()->size(); |
0 | 194 } |
195 return class_size * oopSize; | |
196 } | |
197 | |
198 | |
199 bool ClassLoadingService::set_verbose(bool verbose) { | |
200 MutexLocker m(Management_lock); | |
201 | |
202 // verbose will be set to the previous value | |
203 bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassLoading", &verbose, MANAGEMENT); | |
204 assert(succeed, "Setting TraceClassLoading flag fails"); | |
205 reset_trace_class_unloading(); | |
206 | |
207 return verbose; | |
208 } | |
209 | |
210 // Caller to this function must own Management_lock | |
211 void ClassLoadingService::reset_trace_class_unloading() { | |
212 assert(Management_lock->owned_by_self(), "Must own the Management_lock"); | |
213 bool value = MemoryService::get_verbose() || ClassLoadingService::get_verbose(); | |
214 bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassUnloading", &value, MANAGEMENT); | |
215 assert(succeed, "Setting TraceClassUnLoading flag fails"); | |
216 } | |
217 | |
218 GrowableArray<KlassHandle>* LoadedClassesEnumerator::_loaded_classes = NULL; | |
219 Thread* LoadedClassesEnumerator::_current_thread = NULL; | |
220 | |
221 LoadedClassesEnumerator::LoadedClassesEnumerator(Thread* cur_thread) { | |
222 assert(cur_thread == Thread::current(), "Check current thread"); | |
223 | |
224 int init_size = ClassLoadingService::loaded_class_count(); | |
225 _klass_handle_array = new GrowableArray<KlassHandle>(init_size); | |
226 | |
227 // For consistency of the loaded classes, grab the SystemDictionary lock | |
228 MutexLocker sd_mutex(SystemDictionary_lock); | |
229 | |
230 // Set _loaded_classes and _current_thread and begin enumerating all classes. | |
231 // Only one thread will do the enumeration at a time. | |
232 // These static variables are needed and they are used by the static method | |
233 // add_loaded_class called from classes_do(). | |
234 _loaded_classes = _klass_handle_array; | |
235 _current_thread = cur_thread; | |
236 | |
237 SystemDictionary::classes_do(&add_loaded_class); | |
238 | |
239 // FIXME: Exclude array klasses for now | |
240 // Universe::basic_type_classes_do(&add_loaded_class); | |
241 } |