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