Mercurial > hg > truffle
annotate src/share/vm/classfile/systemDictionary.cpp @ 710:e5b0439ef4ae
6655638: dynamic languages need method handles
Summary: initial implementation, with known omissions (x86/64, sparc, compiler optim., c-oops, C++ interp.)
Reviewed-by: kvn, twisti, never
author | jrose |
---|---|
date | Wed, 08 Apr 2009 10:56:49 -0700 |
parents | c89f86385056 |
children | be93aad57795 |
rev | line source |
---|---|
0 | 1 /* |
579 | 2 * Copyright 1997-2009 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_systemDictionary.cpp.incl" | |
27 | |
28 | |
29 Dictionary* SystemDictionary::_dictionary = NULL; | |
30 PlaceholderTable* SystemDictionary::_placeholders = NULL; | |
31 Dictionary* SystemDictionary::_shared_dictionary = NULL; | |
32 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL; | |
33 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL; | |
710 | 34 SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL; |
0 | 35 |
36 | |
37 int SystemDictionary::_number_of_modifications = 0; | |
38 | |
39 oop SystemDictionary::_system_loader_lock_obj = NULL; | |
40 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
41 klassOop SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT] |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
42 = { NULL /*, NULL...*/ }; |
0 | 43 |
44 klassOop SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ }; | |
45 | |
46 oop SystemDictionary::_java_system_loader = NULL; | |
47 | |
48 bool SystemDictionary::_has_loadClassInternal = false; | |
49 bool SystemDictionary::_has_checkPackageAccess = false; | |
50 | |
51 // lazily initialized klass variables | |
52 volatile klassOop SystemDictionary::_abstract_ownable_synchronizer_klass = NULL; | |
53 | |
54 | |
55 // ---------------------------------------------------------------------------- | |
56 // Java-level SystemLoader | |
57 | |
58 oop SystemDictionary::java_system_loader() { | |
59 return _java_system_loader; | |
60 } | |
61 | |
62 void SystemDictionary::compute_java_system_loader(TRAPS) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
63 KlassHandle system_klass(THREAD, WK_KLASS(classloader_klass)); |
0 | 64 JavaValue result(T_OBJECT); |
65 JavaCalls::call_static(&result, | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
66 KlassHandle(THREAD, WK_KLASS(classloader_klass)), |
0 | 67 vmSymbolHandles::getSystemClassLoader_name(), |
68 vmSymbolHandles::void_classloader_signature(), | |
69 CHECK); | |
70 | |
71 _java_system_loader = (oop)result.get_jobject(); | |
72 } | |
73 | |
74 | |
75 // ---------------------------------------------------------------------------- | |
76 // debugging | |
77 | |
78 #ifdef ASSERT | |
79 | |
80 // return true if class_name contains no '.' (internal format is '/') | |
81 bool SystemDictionary::is_internal_format(symbolHandle class_name) { | |
82 if (class_name.not_null()) { | |
83 ResourceMark rm; | |
84 char* name = class_name->as_C_string(); | |
85 return strchr(name, '.') == NULL; | |
86 } else { | |
87 return true; | |
88 } | |
89 } | |
90 | |
91 #endif | |
92 | |
93 // ---------------------------------------------------------------------------- | |
514 | 94 // Parallel class loading check |
95 | |
96 bool SystemDictionary::is_parallelCapable(Handle class_loader) { | |
97 if (UnsyncloadClass || class_loader.is_null()) return true; | |
98 if (AlwaysLockClassLoader) return false; | |
99 return java_lang_Class::parallelCapable(class_loader()); | |
100 } | |
101 // ---------------------------------------------------------------------------- | |
0 | 102 // Resolving of classes |
103 | |
104 // Forwards to resolve_or_null | |
105 | |
106 klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { | |
107 klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); | |
108 if (HAS_PENDING_EXCEPTION || klass == NULL) { | |
109 KlassHandle k_h(THREAD, klass); | |
110 // can return a null klass | |
111 klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD); | |
112 } | |
113 return klass; | |
114 } | |
115 | |
116 klassOop SystemDictionary::handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) { | |
117 if (HAS_PENDING_EXCEPTION) { | |
118 // If we have a pending exception we forward it to the caller, unless throw_error is true, | |
119 // in which case we have to check whether the pending exception is a ClassNotFoundException, | |
120 // and if so convert it to a NoClassDefFoundError | |
121 // And chain the original ClassNotFoundException | |
122 if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::classNotFoundException_klass())) { | |
123 ResourceMark rm(THREAD); | |
124 assert(klass_h() == NULL, "Should not have result with exception pending"); | |
125 Handle e(THREAD, PENDING_EXCEPTION); | |
126 CLEAR_PENDING_EXCEPTION; | |
127 THROW_MSG_CAUSE_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e); | |
128 } else { | |
129 return NULL; | |
130 } | |
131 } | |
132 // Class not found, throw appropriate error or exception depending on value of throw_error | |
133 if (klass_h() == NULL) { | |
134 ResourceMark rm(THREAD); | |
135 if (throw_error) { | |
136 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); | |
137 } else { | |
138 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); | |
139 } | |
140 } | |
141 return (klassOop)klass_h(); | |
142 } | |
143 | |
144 | |
145 klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, | |
146 bool throw_error, TRAPS) | |
147 { | |
148 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD); | |
149 } | |
150 | |
151 | |
152 // Forwards to resolve_instance_class_or_null | |
153 | |
154 klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) { | |
155 assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread"); | |
156 if (FieldType::is_array(class_name())) { | |
157 return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); | |
158 } else { | |
159 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); | |
160 } | |
161 } | |
162 | |
163 klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, TRAPS) { | |
164 return resolve_or_null(class_name, Handle(), Handle(), THREAD); | |
165 } | |
166 | |
167 // Forwards to resolve_instance_class_or_null | |
168 | |
169 klassOop SystemDictionary::resolve_array_class_or_null(symbolHandle class_name, | |
170 Handle class_loader, | |
171 Handle protection_domain, | |
172 TRAPS) { | |
173 assert(FieldType::is_array(class_name()), "must be array"); | |
174 jint dimension; | |
175 symbolOop object_key; | |
176 klassOop k = NULL; | |
177 // dimension and object_key are assigned as a side-effect of this call | |
178 BasicType t = FieldType::get_array_info(class_name(), | |
179 &dimension, | |
180 &object_key, | |
181 CHECK_NULL); | |
182 | |
183 if (t == T_OBJECT) { | |
184 symbolHandle h_key(THREAD, object_key); | |
185 // naked oop "k" is OK here -- we assign back into it | |
186 k = SystemDictionary::resolve_instance_class_or_null(h_key, | |
187 class_loader, | |
188 protection_domain, | |
189 CHECK_NULL); | |
190 if (k != NULL) { | |
191 k = Klass::cast(k)->array_klass(dimension, CHECK_NULL); | |
192 } | |
193 } else { | |
194 k = Universe::typeArrayKlassObj(t); | |
195 k = typeArrayKlass::cast(k)->array_klass(dimension, CHECK_NULL); | |
196 } | |
197 return k; | |
198 } | |
199 | |
200 | |
201 // Must be called for any super-class or super-interface resolution | |
202 // during class definition to allow class circularity checking | |
203 // super-interface callers: | |
204 // parse_interfaces - for defineClass & jvmtiRedefineClasses | |
205 // super-class callers: | |
206 // ClassFileParser - for defineClass & jvmtiRedefineClasses | |
207 // load_shared_class - while loading a class from shared archive | |
514 | 208 // resolve_instance_class_or_null: |
209 // via: handle_parallel_super_load | |
0 | 210 // when resolving a class that has an existing placeholder with |
211 // a saved superclass [i.e. a defineClass is currently in progress] | |
212 // if another thread is trying to resolve the class, it must do | |
213 // super-class checks on its own thread to catch class circularity | |
214 // This last call is critical in class circularity checking for cases | |
215 // where classloading is delegated to different threads and the | |
216 // classloader lock is released. | |
217 // Take the case: Base->Super->Base | |
218 // 1. If thread T1 tries to do a defineClass of class Base | |
219 // resolve_super_or_fail creates placeholder: T1, Base (super Super) | |
220 // 2. resolve_instance_class_or_null does not find SD or placeholder for Super | |
221 // so it tries to load Super | |
222 // 3. If we load the class internally, or user classloader uses same thread | |
223 // loadClassFromxxx or defineClass via parseClassFile Super ... | |
224 // 3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base) | |
225 // 3.3 resolve_instance_class_or_null Base, finds placeholder for Base | |
226 // 3.4 calls resolve_super_or_fail Base | |
227 // 3.5 finds T1,Base -> throws class circularity | |
228 //OR 4. If T2 tries to resolve Super via defineClass Super ... | |
229 // 4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base) | |
230 // 4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super) | |
231 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2 | |
232 // 4.4 finds T2, Super -> throws class circularity | |
233 // Must be called, even if superclass is null, since this is | |
234 // where the placeholder entry is created which claims this | |
235 // thread is loading this class/classloader. | |
236 klassOop SystemDictionary::resolve_super_or_fail(symbolHandle child_name, | |
237 symbolHandle class_name, | |
238 Handle class_loader, | |
239 Handle protection_domain, | |
240 bool is_superclass, | |
241 TRAPS) { | |
242 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
243 // Try to get one of the well-known klasses. |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
244 // They are trusted, and do not participate in circularities. |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
245 if (LinkWellKnownClasses) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
246 klassOop k = find_well_known_klass(class_name()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
247 if (k != NULL) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
248 return k; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
249 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
250 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
251 |
0 | 252 // Double-check, if child class is already loaded, just return super-class,interface |
253 // Don't add a placedholder if already loaded, i.e. already in system dictionary | |
254 // Make sure there's a placeholder for the *child* before resolving. | |
255 // Used as a claim that this thread is currently loading superclass/classloader | |
256 // Used here for ClassCircularity checks and also for heap verification | |
257 // (every instanceKlass in the heap needs to be in the system dictionary | |
258 // or have a placeholder). | |
259 // Must check ClassCircularity before checking if super class is already loaded | |
260 // | |
261 // We might not already have a placeholder if this child_name was | |
262 // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass); | |
263 // the name of the class might not be known until the stream is actually | |
264 // parsed. | |
265 // Bugs 4643874, 4715493 | |
266 // compute_hash can have a safepoint | |
267 | |
268 unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader); | |
269 int d_index = dictionary()->hash_to_index(d_hash); | |
270 unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader); | |
271 int p_index = placeholders()->hash_to_index(p_hash); | |
272 // can't throw error holding a lock | |
273 bool child_already_loaded = false; | |
274 bool throw_circularity_error = false; | |
275 { | |
276 MutexLocker mu(SystemDictionary_lock, THREAD); | |
277 klassOop childk = find_class(d_index, d_hash, child_name, class_loader); | |
278 klassOop quicksuperk; | |
279 // to support // loading: if child done loading, just return superclass | |
280 // if class_name, & class_loader don't match: | |
281 // if initial define, SD update will give LinkageError | |
282 // if redefine: compare_class_versions will give HIERARCHY_CHANGED | |
283 // so we don't throw an exception here. | |
284 // see: nsk redefclass014 & java.lang.instrument Instrument032 | |
285 if ((childk != NULL ) && (is_superclass) && | |
286 ((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) && | |
287 | |
288 ((Klass::cast(quicksuperk)->name() == class_name()) && | |
289 (Klass::cast(quicksuperk)->class_loader() == class_loader()))) { | |
290 return quicksuperk; | |
291 } else { | |
292 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); | |
293 if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) { | |
294 throw_circularity_error = true; | |
295 } | |
514 | 296 } |
297 if (!throw_circularity_error) { | |
0 | 298 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, class_loader, PlaceholderTable::LOAD_SUPER, class_name, THREAD); |
299 } | |
300 } | |
301 if (throw_circularity_error) { | |
302 ResourceMark rm(THREAD); | |
303 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); | |
304 } | |
305 | |
306 // java.lang.Object should have been found above | |
307 assert(class_name() != NULL, "null super class for resolving"); | |
308 // Resolve the super class or interface, check results on return | |
309 klassOop superk = NULL; | |
310 superk = SystemDictionary::resolve_or_null(class_name, | |
311 class_loader, | |
312 protection_domain, | |
313 THREAD); | |
314 | |
315 KlassHandle superk_h(THREAD, superk); | |
316 | |
317 // Note: clean up of placeholders currently in callers of | |
318 // resolve_super_or_fail - either at update_dictionary time | |
319 // or on error | |
320 { | |
321 MutexLocker mu(SystemDictionary_lock, THREAD); | |
322 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); | |
323 if (probe != NULL) { | |
324 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER); | |
325 } | |
326 } | |
327 if (HAS_PENDING_EXCEPTION || superk_h() == NULL) { | |
328 // can null superk | |
329 superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD)); | |
330 } | |
331 | |
332 return superk_h(); | |
333 } | |
334 | |
335 void SystemDictionary::validate_protection_domain(instanceKlassHandle klass, | |
336 Handle class_loader, | |
337 Handle protection_domain, | |
338 TRAPS) { | |
339 if(!has_checkPackageAccess()) return; | |
340 | |
341 // Now we have to call back to java to check if the initating class has access | |
342 JavaValue result(T_VOID); | |
343 if (TraceProtectionDomainVerification) { | |
344 // Print out trace information | |
345 tty->print_cr("Checking package access"); | |
346 tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr(); | |
347 tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr(); | |
348 tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr(); | |
349 } | |
350 | |
351 assert(class_loader() != NULL, "should not have non-null protection domain for null classloader"); | |
352 | |
353 KlassHandle system_loader(THREAD, SystemDictionary::classloader_klass()); | |
354 JavaCalls::call_special(&result, | |
355 class_loader, | |
356 system_loader, | |
357 vmSymbolHandles::checkPackageAccess_name(), | |
358 vmSymbolHandles::class_protectiondomain_signature(), | |
359 Handle(THREAD, klass->java_mirror()), | |
360 protection_domain, | |
361 THREAD); | |
362 | |
363 if (TraceProtectionDomainVerification) { | |
364 if (HAS_PENDING_EXCEPTION) { | |
365 tty->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!"); | |
366 } else { | |
367 tty->print_cr(" -> granted"); | |
368 } | |
369 tty->cr(); | |
370 } | |
371 | |
372 if (HAS_PENDING_EXCEPTION) return; | |
373 | |
374 // If no exception has been thrown, we have validated the protection domain | |
375 // Insert the protection domain of the initiating class into the set. | |
376 { | |
377 // We recalculate the entry here -- we've called out to java since | |
378 // the last time it was calculated. | |
379 symbolHandle kn(THREAD, klass->name()); | |
380 unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); | |
381 int d_index = dictionary()->hash_to_index(d_hash); | |
382 | |
383 MutexLocker mu(SystemDictionary_lock, THREAD); | |
384 { | |
385 // Note that we have an entry, and entries can be deleted only during GC, | |
386 // so we cannot allow GC to occur while we're holding this entry. | |
387 | |
388 // We're using a No_Safepoint_Verifier to catch any place where we | |
389 // might potentially do a GC at all. | |
390 // SystemDictionary::do_unloading() asserts that classes are only | |
391 // unloaded at a safepoint. | |
392 No_Safepoint_Verifier nosafepoint; | |
393 dictionary()->add_protection_domain(d_index, d_hash, klass, class_loader, | |
394 protection_domain, THREAD); | |
395 } | |
396 } | |
397 } | |
398 | |
399 // We only get here if this thread finds that another thread | |
400 // has already claimed the placeholder token for the current operation, | |
401 // but that other thread either never owned or gave up the | |
402 // object lock | |
403 // Waits on SystemDictionary_lock to indicate placeholder table updated | |
404 // On return, caller must recheck placeholder table state | |
405 // | |
406 // We only get here if | |
407 // 1) custom classLoader, i.e. not bootstrap classloader | |
408 // 2) UnsyncloadClass not set | |
409 // 3) custom classLoader has broken the class loader objectLock | |
410 // so another thread got here in parallel | |
411 // | |
412 // lockObject must be held. | |
413 // Complicated dance due to lock ordering: | |
414 // Must first release the classloader object lock to | |
415 // allow initial definer to complete the class definition | |
416 // and to avoid deadlock | |
417 // Reclaim classloader lock object with same original recursion count | |
418 // Must release SystemDictionary_lock after notify, since | |
419 // class loader lock must be claimed before SystemDictionary_lock | |
420 // to prevent deadlocks | |
421 // | |
422 // The notify allows applications that did an untimed wait() on | |
423 // the classloader object lock to not hang. | |
424 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) { | |
425 assert_lock_strong(SystemDictionary_lock); | |
426 | |
427 bool calledholdinglock | |
428 = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject); | |
429 assert(calledholdinglock,"must hold lock for notify"); | |
514 | 430 assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait"); |
0 | 431 ObjectSynchronizer::notifyall(lockObject, THREAD); |
432 intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD); | |
433 SystemDictionary_lock->wait(); | |
434 SystemDictionary_lock->unlock(); | |
435 ObjectSynchronizer::reenter(lockObject, recursions, THREAD); | |
436 SystemDictionary_lock->lock(); | |
437 } | |
438 | |
439 // If the class in is in the placeholder table, class loading is in progress | |
440 // For cases where the application changes threads to load classes, it | |
441 // is critical to ClassCircularity detection that we try loading | |
442 // the superclass on the same thread internally, so we do parallel | |
443 // super class loading here. | |
444 // This also is critical in cases where the original thread gets stalled | |
445 // even in non-circularity situations. | |
446 // Note: only one thread can define the class, but multiple can resolve | |
447 // Note: must call resolve_super_or_fail even if null super - | |
514 | 448 // to force placeholder entry creation for this class for circularity detection |
0 | 449 // Caller must check for pending exception |
450 // Returns non-null klassOop if other thread has completed load | |
451 // and we are done, | |
452 // If return null klassOop and no pending exception, the caller must load the class | |
453 instanceKlassHandle SystemDictionary::handle_parallel_super_load( | |
454 symbolHandle name, symbolHandle superclassname, Handle class_loader, | |
455 Handle protection_domain, Handle lockObject, TRAPS) { | |
456 | |
457 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | |
458 unsigned int d_hash = dictionary()->compute_hash(name, class_loader); | |
459 int d_index = dictionary()->hash_to_index(d_hash); | |
460 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | |
461 int p_index = placeholders()->hash_to_index(p_hash); | |
462 | |
463 // superk is not used, resolve_super called for circularity check only | |
464 // This code is reached in two situations. One if this thread | |
465 // is loading the same class twice (e.g. ClassCircularity, or | |
466 // java.lang.instrument). | |
467 // The second is if another thread started the resolve_super first | |
468 // and has not yet finished. | |
469 // In both cases the original caller will clean up the placeholder | |
470 // entry on error. | |
471 klassOop superk = SystemDictionary::resolve_super_or_fail(name, | |
472 superclassname, | |
473 class_loader, | |
474 protection_domain, | |
475 true, | |
476 CHECK_(nh)); | |
477 // We don't redefine the class, so we just need to clean up if there | |
478 // was not an error (don't want to modify any system dictionary | |
479 // data structures). | |
480 { | |
481 MutexLocker mu(SystemDictionary_lock, THREAD); | |
482 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | |
483 SystemDictionary_lock->notify_all(); | |
484 } | |
485 | |
514 | 486 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete |
487 // Serial class loaders and bootstrap classloader do wait for superclass loads | |
488 if (!class_loader.is_null() && is_parallelCapable(class_loader)) { | |
0 | 489 MutexLocker mu(SystemDictionary_lock, THREAD); |
490 // Check if classloading completed while we were loading superclass or waiting | |
491 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
492 if (check != NULL) { | |
493 // Klass is already loaded, so just return it | |
494 return(instanceKlassHandle(THREAD, check)); | |
495 } else { | |
496 return nh; | |
497 } | |
498 } | |
499 | |
500 // must loop to both handle other placeholder updates | |
501 // and spurious notifications | |
502 bool super_load_in_progress = true; | |
503 PlaceholderEntry* placeholder; | |
504 while (super_load_in_progress) { | |
505 MutexLocker mu(SystemDictionary_lock, THREAD); | |
506 // Check if classloading completed while we were loading superclass or waiting | |
507 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
508 if (check != NULL) { | |
509 // Klass is already loaded, so just return it | |
510 return(instanceKlassHandle(THREAD, check)); | |
511 } else { | |
512 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); | |
513 if (placeholder && placeholder->super_load_in_progress() ){ | |
514 // Before UnsyncloadClass: | |
515 // We only get here if the application has released the | |
516 // classloader lock when another thread was in the middle of loading a | |
517 // superclass/superinterface for this class, and now | |
518 // this thread is also trying to load this class. | |
519 // To minimize surprises, the first thread that started to | |
520 // load a class should be the one to complete the loading | |
521 // with the classfile it initially expected. | |
522 // This logic has the current thread wait once it has done | |
523 // all the superclass/superinterface loading it can, until | |
524 // the original thread completes the class loading or fails | |
525 // If it completes we will use the resulting instanceKlass | |
526 // which we will find below in the systemDictionary. | |
527 // We also get here for parallel bootstrap classloader | |
528 if (class_loader.is_null()) { | |
529 SystemDictionary_lock->wait(); | |
530 } else { | |
531 double_lock_wait(lockObject, THREAD); | |
532 } | |
533 } else { | |
534 // If not in SD and not in PH, other thread's load must have failed | |
535 super_load_in_progress = false; | |
536 } | |
537 } | |
538 } | |
539 return (nh); | |
540 } | |
541 | |
542 | |
543 klassOop SystemDictionary::resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) { | |
544 assert(class_name.not_null() && !FieldType::is_array(class_name()), "invalid class name"); | |
545 // First check to see if we should remove wrapping L and ; | |
546 symbolHandle name; | |
547 if (FieldType::is_obj(class_name())) { | |
548 ResourceMark rm(THREAD); | |
549 // Ignore wrapping L and ;. | |
550 name = oopFactory::new_symbol_handle(class_name()->as_C_string() + 1, class_name()->utf8_length() - 2, CHECK_NULL); | |
551 } else { | |
552 name = class_name; | |
553 } | |
554 | |
555 // UseNewReflection | |
556 // Fix for 4474172; see evaluation for more details | |
557 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); | |
558 | |
559 // Do lookup to see if class already exist and the protection domain | |
560 // has the right access | |
561 unsigned int d_hash = dictionary()->compute_hash(name, class_loader); | |
562 int d_index = dictionary()->hash_to_index(d_hash); | |
563 klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader, | |
564 protection_domain, THREAD); | |
565 if (probe != NULL) return probe; | |
566 | |
567 | |
568 // Non-bootstrap class loaders will call out to class loader and | |
569 // define via jvm/jni_DefineClass which will acquire the | |
570 // class loader object lock to protect against multiple threads | |
571 // defining the class in parallel by accident. | |
572 // This lock must be acquired here so the waiter will find | |
573 // any successful result in the SystemDictionary and not attempt | |
574 // the define | |
514 | 575 // ParallelCapable Classloaders and the bootstrap classloader, |
0 | 576 // or all classloaders with UnsyncloadClass do not acquire lock here |
577 bool DoObjectLock = true; | |
514 | 578 if (is_parallelCapable(class_loader)) { |
0 | 579 DoObjectLock = false; |
580 } | |
581 | |
582 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | |
583 int p_index = placeholders()->hash_to_index(p_hash); | |
584 | |
585 // Class is not in SystemDictionary so we have to do loading. | |
586 // Make sure we are synchronized on the class loader before we proceed | |
587 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); | |
588 check_loader_lock_contention(lockObject, THREAD); | |
589 ObjectLocker ol(lockObject, THREAD, DoObjectLock); | |
590 | |
591 // Check again (after locking) if class already exist in SystemDictionary | |
592 bool class_has_been_loaded = false; | |
593 bool super_load_in_progress = false; | |
594 bool havesupername = false; | |
595 instanceKlassHandle k; | |
596 PlaceholderEntry* placeholder; | |
597 symbolHandle superclassname; | |
598 | |
599 { | |
600 MutexLocker mu(SystemDictionary_lock, THREAD); | |
601 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
602 if (check != NULL) { | |
603 // Klass is already loaded, so just return it | |
604 class_has_been_loaded = true; | |
605 k = instanceKlassHandle(THREAD, check); | |
606 } else { | |
607 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); | |
608 if (placeholder && placeholder->super_load_in_progress()) { | |
609 super_load_in_progress = true; | |
610 if (placeholder->havesupername() == true) { | |
611 superclassname = symbolHandle(THREAD, placeholder->supername()); | |
612 havesupername = true; | |
613 } | |
614 } | |
615 } | |
616 } | |
617 | |
618 // If the class in is in the placeholder table, class loading is in progress | |
619 if (super_load_in_progress && havesupername==true) { | |
620 k = SystemDictionary::handle_parallel_super_load(name, superclassname, | |
621 class_loader, protection_domain, lockObject, THREAD); | |
622 if (HAS_PENDING_EXCEPTION) { | |
623 return NULL; | |
624 } | |
625 if (!k.is_null()) { | |
626 class_has_been_loaded = true; | |
627 } | |
628 } | |
629 | |
630 if (!class_has_been_loaded) { | |
631 | |
632 // add placeholder entry to record loading instance class | |
633 // Five cases: | |
634 // All cases need to prevent modifying bootclasssearchpath | |
635 // in parallel with a classload of same classname | |
514 | 636 // Redefineclasses uses existence of the placeholder for the duration |
637 // of the class load to prevent concurrent redefinition of not completely | |
638 // defined classes. | |
0 | 639 // case 1. traditional classloaders that rely on the classloader object lock |
640 // - no other need for LOAD_INSTANCE | |
641 // case 2. traditional classloaders that break the classloader object lock | |
642 // as a deadlock workaround. Detection of this case requires that | |
643 // this check is done while holding the classloader object lock, | |
644 // and that lock is still held when calling classloader's loadClass. | |
645 // For these classloaders, we ensure that the first requestor | |
646 // completes the load and other requestors wait for completion. | |
647 // case 3. UnsyncloadClass - don't use objectLocker | |
648 // With this flag, we allow parallel classloading of a | |
649 // class/classloader pair | |
650 // case4. Bootstrap classloader - don't own objectLocker | |
651 // This classloader supports parallelism at the classloader level, | |
652 // but only allows a single load of a class/classloader pair. | |
653 // No performance benefit and no deadlock issues. | |
514 | 654 // case 5. parallelCapable user level classloaders - without objectLocker |
655 // Allow parallel classloading of a class/classloader pair | |
0 | 656 symbolHandle nullsymbolHandle; |
657 bool throw_circularity_error = false; | |
658 { | |
659 MutexLocker mu(SystemDictionary_lock, THREAD); | |
514 | 660 if (class_loader.is_null() || !is_parallelCapable(class_loader)) { |
0 | 661 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
662 if (oldprobe) { | |
663 // only need check_seen_thread once, not on each loop | |
664 // 6341374 java/lang/Instrument with -Xcomp | |
665 if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) { | |
666 throw_circularity_error = true; | |
667 } else { | |
668 // case 1: traditional: should never see load_in_progress. | |
669 while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) { | |
670 | |
671 // case 4: bootstrap classloader: prevent futile classloading, | |
672 // wait on first requestor | |
673 if (class_loader.is_null()) { | |
674 SystemDictionary_lock->wait(); | |
675 } else { | |
676 // case 2: traditional with broken classloader lock. wait on first | |
677 // requestor. | |
678 double_lock_wait(lockObject, THREAD); | |
679 } | |
680 // Check if classloading completed while we were waiting | |
681 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
682 if (check != NULL) { | |
683 // Klass is already loaded, so just return it | |
684 k = instanceKlassHandle(THREAD, check); | |
685 class_has_been_loaded = true; | |
686 } | |
687 // check if other thread failed to load and cleaned up | |
688 oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); | |
689 } | |
690 } | |
691 } | |
692 } | |
693 // All cases: add LOAD_INSTANCE | |
514 | 694 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try |
0 | 695 // LOAD_INSTANCE in parallel |
696 // add placeholder entry even if error - callers will remove on error | |
514 | 697 if (!throw_circularity_error && !class_has_been_loaded) { |
0 | 698 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, nullsymbolHandle, THREAD); |
699 // For class loaders that do not acquire the classloader object lock, | |
700 // if they did not catch another thread holding LOAD_INSTANCE, | |
701 // need a check analogous to the acquire ObjectLocker/find_class | |
702 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL | |
703 // one final check if the load has already completed | |
514 | 704 // class loaders holding the ObjectLock shouldn't find the class here |
0 | 705 klassOop check = find_class(d_index, d_hash, name, class_loader); |
706 if (check != NULL) { | |
707 // Klass is already loaded, so just return it | |
708 k = instanceKlassHandle(THREAD, check); | |
709 class_has_been_loaded = true; | |
710 newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); | |
514 | 711 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); |
712 SystemDictionary_lock->notify_all(); | |
0 | 713 } |
714 } | |
715 } | |
716 // must throw error outside of owning lock | |
717 if (throw_circularity_error) { | |
718 ResourceMark rm(THREAD); | |
719 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string()); | |
720 } | |
721 | |
722 if (!class_has_been_loaded) { | |
723 | |
724 // Do actual loading | |
725 k = load_instance_class(name, class_loader, THREAD); | |
726 | |
514 | 727 // For UnsyncloadClass and AllowParallelDefineClass only: |
0 | 728 // If they got a linkageError, check if a parallel class load succeeded. |
729 // If it did, then for bytecode resolution the specification requires | |
730 // that we return the same result we did for the other thread, i.e. the | |
731 // successfully loaded instanceKlass | |
732 // Should not get here for classloaders that support parallelism | |
514 | 733 // with the new cleaner mechanism |
734 // Bootstrap goes through here to allow for an extra guarantee check | |
0 | 735 if (UnsyncloadClass || (class_loader.is_null())) { |
736 if (k.is_null() && HAS_PENDING_EXCEPTION | |
737 && PENDING_EXCEPTION->is_a(SystemDictionary::linkageError_klass())) { | |
738 MutexLocker mu(SystemDictionary_lock, THREAD); | |
739 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
740 if (check != NULL) { | |
741 // Klass is already loaded, so just use it | |
742 k = instanceKlassHandle(THREAD, check); | |
743 CLEAR_PENDING_EXCEPTION; | |
744 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); | |
745 } | |
746 } | |
747 } | |
748 | |
749 // clean up placeholder entries for success or error | |
750 // This cleans up LOAD_INSTANCE entries | |
751 // It also cleans up LOAD_SUPER entries on errors from | |
752 // calling load_instance_class | |
753 { | |
754 MutexLocker mu(SystemDictionary_lock, THREAD); | |
755 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader); | |
756 if (probe != NULL) { | |
757 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); | |
758 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | |
759 SystemDictionary_lock->notify_all(); | |
760 } | |
761 } | |
762 | |
763 // If everything was OK (no exceptions, no null return value), and | |
764 // class_loader is NOT the defining loader, do a little more bookkeeping. | |
765 if (!HAS_PENDING_EXCEPTION && !k.is_null() && | |
766 k->class_loader() != class_loader()) { | |
767 | |
768 check_constraints(d_index, d_hash, k, class_loader, false, THREAD); | |
769 | |
770 // Need to check for a PENDING_EXCEPTION again; check_constraints | |
771 // can throw and doesn't use the CHECK macro. | |
772 if (!HAS_PENDING_EXCEPTION) { | |
773 { // Grabbing the Compile_lock prevents systemDictionary updates | |
774 // during compilations. | |
775 MutexLocker mu(Compile_lock, THREAD); | |
776 update_dictionary(d_index, d_hash, p_index, p_hash, | |
777 k, class_loader, THREAD); | |
778 } | |
779 if (JvmtiExport::should_post_class_load()) { | |
780 Thread *thread = THREAD; | |
781 assert(thread->is_Java_thread(), "thread->is_Java_thread()"); | |
782 JvmtiExport::post_class_load((JavaThread *) thread, k()); | |
783 } | |
784 } | |
785 } | |
786 if (HAS_PENDING_EXCEPTION || k.is_null()) { | |
787 // On error, clean up placeholders | |
788 { | |
789 MutexLocker mu(SystemDictionary_lock, THREAD); | |
790 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | |
791 SystemDictionary_lock->notify_all(); | |
792 } | |
793 return NULL; | |
794 } | |
795 } | |
796 } | |
797 | |
798 #ifdef ASSERT | |
799 { | |
800 Handle loader (THREAD, k->class_loader()); | |
801 MutexLocker mu(SystemDictionary_lock, THREAD); | |
802 oop kk = find_class_or_placeholder(name, loader); | |
803 assert(kk == k(), "should be present in dictionary"); | |
804 } | |
805 #endif | |
806 | |
807 // return if the protection domain in NULL | |
808 if (protection_domain() == NULL) return k(); | |
809 | |
810 // Check the protection domain has the right access | |
811 { | |
812 MutexLocker mu(SystemDictionary_lock, THREAD); | |
813 // Note that we have an entry, and entries can be deleted only during GC, | |
814 // so we cannot allow GC to occur while we're holding this entry. | |
815 // We're using a No_Safepoint_Verifier to catch any place where we | |
816 // might potentially do a GC at all. | |
817 // SystemDictionary::do_unloading() asserts that classes are only | |
818 // unloaded at a safepoint. | |
819 No_Safepoint_Verifier nosafepoint; | |
820 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, | |
821 class_loader, | |
822 protection_domain)) { | |
823 return k(); | |
824 } | |
825 } | |
826 | |
827 // Verify protection domain. If it fails an exception is thrown | |
828 validate_protection_domain(k, class_loader, protection_domain, CHECK_(klassOop(NULL))); | |
829 | |
830 return k(); | |
831 } | |
832 | |
833 | |
834 // This routine does not lock the system dictionary. | |
835 // | |
836 // Since readers don't hold a lock, we must make sure that system | |
837 // dictionary entries are only removed at a safepoint (when only one | |
838 // thread is running), and are added to in a safe way (all links must | |
839 // be updated in an MT-safe manner). | |
840 // | |
841 // Callers should be aware that an entry could be added just after | |
842 // _dictionary->bucket(index) is read here, so the caller will not see | |
843 // the new entry. | |
844 | |
845 klassOop SystemDictionary::find(symbolHandle class_name, | |
846 Handle class_loader, | |
847 Handle protection_domain, | |
848 TRAPS) { | |
849 | |
556
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
850 // UseNewReflection |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
851 // The result of this call should be consistent with the result |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
852 // of the call to resolve_instance_class_or_null(). |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
853 // See evaluation 6790209 and 4474172 for more details. |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
854 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
48bb4a49b7ac
6790209: server VM fails with assert(will_link,"_new: typeflow responsibility")
kvn
parents:
431
diff
changeset
|
855 |
0 | 856 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); |
857 int d_index = dictionary()->hash_to_index(d_hash); | |
858 | |
859 { | |
860 // Note that we have an entry, and entries can be deleted only during GC, | |
861 // so we cannot allow GC to occur while we're holding this entry. | |
862 // We're using a No_Safepoint_Verifier to catch any place where we | |
863 // might potentially do a GC at all. | |
864 // SystemDictionary::do_unloading() asserts that classes are only | |
865 // unloaded at a safepoint. | |
866 No_Safepoint_Verifier nosafepoint; | |
867 return dictionary()->find(d_index, d_hash, class_name, class_loader, | |
868 protection_domain, THREAD); | |
869 } | |
870 } | |
871 | |
872 | |
873 // Look for a loaded instance or array klass by name. Do not do any loading. | |
874 // return NULL in case of error. | |
875 klassOop SystemDictionary::find_instance_or_array_klass(symbolHandle class_name, | |
876 Handle class_loader, | |
877 Handle protection_domain, | |
878 TRAPS) { | |
879 klassOop k = NULL; | |
880 assert(class_name() != NULL, "class name must be non NULL"); | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
881 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
882 // Try to get one of the well-known klasses. |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
883 if (LinkWellKnownClasses) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
884 k = find_well_known_klass(class_name()); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
885 if (k != NULL) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
886 return k; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
887 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
888 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
889 |
0 | 890 if (FieldType::is_array(class_name())) { |
891 // The name refers to an array. Parse the name. | |
892 jint dimension; | |
893 symbolOop object_key; | |
894 | |
895 // dimension and object_key are assigned as a side-effect of this call | |
896 BasicType t = FieldType::get_array_info(class_name(), &dimension, | |
897 &object_key, CHECK_(NULL)); | |
898 if (t != T_OBJECT) { | |
899 k = Universe::typeArrayKlassObj(t); | |
900 } else { | |
901 symbolHandle h_key(THREAD, object_key); | |
902 k = SystemDictionary::find(h_key, class_loader, protection_domain, THREAD); | |
903 } | |
904 if (k != NULL) { | |
905 k = Klass::cast(k)->array_klass_or_null(dimension); | |
906 } | |
907 } else { | |
908 k = find(class_name, class_loader, protection_domain, THREAD); | |
909 } | |
910 return k; | |
911 } | |
912 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
913 // Quick range check for names of well-known classes: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
914 static symbolOop wk_klass_name_limits[2] = {NULL, NULL}; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
915 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
916 #ifndef PRODUCT |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
917 static int find_wkk_calls, find_wkk_probes, find_wkk_wins; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
918 // counts for "hello world": 3983, 1616, 1075 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
919 // => 60% hit after limit guard, 25% total win rate |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
920 #endif |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
921 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
922 klassOop SystemDictionary::find_well_known_klass(symbolOop class_name) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
923 // A bounds-check on class_name will quickly get a negative result. |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
924 NOT_PRODUCT(find_wkk_calls++); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
925 if (class_name >= wk_klass_name_limits[0] && |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
926 class_name <= wk_klass_name_limits[1]) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
927 NOT_PRODUCT(find_wkk_probes++); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
928 vmSymbols::SID sid = vmSymbols::find_sid(class_name); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
929 if (sid != vmSymbols::NO_SID) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
930 klassOop k = NULL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
931 switch (sid) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
932 #define WK_KLASS_CASE(name, symbol, ignore_option) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
933 case vmSymbols::VM_SYMBOL_ENUM_NAME(symbol): \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
934 k = WK_KLASS(name); break; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
935 WK_KLASSES_DO(WK_KLASS_CASE) |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
936 #undef WK_KLASS_CASE |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
937 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
938 NOT_PRODUCT(if (k != NULL) find_wkk_wins++); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
939 return k; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
940 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
941 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
942 return NULL; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
943 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
944 |
0 | 945 // Note: this method is much like resolve_from_stream, but |
946 // updates no supplemental data structures. | |
947 // TODO consolidate the two methods with a helper routine? | |
948 klassOop SystemDictionary::parse_stream(symbolHandle class_name, | |
949 Handle class_loader, | |
950 Handle protection_domain, | |
951 ClassFileStream* st, | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
952 KlassHandle host_klass, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
953 GrowableArray<Handle>* cp_patches, |
0 | 954 TRAPS) { |
955 symbolHandle parsed_name; | |
956 | |
957 // Parse the stream. Note that we do this even though this klass might | |
958 // already be present in the SystemDictionary, otherwise we would not | |
959 // throw potential ClassFormatErrors. | |
960 // | |
961 // Note: "name" is updated. | |
962 // Further note: a placeholder will be added for this class when | |
963 // super classes are loaded (resolve_super_or_fail). We expect this | |
964 // to be called for all classes but java.lang.Object; and we preload | |
965 // java.lang.Object through resolve_or_fail, not this path. | |
966 | |
967 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, | |
968 class_loader, | |
969 protection_domain, | |
710 | 970 host_klass, |
971 cp_patches, | |
0 | 972 parsed_name, |
973 THREAD); | |
974 | |
514 | 975 |
0 | 976 // We don't redefine the class, so we just need to clean up whether there |
977 // was an error or not (don't want to modify any system dictionary | |
978 // data structures). | |
979 // Parsed name could be null if we threw an error before we got far | |
980 // enough along to parse it -- in that case, there is nothing to clean up. | |
981 if (!parsed_name.is_null()) { | |
982 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | |
983 class_loader); | |
984 int p_index = placeholders()->hash_to_index(p_hash); | |
985 { | |
986 MutexLocker mu(SystemDictionary_lock, THREAD); | |
987 placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD); | |
988 SystemDictionary_lock->notify_all(); | |
989 } | |
990 } | |
991 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
992 if (host_klass.not_null() && k.not_null()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
993 assert(AnonymousClasses, ""); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
994 // If it's anonymous, initialize it now, since nobody else will. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
995 k->set_host_klass(host_klass()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
996 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
997 { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
998 MutexLocker mu_r(Compile_lock, THREAD); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
999 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1000 // Add to class hierarchy, initialize vtables, and do possible |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1001 // deoptimizations. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1002 add_to_hierarchy(k, CHECK_NULL); // No exception, but can block |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1003 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1004 // But, do not add to system dictionary. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1005 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1006 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1007 k->eager_initialize(THREAD); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1008 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1009 // notify jvmti |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1010 if (JvmtiExport::should_post_class_load()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1011 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1012 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1013 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1014 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1015 |
0 | 1016 return k(); |
1017 } | |
1018 | |
1019 // Add a klass to the system from a stream (called by jni_DefineClass and | |
1020 // JVM_DefineClass). | |
1021 // Note: class_name can be NULL. In that case we do not know the name of | |
1022 // the class until we have parsed the stream. | |
1023 | |
1024 klassOop SystemDictionary::resolve_from_stream(symbolHandle class_name, | |
1025 Handle class_loader, | |
1026 Handle protection_domain, | |
1027 ClassFileStream* st, | |
1028 TRAPS) { | |
1029 | |
514 | 1030 // Classloaders that support parallelism, e.g. bootstrap classloader, |
1031 // or all classloaders with UnsyncloadClass do not acquire lock here | |
1032 bool DoObjectLock = true; | |
1033 if (is_parallelCapable(class_loader)) { | |
1034 DoObjectLock = false; | |
1035 } | |
1036 | |
1037 // Make sure we are synchronized on the class loader before we proceed | |
0 | 1038 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
1039 check_loader_lock_contention(lockObject, THREAD); | |
514 | 1040 ObjectLocker ol(lockObject, THREAD, DoObjectLock); |
0 | 1041 |
1042 symbolHandle parsed_name; | |
1043 | |
1044 // Parse the stream. Note that we do this even though this klass might | |
1045 // already be present in the SystemDictionary, otherwise we would not | |
1046 // throw potential ClassFormatErrors. | |
1047 // | |
1048 // Note: "name" is updated. | |
1049 // Further note: a placeholder will be added for this class when | |
1050 // super classes are loaded (resolve_super_or_fail). We expect this | |
1051 // to be called for all classes but java.lang.Object; and we preload | |
1052 // java.lang.Object through resolve_or_fail, not this path. | |
1053 | |
1054 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, | |
1055 class_loader, | |
1056 protection_domain, | |
1057 parsed_name, | |
1058 THREAD); | |
1059 | |
1060 const char* pkg = "java/"; | |
1061 if (!HAS_PENDING_EXCEPTION && | |
1062 !class_loader.is_null() && | |
1063 !parsed_name.is_null() && | |
1064 !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) { | |
1065 // It is illegal to define classes in the "java." package from | |
1066 // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader | |
1067 ResourceMark rm(THREAD); | |
1068 char* name = parsed_name->as_C_string(); | |
1069 char* index = strrchr(name, '/'); | |
1070 *index = '\0'; // chop to just the package name | |
1071 while ((index = strchr(name, '/')) != NULL) { | |
1072 *index = '.'; // replace '/' with '.' in package name | |
1073 } | |
1074 const char* fmt = "Prohibited package name: %s"; | |
1075 size_t len = strlen(fmt) + strlen(name); | |
1076 char* message = NEW_RESOURCE_ARRAY(char, len); | |
1077 jio_snprintf(message, len, fmt, name); | |
1078 Exceptions::_throw_msg(THREAD_AND_LOCATION, | |
1079 vmSymbols::java_lang_SecurityException(), message); | |
1080 } | |
1081 | |
1082 if (!HAS_PENDING_EXCEPTION) { | |
1083 assert(!parsed_name.is_null(), "Sanity"); | |
1084 assert(class_name.is_null() || class_name() == parsed_name(), | |
1085 "name mismatch"); | |
1086 // Verification prevents us from creating names with dots in them, this | |
1087 // asserts that that's the case. | |
1088 assert(is_internal_format(parsed_name), | |
1089 "external class name format used internally"); | |
1090 | |
1091 // Add class just loaded | |
514 | 1092 // If a class loader supports parallel classloading handle parallel define requests |
1093 // find_or_define_instance_class may return a different instanceKlass | |
1094 if (is_parallelCapable(class_loader)) { | |
1095 k = find_or_define_instance_class(class_name, class_loader, k, THREAD); | |
1096 } else { | |
1097 define_instance_class(k, THREAD); | |
1098 } | |
0 | 1099 } |
1100 | |
1101 // If parsing the class file or define_instance_class failed, we | |
1102 // need to remove the placeholder added on our behalf. But we | |
1103 // must make sure parsed_name is valid first (it won't be if we had | |
1104 // a format error before the class was parsed far enough to | |
1105 // find the name). | |
1106 if (HAS_PENDING_EXCEPTION && !parsed_name.is_null()) { | |
1107 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | |
1108 class_loader); | |
1109 int p_index = placeholders()->hash_to_index(p_hash); | |
1110 { | |
1111 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1112 placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD); | |
1113 SystemDictionary_lock->notify_all(); | |
1114 } | |
1115 return NULL; | |
1116 } | |
1117 | |
1118 // Make sure that we didn't leave a place holder in the | |
1119 // SystemDictionary; this is only done on success | |
1120 debug_only( { | |
1121 if (!HAS_PENDING_EXCEPTION) { | |
1122 assert(!parsed_name.is_null(), "parsed_name is still null?"); | |
1123 symbolHandle h_name (THREAD, k->name()); | |
1124 Handle h_loader (THREAD, k->class_loader()); | |
1125 | |
1126 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1127 | |
1128 oop check = find_class_or_placeholder(parsed_name, class_loader); | |
1129 assert(check == k(), "should be present in the dictionary"); | |
1130 | |
1131 oop check2 = find_class_or_placeholder(h_name, h_loader); | |
1132 assert(check == check2, "name inconsistancy in SystemDictionary"); | |
1133 } | |
1134 } ); | |
1135 | |
1136 return k(); | |
1137 } | |
1138 | |
1139 | |
1140 void SystemDictionary::set_shared_dictionary(HashtableBucket* t, int length, | |
1141 int number_of_entries) { | |
1142 assert(length == _nof_buckets * sizeof(HashtableBucket), | |
1143 "bad shared dictionary size."); | |
1144 _shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries); | |
1145 } | |
1146 | |
1147 | |
1148 // If there is a shared dictionary, then find the entry for the | |
1149 // given shared system class, if any. | |
1150 | |
1151 klassOop SystemDictionary::find_shared_class(symbolHandle class_name) { | |
1152 if (shared_dictionary() != NULL) { | |
1153 unsigned int d_hash = dictionary()->compute_hash(class_name, Handle()); | |
1154 int d_index = dictionary()->hash_to_index(d_hash); | |
1155 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); | |
1156 } else { | |
1157 return NULL; | |
1158 } | |
1159 } | |
1160 | |
1161 | |
1162 // Load a class from the shared spaces (found through the shared system | |
1163 // dictionary). Force the superclass and all interfaces to be loaded. | |
1164 // Update the class definition to include sibling classes and no | |
1165 // subclasses (yet). [Classes in the shared space are not part of the | |
1166 // object hierarchy until loaded.] | |
1167 | |
1168 instanceKlassHandle SystemDictionary::load_shared_class( | |
1169 symbolHandle class_name, Handle class_loader, TRAPS) { | |
1170 instanceKlassHandle ik (THREAD, find_shared_class(class_name)); | |
1171 return load_shared_class(ik, class_loader, THREAD); | |
1172 } | |
1173 | |
1174 // Note well! Changes to this method may affect oop access order | |
1175 // in the shared archive. Please take care to not make changes that | |
1176 // adversely affect cold start time by changing the oop access order | |
1177 // that is specified in dump.cpp MarkAndMoveOrderedReadOnly and | |
1178 // MarkAndMoveOrderedReadWrite closures. | |
1179 instanceKlassHandle SystemDictionary::load_shared_class( | |
1180 instanceKlassHandle ik, Handle class_loader, TRAPS) { | |
1181 assert(class_loader.is_null(), "non-null classloader for shared class?"); | |
1182 if (ik.not_null()) { | |
1183 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | |
1184 symbolHandle class_name(THREAD, ik->name()); | |
1185 | |
1186 // Found the class, now load the superclass and interfaces. If they | |
1187 // are shared, add them to the main system dictionary and reset | |
1188 // their hierarchy references (supers, subs, and interfaces). | |
1189 | |
1190 if (ik->super() != NULL) { | |
1191 symbolHandle cn(THREAD, ik->super()->klass_part()->name()); | |
1192 resolve_super_or_fail(class_name, cn, | |
1193 class_loader, Handle(), true, CHECK_(nh)); | |
1194 } | |
1195 | |
1196 objArrayHandle interfaces (THREAD, ik->local_interfaces()); | |
1197 int num_interfaces = interfaces->length(); | |
1198 for (int index = 0; index < num_interfaces; index++) { | |
1199 klassOop k = klassOop(interfaces->obj_at(index)); | |
1200 | |
1201 // Note: can not use instanceKlass::cast here because | |
1202 // interfaces' instanceKlass's C++ vtbls haven't been | |
1203 // reinitialized yet (they will be once the interface classes | |
1204 // are loaded) | |
1205 symbolHandle name (THREAD, k->klass_part()->name()); | |
1206 resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh)); | |
1207 } | |
1208 | |
1209 // Adjust methods to recover missing data. They need addresses for | |
1210 // interpreter entry points and their default native method address | |
1211 // must be reset. | |
1212 | |
1213 // Updating methods must be done under a lock so multiple | |
1214 // threads don't update these in parallel | |
1215 // Shared classes are all currently loaded by the bootstrap | |
1216 // classloader, so this will never cause a deadlock on | |
1217 // a custom class loader lock. | |
1218 | |
1219 { | |
1220 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); | |
1221 check_loader_lock_contention(lockObject, THREAD); | |
1222 ObjectLocker ol(lockObject, THREAD, true); | |
1223 | |
1224 objArrayHandle methods (THREAD, ik->methods()); | |
1225 int num_methods = methods->length(); | |
1226 for (int index2 = 0; index2 < num_methods; ++index2) { | |
1227 methodHandle m(THREAD, methodOop(methods->obj_at(index2))); | |
1228 m()->link_method(m, CHECK_(nh)); | |
1229 } | |
1230 } | |
1231 | |
1232 if (TraceClassLoading) { | |
1233 ResourceMark rm; | |
1234 tty->print("[Loaded %s", ik->external_name()); | |
1235 tty->print(" from shared objects file"); | |
1236 tty->print_cr("]"); | |
1237 } | |
1238 // notify a class loaded from shared object | |
1239 ClassLoadingService::notify_class_loaded(instanceKlass::cast(ik()), | |
1240 true /* shared class */); | |
1241 } | |
1242 return ik; | |
1243 } | |
1244 | |
1245 #ifdef KERNEL | |
1246 // Some classes on the bootstrap class path haven't been installed on the | |
1247 // system yet. Call the DownloadManager method to make them appear in the | |
1248 // bootstrap class path and try again to load the named class. | |
1249 // Note that with delegation class loaders all classes in another loader will | |
1250 // first try to call this so it'd better be fast!! | |
1251 static instanceKlassHandle download_and_retry_class_load( | |
1252 symbolHandle class_name, | |
1253 TRAPS) { | |
1254 | |
1255 klassOop dlm = SystemDictionary::sun_jkernel_DownloadManager_klass(); | |
1256 instanceKlassHandle nk; | |
1257 | |
1258 // If download manager class isn't loaded just return. | |
1259 if (dlm == NULL) return nk; | |
1260 | |
1261 { HandleMark hm(THREAD); | |
1262 ResourceMark rm(THREAD); | |
1263 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nk)); | |
1264 Handle class_string = java_lang_String::externalize_classname(s, CHECK_(nk)); | |
1265 | |
1266 // return value | |
1267 JavaValue result(T_OBJECT); | |
1268 | |
1269 // Call the DownloadManager. We assume that it has a lock because | |
1270 // multiple classes could be not found and downloaded at the same time. | |
1271 // class sun.misc.DownloadManager; | |
1272 // public static String getBootClassPathEntryForClass(String className); | |
1273 JavaCalls::call_static(&result, | |
1274 KlassHandle(THREAD, dlm), | |
1275 vmSymbolHandles::getBootClassPathEntryForClass_name(), | |
1276 vmSymbolHandles::string_string_signature(), | |
1277 class_string, | |
1278 CHECK_(nk)); | |
1279 | |
1280 // Get result.string and add to bootclasspath | |
1281 assert(result.get_type() == T_OBJECT, "just checking"); | |
1282 oop obj = (oop) result.get_jobject(); | |
1283 if (obj == NULL) { return nk; } | |
1284 | |
22
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
1285 Handle h_obj(THREAD, obj); |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
1286 char* new_class_name = java_lang_String::as_platform_dependent_str(h_obj, |
90f5ddc7297b
6646946: Kernel installation failed on Japanese and Chinese XP SP2 (VM part)
coleenp
parents:
0
diff
changeset
|
1287 CHECK_(nk)); |
0 | 1288 |
1289 // lock the loader | |
1290 // we use this lock because JVMTI does. | |
1291 Handle loader_lock(THREAD, SystemDictionary::system_loader_lock()); | |
1292 | |
1293 ObjectLocker ol(loader_lock, THREAD); | |
1294 // add the file to the bootclasspath | |
1295 ClassLoader::update_class_path_entry_list(new_class_name, true); | |
1296 } // end HandleMark | |
1297 | |
1298 if (TraceClassLoading) { | |
1299 ClassLoader::print_bootclasspath(); | |
1300 } | |
1301 return ClassLoader::load_classfile(class_name, CHECK_(nk)); | |
1302 } | |
1303 #endif // KERNEL | |
1304 | |
1305 | |
1306 instanceKlassHandle SystemDictionary::load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS) { | |
1307 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | |
1308 if (class_loader.is_null()) { | |
1309 // Search the shared system dictionary for classes preloaded into the | |
1310 // shared spaces. | |
1311 instanceKlassHandle k; | |
1312 k = load_shared_class(class_name, class_loader, THREAD); | |
1313 | |
1314 if (k.is_null()) { | |
1315 // Use VM class loader | |
1316 k = ClassLoader::load_classfile(class_name, CHECK_(nh)); | |
1317 } | |
1318 | |
1319 #ifdef KERNEL | |
1320 // If the VM class loader has failed to load the class, call the | |
1321 // DownloadManager class to make it magically appear on the classpath | |
1322 // and try again. This is only configured with the Kernel VM. | |
1323 if (k.is_null()) { | |
1324 k = download_and_retry_class_load(class_name, CHECK_(nh)); | |
1325 } | |
1326 #endif // KERNEL | |
1327 | |
514 | 1328 // find_or_define_instance_class may return a different instanceKlass |
0 | 1329 if (!k.is_null()) { |
1330 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh)); | |
1331 } | |
1332 return k; | |
1333 } else { | |
1334 // Use user specified class loader to load class. Call loadClass operation on class_loader. | |
1335 ResourceMark rm(THREAD); | |
1336 | |
1337 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh)); | |
1338 // Translate to external class name format, i.e., convert '/' chars to '.' | |
1339 Handle string = java_lang_String::externalize_classname(s, CHECK_(nh)); | |
1340 | |
1341 JavaValue result(T_OBJECT); | |
1342 | |
1343 KlassHandle spec_klass (THREAD, SystemDictionary::classloader_klass()); | |
1344 | |
514 | 1345 // Call public unsynchronized loadClass(String) directly for all class loaders |
1346 // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will | |
1347 // acquire a class-name based lock rather than the class loader object lock. | |
1348 // JDK < 7 already acquire the class loader lock in loadClass(String, boolean), | |
1349 // so the call to loadClassInternal() was not required. | |
1350 // | |
1351 // UnsyncloadClass flag means both call loadClass(String) and do | |
1352 // not acquire the class loader lock even for class loaders that are | |
1353 // not parallelCapable. This was a risky transitional | |
1354 // flag for diagnostic purposes only. It is risky to call | |
0 | 1355 // custom class loaders without synchronization. |
1356 // WARNING If a custom class loader does NOT synchronizer findClass, or callers of | |
514 | 1357 // findClass, the UnsyncloadClass flag risks unexpected timing bugs in the field. |
0 | 1358 // Do NOT assume this will be supported in future releases. |
514 | 1359 // |
1360 // Added MustCallLoadClassInternal in case we discover in the field | |
1361 // a customer that counts on this call | |
1362 if (MustCallLoadClassInternal && has_loadClassInternal()) { | |
0 | 1363 JavaCalls::call_special(&result, |
1364 class_loader, | |
1365 spec_klass, | |
1366 vmSymbolHandles::loadClassInternal_name(), | |
1367 vmSymbolHandles::string_class_signature(), | |
1368 string, | |
1369 CHECK_(nh)); | |
1370 } else { | |
1371 JavaCalls::call_virtual(&result, | |
1372 class_loader, | |
1373 spec_klass, | |
1374 vmSymbolHandles::loadClass_name(), | |
1375 vmSymbolHandles::string_class_signature(), | |
1376 string, | |
1377 CHECK_(nh)); | |
1378 } | |
1379 | |
1380 assert(result.get_type() == T_OBJECT, "just checking"); | |
1381 oop obj = (oop) result.get_jobject(); | |
1382 | |
1383 // Primitive classes return null since forName() can not be | |
1384 // used to obtain any of the Class objects representing primitives or void | |
1385 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) { | |
1386 instanceKlassHandle k = | |
1387 instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj)); | |
1388 // For user defined Java class loaders, check that the name returned is | |
1389 // the same as that requested. This check is done for the bootstrap | |
1390 // loader when parsing the class file. | |
1391 if (class_name() == k->name()) { | |
1392 return k; | |
1393 } | |
1394 } | |
1395 // Class is not found or has the wrong name, return NULL | |
1396 return nh; | |
1397 } | |
1398 } | |
1399 | |
1400 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { | |
1401 | |
1402 Handle class_loader_h(THREAD, k->class_loader()); | |
1403 | |
514 | 1404 // for bootstrap and other parallel classloaders don't acquire lock, |
1405 // use placeholder token | |
1406 // If a parallelCapable class loader calls define_instance_class instead of | |
1407 // find_or_define_instance_class to get here, we have a timing | |
1408 // hole with systemDictionary updates and check_constraints | |
1409 if (!class_loader_h.is_null() && !is_parallelCapable(class_loader_h)) { | |
0 | 1410 assert(ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, |
1411 compute_loader_lock_object(class_loader_h, THREAD)), | |
1412 "define called without lock"); | |
1413 } | |
1414 | |
1415 // Check class-loading constraints. Throw exception if violation is detected. | |
1416 // Grabs and releases SystemDictionary_lock | |
1417 // The check_constraints/find_class call and update_dictionary sequence | |
1418 // must be "atomic" for a specific class/classloader pair so we never | |
1419 // define two different instanceKlasses for that class/classloader pair. | |
1420 // Existing classloaders will call define_instance_class with the | |
1421 // classloader lock held | |
1422 // Parallel classloaders will call find_or_define_instance_class | |
1423 // which will require a token to perform the define class | |
1424 symbolHandle name_h(THREAD, k->name()); | |
1425 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h); | |
1426 int d_index = dictionary()->hash_to_index(d_hash); | |
1427 check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK); | |
1428 | |
1429 // Register class just loaded with class loader (placed in Vector) | |
1430 // Note we do this before updating the dictionary, as this can | |
1431 // fail with an OutOfMemoryError (if it does, we will *not* put this | |
1432 // class in the dictionary and will not update the class hierarchy). | |
1433 if (k->class_loader() != NULL) { | |
1434 methodHandle m(THREAD, Universe::loader_addClass_method()); | |
1435 JavaValue result(T_VOID); | |
1436 JavaCallArguments args(class_loader_h); | |
1437 args.push_oop(Handle(THREAD, k->java_mirror())); | |
1438 JavaCalls::call(&result, m, &args, CHECK); | |
1439 } | |
1440 | |
1441 // Add the new class. We need recompile lock during update of CHA. | |
1442 { | |
1443 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader_h); | |
1444 int p_index = placeholders()->hash_to_index(p_hash); | |
1445 | |
1446 MutexLocker mu_r(Compile_lock, THREAD); | |
1447 | |
1448 // Add to class hierarchy, initialize vtables, and do possible | |
1449 // deoptimizations. | |
1450 add_to_hierarchy(k, CHECK); // No exception, but can block | |
1451 | |
1452 // Add to systemDictionary - so other classes can see it. | |
1453 // Grabs and releases SystemDictionary_lock | |
1454 update_dictionary(d_index, d_hash, p_index, p_hash, | |
1455 k, class_loader_h, THREAD); | |
1456 } | |
1457 k->eager_initialize(THREAD); | |
1458 | |
1459 // notify jvmti | |
1460 if (JvmtiExport::should_post_class_load()) { | |
1461 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); | |
1462 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); | |
1463 | |
1464 } | |
1465 } | |
1466 | |
1467 // Support parallel classloading | |
1468 // Initial implementation for bootstrap classloader | |
1469 // For custom class loaders that support parallel classloading, | |
514 | 1470 // With AllowParallelDefine flag==true, in case they do not synchronize around |
1471 // FindLoadedClass/DefineClass, calls, we check for parallel | |
0 | 1472 // loading for them, wait if a defineClass is in progress |
1473 // and return the initial requestor's results | |
514 | 1474 // With AllowParallelDefine flag==false, call through to define_instance_class |
1475 // which will throw LinkageError: duplicate class definition. | |
0 | 1476 // For better performance, the class loaders should synchronize |
514 | 1477 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they |
0 | 1478 // potentially waste time reading and parsing the bytestream. |
1479 // Note: VM callers should ensure consistency of k/class_name,class_loader | |
1480 instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { | |
1481 | |
1482 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | |
515 | 1483 symbolHandle name_h(THREAD, k->name()); // passed in class_name may be null |
0 | 1484 |
515 | 1485 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader); |
0 | 1486 int d_index = dictionary()->hash_to_index(d_hash); |
1487 | |
1488 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS | |
515 | 1489 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader); |
0 | 1490 int p_index = placeholders()->hash_to_index(p_hash); |
1491 PlaceholderEntry* probe; | |
1492 | |
1493 { | |
1494 MutexLocker mu(SystemDictionary_lock, THREAD); | |
1495 // First check if class already defined | |
515 | 1496 klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
0 | 1497 if (check != NULL) { |
1498 return(instanceKlassHandle(THREAD, check)); | |
1499 } | |
1500 | |
1501 // Acquire define token for this class/classloader | |
1502 symbolHandle nullsymbolHandle; | |
515 | 1503 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD); |
514 | 1504 // Wait if another thread defining in parallel |
1505 // All threads wait - even those that will throw duplicate class: otherwise | |
1506 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails | |
1507 // if other thread has not finished updating dictionary | |
1508 while (probe->definer() != NULL) { | |
1509 SystemDictionary_lock->wait(); | |
1510 } | |
1511 // Only special cases allow parallel defines and can use other thread's results | |
1512 // Other cases fall through, and may run into duplicate defines | |
1513 // caught by finding an entry in the SystemDictionary | |
1514 if ((UnsyncloadClass || AllowParallelDefineClass) && (probe->instanceKlass() != NULL)) { | |
0 | 1515 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); |
515 | 1516 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); |
514 | 1517 SystemDictionary_lock->notify_all(); |
0 | 1518 #ifdef ASSERT |
515 | 1519 klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
514 | 1520 assert(check != NULL, "definer missed recording success"); |
0 | 1521 #endif |
514 | 1522 return(instanceKlassHandle(THREAD, probe->instanceKlass())); |
0 | 1523 } else { |
514 | 1524 // This thread will define the class (even if earlier thread tried and had an error) |
1525 probe->set_definer(THREAD); | |
0 | 1526 } |
1527 } | |
1528 | |
1529 define_instance_class(k, THREAD); | |
1530 | |
1531 Handle linkage_exception = Handle(); // null handle | |
1532 | |
1533 // definer must notify any waiting threads | |
1534 { | |
1535 MutexLocker mu(SystemDictionary_lock, THREAD); | |
515 | 1536 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, class_loader); |
0 | 1537 assert(probe != NULL, "DEFINE_CLASS placeholder lost?"); |
1538 if (probe != NULL) { | |
1539 if (HAS_PENDING_EXCEPTION) { | |
1540 linkage_exception = Handle(THREAD,PENDING_EXCEPTION); | |
1541 CLEAR_PENDING_EXCEPTION; | |
1542 } else { | |
1543 probe->set_instanceKlass(k()); | |
1544 } | |
1545 probe->set_definer(NULL); | |
1546 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); | |
515 | 1547 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); |
0 | 1548 SystemDictionary_lock->notify_all(); |
1549 } | |
1550 } | |
1551 | |
1552 // Can't throw exception while holding lock due to rank ordering | |
1553 if (linkage_exception() != NULL) { | |
1554 THROW_OOP_(linkage_exception(), nh); // throws exception and returns | |
1555 } | |
1556 | |
1557 return k; | |
1558 } | |
1559 Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) { | |
1560 // If class_loader is NULL we synchronize on _system_loader_lock_obj | |
1561 if (class_loader.is_null()) { | |
1562 return Handle(THREAD, _system_loader_lock_obj); | |
1563 } else { | |
1564 return class_loader; | |
1565 } | |
1566 } | |
1567 | |
1568 // This method is added to check how often we have to wait to grab loader | |
1569 // lock. The results are being recorded in the performance counters defined in | |
1570 // ClassLoader::_sync_systemLoaderLockContentionRate and | |
1571 // ClassLoader::_sync_nonSystemLoaderLockConteionRate. | |
1572 void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) { | |
1573 if (!UsePerfData) { | |
1574 return; | |
1575 } | |
1576 | |
1577 assert(!loader_lock.is_null(), "NULL lock object"); | |
1578 | |
1579 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock) | |
1580 == ObjectSynchronizer::owner_other) { | |
1581 // contention will likely happen, so increment the corresponding | |
1582 // contention counter. | |
1583 if (loader_lock() == _system_loader_lock_obj) { | |
1584 ClassLoader::sync_systemLoaderLockContentionRate()->inc(); | |
1585 } else { | |
1586 ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc(); | |
1587 } | |
1588 } | |
1589 } | |
1590 | |
1591 // ---------------------------------------------------------------------------- | |
1592 // Lookup | |
1593 | |
1594 klassOop SystemDictionary::find_class(int index, unsigned int hash, | |
1595 symbolHandle class_name, | |
1596 Handle class_loader) { | |
1597 assert_locked_or_safepoint(SystemDictionary_lock); | |
1598 assert (index == dictionary()->index_for(class_name, class_loader), | |
1599 "incorrect index?"); | |
1600 | |
1601 klassOop k = dictionary()->find_class(index, hash, class_name, class_loader); | |
1602 return k; | |
1603 } | |
1604 | |
1605 | |
1606 // Basic find on classes in the midst of being loaded | |
1607 symbolOop SystemDictionary::find_placeholder(int index, unsigned int hash, | |
1608 symbolHandle class_name, | |
1609 Handle class_loader) { | |
1610 assert_locked_or_safepoint(SystemDictionary_lock); | |
1611 | |
1612 return placeholders()->find_entry(index, hash, class_name, class_loader); | |
1613 } | |
1614 | |
1615 | |
1616 // Used for assertions and verification only | |
1617 oop SystemDictionary::find_class_or_placeholder(symbolHandle class_name, | |
1618 Handle class_loader) { | |
1619 #ifndef ASSERT | |
1620 guarantee(VerifyBeforeGC || | |
1621 VerifyDuringGC || | |
1622 VerifyBeforeExit || | |
1623 VerifyAfterGC, "too expensive"); | |
1624 #endif | |
1625 assert_locked_or_safepoint(SystemDictionary_lock); | |
1626 symbolOop class_name_ = class_name(); | |
1627 oop class_loader_ = class_loader(); | |
1628 | |
1629 // First look in the loaded class array | |
1630 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); | |
1631 int d_index = dictionary()->hash_to_index(d_hash); | |
1632 oop lookup = find_class(d_index, d_hash, class_name, class_loader); | |
1633 | |
1634 if (lookup == NULL) { | |
1635 // Next try the placeholders | |
1636 unsigned int p_hash = placeholders()->compute_hash(class_name,class_loader); | |
1637 int p_index = placeholders()->hash_to_index(p_hash); | |
1638 lookup = find_placeholder(p_index, p_hash, class_name, class_loader); | |
1639 } | |
1640 | |
1641 return lookup; | |
1642 } | |
1643 | |
1644 | |
1645 // Get the next class in the diictionary. | |
1646 klassOop SystemDictionary::try_get_next_class() { | |
1647 return dictionary()->try_get_next_class(); | |
1648 } | |
1649 | |
1650 | |
1651 // ---------------------------------------------------------------------------- | |
1652 // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock | |
1653 // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in | |
1654 // before a new class is used. | |
1655 | |
1656 void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) { | |
1657 assert(k.not_null(), "just checking"); | |
1658 // Link into hierachy. Make sure the vtables are initialized before linking into | |
1659 k->append_to_sibling_list(); // add to superklass/sibling list | |
1660 k->process_interfaces(THREAD); // handle all "implements" declarations | |
1661 k->set_init_state(instanceKlass::loaded); | |
1662 // Now flush all code that depended on old class hierarchy. | |
1663 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97) | |
1664 // Also, first reinitialize vtable because it may have gotten out of synch | |
1665 // while the new class wasn't connected to the class hierarchy. | |
1666 Universe::flush_dependents_on(k); | |
1667 } | |
1668 | |
1669 | |
1670 // ---------------------------------------------------------------------------- | |
1671 // GC support | |
1672 | |
1673 // Following roots during mark-sweep is separated in two phases. | |
1674 // | |
1675 // The first phase follows preloaded classes and all other system | |
1676 // classes, since these will never get unloaded anyway. | |
1677 // | |
1678 // The second phase removes (unloads) unreachable classes from the | |
1679 // system dictionary and follows the remaining classes' contents. | |
1680 | |
1681 void SystemDictionary::always_strong_oops_do(OopClosure* blk) { | |
1682 // Follow preloaded classes/mirrors and system loader object | |
1683 blk->do_oop(&_java_system_loader); | |
1684 preloaded_oops_do(blk); | |
1685 always_strong_classes_do(blk); | |
1686 } | |
1687 | |
1688 | |
1689 void SystemDictionary::always_strong_classes_do(OopClosure* blk) { | |
1690 // Follow all system classes and temporary placeholders in dictionary | |
1691 dictionary()->always_strong_classes_do(blk); | |
1692 | |
1693 // Placeholders. These are *always* strong roots, as they | |
1694 // represent classes we're actively loading. | |
1695 placeholders_do(blk); | |
1696 | |
710 | 1697 // Visit extra methods |
1698 if (invoke_method_table() != NULL) | |
1699 invoke_method_table()->oops_do(blk); | |
1700 | |
0 | 1701 // Loader constraints. We must keep the symbolOop used in the name alive. |
1702 constraints()->always_strong_classes_do(blk); | |
1703 | |
1704 // Resolution errors keep the symbolOop for the error alive | |
1705 resolution_errors()->always_strong_classes_do(blk); | |
1706 } | |
1707 | |
1708 | |
1709 void SystemDictionary::placeholders_do(OopClosure* blk) { | |
1710 placeholders()->oops_do(blk); | |
1711 } | |
1712 | |
1713 | |
1714 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) { | |
1715 bool result = dictionary()->do_unloading(is_alive); | |
1716 constraints()->purge_loader_constraints(is_alive); | |
1717 resolution_errors()->purge_resolution_errors(is_alive); | |
1718 return result; | |
1719 } | |
1720 | |
1721 | |
1722 // The mirrors are scanned by shared_oops_do() which is | |
1723 // not called by oops_do(). In order to process oops in | |
1724 // a necessary order, shared_oops_do() is call by | |
1725 // Universe::oops_do(). | |
1726 void SystemDictionary::oops_do(OopClosure* f) { | |
1727 // Adjust preloaded classes and system loader object | |
1728 f->do_oop(&_java_system_loader); | |
1729 preloaded_oops_do(f); | |
1730 | |
1731 lazily_loaded_oops_do(f); | |
1732 | |
1733 // Adjust dictionary | |
1734 dictionary()->oops_do(f); | |
1735 | |
710 | 1736 // Visit extra methods |
1737 if (invoke_method_table() != NULL) | |
1738 invoke_method_table()->oops_do(f); | |
1739 | |
0 | 1740 // Partially loaded classes |
1741 placeholders()->oops_do(f); | |
1742 | |
1743 // Adjust constraint table | |
1744 constraints()->oops_do(f); | |
1745 | |
1746 // Adjust resolution error table | |
1747 resolution_errors()->oops_do(f); | |
1748 } | |
1749 | |
1750 | |
1751 void SystemDictionary::preloaded_oops_do(OopClosure* f) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1752 f->do_oop((oop*) &wk_klass_name_limits[0]); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1753 f->do_oop((oop*) &wk_klass_name_limits[1]); |
0 | 1754 |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1755 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1756 f->do_oop((oop*) &_well_known_klasses[k]); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1757 } |
0 | 1758 |
1759 { | |
1760 for (int i = 0; i < T_VOID+1; i++) { | |
1761 if (_box_klasses[i] != NULL) { | |
1762 assert(i >= T_BOOLEAN, "checking"); | |
1763 f->do_oop((oop*) &_box_klasses[i]); | |
1764 } | |
1765 } | |
1766 } | |
1767 | |
1768 // The basic type mirrors would have already been processed in | |
1769 // Universe::oops_do(), via a call to shared_oops_do(), so should | |
1770 // not be processed again. | |
1771 | |
1772 f->do_oop((oop*) &_system_loader_lock_obj); | |
1773 FilteredFieldsMap::klasses_oops_do(f); | |
1774 } | |
1775 | |
1776 void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) { | |
1777 f->do_oop((oop*) &_abstract_ownable_synchronizer_klass); | |
1778 } | |
1779 | |
1780 // Just the classes from defining class loaders | |
1781 // Don't iterate over placeholders | |
1782 void SystemDictionary::classes_do(void f(klassOop)) { | |
1783 dictionary()->classes_do(f); | |
1784 } | |
1785 | |
1786 // Added for initialize_itable_for_klass | |
1787 // Just the classes from defining class loaders | |
1788 // Don't iterate over placeholders | |
1789 void SystemDictionary::classes_do(void f(klassOop, TRAPS), TRAPS) { | |
1790 dictionary()->classes_do(f, CHECK); | |
1791 } | |
1792 | |
1793 // All classes, and their class loaders | |
1794 // Don't iterate over placeholders | |
1795 void SystemDictionary::classes_do(void f(klassOop, oop)) { | |
1796 dictionary()->classes_do(f); | |
1797 } | |
1798 | |
1799 // All classes, and their class loaders | |
1800 // (added for helpers that use HandleMarks and ResourceMarks) | |
1801 // Don't iterate over placeholders | |
1802 void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) { | |
1803 dictionary()->classes_do(f, CHECK); | |
1804 } | |
1805 | |
1806 void SystemDictionary::placeholders_do(void f(symbolOop, oop)) { | |
1807 placeholders()->entries_do(f); | |
1808 } | |
1809 | |
1810 void SystemDictionary::methods_do(void f(methodOop)) { | |
1811 dictionary()->methods_do(f); | |
710 | 1812 if (invoke_method_table() != NULL) |
1813 invoke_method_table()->methods_do(f); | |
0 | 1814 } |
1815 | |
1816 // ---------------------------------------------------------------------------- | |
1817 // Lazily load klasses | |
1818 | |
1819 void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) { | |
1820 assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later"); | |
1821 | |
1822 // if multiple threads calling this function, only one thread will load | |
1823 // the class. The other threads will find the loaded version once the | |
1824 // class is loaded. | |
1825 klassOop aos = _abstract_ownable_synchronizer_klass; | |
1826 if (aos == NULL) { | |
1827 klassOop k = resolve_or_fail(vmSymbolHandles::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK); | |
1828 // Force a fence to prevent any read before the write completes | |
1829 OrderAccess::fence(); | |
1830 _abstract_ownable_synchronizer_klass = k; | |
1831 } | |
1832 } | |
1833 | |
1834 // ---------------------------------------------------------------------------- | |
1835 // Initialization | |
1836 | |
1837 void SystemDictionary::initialize(TRAPS) { | |
1838 // Allocate arrays | |
1839 assert(dictionary() == NULL, | |
1840 "SystemDictionary should only be initialized once"); | |
1841 _dictionary = new Dictionary(_nof_buckets); | |
1842 _placeholders = new PlaceholderTable(_nof_buckets); | |
1843 _number_of_modifications = 0; | |
1844 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size); | |
1845 _resolution_errors = new ResolutionErrorTable(_resolution_error_size); | |
710 | 1846 // _invoke_method_table is allocated lazily in find_method_handle_invoke() |
0 | 1847 |
1848 // Allocate private object used as system class loader lock | |
1849 _system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK); | |
1850 // Initialize basic classes | |
1851 initialize_preloaded_classes(CHECK); | |
1852 } | |
1853 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1854 // Compact table of directions on the initialization of klasses: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1855 static const short wk_init_info[] = { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1856 #define WK_KLASS_INIT_INFO(name, symbol, option) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1857 ( ((int)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1858 << SystemDictionary::CEIL_LG_OPTION_LIMIT) \ |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1859 | (int)SystemDictionary::option ), |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1860 WK_KLASSES_DO(WK_KLASS_INIT_INFO) |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1861 #undef WK_KLASS_INIT_INFO |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1862 0 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1863 }; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1864 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1865 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1866 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1867 int info = wk_init_info[id - FIRST_WKID]; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1868 int sid = (info >> CEIL_LG_OPTION_LIMIT); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1869 symbolHandle symbol = vmSymbolHandles::symbol_handle_at((vmSymbols::SID)sid); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1870 klassOop* klassp = &_well_known_klasses[id]; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1871 bool must_load = (init_opt < SystemDictionary::Opt); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1872 bool try_load = true; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1873 if (init_opt == SystemDictionary::Opt_Kernel) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1874 #ifndef KERNEL |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1875 try_load = false; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1876 #endif //KERNEL |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1877 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1878 if ((*klassp) == NULL && try_load) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1879 if (must_load) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1880 (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1881 } else { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1882 (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1883 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1884 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1885 return ((*klassp) != NULL); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1886 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1887 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1888 void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1889 assert((int)start_id <= (int)limit_id, "IDs are out of order!"); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1890 for (int id = (int)start_id; id < (int)limit_id; id++) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1891 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1892 int info = wk_init_info[id - FIRST_WKID]; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1893 int sid = (info >> CEIL_LG_OPTION_LIMIT); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1894 int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT)); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1895 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1896 initialize_wk_klass((WKID)id, opt, CHECK); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1897 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1898 // Update limits, so find_well_known_klass can be very fast: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1899 symbolOop s = vmSymbols::symbol_at((vmSymbols::SID)sid); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1900 if (wk_klass_name_limits[1] == NULL) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1901 wk_klass_name_limits[0] = wk_klass_name_limits[1] = s; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1902 } else if (wk_klass_name_limits[1] < s) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1903 wk_klass_name_limits[1] = s; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1904 } else if (wk_klass_name_limits[0] > s) { |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1905 wk_klass_name_limits[0] = s; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1906 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1907 } |
710 | 1908 |
1909 // move the starting value forward to the limit: | |
1910 start_id = limit_id; | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1911 } |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1912 |
0 | 1913 |
1914 void SystemDictionary::initialize_preloaded_classes(TRAPS) { | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1915 assert(WK_KLASS(object_klass) == NULL, "preloaded classes should only be initialized once"); |
0 | 1916 // Preload commonly used klasses |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1917 WKID scan = FIRST_WKID; |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1918 // first do Object, String, Class |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1919 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(class_klass), scan, CHECK); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1920 |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1921 debug_only(instanceKlass::verify_class_klass_nonstatic_oop_maps(WK_KLASS(class_klass))); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1922 |
0 | 1923 // Fixup mirrors for classes loaded before java.lang.Class. |
1924 // These calls iterate over the objects currently in the perm gen | |
1925 // so calling them at this point is matters (not before when there | |
1926 // are fewer objects and not later after there are more objects | |
1927 // in the perm gen. | |
1928 Universe::initialize_basic_type_mirrors(CHECK); | |
1929 Universe::fixup_mirrors(CHECK); | |
1930 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1931 // do a bunch more: |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1932 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(reference_klass), scan, CHECK); |
0 | 1933 |
1934 // Preload ref klasses and set reference types | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1935 instanceKlass::cast(WK_KLASS(reference_klass))->set_reference_type(REF_OTHER); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1936 instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(reference_klass)); |
0 | 1937 |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1938 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(phantom_reference_klass), scan, CHECK); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1939 instanceKlass::cast(WK_KLASS(soft_reference_klass))->set_reference_type(REF_SOFT); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1940 instanceKlass::cast(WK_KLASS(weak_reference_klass))->set_reference_type(REF_WEAK); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1941 instanceKlass::cast(WK_KLASS(final_reference_klass))->set_reference_type(REF_FINAL); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1942 instanceKlass::cast(WK_KLASS(phantom_reference_klass))->set_reference_type(REF_PHANTOM); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1943 |
710 | 1944 WKID meth_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass); |
1945 WKID meth_group_end = WK_KLASS_ENUM_NAME(WrongMethodTypeException_klass); | |
1946 initialize_wk_klasses_until(meth_group_start, scan, CHECK); | |
1947 if (EnableMethodHandles) { | |
1948 initialize_wk_klasses_through(meth_group_start, scan, CHECK); | |
1949 } | |
1950 if (_well_known_klasses[meth_group_start] == NULL) { | |
1951 // Skip the rest of the method handle classes, if MethodHandle is not loaded. | |
1952 scan = WKID(meth_group_end+1); | |
1953 } | |
1954 | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1955 initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK); |
0 | 1956 |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1957 _box_klasses[T_BOOLEAN] = WK_KLASS(boolean_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1958 _box_klasses[T_CHAR] = WK_KLASS(char_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1959 _box_klasses[T_FLOAT] = WK_KLASS(float_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1960 _box_klasses[T_DOUBLE] = WK_KLASS(double_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1961 _box_klasses[T_BYTE] = WK_KLASS(byte_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1962 _box_klasses[T_SHORT] = WK_KLASS(short_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1963 _box_klasses[T_INT] = WK_KLASS(int_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1964 _box_klasses[T_LONG] = WK_KLASS(long_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1965 //_box_klasses[T_OBJECT] = WK_KLASS(object_klass); |
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1966 //_box_klasses[T_ARRAY] = WK_KLASS(object_klass); |
0 | 1967 |
1968 #ifdef KERNEL | |
132
60b728ec77c1
6652736: well known classes in system dictionary are inefficiently processed
jrose
parents:
22
diff
changeset
|
1969 if (sun_jkernel_DownloadManager_klass() == NULL) { |
0 | 1970 warning("Cannot find sun/jkernel/DownloadManager"); |
1971 } | |
1972 #endif // KERNEL | |
514 | 1973 |
0 | 1974 { // Compute whether we should use loadClass or loadClassInternal when loading classes. |
1975 methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature()); | |
1976 _has_loadClassInternal = (method != NULL); | |
1977 } | |
1978 { // Compute whether we should use checkPackageAccess or NOT | |
1979 methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature()); | |
1980 _has_checkPackageAccess = (method != NULL); | |
1981 } | |
1982 } | |
1983 | |
1984 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer). | |
1985 // If so, returns the basic type it holds. If not, returns T_OBJECT. | |
1986 BasicType SystemDictionary::box_klass_type(klassOop k) { | |
1987 assert(k != NULL, ""); | |
1988 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { | |
1989 if (_box_klasses[i] == k) | |
1990 return (BasicType)i; | |
1991 } | |
1992 return T_OBJECT; | |
1993 } | |
1994 | |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
1995 KlassHandle SystemDictionaryHandles::box_klass(BasicType t) { |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
1996 if (t >= T_BOOLEAN && t <= T_VOID) |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
1997 return KlassHandle(&SystemDictionary::_box_klasses[t], true); |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
1998 else |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
1999 return KlassHandle(); |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2000 } |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2001 |
0 | 2002 // Constraints on class loaders. The details of the algorithm can be |
2003 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java | |
2004 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is | |
2005 // that the system dictionary needs to maintain a set of contraints that | |
2006 // must be satisfied by all classes in the dictionary. | |
2007 // if defining is true, then LinkageError if already in systemDictionary | |
2008 // if initiating loader, then ok if instanceKlass matches existing entry | |
2009 | |
2010 void SystemDictionary::check_constraints(int d_index, unsigned int d_hash, | |
2011 instanceKlassHandle k, | |
2012 Handle class_loader, bool defining, | |
2013 TRAPS) { | |
2014 const char *linkage_error = NULL; | |
2015 { | |
2016 symbolHandle name (THREAD, k->name()); | |
2017 MutexLocker mu(SystemDictionary_lock, THREAD); | |
2018 | |
2019 klassOop check = find_class(d_index, d_hash, name, class_loader); | |
2020 if (check != (klassOop)NULL) { | |
2021 // if different instanceKlass - duplicate class definition, | |
2022 // else - ok, class loaded by a different thread in parallel, | |
2023 // we should only have found it if it was done loading and ok to use | |
2024 // system dictionary only holds instance classes, placeholders | |
2025 // also holds array classes | |
2026 | |
2027 assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary"); | |
2028 if ((defining == true) || (k() != check)) { | |
2029 linkage_error = "loader (instance of %s): attempted duplicate class " | |
2030 "definition for name: \"%s\""; | |
2031 } else { | |
2032 return; | |
2033 } | |
2034 } | |
2035 | |
2036 #ifdef ASSERT | |
2037 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | |
2038 int p_index = placeholders()->hash_to_index(p_hash); | |
2039 symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader); | |
2040 assert(ph_check == NULL || ph_check == name(), "invalid symbol"); | |
2041 #endif | |
2042 | |
2043 if (linkage_error == NULL) { | |
2044 if (constraints()->check_or_update(k, class_loader, name) == false) { | |
2045 linkage_error = "loader constraint violation: loader (instance of %s)" | |
2046 " previously initiated loading for a different type with name \"%s\""; | |
2047 } | |
2048 } | |
2049 } | |
2050 | |
2051 // Throw error now if needed (cannot throw while holding | |
2052 // SystemDictionary_lock because of rank ordering) | |
2053 | |
2054 if (linkage_error) { | |
2055 ResourceMark rm(THREAD); | |
2056 const char* class_loader_name = loader_name(class_loader()); | |
2057 char* type_name = k->name()->as_C_string(); | |
2058 size_t buflen = strlen(linkage_error) + strlen(class_loader_name) + | |
2059 strlen(type_name); | |
2060 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); | |
2061 jio_snprintf(buf, buflen, linkage_error, class_loader_name, type_name); | |
2062 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); | |
2063 } | |
2064 } | |
2065 | |
2066 | |
2067 // Update system dictionary - done after check_constraint and add_to_hierachy | |
2068 // have been called. | |
2069 void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash, | |
2070 int p_index, unsigned int p_hash, | |
2071 instanceKlassHandle k, | |
2072 Handle class_loader, | |
2073 TRAPS) { | |
2074 // Compile_lock prevents systemDictionary updates during compilations | |
2075 assert_locked_or_safepoint(Compile_lock); | |
2076 symbolHandle name (THREAD, k->name()); | |
2077 | |
2078 { | |
2079 MutexLocker mu1(SystemDictionary_lock, THREAD); | |
2080 | |
2081 // See whether biased locking is enabled and if so set it for this | |
2082 // klass. | |
2083 // Note that this must be done past the last potential blocking | |
2084 // point / safepoint. We enable biased locking lazily using a | |
2085 // VM_Operation to iterate the SystemDictionary and installing the | |
2086 // biasable mark word into each instanceKlass's prototype header. | |
2087 // To avoid race conditions where we accidentally miss enabling the | |
2088 // optimization for one class in the process of being added to the | |
2089 // dictionary, we must not safepoint after the test of | |
2090 // BiasedLocking::enabled(). | |
2091 if (UseBiasedLocking && BiasedLocking::enabled()) { | |
2092 // Set biased locking bit for all loaded classes; it will be | |
2093 // cleared if revocation occurs too often for this type | |
2094 // NOTE that we must only do this when the class is initally | |
2095 // defined, not each time it is referenced from a new class loader | |
2096 if (k->class_loader() == class_loader()) { | |
2097 k->set_prototype_header(markOopDesc::biased_locking_prototype()); | |
2098 } | |
2099 } | |
2100 | |
2101 // Check for a placeholder. If there, remove it and make a | |
2102 // new system dictionary entry. | |
2103 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | |
2104 klassOop sd_check = find_class(d_index, d_hash, name, class_loader); | |
2105 if (sd_check == NULL) { | |
2106 dictionary()->add_klass(name, class_loader, k); | |
2107 notice_modification(); | |
2108 } | |
2109 #ifdef ASSERT | |
2110 sd_check = find_class(d_index, d_hash, name, class_loader); | |
2111 assert (sd_check != NULL, "should have entry in system dictionary"); | |
2112 // Changed to allow PH to remain to complete class circularity checking | |
2113 // while only one thread can define a class at one time, multiple | |
2114 // classes can resolve the superclass for a class at one time, | |
2115 // and the placeholder is used to track that | |
2116 // symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader); | |
2117 // assert (ph_check == NULL, "should not have a placeholder entry"); | |
2118 #endif | |
2119 SystemDictionary_lock->notify_all(); | |
2120 } | |
2121 } | |
2122 | |
2123 | |
2124 klassOop SystemDictionary::find_constrained_instance_or_array_klass( | |
2125 symbolHandle class_name, Handle class_loader, TRAPS) { | |
2126 | |
2127 // First see if it has been loaded directly. | |
2128 // Force the protection domain to be null. (This removes protection checks.) | |
2129 Handle no_protection_domain; | |
2130 klassOop klass = find_instance_or_array_klass(class_name, class_loader, | |
2131 no_protection_domain, CHECK_NULL); | |
2132 if (klass != NULL) | |
2133 return klass; | |
2134 | |
2135 // Now look to see if it has been loaded elsewhere, and is subject to | |
2136 // a loader constraint that would require this loader to return the | |
2137 // klass that is already loaded. | |
2138 if (FieldType::is_array(class_name())) { | |
2139 // Array classes are hard because their klassOops are not kept in the | |
2140 // constraint table. The array klass may be constrained, but the elem class | |
2141 // may not be. | |
2142 jint dimension; | |
2143 symbolOop object_key; | |
2144 BasicType t = FieldType::get_array_info(class_name(), &dimension, | |
2145 &object_key, CHECK_(NULL)); | |
2146 if (t != T_OBJECT) { | |
2147 klass = Universe::typeArrayKlassObj(t); | |
2148 } else { | |
2149 symbolHandle elem_name(THREAD, object_key); | |
2150 MutexLocker mu(SystemDictionary_lock, THREAD); | |
2151 klass = constraints()->find_constrained_elem_klass(class_name, elem_name, class_loader, THREAD); | |
2152 } | |
2153 if (klass != NULL) { | |
2154 klass = Klass::cast(klass)->array_klass_or_null(dimension); | |
2155 } | |
2156 } else { | |
2157 MutexLocker mu(SystemDictionary_lock, THREAD); | |
2158 // Non-array classes are easy: simply check the constraint table. | |
2159 klass = constraints()->find_constrained_klass(class_name, class_loader); | |
2160 } | |
2161 | |
2162 return klass; | |
2163 } | |
2164 | |
2165 | |
2166 bool SystemDictionary::add_loader_constraint(symbolHandle class_name, | |
2167 Handle class_loader1, | |
2168 Handle class_loader2, | |
2169 Thread* THREAD) { | |
2170 unsigned int d_hash1 = dictionary()->compute_hash(class_name, class_loader1); | |
2171 int d_index1 = dictionary()->hash_to_index(d_hash1); | |
2172 | |
2173 unsigned int d_hash2 = dictionary()->compute_hash(class_name, class_loader2); | |
2174 int d_index2 = dictionary()->hash_to_index(d_hash2); | |
2175 | |
2176 { | |
2177 MutexLocker mu_s(SystemDictionary_lock, THREAD); | |
2178 | |
2179 // Better never do a GC while we're holding these oops | |
2180 No_Safepoint_Verifier nosafepoint; | |
2181 | |
2182 klassOop klass1 = find_class(d_index1, d_hash1, class_name, class_loader1); | |
2183 klassOop klass2 = find_class(d_index2, d_hash2, class_name, class_loader2); | |
2184 return constraints()->add_entry(class_name, klass1, class_loader1, | |
2185 klass2, class_loader2); | |
2186 } | |
2187 } | |
2188 | |
2189 // Add entry to resolution error table to record the error when the first | |
2190 // attempt to resolve a reference to a class has failed. | |
2191 void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, symbolHandle error) { | |
2192 unsigned int hash = resolution_errors()->compute_hash(pool, which); | |
2193 int index = resolution_errors()->hash_to_index(hash); | |
2194 { | |
2195 MutexLocker ml(SystemDictionary_lock, Thread::current()); | |
2196 resolution_errors()->add_entry(index, hash, pool, which, error); | |
2197 } | |
2198 } | |
2199 | |
2200 // Lookup resolution error table. Returns error if found, otherwise NULL. | |
2201 symbolOop SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) { | |
2202 unsigned int hash = resolution_errors()->compute_hash(pool, which); | |
2203 int index = resolution_errors()->hash_to_index(hash); | |
2204 { | |
2205 MutexLocker ml(SystemDictionary_lock, Thread::current()); | |
2206 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which); | |
2207 return (entry != NULL) ? entry->error() : (symbolOop)NULL; | |
2208 } | |
2209 } | |
2210 | |
2211 | |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2212 // Signature constraints ensure that callers and callees agree about |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2213 // the meaning of type names in their signatures. This routine is the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2214 // intake for constraints. It collects them from several places: |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2215 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2216 // * LinkResolver::resolve_method (if check_access is true) requires |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2217 // that the resolving class (the caller) and the defining class of |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2218 // the resolved method (the callee) agree on each type in the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2219 // method's signature. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2220 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2221 // * LinkResolver::resolve_interface_method performs exactly the same |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2222 // checks. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2223 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2224 // * LinkResolver::resolve_field requires that the constant pool |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2225 // attempting to link to a field agree with the field's defining |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2226 // class about the type of the field signature. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2227 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2228 // * klassVtable::initialize_vtable requires that, when a class |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2229 // overrides a vtable entry allocated by a superclass, that the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2230 // overriding method (i.e., the callee) agree with the superclass |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2231 // on each type in the method's signature. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2232 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2233 // * klassItable::initialize_itable requires that, when a class fills |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2234 // in its itables, for each non-abstract method installed in an |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2235 // itable, the method (i.e., the callee) agree with the interface |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2236 // on each type in the method's signature. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2237 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2238 // All those methods have a boolean (check_access, checkconstraints) |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2239 // which turns off the checks. This is used from specialized contexts |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2240 // such as bootstrapping, dumping, and debugging. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2241 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2242 // No direct constraint is placed between the class and its |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2243 // supertypes. Constraints are only placed along linked relations |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2244 // between callers and callees. When a method overrides or implements |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2245 // an abstract method in a supertype (superclass or interface), the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2246 // constraints are placed as if the supertype were the caller to the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2247 // overriding method. (This works well, since callers to the |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2248 // supertype have already established agreement between themselves and |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2249 // the supertype.) As a result of all this, a class can disagree with |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2250 // its supertype about the meaning of a type name, as long as that |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2251 // class neither calls a relevant method of the supertype, nor is |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2252 // called (perhaps via an override) from the supertype. |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2253 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2254 // |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2255 // SystemDictionary::check_signature_loaders(sig, l1, l2) |
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2256 // |
0 | 2257 // Make sure all class components (including arrays) in the given |
2258 // signature will be resolved to the same class in both loaders. | |
2259 // Returns the name of the type that failed a loader constraint check, or | |
2260 // NULL if no constraint failed. The returned C string needs cleaning up | |
665
c89f86385056
6814659: separable cleanups and subroutines for 6655638
jrose
parents:
579
diff
changeset
|
2261 // with a ResourceMark in the caller. No exception except OOME is thrown. |
0 | 2262 char* SystemDictionary::check_signature_loaders(symbolHandle signature, |
2263 Handle loader1, Handle loader2, | |
2264 bool is_method, TRAPS) { | |
2265 // Nothing to do if loaders are the same. | |
2266 if (loader1() == loader2()) { | |
2267 return NULL; | |
2268 } | |
2269 | |
2270 SignatureStream sig_strm(signature, is_method); | |
2271 while (!sig_strm.is_done()) { | |
2272 if (sig_strm.is_object()) { | |
2273 symbolOop s = sig_strm.as_symbol(CHECK_NULL); | |
2274 symbolHandle sig (THREAD, s); | |
2275 if (!add_loader_constraint(sig, loader1, loader2, THREAD)) { | |
2276 return sig()->as_C_string(); | |
2277 } | |
2278 } | |
2279 sig_strm.next(); | |
2280 } | |
2281 return NULL; | |
2282 } | |
2283 | |
2284 | |
710 | 2285 methodOop SystemDictionary::find_method_handle_invoke(symbolHandle signature, |
2286 Handle class_loader, | |
2287 Handle protection_domain, | |
2288 TRAPS) { | |
2289 if (!EnableMethodHandles) return NULL; | |
2290 assert(class_loader.is_null() && protection_domain.is_null(), | |
2291 "cannot load specialized versions of MethodHandle.invoke"); | |
2292 if (invoke_method_table() == NULL) { | |
2293 // create this side table lazily | |
2294 _invoke_method_table = new SymbolPropertyTable(_invoke_method_size); | |
2295 } | |
2296 unsigned int hash = invoke_method_table()->compute_hash(signature); | |
2297 int index = invoke_method_table()->hash_to_index(hash); | |
2298 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature); | |
2299 if (spe == NULL || spe->property_oop() == NULL) { | |
2300 // Must create lots of stuff here, but outside of the SystemDictionary lock. | |
2301 Handle mt = compute_method_handle_type(signature(), | |
2302 class_loader, protection_domain, | |
2303 CHECK_NULL); | |
2304 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass(); | |
2305 methodHandle m = methodOopDesc::make_invoke_method(mh_klass, signature, | |
2306 mt, CHECK_NULL); | |
2307 // Now grab the lock. We might have to throw away the new method, | |
2308 // if a racing thread has managed to install one at the same time. | |
2309 { | |
2310 MutexLocker ml(SystemDictionary_lock, Thread::current()); | |
2311 spe = invoke_method_table()->find_entry(index, hash, signature); | |
2312 if (spe == NULL) | |
2313 spe = invoke_method_table()->add_entry(index, hash, signature); | |
2314 if (spe->property_oop() == NULL) | |
2315 spe->set_property_oop(m()); | |
2316 } | |
2317 } | |
2318 methodOop m = (methodOop) spe->property_oop(); | |
2319 assert(m->is_method(), ""); | |
2320 return m; | |
2321 } | |
2322 | |
2323 // Ask Java code to find or construct a java.dyn.MethodType for the given | |
2324 // signature, as interpreted relative to the given class loader. | |
2325 // Because of class loader constraints, all method handle usage must be | |
2326 // consistent with this loader. | |
2327 Handle SystemDictionary::compute_method_handle_type(symbolHandle signature, | |
2328 Handle class_loader, | |
2329 Handle protection_domain, | |
2330 TRAPS) { | |
2331 Handle empty; | |
2332 int npts = ArgumentCount(signature()).size(); | |
2333 objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::class_klass(), npts, CHECK_(empty)); | |
2334 int arg = 0; | |
2335 Handle rt; // the return type from the signature | |
2336 for (SignatureStream ss(signature()); !ss.is_done(); ss.next()) { | |
2337 oop mirror; | |
2338 if (!ss.is_object()) { | |
2339 mirror = Universe::java_mirror(ss.type()); | |
2340 } else { | |
2341 symbolOop name_oop = ss.as_symbol(CHECK_(empty)); | |
2342 symbolHandle name(THREAD, name_oop); | |
2343 klassOop klass = resolve_or_fail(name, | |
2344 class_loader, protection_domain, | |
2345 true, CHECK_(empty)); | |
2346 mirror = Klass::cast(klass)->java_mirror(); | |
2347 } | |
2348 if (ss.at_return_type()) | |
2349 rt = Handle(THREAD, mirror); | |
2350 else | |
2351 pts->obj_at_put(arg++, mirror); | |
2352 } | |
2353 assert(arg == npts, ""); | |
2354 | |
2355 // call MethodType java.dyn.MethodType::makeImpl(Class rt, Class[] pts, false, true) | |
2356 bool varargs = false, trusted = true; | |
2357 JavaCallArguments args(Handle(THREAD, rt())); | |
2358 args.push_oop(pts()); | |
2359 args.push_int(false); | |
2360 args.push_int(trusted); | |
2361 JavaValue result(T_OBJECT); | |
2362 JavaCalls::call_static(&result, | |
2363 SystemDictionary::MethodType_klass(), | |
2364 vmSymbols::makeImpl_name(), vmSymbols::makeImpl_signature(), | |
2365 &args, CHECK_(empty)); | |
2366 return Handle(THREAD, (oop) result.get_jobject()); | |
2367 } | |
2368 | |
2369 | |
0 | 2370 // Since the identity hash code for symbols changes when the symbols are |
2371 // moved from the regular perm gen (hash in the mark word) to the shared | |
2372 // spaces (hash is the address), the classes loaded into the dictionary | |
2373 // may be in the wrong buckets. | |
2374 | |
2375 void SystemDictionary::reorder_dictionary() { | |
2376 dictionary()->reorder_dictionary(); | |
2377 } | |
2378 | |
2379 | |
2380 void SystemDictionary::copy_buckets(char** top, char* end) { | |
2381 dictionary()->copy_buckets(top, end); | |
2382 } | |
2383 | |
2384 | |
2385 void SystemDictionary::copy_table(char** top, char* end) { | |
2386 dictionary()->copy_table(top, end); | |
2387 } | |
2388 | |
2389 | |
2390 void SystemDictionary::reverse() { | |
2391 dictionary()->reverse(); | |
2392 } | |
2393 | |
2394 int SystemDictionary::number_of_classes() { | |
2395 return dictionary()->number_of_entries(); | |
2396 } | |
2397 | |
2398 | |
2399 // ---------------------------------------------------------------------------- | |
2400 #ifndef PRODUCT | |
2401 | |
2402 void SystemDictionary::print() { | |
2403 dictionary()->print(); | |
2404 | |
2405 // Placeholders | |
2406 GCMutexLocker mu(SystemDictionary_lock); | |
2407 placeholders()->print(); | |
2408 | |
2409 // loader constraints - print under SD_lock | |
2410 constraints()->print(); | |
2411 } | |
2412 | |
2413 #endif | |
2414 | |
2415 void SystemDictionary::verify() { | |
2416 guarantee(dictionary() != NULL, "Verify of system dictionary failed"); | |
2417 guarantee(constraints() != NULL, | |
2418 "Verify of loader constraints failed"); | |
2419 guarantee(dictionary()->number_of_entries() >= 0 && | |
2420 placeholders()->number_of_entries() >= 0, | |
2421 "Verify of system dictionary failed"); | |
2422 | |
2423 // Verify dictionary | |
2424 dictionary()->verify(); | |
2425 | |
2426 GCMutexLocker mu(SystemDictionary_lock); | |
2427 placeholders()->verify(); | |
2428 | |
2429 // Verify constraint table | |
2430 guarantee(constraints() != NULL, "Verify of loader constraints failed"); | |
2431 constraints()->verify(dictionary()); | |
2432 } | |
2433 | |
2434 | |
2435 void SystemDictionary::verify_obj_klass_present(Handle obj, | |
2436 symbolHandle class_name, | |
2437 Handle class_loader) { | |
2438 GCMutexLocker mu(SystemDictionary_lock); | |
2439 oop probe = find_class_or_placeholder(class_name, class_loader); | |
2440 if (probe == NULL) { | |
2441 probe = SystemDictionary::find_shared_class(class_name); | |
2442 } | |
2443 guarantee(probe != NULL && | |
2444 (!probe->is_klass() || probe == obj()), | |
2445 "Loaded klasses should be in SystemDictionary"); | |
2446 } | |
2447 | |
2448 #ifndef PRODUCT | |
2449 | |
2450 // statistics code | |
2451 class ClassStatistics: AllStatic { | |
2452 private: | |
2453 static int nclasses; // number of classes | |
2454 static int nmethods; // number of methods | |
2455 static int nmethoddata; // number of methodData | |
2456 static int class_size; // size of class objects in words | |
2457 static int method_size; // size of method objects in words | |
2458 static int debug_size; // size of debug info in methods | |
2459 static int methoddata_size; // size of methodData objects in words | |
2460 | |
2461 static void do_class(klassOop k) { | |
2462 nclasses++; | |
2463 class_size += k->size(); | |
2464 if (k->klass_part()->oop_is_instance()) { | |
2465 instanceKlass* ik = (instanceKlass*)k->klass_part(); | |
2466 class_size += ik->methods()->size(); | |
2467 class_size += ik->constants()->size(); | |
2468 class_size += ik->local_interfaces()->size(); | |
2469 class_size += ik->transitive_interfaces()->size(); | |
2470 // We do not have to count implementors, since we only store one! | |
2471 class_size += ik->fields()->size(); | |
2472 } | |
2473 } | |
2474 | |
2475 static void do_method(methodOop m) { | |
2476 nmethods++; | |
2477 method_size += m->size(); | |
2478 // class loader uses same objArray for empty vectors, so don't count these | |
2479 if (m->exception_table()->length() != 0) method_size += m->exception_table()->size(); | |
2480 if (m->has_stackmap_table()) { | |
2481 method_size += m->stackmap_data()->size(); | |
2482 } | |
2483 | |
2484 methodDataOop mdo = m->method_data(); | |
2485 if (mdo != NULL) { | |
2486 nmethoddata++; | |
2487 methoddata_size += mdo->size(); | |
2488 } | |
2489 } | |
2490 | |
2491 public: | |
2492 static void print() { | |
2493 SystemDictionary::classes_do(do_class); | |
2494 SystemDictionary::methods_do(do_method); | |
2495 tty->print_cr("Class statistics:"); | |
2496 tty->print_cr("%d classes (%d bytes)", nclasses, class_size * oopSize); | |
2497 tty->print_cr("%d methods (%d bytes = %d base + %d debug info)", nmethods, | |
2498 (method_size + debug_size) * oopSize, method_size * oopSize, debug_size * oopSize); | |
2499 tty->print_cr("%d methoddata (%d bytes)", nmethoddata, methoddata_size * oopSize); | |
2500 } | |
2501 }; | |
2502 | |
2503 | |
2504 int ClassStatistics::nclasses = 0; | |
2505 int ClassStatistics::nmethods = 0; | |
2506 int ClassStatistics::nmethoddata = 0; | |
2507 int ClassStatistics::class_size = 0; | |
2508 int ClassStatistics::method_size = 0; | |
2509 int ClassStatistics::debug_size = 0; | |
2510 int ClassStatistics::methoddata_size = 0; | |
2511 | |
2512 void SystemDictionary::print_class_statistics() { | |
2513 ResourceMark rm; | |
2514 ClassStatistics::print(); | |
2515 } | |
2516 | |
2517 | |
2518 class MethodStatistics: AllStatic { | |
2519 public: | |
2520 enum { | |
2521 max_parameter_size = 10 | |
2522 }; | |
2523 private: | |
2524 | |
2525 static int _number_of_methods; | |
2526 static int _number_of_final_methods; | |
2527 static int _number_of_static_methods; | |
2528 static int _number_of_native_methods; | |
2529 static int _number_of_synchronized_methods; | |
2530 static int _number_of_profiled_methods; | |
2531 static int _number_of_bytecodes; | |
2532 static int _parameter_size_profile[max_parameter_size]; | |
2533 static int _bytecodes_profile[Bytecodes::number_of_java_codes]; | |
2534 | |
2535 static void initialize() { | |
2536 _number_of_methods = 0; | |
2537 _number_of_final_methods = 0; | |
2538 _number_of_static_methods = 0; | |
2539 _number_of_native_methods = 0; | |
2540 _number_of_synchronized_methods = 0; | |
2541 _number_of_profiled_methods = 0; | |
2542 _number_of_bytecodes = 0; | |
2543 for (int i = 0; i < max_parameter_size ; i++) _parameter_size_profile[i] = 0; | |
2544 for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile [j] = 0; | |
2545 }; | |
2546 | |
2547 static void do_method(methodOop m) { | |
2548 _number_of_methods++; | |
2549 // collect flag info | |
2550 if (m->is_final() ) _number_of_final_methods++; | |
2551 if (m->is_static() ) _number_of_static_methods++; | |
2552 if (m->is_native() ) _number_of_native_methods++; | |
2553 if (m->is_synchronized()) _number_of_synchronized_methods++; | |
2554 if (m->method_data() != NULL) _number_of_profiled_methods++; | |
2555 // collect parameter size info (add one for receiver, if any) | |
2556 _parameter_size_profile[MIN2(m->size_of_parameters() + (m->is_static() ? 0 : 1), max_parameter_size - 1)]++; | |
2557 // collect bytecodes info | |
2558 { | |
2559 Thread *thread = Thread::current(); | |
2560 HandleMark hm(thread); | |
2561 BytecodeStream s(methodHandle(thread, m)); | |
2562 Bytecodes::Code c; | |
2563 while ((c = s.next()) >= 0) { | |
2564 _number_of_bytecodes++; | |
2565 _bytecodes_profile[c]++; | |
2566 } | |
2567 } | |
2568 } | |
2569 | |
2570 public: | |
2571 static void print() { | |
2572 initialize(); | |
2573 SystemDictionary::methods_do(do_method); | |
2574 // generate output | |
2575 tty->cr(); | |
2576 tty->print_cr("Method statistics (static):"); | |
2577 // flag distribution | |
2578 tty->cr(); | |
2579 tty->print_cr("%6d final methods %6.1f%%", _number_of_final_methods , _number_of_final_methods * 100.0F / _number_of_methods); | |
2580 tty->print_cr("%6d static methods %6.1f%%", _number_of_static_methods , _number_of_static_methods * 100.0F / _number_of_methods); | |
2581 tty->print_cr("%6d native methods %6.1f%%", _number_of_native_methods , _number_of_native_methods * 100.0F / _number_of_methods); | |
2582 tty->print_cr("%6d synchronized methods %6.1f%%", _number_of_synchronized_methods, _number_of_synchronized_methods * 100.0F / _number_of_methods); | |
2583 tty->print_cr("%6d profiled methods %6.1f%%", _number_of_profiled_methods, _number_of_profiled_methods * 100.0F / _number_of_methods); | |
2584 // parameter size profile | |
2585 tty->cr(); | |
2586 { int tot = 0; | |
2587 int avg = 0; | |
2588 for (int i = 0; i < max_parameter_size; i++) { | |
2589 int n = _parameter_size_profile[i]; | |
2590 tot += n; | |
2591 avg += n*i; | |
2592 tty->print_cr("parameter size = %1d: %6d methods %5.1f%%", i, n, n * 100.0F / _number_of_methods); | |
2593 } | |
2594 assert(tot == _number_of_methods, "should be the same"); | |
2595 tty->print_cr(" %6d methods 100.0%%", _number_of_methods); | |
2596 tty->print_cr("(average parameter size = %3.1f including receiver, if any)", (float)avg / _number_of_methods); | |
2597 } | |
2598 // bytecodes profile | |
2599 tty->cr(); | |
2600 { int tot = 0; | |
2601 for (int i = 0; i < Bytecodes::number_of_java_codes; i++) { | |
2602 if (Bytecodes::is_defined(i)) { | |
2603 Bytecodes::Code c = Bytecodes::cast(i); | |
2604 int n = _bytecodes_profile[c]; | |
2605 tot += n; | |
2606 tty->print_cr("%9d %7.3f%% %s", n, n * 100.0F / _number_of_bytecodes, Bytecodes::name(c)); | |
2607 } | |
2608 } | |
2609 assert(tot == _number_of_bytecodes, "should be the same"); | |
2610 tty->print_cr("%9d 100.000%%", _number_of_bytecodes); | |
2611 } | |
2612 tty->cr(); | |
2613 } | |
2614 }; | |
2615 | |
2616 int MethodStatistics::_number_of_methods; | |
2617 int MethodStatistics::_number_of_final_methods; | |
2618 int MethodStatistics::_number_of_static_methods; | |
2619 int MethodStatistics::_number_of_native_methods; | |
2620 int MethodStatistics::_number_of_synchronized_methods; | |
2621 int MethodStatistics::_number_of_profiled_methods; | |
2622 int MethodStatistics::_number_of_bytecodes; | |
2623 int MethodStatistics::_parameter_size_profile[MethodStatistics::max_parameter_size]; | |
2624 int MethodStatistics::_bytecodes_profile[Bytecodes::number_of_java_codes]; | |
2625 | |
2626 | |
2627 void SystemDictionary::print_method_statistics() { | |
2628 MethodStatistics::print(); | |
2629 } | |
2630 | |
2631 #endif // PRODUCT |