Mercurial > hg > graal-jvmci-8
comparison src/share/vm/classfile/systemDictionary.cpp @ 6948:e522a00b91aa
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 12 Nov 2012 23:14:12 +0100 |
parents | 957c266d8bc5 633ba56cb013 |
children | 2cb439954abf |
comparison
equal
deleted
inserted
replaced
6711:ae13cc658b80 | 6948:e522a00b91aa |
---|---|
21 * questions. | 21 * questions. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "classfile/classLoaderData.inline.hpp" | |
26 #include "classfile/dictionary.hpp" | 27 #include "classfile/dictionary.hpp" |
27 #include "classfile/javaClasses.hpp" | 28 #include "classfile/javaClasses.hpp" |
28 #include "classfile/loaderConstraints.hpp" | 29 #include "classfile/loaderConstraints.hpp" |
29 #include "classfile/placeholders.hpp" | 30 #include "classfile/placeholders.hpp" |
30 #include "classfile/resolutionErrors.hpp" | 31 #include "classfile/resolutionErrors.hpp" |
36 #include "memory/gcLocker.hpp" | 37 #include "memory/gcLocker.hpp" |
37 #include "memory/oopFactory.hpp" | 38 #include "memory/oopFactory.hpp" |
38 #include "oops/instanceKlass.hpp" | 39 #include "oops/instanceKlass.hpp" |
39 #include "oops/instanceRefKlass.hpp" | 40 #include "oops/instanceRefKlass.hpp" |
40 #include "oops/klass.inline.hpp" | 41 #include "oops/klass.inline.hpp" |
41 #include "oops/methodDataOop.hpp" | 42 #include "oops/methodData.hpp" |
42 #include "oops/objArrayKlass.hpp" | 43 #include "oops/objArrayKlass.hpp" |
43 #include "oops/oop.inline.hpp" | 44 #include "oops/oop.inline.hpp" |
44 #include "oops/oop.inline2.hpp" | 45 #include "oops/oop.inline2.hpp" |
45 #include "oops/typeArrayKlass.hpp" | 46 #include "oops/typeArrayKlass.hpp" |
46 #include "prims/jvmtiEnvBase.hpp" | 47 #include "prims/jvmtiEnvBase.hpp" |
69 const int SystemDictionary::_primelist[_prime_array_size] = {1009,2017,4049,5051,10103, | 70 const int SystemDictionary::_primelist[_prime_array_size] = {1009,2017,4049,5051,10103, |
70 20201,40423,99991}; | 71 20201,40423,99991}; |
71 | 72 |
72 oop SystemDictionary::_system_loader_lock_obj = NULL; | 73 oop SystemDictionary::_system_loader_lock_obj = NULL; |
73 | 74 |
74 klassOop SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT] | 75 Klass* SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT] |
75 = { NULL /*, NULL...*/ }; | 76 = { NULL /*, NULL...*/ }; |
76 | 77 |
77 klassOop SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ }; | 78 Klass* SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ }; |
78 | 79 |
79 oop SystemDictionary::_java_system_loader = NULL; | 80 oop SystemDictionary::_java_system_loader = NULL; |
80 | 81 |
81 bool SystemDictionary::_has_loadClassInternal = false; | 82 bool SystemDictionary::_has_loadClassInternal = false; |
82 bool SystemDictionary::_has_checkPackageAccess = false; | 83 bool SystemDictionary::_has_checkPackageAccess = false; |
83 | 84 |
84 // lazily initialized klass variables | 85 // lazily initialized klass variables |
85 volatile klassOop SystemDictionary::_abstract_ownable_synchronizer_klass = NULL; | 86 Klass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL; |
86 | 87 |
87 | 88 |
88 // ---------------------------------------------------------------------------- | 89 // ---------------------------------------------------------------------------- |
89 // Java-level SystemLoader | 90 // Java-level SystemLoader |
90 | 91 |
103 | 104 |
104 _java_system_loader = (oop)result.get_jobject(); | 105 _java_system_loader = (oop)result.get_jobject(); |
105 } | 106 } |
106 | 107 |
107 | 108 |
109 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader) { | |
110 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data(); | |
111 return ClassLoaderDataGraph::find_or_create(class_loader); | |
112 } | |
113 | |
108 // ---------------------------------------------------------------------------- | 114 // ---------------------------------------------------------------------------- |
109 // debugging | 115 // debugging |
110 | 116 |
111 #ifdef ASSERT | 117 #ifdef ASSERT |
112 | 118 |
143 // ---------------------------------------------------------------------------- | 149 // ---------------------------------------------------------------------------- |
144 // Resolving of classes | 150 // Resolving of classes |
145 | 151 |
146 // Forwards to resolve_or_null | 152 // Forwards to resolve_or_null |
147 | 153 |
148 klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { | 154 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { |
149 klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); | 155 Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); |
150 if (HAS_PENDING_EXCEPTION || klass == NULL) { | 156 if (HAS_PENDING_EXCEPTION || klass == NULL) { |
151 KlassHandle k_h(THREAD, klass); | 157 KlassHandle k_h(THREAD, klass); |
152 // can return a null klass | 158 // can return a null klass |
153 klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD); | 159 klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD); |
154 } | 160 } |
155 return klass; | 161 return klass; |
156 } | 162 } |
157 | 163 |
158 klassOop SystemDictionary::handle_resolution_exception(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) { | 164 Klass* SystemDictionary::handle_resolution_exception(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) { |
159 if (HAS_PENDING_EXCEPTION) { | 165 if (HAS_PENDING_EXCEPTION) { |
160 // If we have a pending exception we forward it to the caller, unless throw_error is true, | 166 // If we have a pending exception we forward it to the caller, unless throw_error is true, |
161 // in which case we have to check whether the pending exception is a ClassNotFoundException, | 167 // in which case we have to check whether the pending exception is a ClassNotFoundException, |
162 // and if so convert it to a NoClassDefFoundError | 168 // and if so convert it to a NoClassDefFoundError |
163 // And chain the original ClassNotFoundException | 169 // And chain the original ClassNotFoundException |
178 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); | 184 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); |
179 } else { | 185 } else { |
180 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); | 186 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); |
181 } | 187 } |
182 } | 188 } |
183 return (klassOop)klass_h(); | 189 return (Klass*)klass_h(); |
184 } | 190 } |
185 | 191 |
186 | 192 |
187 klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, | 193 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, |
188 bool throw_error, TRAPS) | 194 bool throw_error, TRAPS) |
189 { | 195 { |
190 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD); | 196 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD); |
191 } | 197 } |
192 | 198 |
193 | 199 |
194 // Forwards to resolve_instance_class_or_null | 200 // Forwards to resolve_instance_class_or_null |
195 | 201 |
196 klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) { | 202 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) { |
197 assert(!THREAD->is_Compiler_thread(), | 203 assert(!THREAD->is_Compiler_thread(), |
198 err_msg("can not load classes with compiler thread: class=%s, classloader=%s", | 204 err_msg("can not load classes with compiler thread: class=%s, classloader=%s", |
199 class_name->as_C_string(), | 205 class_name->as_C_string(), |
200 class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string())); | 206 class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string())); |
201 if (FieldType::is_array(class_name)) { | 207 if (FieldType::is_array(class_name)) { |
202 return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); | 208 return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); |
203 } else if (FieldType::is_obj(class_name)) { | 209 } else if (FieldType::is_obj(class_name)) { |
204 ResourceMark rm(THREAD); | 210 ResourceMark rm(THREAD); |
205 // Ignore wrapping L and ;. | 211 // Ignore wrapping L and ;. |
209 } else { | 215 } else { |
210 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); | 216 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); |
211 } | 217 } |
212 } | 218 } |
213 | 219 |
214 klassOop SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) { | 220 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) { |
215 return resolve_or_null(class_name, Handle(), Handle(), THREAD); | 221 return resolve_or_null(class_name, Handle(), Handle(), THREAD); |
216 } | 222 } |
217 | 223 |
218 // Forwards to resolve_instance_class_or_null | 224 // Forwards to resolve_instance_class_or_null |
219 | 225 |
220 klassOop SystemDictionary::resolve_array_class_or_null(Symbol* class_name, | 226 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name, |
221 Handle class_loader, | 227 Handle class_loader, |
222 Handle protection_domain, | 228 Handle protection_domain, |
223 TRAPS) { | 229 TRAPS) { |
224 assert(FieldType::is_array(class_name), "must be array"); | 230 assert(FieldType::is_array(class_name), "must be array"); |
225 klassOop k = NULL; | 231 Klass* k = NULL; |
226 FieldArrayInfo fd; | 232 FieldArrayInfo fd; |
227 // dimension and object_key in FieldArrayInfo are assigned as a side-effect | 233 // dimension and object_key in FieldArrayInfo are assigned as a side-effect |
228 // of this call | 234 // of this call |
229 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL); | 235 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL); |
230 if (t == T_OBJECT) { | 236 if (t == T_OBJECT) { |
236 if (k != NULL) { | 242 if (k != NULL) { |
237 k = Klass::cast(k)->array_klass(fd.dimension(), CHECK_NULL); | 243 k = Klass::cast(k)->array_klass(fd.dimension(), CHECK_NULL); |
238 } | 244 } |
239 } else { | 245 } else { |
240 k = Universe::typeArrayKlassObj(t); | 246 k = Universe::typeArrayKlassObj(t); |
241 k = typeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL); | 247 k = TypeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL); |
242 } | 248 } |
243 return k; | 249 return k; |
244 } | 250 } |
245 | 251 |
246 | 252 |
277 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2 | 283 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2 |
278 // 4.4 finds T2, Super -> throws class circularity | 284 // 4.4 finds T2, Super -> throws class circularity |
279 // Must be called, even if superclass is null, since this is | 285 // Must be called, even if superclass is null, since this is |
280 // where the placeholder entry is created which claims this | 286 // where the placeholder entry is created which claims this |
281 // thread is loading this class/classloader. | 287 // thread is loading this class/classloader. |
282 klassOop SystemDictionary::resolve_super_or_fail(Symbol* child_name, | 288 Klass* SystemDictionary::resolve_super_or_fail(Symbol* child_name, |
283 Symbol* class_name, | 289 Symbol* class_name, |
284 Handle class_loader, | 290 Handle class_loader, |
285 Handle protection_domain, | 291 Handle protection_domain, |
286 bool is_superclass, | 292 bool is_superclass, |
287 TRAPS) { | 293 TRAPS) { |
288 | |
289 // Try to get one of the well-known klasses. | |
290 // They are trusted, and do not participate in circularities. | |
291 if (LinkWellKnownClasses) { | |
292 klassOop k = find_well_known_klass(class_name); | |
293 if (k != NULL) { | |
294 return k; | |
295 } | |
296 } | |
297 | |
298 // Double-check, if child class is already loaded, just return super-class,interface | 294 // Double-check, if child class is already loaded, just return super-class,interface |
299 // Don't add a placedholder if already loaded, i.e. already in system dictionary | 295 // Don't add a placedholder if already loaded, i.e. already in system dictionary |
300 // Make sure there's a placeholder for the *child* before resolving. | 296 // Make sure there's a placeholder for the *child* before resolving. |
301 // Used as a claim that this thread is currently loading superclass/classloader | 297 // Used as a claim that this thread is currently loading superclass/classloader |
302 // Used here for ClassCircularity checks and also for heap verification | 298 // Used here for ClassCircularity checks and also for heap verification |
303 // (every instanceKlass in the heap needs to be in the system dictionary | 299 // (every InstanceKlass in the heap needs to be in the system dictionary |
304 // or have a placeholder). | 300 // or have a placeholder). |
305 // Must check ClassCircularity before checking if super class is already loaded | 301 // Must check ClassCircularity before checking if super class is already loaded |
306 // | 302 // |
307 // We might not already have a placeholder if this child_name was | 303 // We might not already have a placeholder if this child_name was |
308 // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass); | 304 // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass); |
309 // the name of the class might not be known until the stream is actually | 305 // the name of the class might not be known until the stream is actually |
310 // parsed. | 306 // parsed. |
311 // Bugs 4643874, 4715493 | 307 // Bugs 4643874, 4715493 |
312 // compute_hash can have a safepoint | 308 // compute_hash can have a safepoint |
313 | 309 |
314 unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader); | 310 ClassLoaderData* loader_data = class_loader_data(class_loader); |
311 unsigned int d_hash = dictionary()->compute_hash(child_name, loader_data); | |
315 int d_index = dictionary()->hash_to_index(d_hash); | 312 int d_index = dictionary()->hash_to_index(d_hash); |
316 unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader); | 313 unsigned int p_hash = placeholders()->compute_hash(child_name, loader_data); |
317 int p_index = placeholders()->hash_to_index(p_hash); | 314 int p_index = placeholders()->hash_to_index(p_hash); |
318 // can't throw error holding a lock | 315 // can't throw error holding a lock |
319 bool child_already_loaded = false; | 316 bool child_already_loaded = false; |
320 bool throw_circularity_error = false; | 317 bool throw_circularity_error = false; |
321 { | 318 { |
322 MutexLocker mu(SystemDictionary_lock, THREAD); | 319 MutexLocker mu(SystemDictionary_lock, THREAD); |
323 klassOop childk = find_class(d_index, d_hash, child_name, class_loader); | 320 Klass* childk = find_class(d_index, d_hash, child_name, loader_data); |
324 klassOop quicksuperk; | 321 Klass* quicksuperk; |
325 // to support // loading: if child done loading, just return superclass | 322 // to support // loading: if child done loading, just return superclass |
326 // if class_name, & class_loader don't match: | 323 // if class_name, & class_loader don't match: |
327 // if initial define, SD update will give LinkageError | 324 // if initial define, SD update will give LinkageError |
328 // if redefine: compare_class_versions will give HIERARCHY_CHANGED | 325 // if redefine: compare_class_versions will give HIERARCHY_CHANGED |
329 // so we don't throw an exception here. | 326 // so we don't throw an exception here. |
330 // see: nsk redefclass014 & java.lang.instrument Instrument032 | 327 // see: nsk redefclass014 & java.lang.instrument Instrument032 |
331 if ((childk != NULL ) && (is_superclass) && | 328 if ((childk != NULL ) && (is_superclass) && |
332 ((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) && | 329 ((quicksuperk = InstanceKlass::cast(childk)->super()) != NULL) && |
333 | 330 |
334 ((Klass::cast(quicksuperk)->name() == class_name) && | 331 ((Klass::cast(quicksuperk)->name() == class_name) && |
335 (Klass::cast(quicksuperk)->class_loader() == class_loader()))) { | 332 (Klass::cast(quicksuperk)->class_loader() == class_loader()))) { |
336 return quicksuperk; | 333 return quicksuperk; |
337 } else { | 334 } else { |
338 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); | 335 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data); |
339 if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) { | 336 if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) { |
340 throw_circularity_error = true; | 337 throw_circularity_error = true; |
341 } | 338 } |
342 } | 339 } |
343 if (!throw_circularity_error) { | 340 if (!throw_circularity_error) { |
344 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, class_loader, PlaceholderTable::LOAD_SUPER, class_name, THREAD); | 341 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, class_name, THREAD); |
345 } | 342 } |
346 } | 343 } |
347 if (throw_circularity_error) { | 344 if (throw_circularity_error) { |
348 ResourceMark rm(THREAD); | 345 ResourceMark rm(THREAD); |
349 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); | 346 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); |
350 } | 347 } |
351 | 348 |
352 // java.lang.Object should have been found above | 349 // java.lang.Object should have been found above |
353 assert(class_name != NULL, "null super class for resolving"); | 350 assert(class_name != NULL, "null super class for resolving"); |
354 // Resolve the super class or interface, check results on return | 351 // Resolve the super class or interface, check results on return |
355 klassOop superk = NULL; | 352 Klass* superk = NULL; |
356 superk = SystemDictionary::resolve_or_null(class_name, | 353 superk = SystemDictionary::resolve_or_null(class_name, |
357 class_loader, | 354 class_loader, |
358 protection_domain, | 355 protection_domain, |
359 THREAD); | 356 THREAD); |
360 | 357 |
363 // Note: clean up of placeholders currently in callers of | 360 // Note: clean up of placeholders currently in callers of |
364 // resolve_super_or_fail - either at update_dictionary time | 361 // resolve_super_or_fail - either at update_dictionary time |
365 // or on error | 362 // or on error |
366 { | 363 { |
367 MutexLocker mu(SystemDictionary_lock, THREAD); | 364 MutexLocker mu(SystemDictionary_lock, THREAD); |
368 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); | 365 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data); |
369 if (probe != NULL) { | 366 if (probe != NULL) { |
370 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER); | 367 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER); |
371 } | 368 } |
372 } | 369 } |
373 if (HAS_PENDING_EXCEPTION || superk_h() == NULL) { | 370 if (HAS_PENDING_EXCEPTION || superk_h() == NULL) { |
391 tty->print_cr("Checking package access"); | 388 tty->print_cr("Checking package access"); |
392 tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr(); | 389 tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr(); |
393 tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr(); | 390 tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr(); |
394 tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr(); | 391 tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr(); |
395 } | 392 } |
396 | |
397 assert(class_loader() != NULL, "should not have non-null protection domain for null classloader"); | |
398 | 393 |
399 KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass()); | 394 KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass()); |
400 JavaCalls::call_special(&result, | 395 JavaCalls::call_special(&result, |
401 class_loader, | 396 class_loader, |
402 system_loader, | 397 system_loader, |
420 // If no exception has been thrown, we have validated the protection domain | 415 // If no exception has been thrown, we have validated the protection domain |
421 // Insert the protection domain of the initiating class into the set. | 416 // Insert the protection domain of the initiating class into the set. |
422 { | 417 { |
423 // We recalculate the entry here -- we've called out to java since | 418 // We recalculate the entry here -- we've called out to java since |
424 // the last time it was calculated. | 419 // the last time it was calculated. |
420 ClassLoaderData* loader_data = class_loader_data(class_loader); | |
421 | |
425 Symbol* kn = klass->name(); | 422 Symbol* kn = klass->name(); |
426 unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); | 423 unsigned int d_hash = dictionary()->compute_hash(kn, loader_data); |
427 int d_index = dictionary()->hash_to_index(d_hash); | 424 int d_index = dictionary()->hash_to_index(d_hash); |
428 | 425 |
429 MutexLocker mu(SystemDictionary_lock, THREAD); | 426 MutexLocker mu(SystemDictionary_lock, THREAD); |
430 { | 427 { |
431 // Note that we have an entry, and entries can be deleted only during GC, | 428 // Note that we have an entry, and entries can be deleted only during GC, |
434 // We're using a No_Safepoint_Verifier to catch any place where we | 431 // We're using a No_Safepoint_Verifier to catch any place where we |
435 // might potentially do a GC at all. | 432 // might potentially do a GC at all. |
436 // SystemDictionary::do_unloading() asserts that classes are only | 433 // SystemDictionary::do_unloading() asserts that classes are only |
437 // unloaded at a safepoint. | 434 // unloaded at a safepoint. |
438 No_Safepoint_Verifier nosafepoint; | 435 No_Safepoint_Verifier nosafepoint; |
439 dictionary()->add_protection_domain(d_index, d_hash, klass, class_loader, | 436 dictionary()->add_protection_domain(d_index, d_hash, klass, loader_data, |
440 protection_domain, THREAD); | 437 protection_domain, THREAD); |
441 } | 438 } |
442 } | 439 } |
443 } | 440 } |
444 | 441 |
491 // even in non-circularity situations. | 488 // even in non-circularity situations. |
492 // Note: only one thread can define the class, but multiple can resolve | 489 // Note: only one thread can define the class, but multiple can resolve |
493 // Note: must call resolve_super_or_fail even if null super - | 490 // Note: must call resolve_super_or_fail even if null super - |
494 // to force placeholder entry creation for this class for circularity detection | 491 // to force placeholder entry creation for this class for circularity detection |
495 // Caller must check for pending exception | 492 // Caller must check for pending exception |
496 // Returns non-null klassOop if other thread has completed load | 493 // Returns non-null Klass* if other thread has completed load |
497 // and we are done, | 494 // and we are done, |
498 // If return null klassOop and no pending exception, the caller must load the class | 495 // If return null Klass* and no pending exception, the caller must load the class |
499 instanceKlassHandle SystemDictionary::handle_parallel_super_load( | 496 instanceKlassHandle SystemDictionary::handle_parallel_super_load( |
500 Symbol* name, Symbol* superclassname, Handle class_loader, | 497 Symbol* name, Symbol* superclassname, Handle class_loader, |
501 Handle protection_domain, Handle lockObject, TRAPS) { | 498 Handle protection_domain, Handle lockObject, TRAPS) { |
502 | 499 |
503 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | 500 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
504 unsigned int d_hash = dictionary()->compute_hash(name, class_loader); | 501 ClassLoaderData* loader_data = class_loader_data(class_loader); |
502 unsigned int d_hash = dictionary()->compute_hash(name, loader_data); | |
505 int d_index = dictionary()->hash_to_index(d_hash); | 503 int d_index = dictionary()->hash_to_index(d_hash); |
506 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | 504 unsigned int p_hash = placeholders()->compute_hash(name, loader_data); |
507 int p_index = placeholders()->hash_to_index(p_hash); | 505 int p_index = placeholders()->hash_to_index(p_hash); |
508 | 506 |
509 // superk is not used, resolve_super called for circularity check only | 507 // superk is not used, resolve_super called for circularity check only |
510 // This code is reached in two situations. One if this thread | 508 // This code is reached in two situations. One if this thread |
511 // is loading the same class twice (e.g. ClassCircularity, or | 509 // is loading the same class twice (e.g. ClassCircularity, or |
512 // java.lang.instrument). | 510 // java.lang.instrument). |
513 // The second is if another thread started the resolve_super first | 511 // The second is if another thread started the resolve_super first |
514 // and has not yet finished. | 512 // and has not yet finished. |
515 // In both cases the original caller will clean up the placeholder | 513 // In both cases the original caller will clean up the placeholder |
516 // entry on error. | 514 // entry on error. |
517 klassOop superk = SystemDictionary::resolve_super_or_fail(name, | 515 Klass* superk = SystemDictionary::resolve_super_or_fail(name, |
518 superclassname, | 516 superclassname, |
519 class_loader, | 517 class_loader, |
520 protection_domain, | 518 protection_domain, |
521 true, | 519 true, |
522 CHECK_(nh)); | 520 CHECK_(nh)); |
523 // We don't redefine the class, so we just need to clean up if there | 521 // We don't redefine the class, so we just need to clean up if there |
524 // was not an error (don't want to modify any system dictionary | 522 // was not an error (don't want to modify any system dictionary |
525 // data structures). | 523 // data structures). |
526 { | 524 { |
527 MutexLocker mu(SystemDictionary_lock, THREAD); | 525 MutexLocker mu(SystemDictionary_lock, THREAD); |
528 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | 526 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); |
529 SystemDictionary_lock->notify_all(); | 527 SystemDictionary_lock->notify_all(); |
530 } | 528 } |
531 | 529 |
532 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete | 530 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete |
533 // Serial class loaders and bootstrap classloader do wait for superclass loads | 531 // Serial class loaders and bootstrap classloader do wait for superclass loads |
534 if (!class_loader.is_null() && is_parallelCapable(class_loader)) { | 532 if (!class_loader.is_null() && is_parallelCapable(class_loader)) { |
535 MutexLocker mu(SystemDictionary_lock, THREAD); | 533 MutexLocker mu(SystemDictionary_lock, THREAD); |
536 // Check if classloading completed while we were loading superclass or waiting | 534 // Check if classloading completed while we were loading superclass or waiting |
537 klassOop check = find_class(d_index, d_hash, name, class_loader); | 535 Klass* check = find_class(d_index, d_hash, name, loader_data); |
538 if (check != NULL) { | 536 if (check != NULL) { |
539 // Klass is already loaded, so just return it | 537 // Klass is already loaded, so just return it |
540 return(instanceKlassHandle(THREAD, check)); | 538 return(instanceKlassHandle(THREAD, check)); |
541 } else { | 539 } else { |
542 return nh; | 540 return nh; |
548 bool super_load_in_progress = true; | 546 bool super_load_in_progress = true; |
549 PlaceholderEntry* placeholder; | 547 PlaceholderEntry* placeholder; |
550 while (super_load_in_progress) { | 548 while (super_load_in_progress) { |
551 MutexLocker mu(SystemDictionary_lock, THREAD); | 549 MutexLocker mu(SystemDictionary_lock, THREAD); |
552 // Check if classloading completed while we were loading superclass or waiting | 550 // Check if classloading completed while we were loading superclass or waiting |
553 klassOop check = find_class(d_index, d_hash, name, class_loader); | 551 Klass* check = find_class(d_index, d_hash, name, loader_data); |
554 if (check != NULL) { | 552 if (check != NULL) { |
555 // Klass is already loaded, so just return it | 553 // Klass is already loaded, so just return it |
556 return(instanceKlassHandle(THREAD, check)); | 554 return(instanceKlassHandle(THREAD, check)); |
557 } else { | 555 } else { |
558 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); | 556 placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
559 if (placeholder && placeholder->super_load_in_progress() ){ | 557 if (placeholder && placeholder->super_load_in_progress() ){ |
560 // Before UnsyncloadClass: | 558 // Before UnsyncloadClass: |
561 // We only get here if the application has released the | 559 // We only get here if the application has released the |
562 // classloader lock when another thread was in the middle of loading a | 560 // classloader lock when another thread was in the middle of loading a |
563 // superclass/superinterface for this class, and now | 561 // superclass/superinterface for this class, and now |
566 // load a class should be the one to complete the loading | 564 // load a class should be the one to complete the loading |
567 // with the classfile it initially expected. | 565 // with the classfile it initially expected. |
568 // This logic has the current thread wait once it has done | 566 // This logic has the current thread wait once it has done |
569 // all the superclass/superinterface loading it can, until | 567 // all the superclass/superinterface loading it can, until |
570 // the original thread completes the class loading or fails | 568 // the original thread completes the class loading or fails |
571 // If it completes we will use the resulting instanceKlass | 569 // If it completes we will use the resulting InstanceKlass |
572 // which we will find below in the systemDictionary. | 570 // which we will find below in the systemDictionary. |
573 // We also get here for parallel bootstrap classloader | 571 // We also get here for parallel bootstrap classloader |
574 if (class_loader.is_null()) { | 572 if (class_loader.is_null()) { |
575 SystemDictionary_lock->wait(); | 573 SystemDictionary_lock->wait(); |
576 } else { | 574 } else { |
584 } | 582 } |
585 return (nh); | 583 return (nh); |
586 } | 584 } |
587 | 585 |
588 | 586 |
589 klassOop SystemDictionary::resolve_instance_class_or_null(Symbol* name, Handle class_loader, Handle protection_domain, TRAPS) { | 587 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name, Handle class_loader, Handle protection_domain, TRAPS) { |
590 assert(name != NULL && !FieldType::is_array(name) && | 588 assert(name != NULL && !FieldType::is_array(name) && |
591 !FieldType::is_obj(name), "invalid class name"); | 589 !FieldType::is_obj(name), "invalid class name"); |
592 | 590 |
593 // UseNewReflection | 591 // UseNewReflection |
594 // Fix for 4474172; see evaluation for more details | 592 // Fix for 4474172; see evaluation for more details |
595 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); | 593 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
594 ClassLoaderData *loader_data = register_loader(class_loader); | |
596 | 595 |
597 // Do lookup to see if class already exist and the protection domain | 596 // Do lookup to see if class already exist and the protection domain |
598 // has the right access | 597 // has the right access |
599 unsigned int d_hash = dictionary()->compute_hash(name, class_loader); | 598 unsigned int d_hash = dictionary()->compute_hash(name, loader_data); |
600 int d_index = dictionary()->hash_to_index(d_hash); | 599 int d_index = dictionary()->hash_to_index(d_hash); |
601 klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader, | 600 Klass* probe = dictionary()->find(d_index, d_hash, name, loader_data, |
602 protection_domain, THREAD); | 601 protection_domain, THREAD); |
603 if (probe != NULL) return probe; | 602 if (probe != NULL) return probe; |
604 | 603 |
605 | 604 |
606 // Non-bootstrap class loaders will call out to class loader and | 605 // Non-bootstrap class loaders will call out to class loader and |
615 bool DoObjectLock = true; | 614 bool DoObjectLock = true; |
616 if (is_parallelCapable(class_loader)) { | 615 if (is_parallelCapable(class_loader)) { |
617 DoObjectLock = false; | 616 DoObjectLock = false; |
618 } | 617 } |
619 | 618 |
620 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | 619 unsigned int p_hash = placeholders()->compute_hash(name, loader_data); |
621 int p_index = placeholders()->hash_to_index(p_hash); | 620 int p_index = placeholders()->hash_to_index(p_hash); |
622 | 621 |
623 // Class is not in SystemDictionary so we have to do loading. | 622 // Class is not in SystemDictionary so we have to do loading. |
624 // Make sure we are synchronized on the class loader before we proceed | 623 // Make sure we are synchronized on the class loader before we proceed |
625 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); | 624 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
634 PlaceholderEntry* placeholder; | 633 PlaceholderEntry* placeholder; |
635 Symbol* superclassname = NULL; | 634 Symbol* superclassname = NULL; |
636 | 635 |
637 { | 636 { |
638 MutexLocker mu(SystemDictionary_lock, THREAD); | 637 MutexLocker mu(SystemDictionary_lock, THREAD); |
639 klassOop check = find_class(d_index, d_hash, name, class_loader); | 638 Klass* check = find_class(d_index, d_hash, name, loader_data); |
640 if (check != NULL) { | 639 if (check != NULL) { |
641 // Klass is already loaded, so just return it | 640 // Klass is already loaded, so just return it |
642 class_has_been_loaded = true; | 641 class_has_been_loaded = true; |
643 k = instanceKlassHandle(THREAD, check); | 642 k = instanceKlassHandle(THREAD, check); |
644 } else { | 643 } else { |
645 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); | 644 placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
646 if (placeholder && placeholder->super_load_in_progress()) { | 645 if (placeholder && placeholder->super_load_in_progress()) { |
647 super_load_in_progress = true; | 646 super_load_in_progress = true; |
648 if (placeholder->havesupername() == true) { | 647 if (placeholder->havesupername() == true) { |
649 superclassname = placeholder->supername(); | 648 superclassname = placeholder->supername(); |
650 havesupername = true; | 649 havesupername = true; |
693 // Allow parallel classloading of a class/classloader pair | 692 // Allow parallel classloading of a class/classloader pair |
694 bool throw_circularity_error = false; | 693 bool throw_circularity_error = false; |
695 { | 694 { |
696 MutexLocker mu(SystemDictionary_lock, THREAD); | 695 MutexLocker mu(SystemDictionary_lock, THREAD); |
697 if (class_loader.is_null() || !is_parallelCapable(class_loader)) { | 696 if (class_loader.is_null() || !is_parallelCapable(class_loader)) { |
698 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); | 697 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
699 if (oldprobe) { | 698 if (oldprobe) { |
700 // only need check_seen_thread once, not on each loop | 699 // only need check_seen_thread once, not on each loop |
701 // 6341374 java/lang/Instrument with -Xcomp | 700 // 6341374 java/lang/Instrument with -Xcomp |
702 if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) { | 701 if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) { |
703 throw_circularity_error = true; | 702 throw_circularity_error = true; |
713 // case 2: traditional with broken classloader lock. wait on first | 712 // case 2: traditional with broken classloader lock. wait on first |
714 // requestor. | 713 // requestor. |
715 double_lock_wait(lockObject, THREAD); | 714 double_lock_wait(lockObject, THREAD); |
716 } | 715 } |
717 // Check if classloading completed while we were waiting | 716 // Check if classloading completed while we were waiting |
718 klassOop check = find_class(d_index, d_hash, name, class_loader); | 717 Klass* check = find_class(d_index, d_hash, name, loader_data); |
719 if (check != NULL) { | 718 if (check != NULL) { |
720 // Klass is already loaded, so just return it | 719 // Klass is already loaded, so just return it |
721 k = instanceKlassHandle(THREAD, check); | 720 k = instanceKlassHandle(THREAD, check); |
722 class_has_been_loaded = true; | 721 class_has_been_loaded = true; |
723 } | 722 } |
724 // check if other thread failed to load and cleaned up | 723 // check if other thread failed to load and cleaned up |
725 oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); | 724 oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
726 } | 725 } |
727 } | 726 } |
728 } | 727 } |
729 } | 728 } |
730 // All cases: add LOAD_INSTANCE | 729 // All cases: add LOAD_INSTANCE |
731 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try | 730 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try |
732 // LOAD_INSTANCE in parallel | 731 // LOAD_INSTANCE in parallel |
733 // add placeholder entry even if error - callers will remove on error | 732 // add placeholder entry even if error - callers will remove on error |
734 if (!throw_circularity_error && !class_has_been_loaded) { | 733 if (!throw_circularity_error && !class_has_been_loaded) { |
735 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD); | 734 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD); |
736 // For class loaders that do not acquire the classloader object lock, | 735 // For class loaders that do not acquire the classloader object lock, |
737 // if they did not catch another thread holding LOAD_INSTANCE, | 736 // if they did not catch another thread holding LOAD_INSTANCE, |
738 // need a check analogous to the acquire ObjectLocker/find_class | 737 // need a check analogous to the acquire ObjectLocker/find_class |
739 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL | 738 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL |
740 // one final check if the load has already completed | 739 // one final check if the load has already completed |
741 // class loaders holding the ObjectLock shouldn't find the class here | 740 // class loaders holding the ObjectLock shouldn't find the class here |
742 klassOop check = find_class(d_index, d_hash, name, class_loader); | 741 Klass* check = find_class(d_index, d_hash, name, loader_data); |
743 if (check != NULL) { | 742 if (check != NULL) { |
744 // Klass is already loaded, so just return it | 743 // Klass is already loaded, so just return it |
745 k = instanceKlassHandle(THREAD, check); | 744 k = instanceKlassHandle(THREAD, check); |
746 class_has_been_loaded = true; | 745 class_has_been_loaded = true; |
747 newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); | 746 newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); |
748 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | 747 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); |
749 SystemDictionary_lock->notify_all(); | 748 SystemDictionary_lock->notify_all(); |
750 } | 749 } |
751 } | 750 } |
752 } | 751 } |
753 // must throw error outside of owning lock | 752 // must throw error outside of owning lock |
763 | 762 |
764 // For UnsyncloadClass only | 763 // For UnsyncloadClass only |
765 // If they got a linkageError, check if a parallel class load succeeded. | 764 // If they got a linkageError, check if a parallel class load succeeded. |
766 // If it did, then for bytecode resolution the specification requires | 765 // If it did, then for bytecode resolution the specification requires |
767 // that we return the same result we did for the other thread, i.e. the | 766 // that we return the same result we did for the other thread, i.e. the |
768 // successfully loaded instanceKlass | 767 // successfully loaded InstanceKlass |
769 // Should not get here for classloaders that support parallelism | 768 // Should not get here for classloaders that support parallelism |
770 // with the new cleaner mechanism, even with AllowParallelDefineClass | 769 // with the new cleaner mechanism, even with AllowParallelDefineClass |
771 // Bootstrap goes through here to allow for an extra guarantee check | 770 // Bootstrap goes through here to allow for an extra guarantee check |
772 if (UnsyncloadClass || (class_loader.is_null())) { | 771 if (UnsyncloadClass || (class_loader.is_null())) { |
773 if (k.is_null() && HAS_PENDING_EXCEPTION | 772 if (k.is_null() && HAS_PENDING_EXCEPTION |
774 && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { | 773 && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { |
775 MutexLocker mu(SystemDictionary_lock, THREAD); | 774 MutexLocker mu(SystemDictionary_lock, THREAD); |
776 klassOop check = find_class(d_index, d_hash, name, class_loader); | 775 Klass* check = find_class(d_index, d_hash, name, loader_data); |
777 if (check != NULL) { | 776 if (check != NULL) { |
778 // Klass is already loaded, so just use it | 777 // Klass is already loaded, so just use it |
779 k = instanceKlassHandle(THREAD, check); | 778 k = instanceKlassHandle(THREAD, check); |
780 CLEAR_PENDING_EXCEPTION; | 779 CLEAR_PENDING_EXCEPTION; |
781 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); | 780 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); |
787 // This cleans up LOAD_INSTANCE entries | 786 // This cleans up LOAD_INSTANCE entries |
788 // It also cleans up LOAD_SUPER entries on errors from | 787 // It also cleans up LOAD_SUPER entries on errors from |
789 // calling load_instance_class | 788 // calling load_instance_class |
790 { | 789 { |
791 MutexLocker mu(SystemDictionary_lock, THREAD); | 790 MutexLocker mu(SystemDictionary_lock, THREAD); |
792 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader); | 791 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, loader_data); |
793 if (probe != NULL) { | 792 if (probe != NULL) { |
794 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); | 793 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); |
795 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | 794 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); |
796 SystemDictionary_lock->notify_all(); | 795 SystemDictionary_lock->notify_all(); |
797 } | 796 } |
798 } | 797 } |
799 | 798 |
800 // If everything was OK (no exceptions, no null return value), and | 799 // If everything was OK (no exceptions, no null return value), and |
822 } | 821 } |
823 if (HAS_PENDING_EXCEPTION || k.is_null()) { | 822 if (HAS_PENDING_EXCEPTION || k.is_null()) { |
824 // On error, clean up placeholders | 823 // On error, clean up placeholders |
825 { | 824 { |
826 MutexLocker mu(SystemDictionary_lock, THREAD); | 825 MutexLocker mu(SystemDictionary_lock, THREAD); |
827 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | 826 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); |
828 SystemDictionary_lock->notify_all(); | 827 SystemDictionary_lock->notify_all(); |
829 } | 828 } |
830 return NULL; | 829 return NULL; |
831 } | 830 } |
832 } | 831 } |
833 } | 832 } |
834 | 833 |
835 #ifdef ASSERT | 834 #ifdef ASSERT |
836 { | 835 { |
837 Handle loader (THREAD, k->class_loader()); | 836 ClassLoaderData* loader_data = k->class_loader_data(); |
838 MutexLocker mu(SystemDictionary_lock, THREAD); | 837 MutexLocker mu(SystemDictionary_lock, THREAD); |
839 oop kk = find_class(name, loader); | 838 Klass* kk = find_class(name, loader_data); |
840 assert(kk == k(), "should be present in dictionary"); | 839 assert(kk == k(), "should be present in dictionary"); |
841 } | 840 } |
842 #endif | 841 #endif |
843 | 842 |
844 // return if the protection domain in NULL | 843 // return if the protection domain in NULL |
853 // might potentially do a GC at all. | 852 // might potentially do a GC at all. |
854 // SystemDictionary::do_unloading() asserts that classes are only | 853 // SystemDictionary::do_unloading() asserts that classes are only |
855 // unloaded at a safepoint. | 854 // unloaded at a safepoint. |
856 No_Safepoint_Verifier nosafepoint; | 855 No_Safepoint_Verifier nosafepoint; |
857 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, | 856 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, |
858 class_loader, | 857 loader_data, |
859 protection_domain)) { | 858 protection_domain)) { |
860 return k(); | 859 return k(); |
861 } | 860 } |
862 } | 861 } |
863 | 862 |
864 // Verify protection domain. If it fails an exception is thrown | 863 // Verify protection domain. If it fails an exception is thrown |
865 validate_protection_domain(k, class_loader, protection_domain, CHECK_(klassOop(NULL))); | 864 validate_protection_domain(k, class_loader, protection_domain, CHECK_NULL); |
866 | 865 |
867 return k(); | 866 return k(); |
868 } | 867 } |
869 | 868 |
870 | 869 |
877 // | 876 // |
878 // Callers should be aware that an entry could be added just after | 877 // Callers should be aware that an entry could be added just after |
879 // _dictionary->bucket(index) is read here, so the caller will not see | 878 // _dictionary->bucket(index) is read here, so the caller will not see |
880 // the new entry. | 879 // the new entry. |
881 | 880 |
882 klassOop SystemDictionary::find(Symbol* class_name, | 881 Klass* SystemDictionary::find(Symbol* class_name, |
883 Handle class_loader, | 882 Handle class_loader, |
884 Handle protection_domain, | 883 Handle protection_domain, |
885 TRAPS) { | 884 TRAPS) { |
886 | 885 |
887 // UseNewReflection | 886 // UseNewReflection |
888 // The result of this call should be consistent with the result | 887 // The result of this call should be consistent with the result |
889 // of the call to resolve_instance_class_or_null(). | 888 // of the call to resolve_instance_class_or_null(). |
890 // See evaluation 6790209 and 4474172 for more details. | 889 // See evaluation 6790209 and 4474172 for more details. |
891 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); | 890 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
892 | 891 ClassLoaderData* loader_data = register_loader(class_loader); |
893 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); | 892 |
893 unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data); | |
894 int d_index = dictionary()->hash_to_index(d_hash); | 894 int d_index = dictionary()->hash_to_index(d_hash); |
895 | 895 |
896 { | 896 { |
897 // Note that we have an entry, and entries can be deleted only during GC, | 897 // Note that we have an entry, and entries can be deleted only during GC, |
898 // so we cannot allow GC to occur while we're holding this entry. | 898 // so we cannot allow GC to occur while we're holding this entry. |
899 // We're using a No_Safepoint_Verifier to catch any place where we | 899 // We're using a No_Safepoint_Verifier to catch any place where we |
900 // might potentially do a GC at all. | 900 // might potentially do a GC at all. |
901 // SystemDictionary::do_unloading() asserts that classes are only | 901 // SystemDictionary::do_unloading() asserts that classes are only |
902 // unloaded at a safepoint. | 902 // unloaded at a safepoint. |
903 No_Safepoint_Verifier nosafepoint; | 903 No_Safepoint_Verifier nosafepoint; |
904 return dictionary()->find(d_index, d_hash, class_name, class_loader, | 904 return dictionary()->find(d_index, d_hash, class_name, loader_data, |
905 protection_domain, THREAD); | 905 protection_domain, THREAD); |
906 } | 906 } |
907 } | 907 } |
908 | 908 |
909 | 909 |
910 // Look for a loaded instance or array klass by name. Do not do any loading. | 910 // Look for a loaded instance or array klass by name. Do not do any loading. |
911 // return NULL in case of error. | 911 // return NULL in case of error. |
912 klassOop SystemDictionary::find_instance_or_array_klass(Symbol* class_name, | 912 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name, |
913 Handle class_loader, | 913 Handle class_loader, |
914 Handle protection_domain, | 914 Handle protection_domain, |
915 TRAPS) { | 915 TRAPS) { |
916 klassOop k = NULL; | 916 Klass* k = NULL; |
917 assert(class_name != NULL, "class name must be non NULL"); | 917 assert(class_name != NULL, "class name must be non NULL"); |
918 | |
919 // Try to get one of the well-known klasses. | |
920 if (LinkWellKnownClasses) { | |
921 k = find_well_known_klass(class_name); | |
922 if (k != NULL) { | |
923 return k; | |
924 } | |
925 } | |
926 | 918 |
927 if (FieldType::is_array(class_name)) { | 919 if (FieldType::is_array(class_name)) { |
928 // The name refers to an array. Parse the name. | 920 // The name refers to an array. Parse the name. |
929 // dimension and object_key in FieldArrayInfo are assigned as a | 921 // dimension and object_key in FieldArrayInfo are assigned as a |
930 // side-effect of this call | 922 // side-effect of this call |
942 k = find(class_name, class_loader, protection_domain, THREAD); | 934 k = find(class_name, class_loader, protection_domain, THREAD); |
943 } | 935 } |
944 return k; | 936 return k; |
945 } | 937 } |
946 | 938 |
947 // Quick range check for names of well-known classes: | |
948 static Symbol* wk_klass_name_limits[2] = {NULL, NULL}; | |
949 | |
950 #ifndef PRODUCT | |
951 static int find_wkk_calls, find_wkk_probes, find_wkk_wins; | |
952 // counts for "hello world": 3983, 1616, 1075 | |
953 // => 60% hit after limit guard, 25% total win rate | |
954 #endif | |
955 | |
956 klassOop SystemDictionary::find_well_known_klass(Symbol* class_name) { | |
957 // A bounds-check on class_name will quickly get a negative result. | |
958 NOT_PRODUCT(find_wkk_calls++); | |
959 if (class_name >= wk_klass_name_limits[0] && | |
960 class_name <= wk_klass_name_limits[1]) { | |
961 NOT_PRODUCT(find_wkk_probes++); | |
962 vmSymbols::SID sid = vmSymbols::find_sid(class_name); | |
963 if (sid != vmSymbols::NO_SID) { | |
964 klassOop k = NULL; | |
965 switch (sid) { | |
966 #define WK_KLASS_CASE(name, symbol, ignore_option) \ | |
967 case vmSymbols::VM_SYMBOL_ENUM_NAME(symbol): \ | |
968 k = WK_KLASS(name); break; | |
969 WK_KLASSES_DO(WK_KLASS_CASE) | |
970 #undef WK_KLASS_CASE | |
971 } | |
972 NOT_PRODUCT(if (k != NULL) find_wkk_wins++); | |
973 return k; | |
974 } | |
975 } | |
976 return NULL; | |
977 } | |
978 | |
979 // Note: this method is much like resolve_from_stream, but | 939 // Note: this method is much like resolve_from_stream, but |
980 // updates no supplemental data structures. | 940 // updates no supplemental data structures. |
981 // TODO consolidate the two methods with a helper routine? | 941 // TODO consolidate the two methods with a helper routine? |
982 klassOop SystemDictionary::parse_stream(Symbol* class_name, | 942 Klass* SystemDictionary::parse_stream(Symbol* class_name, |
983 Handle class_loader, | 943 Handle class_loader, |
984 Handle protection_domain, | 944 Handle protection_domain, |
985 ClassFileStream* st, | 945 ClassFileStream* st, |
986 KlassHandle host_klass, | 946 KlassHandle host_klass, |
987 GrowableArray<Handle>* cp_patches, | 947 GrowableArray<Handle>* cp_patches, |
988 TRAPS) { | 948 TRAPS) { |
989 TempNewSymbol parsed_name = NULL; | 949 TempNewSymbol parsed_name = NULL; |
990 | 950 |
991 // Parse the stream. Note that we do this even though this klass might | 951 // Parse the stream. Note that we do this even though this klass might |
992 // already be present in the SystemDictionary, otherwise we would not | 952 // already be present in the SystemDictionary, otherwise we would not |
993 // throw potential ClassFormatErrors. | 953 // throw potential ClassFormatErrors. |
1011 // was an error or not (don't want to modify any system dictionary | 971 // was an error or not (don't want to modify any system dictionary |
1012 // data structures). | 972 // data structures). |
1013 // Parsed name could be null if we threw an error before we got far | 973 // Parsed name could be null if we threw an error before we got far |
1014 // enough along to parse it -- in that case, there is nothing to clean up. | 974 // enough along to parse it -- in that case, there is nothing to clean up. |
1015 if (parsed_name != NULL) { | 975 if (parsed_name != NULL) { |
976 ClassLoaderData* loader_data = class_loader_data(class_loader); | |
977 | |
1016 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | 978 unsigned int p_hash = placeholders()->compute_hash(parsed_name, |
1017 class_loader); | 979 loader_data); |
1018 int p_index = placeholders()->hash_to_index(p_hash); | 980 int p_index = placeholders()->hash_to_index(p_hash); |
1019 { | 981 { |
1020 MutexLocker mu(SystemDictionary_lock, THREAD); | 982 MutexLocker mu(SystemDictionary_lock, THREAD); |
1021 placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD); | 983 placeholders()->find_and_remove(p_index, p_hash, parsed_name, loader_data, THREAD); |
1022 SystemDictionary_lock->notify_all(); | 984 SystemDictionary_lock->notify_all(); |
1023 } | 985 } |
1024 } | 986 } |
1025 | 987 |
1026 if (host_klass.not_null() && k.not_null()) { | 988 if (host_klass.not_null() && k.not_null()) { |
1027 assert(EnableInvokeDynamic, ""); | 989 assert(EnableInvokeDynamic, ""); |
1028 // If it's anonymous, initialize it now, since nobody else will. | 990 // If it's anonymous, initialize it now, since nobody else will. |
991 k->class_loader_data()->record_dependency(host_klass(), CHECK_NULL); | |
1029 k->set_host_klass(host_klass()); | 992 k->set_host_klass(host_klass()); |
1030 | 993 |
1031 { | 994 { |
1032 MutexLocker mu_r(Compile_lock, THREAD); | 995 MutexLocker mu_r(Compile_lock, THREAD); |
1033 | 996 |
1036 add_to_hierarchy(k, CHECK_NULL); // No exception, but can block | 999 add_to_hierarchy(k, CHECK_NULL); // No exception, but can block |
1037 | 1000 |
1038 // But, do not add to system dictionary. | 1001 // But, do not add to system dictionary. |
1039 } | 1002 } |
1040 | 1003 |
1004 // Rewrite and patch constant pool here. | |
1005 k->link_class(THREAD); | |
1006 if (cp_patches != NULL) { | |
1007 k->constants()->patch_resolved_references(cp_patches); | |
1008 } | |
1041 k->eager_initialize(THREAD); | 1009 k->eager_initialize(THREAD); |
1042 | 1010 |
1043 // notify jvmti | 1011 // notify jvmti |
1044 if (JvmtiExport::should_post_class_load()) { | 1012 if (JvmtiExport::should_post_class_load()) { |
1045 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); | 1013 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1046 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); | 1014 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1047 } | 1015 } |
1048 } | 1016 } |
1017 assert(host_klass.not_null() || cp_patches == NULL, | |
1018 "cp_patches only found with host_klass"); | |
1049 | 1019 |
1050 return k(); | 1020 return k(); |
1051 } | 1021 } |
1052 | 1022 |
1053 // Add a klass to the system from a stream (called by jni_DefineClass and | 1023 // Add a klass to the system from a stream (called by jni_DefineClass and |
1054 // JVM_DefineClass). | 1024 // JVM_DefineClass). |
1055 // Note: class_name can be NULL. In that case we do not know the name of | 1025 // Note: class_name can be NULL. In that case we do not know the name of |
1056 // the class until we have parsed the stream. | 1026 // the class until we have parsed the stream. |
1057 | 1027 |
1058 klassOop SystemDictionary::resolve_from_stream(Symbol* class_name, | 1028 Klass* SystemDictionary::resolve_from_stream(Symbol* class_name, |
1059 Handle class_loader, | 1029 Handle class_loader, |
1060 Handle protection_domain, | 1030 Handle protection_domain, |
1061 ClassFileStream* st, | 1031 ClassFileStream* st, |
1062 bool verify, | 1032 bool verify, |
1063 TRAPS) { | 1033 TRAPS) { |
1064 | 1034 |
1065 // Classloaders that support parallelism, e.g. bootstrap classloader, | 1035 // Classloaders that support parallelism, e.g. bootstrap classloader, |
1066 // or all classloaders with UnsyncloadClass do not acquire lock here | 1036 // or all classloaders with UnsyncloadClass do not acquire lock here |
1067 bool DoObjectLock = true; | 1037 bool DoObjectLock = true; |
1068 if (is_parallelCapable(class_loader)) { | 1038 if (is_parallelCapable(class_loader)) { |
1069 DoObjectLock = false; | 1039 DoObjectLock = false; |
1070 } | 1040 } |
1041 | |
1042 ClassLoaderData* loader_data = register_loader(class_loader); | |
1071 | 1043 |
1072 // Make sure we are synchronized on the class loader before we proceed | 1044 // Make sure we are synchronized on the class loader before we proceed |
1073 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); | 1045 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
1074 check_loader_lock_contention(lockObject, THREAD); | 1046 check_loader_lock_contention(lockObject, THREAD); |
1075 ObjectLocker ol(lockObject, THREAD, DoObjectLock); | 1047 ObjectLocker ol(lockObject, THREAD, DoObjectLock); |
1123 assert(is_internal_format(parsed_name), | 1095 assert(is_internal_format(parsed_name), |
1124 "external class name format used internally"); | 1096 "external class name format used internally"); |
1125 | 1097 |
1126 // Add class just loaded | 1098 // Add class just loaded |
1127 // If a class loader supports parallel classloading handle parallel define requests | 1099 // If a class loader supports parallel classloading handle parallel define requests |
1128 // find_or_define_instance_class may return a different instanceKlass | 1100 // find_or_define_instance_class may return a different InstanceKlass |
1129 if (is_parallelCapable(class_loader)) { | 1101 if (is_parallelCapable(class_loader)) { |
1130 k = find_or_define_instance_class(class_name, class_loader, k, THREAD); | 1102 k = find_or_define_instance_class(class_name, class_loader, k, THREAD); |
1131 } else { | 1103 } else { |
1132 define_instance_class(k, THREAD); | 1104 define_instance_class(k, THREAD); |
1133 } | 1105 } |
1138 // must make sure parsed_name is valid first (it won't be if we had | 1110 // must make sure parsed_name is valid first (it won't be if we had |
1139 // a format error before the class was parsed far enough to | 1111 // a format error before the class was parsed far enough to |
1140 // find the name). | 1112 // find the name). |
1141 if (HAS_PENDING_EXCEPTION && parsed_name != NULL) { | 1113 if (HAS_PENDING_EXCEPTION && parsed_name != NULL) { |
1142 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | 1114 unsigned int p_hash = placeholders()->compute_hash(parsed_name, |
1143 class_loader); | 1115 loader_data); |
1144 int p_index = placeholders()->hash_to_index(p_hash); | 1116 int p_index = placeholders()->hash_to_index(p_hash); |
1145 { | 1117 { |
1146 MutexLocker mu(SystemDictionary_lock, THREAD); | 1118 MutexLocker mu(SystemDictionary_lock, THREAD); |
1147 placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD); | 1119 placeholders()->find_and_remove(p_index, p_hash, parsed_name, loader_data, THREAD); |
1148 SystemDictionary_lock->notify_all(); | 1120 SystemDictionary_lock->notify_all(); |
1149 } | 1121 } |
1150 return NULL; | 1122 return NULL; |
1151 } | 1123 } |
1152 | 1124 |
1154 // SystemDictionary; this is only done on success | 1126 // SystemDictionary; this is only done on success |
1155 debug_only( { | 1127 debug_only( { |
1156 if (!HAS_PENDING_EXCEPTION) { | 1128 if (!HAS_PENDING_EXCEPTION) { |
1157 assert(parsed_name != NULL, "parsed_name is still null?"); | 1129 assert(parsed_name != NULL, "parsed_name is still null?"); |
1158 Symbol* h_name = k->name(); | 1130 Symbol* h_name = k->name(); |
1159 Handle h_loader (THREAD, k->class_loader()); | 1131 ClassLoaderData *defining_loader_data = k->class_loader_data(); |
1160 | 1132 |
1161 MutexLocker mu(SystemDictionary_lock, THREAD); | 1133 MutexLocker mu(SystemDictionary_lock, THREAD); |
1162 | 1134 |
1163 klassOop check = find_class(parsed_name, class_loader); | 1135 Klass* check = find_class(parsed_name, loader_data); |
1164 assert(check == k(), "should be present in the dictionary"); | 1136 assert(check == k(), "should be present in the dictionary"); |
1165 | 1137 |
1166 klassOop check2 = find_class(h_name, h_loader); | 1138 Klass* check2 = find_class(h_name, defining_loader_data); |
1167 assert(check == check2, "name inconsistancy in SystemDictionary"); | 1139 assert(check == check2, "name inconsistancy in SystemDictionary"); |
1168 } | 1140 } |
1169 } ); | 1141 } ); |
1170 | 1142 |
1171 return k(); | 1143 return k(); |
1181 | 1153 |
1182 | 1154 |
1183 // If there is a shared dictionary, then find the entry for the | 1155 // If there is a shared dictionary, then find the entry for the |
1184 // given shared system class, if any. | 1156 // given shared system class, if any. |
1185 | 1157 |
1186 klassOop SystemDictionary::find_shared_class(Symbol* class_name) { | 1158 Klass* SystemDictionary::find_shared_class(Symbol* class_name) { |
1187 if (shared_dictionary() != NULL) { | 1159 if (shared_dictionary() != NULL) { |
1188 unsigned int d_hash = shared_dictionary()->compute_hash(class_name, Handle()); | 1160 unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL); |
1189 int d_index = shared_dictionary()->hash_to_index(d_hash); | 1161 int d_index = shared_dictionary()->hash_to_index(d_hash); |
1162 | |
1190 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); | 1163 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); |
1191 } else { | 1164 } else { |
1192 return NULL; | 1165 return NULL; |
1193 } | 1166 } |
1194 } | 1167 } |
1221 // Found the class, now load the superclass and interfaces. If they | 1194 // Found the class, now load the superclass and interfaces. If they |
1222 // are shared, add them to the main system dictionary and reset | 1195 // are shared, add them to the main system dictionary and reset |
1223 // their hierarchy references (supers, subs, and interfaces). | 1196 // their hierarchy references (supers, subs, and interfaces). |
1224 | 1197 |
1225 if (ik->super() != NULL) { | 1198 if (ik->super() != NULL) { |
1226 Symbol* cn = ik->super()->klass_part()->name(); | 1199 Symbol* cn = ik->super()->name(); |
1227 resolve_super_or_fail(class_name, cn, | 1200 resolve_super_or_fail(class_name, cn, |
1228 class_loader, Handle(), true, CHECK_(nh)); | 1201 class_loader, Handle(), true, CHECK_(nh)); |
1229 } | 1202 } |
1230 | 1203 |
1231 objArrayHandle interfaces (THREAD, ik->local_interfaces()); | 1204 Array<Klass*>* interfaces = ik->local_interfaces(); |
1232 int num_interfaces = interfaces->length(); | 1205 int num_interfaces = interfaces->length(); |
1233 for (int index = 0; index < num_interfaces; index++) { | 1206 for (int index = 0; index < num_interfaces; index++) { |
1234 klassOop k = klassOop(interfaces->obj_at(index)); | 1207 Klass* k = interfaces->at(index); |
1235 | 1208 |
1236 // Note: can not use instanceKlass::cast here because | 1209 // Note: can not use InstanceKlass::cast here because |
1237 // interfaces' instanceKlass's C++ vtbls haven't been | 1210 // interfaces' InstanceKlass's C++ vtbls haven't been |
1238 // reinitialized yet (they will be once the interface classes | 1211 // reinitialized yet (they will be once the interface classes |
1239 // are loaded) | 1212 // are loaded) |
1240 Symbol* name = k->klass_part()->name(); | 1213 Symbol* name = k->name(); |
1241 resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh)); | 1214 resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh)); |
1242 } | 1215 } |
1243 | 1216 |
1244 // Adjust methods to recover missing data. They need addresses for | 1217 // Adjust methods to recover missing data. They need addresses for |
1245 // interpreter entry points and their default native method address | 1218 // interpreter entry points and their default native method address |
1253 | 1226 |
1254 { | 1227 { |
1255 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); | 1228 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
1256 check_loader_lock_contention(lockObject, THREAD); | 1229 check_loader_lock_contention(lockObject, THREAD); |
1257 ObjectLocker ol(lockObject, THREAD, true); | 1230 ObjectLocker ol(lockObject, THREAD, true); |
1258 | 1231 ik->restore_unshareable_info(CHECK_(nh)); |
1259 objArrayHandle methods (THREAD, ik->methods()); | |
1260 int num_methods = methods->length(); | |
1261 for (int index2 = 0; index2 < num_methods; ++index2) { | |
1262 methodHandle m(THREAD, methodOop(methods->obj_at(index2))); | |
1263 m()->link_method(m, CHECK_(nh)); | |
1264 } | |
1265 if (JvmtiExport::has_redefined_a_class()) { | |
1266 // Reinitialize vtable because RedefineClasses may have changed some | |
1267 // entries in this vtable for super classes so the CDS vtable might | |
1268 // point to old or obsolete entries. RedefineClasses doesn't fix up | |
1269 // vtables in the shared system dictionary, only the main one. | |
1270 // It also redefines the itable too so fix that too. | |
1271 ResourceMark rm(THREAD); | |
1272 ik->vtable()->initialize_vtable(false, CHECK_(nh)); | |
1273 ik->itable()->initialize_itable(false, CHECK_(nh)); | |
1274 } | |
1275 } | 1232 } |
1276 | 1233 |
1277 if (TraceClassLoading) { | 1234 if (TraceClassLoading) { |
1278 ResourceMark rm; | 1235 ResourceMark rm; |
1279 tty->print("[Loaded %s", ik->external_name()); | 1236 tty->print("[Loaded %s", ik->external_name()); |
1280 tty->print(" from shared objects file"); | 1237 tty->print(" from shared objects file"); |
1281 tty->print_cr("]"); | 1238 tty->print_cr("]"); |
1282 } | 1239 } |
1283 // notify a class loaded from shared object | 1240 // notify a class loaded from shared object |
1284 ClassLoadingService::notify_class_loaded(instanceKlass::cast(ik()), | 1241 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(ik()), |
1285 true /* shared class */); | 1242 true /* shared class */); |
1286 } | 1243 } |
1287 return ik; | 1244 return ik; |
1288 } | 1245 } |
1289 | 1246 |
1295 // first try to call this so it'd better be fast!! | 1252 // first try to call this so it'd better be fast!! |
1296 static instanceKlassHandle download_and_retry_class_load( | 1253 static instanceKlassHandle download_and_retry_class_load( |
1297 Symbol* class_name, | 1254 Symbol* class_name, |
1298 TRAPS) { | 1255 TRAPS) { |
1299 | 1256 |
1300 klassOop dlm = SystemDictionary::DownloadManager_klass(); | 1257 Klass* dlm = SystemDictionary::DownloadManager_klass(); |
1301 instanceKlassHandle nk; | 1258 instanceKlassHandle nk; |
1302 | 1259 |
1303 // If download manager class isn't loaded just return. | 1260 // If download manager class isn't loaded just return. |
1304 if (dlm == NULL) return nk; | 1261 if (dlm == NULL) return nk; |
1305 | 1262 |
1373 if (k.is_null()) { | 1330 if (k.is_null()) { |
1374 k = download_and_retry_class_load(class_name, CHECK_(nh)); | 1331 k = download_and_retry_class_load(class_name, CHECK_(nh)); |
1375 } | 1332 } |
1376 #endif // KERNEL | 1333 #endif // KERNEL |
1377 | 1334 |
1378 // find_or_define_instance_class may return a different instanceKlass | 1335 // find_or_define_instance_class may return a different InstanceKlass |
1379 if (!k.is_null()) { | 1336 if (!k.is_null()) { |
1380 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh)); | 1337 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh)); |
1381 } | 1338 } |
1382 return k; | 1339 return k; |
1383 } else { | 1340 } else { |
1442 | 1399 |
1443 // Primitive classes return null since forName() can not be | 1400 // Primitive classes return null since forName() can not be |
1444 // used to obtain any of the Class objects representing primitives or void | 1401 // used to obtain any of the Class objects representing primitives or void |
1445 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) { | 1402 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) { |
1446 instanceKlassHandle k = | 1403 instanceKlassHandle k = |
1447 instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj)); | 1404 instanceKlassHandle(THREAD, java_lang_Class::as_Klass(obj)); |
1448 // For user defined Java class loaders, check that the name returned is | 1405 // For user defined Java class loaders, check that the name returned is |
1449 // the same as that requested. This check is done for the bootstrap | 1406 // the same as that requested. This check is done for the bootstrap |
1450 // loader when parsing the class file. | 1407 // loader when parsing the class file. |
1451 if (class_name == k->name()) { | 1408 if (class_name == k->name()) { |
1452 return k; | 1409 return k; |
1457 } | 1414 } |
1458 } | 1415 } |
1459 | 1416 |
1460 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { | 1417 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { |
1461 | 1418 |
1462 Handle class_loader_h(THREAD, k->class_loader()); | 1419 ClassLoaderData* loader_data = k->class_loader_data(); |
1420 Handle class_loader_h(THREAD, loader_data->class_loader()); | |
1421 | |
1422 for (uintx it = 0; it < GCExpandToAllocateDelayMillis; it++){} | |
1463 | 1423 |
1464 // for bootstrap and other parallel classloaders don't acquire lock, | 1424 // for bootstrap and other parallel classloaders don't acquire lock, |
1465 // use placeholder token | 1425 // use placeholder token |
1466 // If a parallelCapable class loader calls define_instance_class instead of | 1426 // If a parallelCapable class loader calls define_instance_class instead of |
1467 // find_or_define_instance_class to get here, we have a timing | 1427 // find_or_define_instance_class to get here, we have a timing |
1480 // Existing classloaders will call define_instance_class with the | 1440 // Existing classloaders will call define_instance_class with the |
1481 // classloader lock held | 1441 // classloader lock held |
1482 // Parallel classloaders will call find_or_define_instance_class | 1442 // Parallel classloaders will call find_or_define_instance_class |
1483 // which will require a token to perform the define class | 1443 // which will require a token to perform the define class |
1484 Symbol* name_h = k->name(); | 1444 Symbol* name_h = k->name(); |
1485 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h); | 1445 unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data); |
1486 int d_index = dictionary()->hash_to_index(d_hash); | 1446 int d_index = dictionary()->hash_to_index(d_hash); |
1487 check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK); | 1447 check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK); |
1488 | 1448 |
1489 // Register class just loaded with class loader (placed in Vector) | 1449 // Register class just loaded with class loader (placed in Vector) |
1490 // Note we do this before updating the dictionary, as this can | 1450 // Note we do this before updating the dictionary, as this can |
1491 // fail with an OutOfMemoryError (if it does, we will *not* put this | 1451 // fail with an OutOfMemoryError (if it does, we will *not* put this |
1492 // class in the dictionary and will not update the class hierarchy). | 1452 // class in the dictionary and will not update the class hierarchy). |
1453 // JVMTI FollowReferences needs to find the classes this way. | |
1493 if (k->class_loader() != NULL) { | 1454 if (k->class_loader() != NULL) { |
1494 methodHandle m(THREAD, Universe::loader_addClass_method()); | 1455 methodHandle m(THREAD, Universe::loader_addClass_method()); |
1495 JavaValue result(T_VOID); | 1456 JavaValue result(T_VOID); |
1496 JavaCallArguments args(class_loader_h); | 1457 JavaCallArguments args(class_loader_h); |
1497 args.push_oop(Handle(THREAD, k->java_mirror())); | 1458 args.push_oop(Handle(THREAD, k->java_mirror())); |
1498 JavaCalls::call(&result, m, &args, CHECK); | 1459 JavaCalls::call(&result, m, &args, CHECK); |
1499 } | 1460 } |
1500 | 1461 |
1501 // Add the new class. We need recompile lock during update of CHA. | 1462 // Add the new class. We need recompile lock during update of CHA. |
1502 { | 1463 { |
1503 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader_h); | 1464 unsigned int p_hash = placeholders()->compute_hash(name_h, loader_data); |
1504 int p_index = placeholders()->hash_to_index(p_hash); | 1465 int p_index = placeholders()->hash_to_index(p_hash); |
1505 | 1466 |
1506 MutexLocker mu_r(Compile_lock, THREAD); | 1467 MutexLocker mu_r(Compile_lock, THREAD); |
1507 | 1468 |
1508 // Add to class hierarchy, initialize vtables, and do possible | 1469 // Add to class hierarchy, initialize vtables, and do possible |
1542 // Note: VM callers should ensure consistency of k/class_name,class_loader | 1503 // Note: VM callers should ensure consistency of k/class_name,class_loader |
1543 instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { | 1504 instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { |
1544 | 1505 |
1545 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | 1506 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1546 Symbol* name_h = k->name(); // passed in class_name may be null | 1507 Symbol* name_h = k->name(); // passed in class_name may be null |
1547 | 1508 ClassLoaderData* loader_data = class_loader_data(class_loader); |
1548 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader); | 1509 |
1510 unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data); | |
1549 int d_index = dictionary()->hash_to_index(d_hash); | 1511 int d_index = dictionary()->hash_to_index(d_hash); |
1550 | 1512 |
1551 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS | 1513 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS |
1552 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader); | 1514 unsigned int p_hash = placeholders()->compute_hash(name_h, loader_data); |
1553 int p_index = placeholders()->hash_to_index(p_hash); | 1515 int p_index = placeholders()->hash_to_index(p_hash); |
1554 PlaceholderEntry* probe; | 1516 PlaceholderEntry* probe; |
1555 | 1517 |
1556 { | 1518 { |
1557 MutexLocker mu(SystemDictionary_lock, THREAD); | 1519 MutexLocker mu(SystemDictionary_lock, THREAD); |
1558 // First check if class already defined | 1520 // First check if class already defined |
1559 if (UnsyncloadClass || (is_parallelDefine(class_loader))) { | 1521 if (UnsyncloadClass || (is_parallelDefine(class_loader))) { |
1560 klassOop check = find_class(d_index, d_hash, name_h, class_loader); | 1522 Klass* check = find_class(d_index, d_hash, name_h, loader_data); |
1561 if (check != NULL) { | 1523 if (check != NULL) { |
1562 return(instanceKlassHandle(THREAD, check)); | 1524 return(instanceKlassHandle(THREAD, check)); |
1563 } | 1525 } |
1564 } | 1526 } |
1565 | 1527 |
1566 // Acquire define token for this class/classloader | 1528 // Acquire define token for this class/classloader |
1567 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, NULL, THREAD); | 1529 probe = placeholders()->find_and_add(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, NULL, THREAD); |
1568 // Wait if another thread defining in parallel | 1530 // Wait if another thread defining in parallel |
1569 // All threads wait - even those that will throw duplicate class: otherwise | 1531 // All threads wait - even those that will throw duplicate class: otherwise |
1570 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails | 1532 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails |
1571 // if other thread has not finished updating dictionary | 1533 // if other thread has not finished updating dictionary |
1572 while (probe->definer() != NULL) { | 1534 while (probe->definer() != NULL) { |
1573 SystemDictionary_lock->wait(); | 1535 SystemDictionary_lock->wait(); |
1574 } | 1536 } |
1575 // Only special cases allow parallel defines and can use other thread's results | 1537 // Only special cases allow parallel defines and can use other thread's results |
1576 // Other cases fall through, and may run into duplicate defines | 1538 // Other cases fall through, and may run into duplicate defines |
1577 // caught by finding an entry in the SystemDictionary | 1539 // caught by finding an entry in the SystemDictionary |
1578 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instanceKlass() != NULL)) { | 1540 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->InstanceKlass() != NULL)) { |
1579 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); | 1541 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); |
1580 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); | 1542 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, THREAD); |
1581 SystemDictionary_lock->notify_all(); | 1543 SystemDictionary_lock->notify_all(); |
1582 #ifdef ASSERT | 1544 #ifdef ASSERT |
1583 klassOop check = find_class(d_index, d_hash, name_h, class_loader); | 1545 Klass* check = find_class(d_index, d_hash, name_h, loader_data); |
1584 assert(check != NULL, "definer missed recording success"); | 1546 assert(check != NULL, "definer missed recording success"); |
1585 #endif | 1547 #endif |
1586 return(instanceKlassHandle(THREAD, probe->instanceKlass())); | 1548 return(instanceKlassHandle(THREAD, probe->InstanceKlass())); |
1587 } else { | 1549 } else { |
1588 // This thread will define the class (even if earlier thread tried and had an error) | 1550 // This thread will define the class (even if earlier thread tried and had an error) |
1589 probe->set_definer(THREAD); | 1551 probe->set_definer(THREAD); |
1590 } | 1552 } |
1591 } | 1553 } |
1595 Handle linkage_exception = Handle(); // null handle | 1557 Handle linkage_exception = Handle(); // null handle |
1596 | 1558 |
1597 // definer must notify any waiting threads | 1559 // definer must notify any waiting threads |
1598 { | 1560 { |
1599 MutexLocker mu(SystemDictionary_lock, THREAD); | 1561 MutexLocker mu(SystemDictionary_lock, THREAD); |
1600 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, class_loader); | 1562 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, loader_data); |
1601 assert(probe != NULL, "DEFINE_CLASS placeholder lost?"); | 1563 assert(probe != NULL, "DEFINE_CLASS placeholder lost?"); |
1602 if (probe != NULL) { | 1564 if (probe != NULL) { |
1603 if (HAS_PENDING_EXCEPTION) { | 1565 if (HAS_PENDING_EXCEPTION) { |
1604 linkage_exception = Handle(THREAD,PENDING_EXCEPTION); | 1566 linkage_exception = Handle(THREAD,PENDING_EXCEPTION); |
1605 CLEAR_PENDING_EXCEPTION; | 1567 CLEAR_PENDING_EXCEPTION; |
1606 } else { | 1568 } else { |
1607 probe->set_instanceKlass(k()); | 1569 probe->set_instanceKlass(k()); |
1608 } | 1570 } |
1609 probe->set_definer(NULL); | 1571 probe->set_definer(NULL); |
1610 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); | 1572 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); |
1611 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); | 1573 placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, THREAD); |
1612 SystemDictionary_lock->notify_all(); | 1574 SystemDictionary_lock->notify_all(); |
1613 } | 1575 } |
1614 } | 1576 } |
1615 | 1577 |
1616 // Can't throw exception while holding lock due to rank ordering | 1578 // Can't throw exception while holding lock due to rank ordering |
1653 } | 1615 } |
1654 | 1616 |
1655 // ---------------------------------------------------------------------------- | 1617 // ---------------------------------------------------------------------------- |
1656 // Lookup | 1618 // Lookup |
1657 | 1619 |
1658 klassOop SystemDictionary::find_class(int index, unsigned int hash, | 1620 Klass* SystemDictionary::find_class(int index, unsigned int hash, |
1659 Symbol* class_name, | 1621 Symbol* class_name, |
1660 Handle class_loader) { | 1622 ClassLoaderData* loader_data) { |
1661 assert_locked_or_safepoint(SystemDictionary_lock); | 1623 assert_locked_or_safepoint(SystemDictionary_lock); |
1662 assert (index == dictionary()->index_for(class_name, class_loader), | 1624 assert (index == dictionary()->index_for(class_name, loader_data), |
1663 "incorrect index?"); | 1625 "incorrect index?"); |
1664 | 1626 |
1665 klassOop k = dictionary()->find_class(index, hash, class_name, class_loader); | 1627 Klass* k = dictionary()->find_class(index, hash, class_name, loader_data); |
1666 return k; | 1628 return k; |
1667 } | 1629 } |
1668 | 1630 |
1669 | 1631 |
1670 // Basic find on classes in the midst of being loaded | 1632 // Basic find on classes in the midst of being loaded |
1671 Symbol* SystemDictionary::find_placeholder(Symbol* class_name, | 1633 Symbol* SystemDictionary::find_placeholder(Symbol* class_name, |
1672 Handle class_loader) { | 1634 ClassLoaderData* loader_data) { |
1673 assert_locked_or_safepoint(SystemDictionary_lock); | 1635 assert_locked_or_safepoint(SystemDictionary_lock); |
1674 unsigned int p_hash = placeholders()->compute_hash(class_name, class_loader); | 1636 unsigned int p_hash = placeholders()->compute_hash(class_name, loader_data); |
1675 int p_index = placeholders()->hash_to_index(p_hash); | 1637 int p_index = placeholders()->hash_to_index(p_hash); |
1676 return placeholders()->find_entry(p_index, p_hash, class_name, class_loader); | 1638 return placeholders()->find_entry(p_index, p_hash, class_name, loader_data); |
1677 } | 1639 } |
1678 | 1640 |
1679 | 1641 |
1680 // Used for assertions and verification only | 1642 // Used for assertions and verification only |
1681 klassOop SystemDictionary::find_class(Symbol* class_name, Handle class_loader) { | 1643 Klass* SystemDictionary::find_class(Symbol* class_name, ClassLoaderData* loader_data) { |
1682 #ifndef ASSERT | 1644 #ifndef ASSERT |
1683 guarantee(VerifyBeforeGC || | 1645 guarantee(VerifyBeforeGC || |
1684 VerifyDuringGC || | 1646 VerifyDuringGC || |
1685 VerifyBeforeExit || | 1647 VerifyBeforeExit || |
1686 VerifyAfterGC, "too expensive"); | 1648 VerifyAfterGC, "too expensive"); |
1687 #endif | 1649 #endif |
1688 assert_locked_or_safepoint(SystemDictionary_lock); | 1650 assert_locked_or_safepoint(SystemDictionary_lock); |
1689 | 1651 |
1690 // First look in the loaded class array | 1652 // First look in the loaded class array |
1691 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); | 1653 unsigned int d_hash = dictionary()->compute_hash(class_name, loader_data); |
1692 int d_index = dictionary()->hash_to_index(d_hash); | 1654 int d_index = dictionary()->hash_to_index(d_hash); |
1693 return find_class(d_index, d_hash, class_name, class_loader); | 1655 return find_class(d_index, d_hash, class_name, loader_data); |
1694 } | 1656 } |
1695 | 1657 |
1696 | 1658 |
1697 // Get the next class in the diictionary. | 1659 // Get the next class in the diictionary. |
1698 klassOop SystemDictionary::try_get_next_class() { | 1660 Klass* SystemDictionary::try_get_next_class() { |
1699 return dictionary()->try_get_next_class(); | 1661 return dictionary()->try_get_next_class(); |
1700 } | 1662 } |
1701 | 1663 |
1702 | 1664 |
1703 // ---------------------------------------------------------------------------- | 1665 // ---------------------------------------------------------------------------- |
1710 assert_locked_or_safepoint(Compile_lock); | 1672 assert_locked_or_safepoint(Compile_lock); |
1711 | 1673 |
1712 // Link into hierachy. Make sure the vtables are initialized before linking into | 1674 // Link into hierachy. Make sure the vtables are initialized before linking into |
1713 k->append_to_sibling_list(); // add to superklass/sibling list | 1675 k->append_to_sibling_list(); // add to superklass/sibling list |
1714 k->process_interfaces(THREAD); // handle all "implements" declarations | 1676 k->process_interfaces(THREAD); // handle all "implements" declarations |
1715 k->set_init_state(instanceKlass::loaded); | 1677 k->set_init_state(InstanceKlass::loaded); |
1716 // Now flush all code that depended on old class hierarchy. | 1678 // Now flush all code that depended on old class hierarchy. |
1717 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97) | 1679 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97) |
1718 // Also, first reinitialize vtable because it may have gotten out of synch | 1680 // Also, first reinitialize vtable because it may have gotten out of synch |
1719 // while the new class wasn't connected to the class hierarchy. | 1681 // while the new class wasn't connected to the class hierarchy. |
1720 Universe::flush_dependents_on(k); | 1682 Universe::flush_dependents_on(k); |
1731 // | 1693 // |
1732 // The second phase removes (unloads) unreachable classes from the | 1694 // The second phase removes (unloads) unreachable classes from the |
1733 // system dictionary and follows the remaining classes' contents. | 1695 // system dictionary and follows the remaining classes' contents. |
1734 | 1696 |
1735 void SystemDictionary::always_strong_oops_do(OopClosure* blk) { | 1697 void SystemDictionary::always_strong_oops_do(OopClosure* blk) { |
1736 // Follow preloaded classes/mirrors and system loader object | |
1737 blk->do_oop(&_java_system_loader); | 1698 blk->do_oop(&_java_system_loader); |
1738 preloaded_oops_do(blk); | 1699 blk->do_oop(&_system_loader_lock_obj); |
1739 always_strong_classes_do(blk); | 1700 |
1740 } | 1701 dictionary()->always_strong_oops_do(blk); |
1741 | |
1742 | |
1743 void SystemDictionary::always_strong_classes_do(OopClosure* blk) { | |
1744 // Follow all system classes and temporary placeholders in dictionary | |
1745 dictionary()->always_strong_classes_do(blk); | |
1746 | |
1747 // Placeholders. These are *always* strong roots, as they | |
1748 // represent classes we're actively loading. | |
1749 placeholders_do(blk); | |
1750 | 1702 |
1751 // Visit extra methods | 1703 // Visit extra methods |
1752 invoke_method_table()->oops_do(blk); | 1704 invoke_method_table()->oops_do(blk); |
1753 } | 1705 } |
1754 | 1706 |
1755 | 1707 void SystemDictionary::always_strong_classes_do(KlassClosure* closure) { |
1756 void SystemDictionary::placeholders_do(OopClosure* blk) { | 1708 // Follow all system classes and temporary placeholders in dictionary |
1757 placeholders()->oops_do(blk); | 1709 dictionary()->always_strong_classes_do(closure); |
1710 | |
1711 // Placeholders. These represent classes we're actively loading. | |
1712 placeholders()->classes_do(closure); | |
1758 } | 1713 } |
1759 | 1714 |
1760 // Calculate a "good" systemdictionary size based | 1715 // Calculate a "good" systemdictionary size based |
1761 // on predicted or current loaded classes count | 1716 // on predicted or current loaded classes count |
1762 int SystemDictionary::calculate_systemdictionary_size(int classcount) { | 1717 int SystemDictionary::calculate_systemdictionary_size(int classcount) { |
1771 } | 1726 } |
1772 } | 1727 } |
1773 return newsize; | 1728 return newsize; |
1774 } | 1729 } |
1775 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) { | 1730 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) { |
1776 bool result = dictionary()->do_unloading(is_alive); | 1731 // First, mark for unload all ClassLoaderData referencing a dead class loader. |
1777 constraints()->purge_loader_constraints(is_alive); | 1732 bool has_dead_loaders = ClassLoaderDataGraph::do_unloading(is_alive); |
1778 resolution_errors()->purge_resolution_errors(is_alive); | 1733 bool unloading_occurred = false; |
1779 return result; | 1734 if (has_dead_loaders) { |
1780 } | 1735 unloading_occurred = dictionary()->do_unloading(); |
1781 | 1736 constraints()->purge_loader_constraints(); |
1782 | 1737 resolution_errors()->purge_resolution_errors(); |
1783 // The mirrors are scanned by shared_oops_do() which is | 1738 } |
1784 // not called by oops_do(). In order to process oops in | 1739 return unloading_occurred; |
1785 // a necessary order, shared_oops_do() is call by | 1740 } |
1786 // Universe::oops_do(). | 1741 |
1787 void SystemDictionary::oops_do(OopClosure* f) { | 1742 void SystemDictionary::oops_do(OopClosure* f) { |
1788 // Adjust preloaded classes and system loader object | |
1789 f->do_oop(&_java_system_loader); | 1743 f->do_oop(&_java_system_loader); |
1790 preloaded_oops_do(f); | 1744 f->do_oop(&_system_loader_lock_obj); |
1791 | |
1792 lazily_loaded_oops_do(f); | |
1793 | 1745 |
1794 // Adjust dictionary | 1746 // Adjust dictionary |
1795 dictionary()->oops_do(f); | 1747 dictionary()->oops_do(f); |
1796 | 1748 |
1797 // Visit extra methods | 1749 // Visit extra methods |
1798 invoke_method_table()->oops_do(f); | 1750 invoke_method_table()->oops_do(f); |
1799 | 1751 } |
1800 // Partially loaded classes | 1752 |
1801 placeholders()->oops_do(f); | 1753 // Extended Class redefinition support. |
1802 | 1754 // If one of these classes is replaced, we need to replace it in these places. |
1803 // Adjust constraint table | 1755 // KlassClosure::do_klass should take the address of a class but we can |
1804 constraints()->oops_do(f); | 1756 // change that later. |
1805 | 1757 void SystemDictionary::preloaded_classes_do(KlassClosure* f) { |
1806 // Adjust resolution error table | |
1807 resolution_errors()->oops_do(f); | |
1808 } | |
1809 | |
1810 | |
1811 void SystemDictionary::preloaded_oops_do(OopClosure* f) { | |
1812 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) { | 1758 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) { |
1813 f->do_oop((oop*) &_well_known_klasses[k]); | 1759 f->do_klass(_well_known_klasses[k]); |
1814 } | 1760 } |
1815 | 1761 |
1816 { | 1762 { |
1817 for (int i = 0; i < T_VOID+1; i++) { | 1763 for (int i = 0; i < T_VOID+1; i++) { |
1818 if (_box_klasses[i] != NULL) { | 1764 if (_box_klasses[i] != NULL) { |
1819 assert(i >= T_BOOLEAN, "checking"); | 1765 assert(i >= T_BOOLEAN, "checking"); |
1820 f->do_oop((oop*) &_box_klasses[i]); | 1766 f->do_klass(_box_klasses[i]); |
1821 } | 1767 } |
1822 } | 1768 } |
1823 } | 1769 } |
1824 | 1770 |
1825 // The basic type mirrors would have already been processed in | 1771 FilteredFieldsMap::classes_do(f); |
1826 // Universe::oops_do(), via a call to shared_oops_do(), so should | 1772 } |
1827 // not be processed again. | 1773 |
1828 | 1774 void SystemDictionary::lazily_loaded_classes_do(KlassClosure* f) { |
1829 f->do_oop((oop*) &_system_loader_lock_obj); | 1775 f->do_klass(_abstract_ownable_synchronizer_klass); |
1830 FilteredFieldsMap::klasses_oops_do(f); | |
1831 } | |
1832 | |
1833 void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) { | |
1834 f->do_oop((oop*) &_abstract_ownable_synchronizer_klass); | |
1835 } | 1776 } |
1836 | 1777 |
1837 // Just the classes from defining class loaders | 1778 // Just the classes from defining class loaders |
1838 // Don't iterate over placeholders | 1779 // Don't iterate over placeholders |
1839 void SystemDictionary::classes_do(void f(klassOop)) { | 1780 void SystemDictionary::classes_do(void f(Klass*)) { |
1840 dictionary()->classes_do(f); | 1781 dictionary()->classes_do(f); |
1841 } | 1782 } |
1842 | 1783 |
1843 // Added for initialize_itable_for_klass | 1784 // Added for initialize_itable_for_klass |
1844 // Just the classes from defining class loaders | 1785 // Just the classes from defining class loaders |
1845 // Don't iterate over placeholders | 1786 // Don't iterate over placeholders |
1846 void SystemDictionary::classes_do(void f(klassOop, TRAPS), TRAPS) { | 1787 void SystemDictionary::classes_do(void f(Klass*, TRAPS), TRAPS) { |
1847 dictionary()->classes_do(f, CHECK); | 1788 dictionary()->classes_do(f, CHECK); |
1848 } | 1789 } |
1849 | 1790 |
1850 // All classes, and their class loaders | 1791 // All classes, and their class loaders |
1851 // Don't iterate over placeholders | 1792 // Don't iterate over placeholders |
1852 void SystemDictionary::classes_do(void f(klassOop, oop)) { | 1793 void SystemDictionary::classes_do(void f(Klass*, ClassLoaderData*)) { |
1853 dictionary()->classes_do(f); | 1794 dictionary()->classes_do(f); |
1854 } | 1795 } |
1855 | 1796 |
1856 // All classes, and their class loaders | 1797 // All classes, and their class loaders |
1857 // (added for helpers that use HandleMarks and ResourceMarks) | 1798 // (added for helpers that use HandleMarks and ResourceMarks) |
1858 // Don't iterate over placeholders | 1799 // Don't iterate over placeholders |
1859 void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) { | 1800 void SystemDictionary::classes_do(void f(Klass*, ClassLoaderData*, TRAPS), TRAPS) { |
1860 dictionary()->classes_do(f, CHECK); | 1801 dictionary()->classes_do(f, CHECK); |
1861 } | 1802 } |
1862 | 1803 |
1863 void SystemDictionary::placeholders_do(void f(Symbol*, oop)) { | 1804 void SystemDictionary::placeholders_do(void f(Symbol*)) { |
1864 placeholders()->entries_do(f); | 1805 placeholders()->entries_do(f); |
1865 } | 1806 } |
1866 | 1807 |
1867 void SystemDictionary::methods_do(void f(methodOop)) { | 1808 void SystemDictionary::methods_do(void f(Method*)) { |
1868 dictionary()->methods_do(f); | 1809 dictionary()->methods_do(f); |
1869 invoke_method_table()->methods_do(f); | 1810 invoke_method_table()->methods_do(f); |
1870 } | 1811 } |
1871 | 1812 |
1872 // ---------------------------------------------------------------------------- | 1813 // ---------------------------------------------------------------------------- |
1876 assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later"); | 1817 assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later"); |
1877 | 1818 |
1878 // if multiple threads calling this function, only one thread will load | 1819 // if multiple threads calling this function, only one thread will load |
1879 // the class. The other threads will find the loaded version once the | 1820 // the class. The other threads will find the loaded version once the |
1880 // class is loaded. | 1821 // class is loaded. |
1881 klassOop aos = _abstract_ownable_synchronizer_klass; | 1822 Klass* aos = _abstract_ownable_synchronizer_klass; |
1882 if (aos == NULL) { | 1823 if (aos == NULL) { |
1883 klassOop k = resolve_or_fail(vmSymbols::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK); | 1824 Klass* k = resolve_or_fail(vmSymbols::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK); |
1884 // Force a fence to prevent any read before the write completes | 1825 // Force a fence to prevent any read before the write completes |
1885 OrderAccess::fence(); | 1826 OrderAccess::fence(); |
1886 _abstract_ownable_synchronizer_klass = k; | 1827 _abstract_ownable_synchronizer_klass = k; |
1887 } | 1828 } |
1888 } | 1829 } |
1901 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size); | 1842 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size); |
1902 _resolution_errors = new ResolutionErrorTable(_resolution_error_size); | 1843 _resolution_errors = new ResolutionErrorTable(_resolution_error_size); |
1903 _invoke_method_table = new SymbolPropertyTable(_invoke_method_size); | 1844 _invoke_method_table = new SymbolPropertyTable(_invoke_method_size); |
1904 | 1845 |
1905 // Allocate private object used as system class loader lock | 1846 // Allocate private object used as system class loader lock |
1906 _system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK); | 1847 _system_loader_lock_obj = oopFactory::new_intArray(0, CHECK); |
1907 // Initialize basic classes | 1848 // Initialize basic classes |
1908 initialize_preloaded_classes(CHECK); | 1849 initialize_preloaded_classes(CHECK); |
1909 } | 1850 } |
1910 | 1851 |
1911 // Compact table of directions on the initialization of klasses: | 1852 // Compact table of directions on the initialization of klasses: |
1922 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { | 1863 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { |
1923 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); | 1864 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); |
1924 int info = wk_init_info[id - FIRST_WKID]; | 1865 int info = wk_init_info[id - FIRST_WKID]; |
1925 int sid = (info >> CEIL_LG_OPTION_LIMIT); | 1866 int sid = (info >> CEIL_LG_OPTION_LIMIT); |
1926 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid); | 1867 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid); |
1927 klassOop* klassp = &_well_known_klasses[id]; | 1868 Klass** klassp = &_well_known_klasses[id]; |
1928 bool must_load = (init_opt < SystemDictionary::Opt); | 1869 bool must_load = (init_opt < SystemDictionary::Opt); |
1929 bool try_load = true; | 1870 bool try_load = true; |
1930 if (init_opt == SystemDictionary::Opt_Kernel) { | 1871 if (init_opt == SystemDictionary::Opt_Kernel) { |
1931 #ifndef KERNEL | 1872 #ifndef KERNEL |
1932 try_load = false; | 1873 try_load = false; |
1949 int info = wk_init_info[id - FIRST_WKID]; | 1890 int info = wk_init_info[id - FIRST_WKID]; |
1950 int sid = (info >> CEIL_LG_OPTION_LIMIT); | 1891 int sid = (info >> CEIL_LG_OPTION_LIMIT); |
1951 int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT)); | 1892 int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT)); |
1952 | 1893 |
1953 initialize_wk_klass((WKID)id, opt, CHECK); | 1894 initialize_wk_klass((WKID)id, opt, CHECK); |
1954 | |
1955 // Update limits, so find_well_known_klass can be very fast: | |
1956 Symbol* s = vmSymbols::symbol_at((vmSymbols::SID)sid); | |
1957 if (wk_klass_name_limits[1] == NULL) { | |
1958 wk_klass_name_limits[0] = wk_klass_name_limits[1] = s; | |
1959 } else if (wk_klass_name_limits[1] < s) { | |
1960 wk_klass_name_limits[1] = s; | |
1961 } else if (wk_klass_name_limits[0] > s) { | |
1962 wk_klass_name_limits[0] = s; | |
1963 } | |
1964 } | 1895 } |
1965 | 1896 |
1966 // move the starting value forward to the limit: | 1897 // move the starting value forward to the limit: |
1967 start_id = limit_id; | 1898 start_id = limit_id; |
1968 } | 1899 } |
1969 | |
1970 | 1900 |
1971 void SystemDictionary::initialize_preloaded_classes(TRAPS) { | 1901 void SystemDictionary::initialize_preloaded_classes(TRAPS) { |
1972 assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once"); | 1902 assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once"); |
1973 // Preload commonly used klasses | 1903 // Preload commonly used klasses |
1974 WKID scan = FIRST_WKID; | 1904 WKID scan = FIRST_WKID; |
1975 // first do Object, String, Class | 1905 // first do Object, then String, Class |
1976 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); | 1906 if (UseSharedSpaces) { |
1907 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK); | |
1908 // Initialize the constant pool for the Object_class | |
1909 InstanceKlass* ik = InstanceKlass::cast(Object_klass()); | |
1910 ik->constants()->restore_unshareable_info(CHECK); | |
1911 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); | |
1912 } else { | |
1913 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); | |
1914 } | |
1977 | 1915 |
1978 // Calculate offsets for String and Class classes since they are loaded and | 1916 // Calculate offsets for String and Class classes since they are loaded and |
1979 // can be used after this point. | 1917 // can be used after this point. |
1980 java_lang_String::compute_offsets(); | 1918 java_lang_String::compute_offsets(); |
1981 java_lang_Class::compute_offsets(); | 1919 java_lang_Class::compute_offsets(); |
1990 | 1928 |
1991 // do a bunch more: | 1929 // do a bunch more: |
1992 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK); | 1930 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK); |
1993 | 1931 |
1994 // Preload ref klasses and set reference types | 1932 // Preload ref klasses and set reference types |
1995 instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER); | 1933 InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER); |
1996 instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass)); | 1934 InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass)); |
1997 | 1935 |
1998 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK); | 1936 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK); |
1999 instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT); | 1937 InstanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT); |
2000 instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK); | 1938 InstanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK); |
2001 instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL); | 1939 InstanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL); |
2002 instanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM); | 1940 InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM); |
2003 | 1941 |
2004 // JSR 292 classes | 1942 // JSR 292 classes |
2005 WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass); | 1943 WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass); |
2006 WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass); | 1944 WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass); |
2007 initialize_wk_klasses_until(jsr292_group_start, scan, CHECK); | 1945 initialize_wk_klasses_until(jsr292_group_start, scan, CHECK); |
2030 warning("Cannot find sun/jkernel/DownloadManager"); | 1968 warning("Cannot find sun/jkernel/DownloadManager"); |
2031 } | 1969 } |
2032 #endif // KERNEL | 1970 #endif // KERNEL |
2033 | 1971 |
2034 { // Compute whether we should use loadClass or loadClassInternal when loading classes. | 1972 { // Compute whether we should use loadClass or loadClassInternal when loading classes. |
2035 methodOop method = instanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature()); | 1973 Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature()); |
2036 _has_loadClassInternal = (method != NULL); | 1974 _has_loadClassInternal = (method != NULL); |
2037 } | 1975 } |
2038 { // Compute whether we should use checkPackageAccess or NOT | 1976 { // Compute whether we should use checkPackageAccess or NOT |
2039 methodOop method = instanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature()); | 1977 Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature()); |
2040 _has_checkPackageAccess = (method != NULL); | 1978 _has_checkPackageAccess = (method != NULL); |
2041 } | 1979 } |
2042 } | 1980 } |
2043 | 1981 |
2044 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer). | 1982 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer). |
2045 // If so, returns the basic type it holds. If not, returns T_OBJECT. | 1983 // If so, returns the basic type it holds. If not, returns T_OBJECT. |
2046 BasicType SystemDictionary::box_klass_type(klassOop k) { | 1984 BasicType SystemDictionary::box_klass_type(Klass* k) { |
2047 assert(k != NULL, ""); | 1985 assert(k != NULL, ""); |
2048 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { | 1986 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { |
2049 if (_box_klasses[i] == k) | 1987 if (_box_klasses[i] == k) |
2050 return (BasicType)i; | 1988 return (BasicType)i; |
2051 } | 1989 } |
2052 return T_OBJECT; | 1990 return T_OBJECT; |
2053 } | |
2054 | |
2055 KlassHandle SystemDictionaryHandles::box_klass(BasicType t) { | |
2056 if (t >= T_BOOLEAN && t <= T_VOID) | |
2057 return KlassHandle(&SystemDictionary::_box_klasses[t], true); | |
2058 else | |
2059 return KlassHandle(); | |
2060 } | 1991 } |
2061 | 1992 |
2062 // Constraints on class loaders. The details of the algorithm can be | 1993 // Constraints on class loaders. The details of the algorithm can be |
2063 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java | 1994 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java |
2064 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is | 1995 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is |
2065 // that the system dictionary needs to maintain a set of contraints that | 1996 // that the system dictionary needs to maintain a set of contraints that |
2066 // must be satisfied by all classes in the dictionary. | 1997 // must be satisfied by all classes in the dictionary. |
2067 // if defining is true, then LinkageError if already in systemDictionary | 1998 // if defining is true, then LinkageError if already in systemDictionary |
2068 // if initiating loader, then ok if instanceKlass matches existing entry | 1999 // if initiating loader, then ok if InstanceKlass matches existing entry |
2069 | 2000 |
2070 void SystemDictionary::check_constraints(int d_index, unsigned int d_hash, | 2001 void SystemDictionary::check_constraints(int d_index, unsigned int d_hash, |
2071 instanceKlassHandle k, | 2002 instanceKlassHandle k, |
2072 Handle class_loader, bool defining, | 2003 Handle class_loader, bool defining, |
2073 TRAPS) { | 2004 TRAPS) { |
2074 const char *linkage_error = NULL; | 2005 const char *linkage_error = NULL; |
2075 { | 2006 { |
2076 Symbol* name = k->name(); | 2007 Symbol* name = k->name(); |
2008 ClassLoaderData *loader_data = class_loader_data(class_loader); | |
2009 | |
2077 MutexLocker mu(SystemDictionary_lock, THREAD); | 2010 MutexLocker mu(SystemDictionary_lock, THREAD); |
2078 | 2011 |
2079 klassOop check = find_class(d_index, d_hash, name, class_loader); | 2012 Klass* check = find_class(d_index, d_hash, name, loader_data); |
2080 if (check != (klassOop)NULL) { | 2013 if (check != (Klass*)NULL) { |
2081 // if different instanceKlass - duplicate class definition, | 2014 // if different InstanceKlass - duplicate class definition, |
2082 // else - ok, class loaded by a different thread in parallel, | 2015 // else - ok, class loaded by a different thread in parallel, |
2083 // we should only have found it if it was done loading and ok to use | 2016 // we should only have found it if it was done loading and ok to use |
2084 // system dictionary only holds instance classes, placeholders | 2017 // system dictionary only holds instance classes, placeholders |
2085 // also holds array classes | 2018 // also holds array classes |
2086 | 2019 |
2087 assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary"); | 2020 assert(check->oop_is_instance(), "noninstance in systemdictionary"); |
2088 if ((defining == true) || (k() != check)) { | 2021 if ((defining == true) || (k() != check)) { |
2089 linkage_error = "loader (instance of %s): attempted duplicate class " | 2022 linkage_error = "loader (instance of %s): attempted duplicate class " |
2090 "definition for name: \"%s\""; | 2023 "definition for name: \"%s\""; |
2091 } else { | 2024 } else { |
2092 return; | 2025 return; |
2093 } | 2026 } |
2094 } | 2027 } |
2095 | 2028 |
2096 #ifdef ASSERT | 2029 #ifdef ASSERT |
2097 Symbol* ph_check = find_placeholder(name, class_loader); | 2030 Symbol* ph_check = find_placeholder(name, loader_data); |
2098 assert(ph_check == NULL || ph_check == name, "invalid symbol"); | 2031 assert(ph_check == NULL || ph_check == name, "invalid symbol"); |
2099 #endif | 2032 #endif |
2100 | 2033 |
2101 if (linkage_error == NULL) { | 2034 if (linkage_error == NULL) { |
2102 if (constraints()->check_or_update(k, class_loader, name) == false) { | 2035 if (constraints()->check_or_update(k, class_loader, name) == false) { |
2130 Handle class_loader, | 2063 Handle class_loader, |
2131 TRAPS) { | 2064 TRAPS) { |
2132 // Compile_lock prevents systemDictionary updates during compilations | 2065 // Compile_lock prevents systemDictionary updates during compilations |
2133 assert_locked_or_safepoint(Compile_lock); | 2066 assert_locked_or_safepoint(Compile_lock); |
2134 Symbol* name = k->name(); | 2067 Symbol* name = k->name(); |
2068 ClassLoaderData *loader_data = class_loader_data(class_loader); | |
2135 | 2069 |
2136 { | 2070 { |
2137 MutexLocker mu1(SystemDictionary_lock, THREAD); | 2071 MutexLocker mu1(SystemDictionary_lock, THREAD); |
2138 | 2072 |
2139 // See whether biased locking is enabled and if so set it for this | 2073 // See whether biased locking is enabled and if so set it for this |
2140 // klass. | 2074 // klass. |
2141 // Note that this must be done past the last potential blocking | 2075 // Note that this must be done past the last potential blocking |
2142 // point / safepoint. We enable biased locking lazily using a | 2076 // point / safepoint. We enable biased locking lazily using a |
2143 // VM_Operation to iterate the SystemDictionary and installing the | 2077 // VM_Operation to iterate the SystemDictionary and installing the |
2144 // biasable mark word into each instanceKlass's prototype header. | 2078 // biasable mark word into each InstanceKlass's prototype header. |
2145 // To avoid race conditions where we accidentally miss enabling the | 2079 // To avoid race conditions where we accidentally miss enabling the |
2146 // optimization for one class in the process of being added to the | 2080 // optimization for one class in the process of being added to the |
2147 // dictionary, we must not safepoint after the test of | 2081 // dictionary, we must not safepoint after the test of |
2148 // BiasedLocking::enabled(). | 2082 // BiasedLocking::enabled(). |
2149 if (UseBiasedLocking && BiasedLocking::enabled()) { | 2083 if (UseBiasedLocking && BiasedLocking::enabled()) { |
2162 // All loaded classes get a unique ID. | 2096 // All loaded classes get a unique ID. |
2163 TRACE_INIT_ID(k); | 2097 TRACE_INIT_ID(k); |
2164 | 2098 |
2165 // Check for a placeholder. If there, remove it and make a | 2099 // Check for a placeholder. If there, remove it and make a |
2166 // new system dictionary entry. | 2100 // new system dictionary entry. |
2167 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); | 2101 placeholders()->find_and_remove(p_index, p_hash, name, loader_data, THREAD); |
2168 klassOop sd_check = find_class(d_index, d_hash, name, class_loader); | 2102 Klass* sd_check = find_class(d_index, d_hash, name, loader_data); |
2169 if (sd_check == NULL) { | 2103 if (sd_check == NULL) { |
2170 dictionary()->add_klass(name, class_loader, k); | 2104 dictionary()->add_klass(name, loader_data, k); |
2171 notice_modification(); | 2105 notice_modification(); |
2172 } | 2106 } |
2173 #ifdef ASSERT | 2107 #ifdef ASSERT |
2174 sd_check = find_class(d_index, d_hash, name, class_loader); | 2108 sd_check = find_class(d_index, d_hash, name, loader_data); |
2175 assert (sd_check != NULL, "should have entry in system dictionary"); | 2109 assert (sd_check != NULL, "should have entry in system dictionary"); |
2176 // Changed to allow PH to remain to complete class circularity checking | 2110 // Changed to allow PH to remain to complete class circularity checking |
2177 // while only one thread can define a class at one time, multiple | 2111 // while only one thread can define a class at one time, multiple |
2178 // classes can resolve the superclass for a class at one time, | 2112 // classes can resolve the superclass for a class at one time, |
2179 // and the placeholder is used to track that | 2113 // and the placeholder is used to track that |
2186 | 2120 |
2187 | 2121 |
2188 // Try to find a class name using the loader constraints. The | 2122 // Try to find a class name using the loader constraints. The |
2189 // loader constraints might know about a class that isn't fully loaded | 2123 // loader constraints might know about a class that isn't fully loaded |
2190 // yet and these will be ignored. | 2124 // yet and these will be ignored. |
2191 klassOop SystemDictionary::find_constrained_instance_or_array_klass( | 2125 Klass* SystemDictionary::find_constrained_instance_or_array_klass( |
2192 Symbol* class_name, Handle class_loader, TRAPS) { | 2126 Symbol* class_name, Handle class_loader, TRAPS) { |
2193 | 2127 |
2194 // First see if it has been loaded directly. | 2128 // First see if it has been loaded directly. |
2195 // Force the protection domain to be null. (This removes protection checks.) | 2129 // Force the protection domain to be null. (This removes protection checks.) |
2196 Handle no_protection_domain; | 2130 Handle no_protection_domain; |
2197 klassOop klass = find_instance_or_array_klass(class_name, class_loader, | 2131 Klass* klass = find_instance_or_array_klass(class_name, class_loader, |
2198 no_protection_domain, CHECK_NULL); | 2132 no_protection_domain, CHECK_NULL); |
2199 if (klass != NULL) | 2133 if (klass != NULL) |
2200 return klass; | 2134 return klass; |
2201 | 2135 |
2202 // Now look to see if it has been loaded elsewhere, and is subject to | 2136 // Now look to see if it has been loaded elsewhere, and is subject to |
2203 // a loader constraint that would require this loader to return the | 2137 // a loader constraint that would require this loader to return the |
2204 // klass that is already loaded. | 2138 // klass that is already loaded. |
2205 if (FieldType::is_array(class_name)) { | 2139 if (FieldType::is_array(class_name)) { |
2206 // For array classes, their klassOops are not kept in the | 2140 // For array classes, their Klass*s are not kept in the |
2207 // constraint table. The element klassOops are. | 2141 // constraint table. The element Klass*s are. |
2208 FieldArrayInfo fd; | 2142 FieldArrayInfo fd; |
2209 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL)); | 2143 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL)); |
2210 if (t != T_OBJECT) { | 2144 if (t != T_OBJECT) { |
2211 klass = Universe::typeArrayKlassObj(t); | 2145 klass = Universe::typeArrayKlassObj(t); |
2212 } else { | 2146 } else { |
2229 | 2163 |
2230 bool SystemDictionary::add_loader_constraint(Symbol* class_name, | 2164 bool SystemDictionary::add_loader_constraint(Symbol* class_name, |
2231 Handle class_loader1, | 2165 Handle class_loader1, |
2232 Handle class_loader2, | 2166 Handle class_loader2, |
2233 Thread* THREAD) { | 2167 Thread* THREAD) { |
2168 ClassLoaderData* loader_data1 = class_loader_data(class_loader1); | |
2169 ClassLoaderData* loader_data2 = class_loader_data(class_loader2); | |
2170 | |
2234 Symbol* constraint_name = NULL; | 2171 Symbol* constraint_name = NULL; |
2235 if (!FieldType::is_array(class_name)) { | 2172 if (!FieldType::is_array(class_name)) { |
2236 constraint_name = class_name; | 2173 constraint_name = class_name; |
2237 } else { | 2174 } else { |
2238 // For array classes, their klassOops are not kept in the | 2175 // For array classes, their Klass*s are not kept in the |
2239 // constraint table. The element classes are. | 2176 // constraint table. The element classes are. |
2240 FieldArrayInfo fd; | 2177 FieldArrayInfo fd; |
2241 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false)); | 2178 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false)); |
2242 // primitive types always pass | 2179 // primitive types always pass |
2243 if (t != T_OBJECT) { | 2180 if (t != T_OBJECT) { |
2244 return true; | 2181 return true; |
2245 } else { | 2182 } else { |
2246 constraint_name = fd.object_key(); | 2183 constraint_name = fd.object_key(); |
2247 } | 2184 } |
2248 } | 2185 } |
2249 unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, class_loader1); | 2186 unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, loader_data1); |
2250 int d_index1 = dictionary()->hash_to_index(d_hash1); | 2187 int d_index1 = dictionary()->hash_to_index(d_hash1); |
2251 | 2188 |
2252 unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, class_loader2); | 2189 unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, loader_data2); |
2253 int d_index2 = dictionary()->hash_to_index(d_hash2); | 2190 int d_index2 = dictionary()->hash_to_index(d_hash2); |
2254 { | 2191 { |
2255 MutexLocker mu_s(SystemDictionary_lock, THREAD); | 2192 MutexLocker mu_s(SystemDictionary_lock, THREAD); |
2256 | 2193 |
2257 // Better never do a GC while we're holding these oops | 2194 // Better never do a GC while we're holding these oops |
2258 No_Safepoint_Verifier nosafepoint; | 2195 No_Safepoint_Verifier nosafepoint; |
2259 | 2196 |
2260 klassOop klass1 = find_class(d_index1, d_hash1, constraint_name, class_loader1); | 2197 Klass* klass1 = find_class(d_index1, d_hash1, constraint_name, loader_data1); |
2261 klassOop klass2 = find_class(d_index2, d_hash2, constraint_name, class_loader2); | 2198 Klass* klass2 = find_class(d_index2, d_hash2, constraint_name, loader_data2); |
2262 return constraints()->add_entry(constraint_name, klass1, class_loader1, | 2199 return constraints()->add_entry(constraint_name, klass1, class_loader1, |
2263 klass2, class_loader2); | 2200 klass2, class_loader2); |
2264 } | 2201 } |
2265 } | 2202 } |
2266 | 2203 |
2271 int index = resolution_errors()->hash_to_index(hash); | 2208 int index = resolution_errors()->hash_to_index(hash); |
2272 { | 2209 { |
2273 MutexLocker ml(SystemDictionary_lock, Thread::current()); | 2210 MutexLocker ml(SystemDictionary_lock, Thread::current()); |
2274 resolution_errors()->add_entry(index, hash, pool, which, error); | 2211 resolution_errors()->add_entry(index, hash, pool, which, error); |
2275 } | 2212 } |
2213 } | |
2214 | |
2215 // Delete a resolution error for RedefineClasses for a constant pool is going away | |
2216 void SystemDictionary::delete_resolution_error(ConstantPool* pool) { | |
2217 resolution_errors()->delete_entry(pool); | |
2276 } | 2218 } |
2277 | 2219 |
2278 // Lookup resolution error table. Returns error if found, otherwise NULL. | 2220 // Lookup resolution error table. Returns error if found, otherwise NULL. |
2279 Symbol* SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) { | 2221 Symbol* SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) { |
2280 unsigned int hash = resolution_errors()->compute_hash(pool, which); | 2222 unsigned int hash = resolution_errors()->compute_hash(pool, which); |
2374 | 2316 |
2375 unsigned int hash = invoke_method_table()->compute_hash(signature, iid); | 2317 unsigned int hash = invoke_method_table()->compute_hash(signature, iid); |
2376 int index = invoke_method_table()->hash_to_index(hash); | 2318 int index = invoke_method_table()->hash_to_index(hash); |
2377 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid); | 2319 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid); |
2378 methodHandle m; | 2320 methodHandle m; |
2379 if (spe == NULL || spe->property_oop() == NULL) { | 2321 if (spe == NULL || spe->method() == NULL) { |
2380 spe = NULL; | 2322 spe = NULL; |
2381 // Must create lots of stuff here, but outside of the SystemDictionary lock. | 2323 // Must create lots of stuff here, but outside of the SystemDictionary lock. |
2382 m = methodOopDesc::make_method_handle_intrinsic(iid, signature, CHECK_(empty)); | 2324 m = Method::make_method_handle_intrinsic(iid, signature, CHECK_(empty)); |
2383 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_highest_tier, | 2325 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_highest_tier, |
2384 methodHandle(), CompileThreshold, "MH", CHECK_(empty)); | 2326 methodHandle(), CompileThreshold, "MH", CHECK_(empty)); |
2385 | 2327 |
2386 // Now grab the lock. We might have to throw away the new method, | 2328 // Now grab the lock. We might have to throw away the new method, |
2387 // if a racing thread has managed to install one at the same time. | 2329 // if a racing thread has managed to install one at the same time. |
2388 { | 2330 { |
2389 MutexLocker ml(SystemDictionary_lock, THREAD); | 2331 MutexLocker ml(SystemDictionary_lock, THREAD); |
2390 spe = invoke_method_table()->find_entry(index, hash, signature, iid); | 2332 spe = invoke_method_table()->find_entry(index, hash, signature, iid); |
2391 if (spe == NULL) | 2333 if (spe == NULL) |
2392 spe = invoke_method_table()->add_entry(index, hash, signature, iid); | 2334 spe = invoke_method_table()->add_entry(index, hash, signature, iid); |
2393 if (spe->property_oop() == NULL) | 2335 if (spe->method() == NULL) |
2394 spe->set_property_oop(m()); | 2336 spe->set_method(m()); |
2395 } | 2337 } |
2396 } | 2338 } |
2397 | 2339 |
2398 assert(spe != NULL && spe->property_oop() != NULL, ""); | 2340 assert(spe != NULL && spe->method() != NULL, ""); |
2399 m = methodOop(spe->property_oop()); | 2341 return spe->method(); |
2400 assert(m->is_method(), ""); | |
2401 | |
2402 return m; | |
2403 } | 2342 } |
2404 | 2343 |
2405 // Helper for unpacking the return value from linkMethod and linkCallSite. | 2344 // Helper for unpacking the return value from linkMethod and linkCallSite. |
2406 static methodHandle unpack_method_and_appendix(Handle mname, | 2345 static methodHandle unpack_method_and_appendix(Handle mname, |
2407 objArrayHandle appendix_box, | 2346 objArrayHandle appendix_box, |
2408 Handle* appendix_result, | 2347 Handle* appendix_result, |
2409 TRAPS) { | 2348 TRAPS) { |
2410 methodHandle empty; | 2349 methodHandle empty; |
2411 if (mname.not_null()) { | 2350 if (mname.not_null()) { |
2412 oop vmtarget = java_lang_invoke_MemberName::vmtarget(mname()); | 2351 Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(mname()); |
2413 if (vmtarget != NULL && vmtarget->is_method()) { | 2352 if (vmtarget != NULL && vmtarget->is_method()) { |
2414 methodOop m = methodOop(vmtarget); | 2353 Method* m = (Method*)vmtarget; |
2415 oop appendix = appendix_box->obj_at(0); | 2354 oop appendix = appendix_box->obj_at(0); |
2416 if (TraceMethodHandles) { | 2355 if (TraceMethodHandles) { |
2417 #ifndef PRODUCT | 2356 #ifndef PRODUCT |
2418 tty->print("Linked method="INTPTR_FORMAT": ", m); | 2357 tty->print("Linked method="INTPTR_FORMAT": ", m); |
2419 m->print(); | 2358 m->print(); |
2430 } | 2369 } |
2431 | 2370 |
2432 methodHandle SystemDictionary::find_method_handle_invoker(Symbol* name, | 2371 methodHandle SystemDictionary::find_method_handle_invoker(Symbol* name, |
2433 Symbol* signature, | 2372 Symbol* signature, |
2434 KlassHandle accessing_klass, | 2373 KlassHandle accessing_klass, |
2435 Handle* appendix_result, | 2374 Handle *appendix_result, |
2375 Handle *method_type_result, | |
2436 TRAPS) { | 2376 TRAPS) { |
2437 methodHandle empty; | 2377 methodHandle empty; |
2438 assert(EnableInvokeDynamic, ""); | 2378 assert(EnableInvokeDynamic, ""); |
2439 assert(!THREAD->is_Compiler_thread(), ""); | 2379 assert(!THREAD->is_Compiler_thread(), ""); |
2440 Handle method_type = | 2380 Handle method_type = |
2441 SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty)); | 2381 SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty)); |
2442 if (false) { // FIXME: Decide if the Java upcall should resolve signatures. | 2382 if (false) { // FIXME: Decide if the Java upcall should resolve signatures. |
2443 method_type = java_lang_String::create_from_symbol(signature, CHECK_(empty)); | 2383 method_type = java_lang_String::create_from_symbol(signature, CHECK_(empty)); |
2444 } | 2384 } |
2445 | 2385 |
2446 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass(); | 2386 KlassHandle mh_klass = SystemDictionary::MethodHandle_klass(); |
2447 int ref_kind = JVM_REF_invokeVirtual; | 2387 int ref_kind = JVM_REF_invokeVirtual; |
2448 Handle name_str = StringTable::intern(name, CHECK_(empty)); | 2388 Handle name_str = StringTable::intern(name, CHECK_(empty)); |
2449 objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty)); | 2389 objArrayHandle appendix_box = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1, CHECK_(empty)); |
2450 assert(appendix_box->obj_at(0) == NULL, ""); | 2390 assert(appendix_box->obj_at(0) == NULL, ""); |
2451 | 2391 |
2462 SystemDictionary::MethodHandleNatives_klass(), | 2402 SystemDictionary::MethodHandleNatives_klass(), |
2463 vmSymbols::linkMethod_name(), | 2403 vmSymbols::linkMethod_name(), |
2464 vmSymbols::linkMethod_signature(), | 2404 vmSymbols::linkMethod_signature(), |
2465 &args, CHECK_(empty)); | 2405 &args, CHECK_(empty)); |
2466 Handle mname(THREAD, (oop) result.get_jobject()); | 2406 Handle mname(THREAD, (oop) result.get_jobject()); |
2407 (*method_type_result) = method_type; | |
2467 return unpack_method_and_appendix(mname, appendix_box, appendix_result, THREAD); | 2408 return unpack_method_and_appendix(mname, appendix_box, appendix_result, THREAD); |
2468 } | 2409 } |
2469 | 2410 |
2470 | 2411 |
2471 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given | 2412 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given |
2478 Handle empty; | 2419 Handle empty; |
2479 vmIntrinsics::ID null_iid = vmIntrinsics::_none; // distinct from all method handle invoker intrinsics | 2420 vmIntrinsics::ID null_iid = vmIntrinsics::_none; // distinct from all method handle invoker intrinsics |
2480 unsigned int hash = invoke_method_table()->compute_hash(signature, null_iid); | 2421 unsigned int hash = invoke_method_table()->compute_hash(signature, null_iid); |
2481 int index = invoke_method_table()->hash_to_index(hash); | 2422 int index = invoke_method_table()->hash_to_index(hash); |
2482 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid); | 2423 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid); |
2483 if (spe != NULL && spe->property_oop() != NULL) { | 2424 if (spe != NULL && spe->method_type() != NULL) { |
2484 assert(java_lang_invoke_MethodType::is_instance(spe->property_oop()), ""); | 2425 assert(java_lang_invoke_MethodType::is_instance(spe->method_type()), ""); |
2485 return Handle(THREAD, spe->property_oop()); | 2426 return Handle(THREAD, spe->method_type()); |
2486 } else if (THREAD->is_Compiler_thread()) { | 2427 } else if (THREAD->is_Compiler_thread()) { |
2487 warning("SystemDictionary::find_method_handle_type called from compiler thread"); // FIXME | 2428 warning("SystemDictionary::find_method_handle_type called from compiler thread"); // FIXME |
2488 return Handle(); // do not attempt from within compiler, unless it was cached | 2429 return Handle(); // do not attempt from within compiler, unless it was cached |
2489 } | 2430 } |
2490 | 2431 |
2502 mirror = ss.as_java_mirror(class_loader, protection_domain, | 2443 mirror = ss.as_java_mirror(class_loader, protection_domain, |
2503 SignatureStream::ReturnNull, CHECK_(empty)); | 2444 SignatureStream::ReturnNull, CHECK_(empty)); |
2504 if (mirror == NULL) { | 2445 if (mirror == NULL) { |
2505 // fall back from BCP to accessing_klass | 2446 // fall back from BCP to accessing_klass |
2506 if (accessing_klass.not_null()) { | 2447 if (accessing_klass.not_null()) { |
2507 class_loader = Handle(THREAD, instanceKlass::cast(accessing_klass())->class_loader()); | 2448 class_loader = Handle(THREAD, InstanceKlass::cast(accessing_klass())->class_loader()); |
2508 protection_domain = Handle(THREAD, instanceKlass::cast(accessing_klass())->protection_domain()); | 2449 protection_domain = Handle(THREAD, InstanceKlass::cast(accessing_klass())->protection_domain()); |
2509 } | 2450 } |
2510 is_on_bcp = false; | 2451 is_on_bcp = false; |
2511 } | 2452 } |
2512 } | 2453 } |
2513 if (!is_on_bcp) { | 2454 if (!is_on_bcp) { |
2520 else | 2461 else |
2521 pts->obj_at_put(arg++, mirror); | 2462 pts->obj_at_put(arg++, mirror); |
2522 | 2463 |
2523 // Check accessibility. | 2464 // Check accessibility. |
2524 if (ss.is_object() && accessing_klass.not_null()) { | 2465 if (ss.is_object() && accessing_klass.not_null()) { |
2525 klassOop sel_klass = java_lang_Class::as_klassOop(mirror); | 2466 Klass* sel_klass = java_lang_Class::as_Klass(mirror); |
2526 mirror = NULL; // safety | 2467 mirror = NULL; // safety |
2527 // Emulate constantPoolOopDesc::verify_constant_pool_resolve. | 2468 // Emulate ConstantPool::verify_constant_pool_resolve. |
2528 if (Klass::cast(sel_klass)->oop_is_objArray()) | 2469 if (Klass::cast(sel_klass)->oop_is_objArray()) |
2529 sel_klass = objArrayKlass::cast(sel_klass)->bottom_klass(); | 2470 sel_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass(); |
2530 if (Klass::cast(sel_klass)->oop_is_instance()) { | 2471 if (Klass::cast(sel_klass)->oop_is_instance()) { |
2531 KlassHandle sel_kh(THREAD, sel_klass); | 2472 KlassHandle sel_kh(THREAD, sel_klass); |
2532 LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty)); | 2473 LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty)); |
2533 } | 2474 } |
2534 } | 2475 } |
2550 // We can cache this MethodType inside the JVM. | 2491 // We can cache this MethodType inside the JVM. |
2551 MutexLocker ml(SystemDictionary_lock, THREAD); | 2492 MutexLocker ml(SystemDictionary_lock, THREAD); |
2552 spe = invoke_method_table()->find_entry(index, hash, signature, null_iid); | 2493 spe = invoke_method_table()->find_entry(index, hash, signature, null_iid); |
2553 if (spe == NULL) | 2494 if (spe == NULL) |
2554 spe = invoke_method_table()->add_entry(index, hash, signature, null_iid); | 2495 spe = invoke_method_table()->add_entry(index, hash, signature, null_iid); |
2555 if (spe->property_oop() == NULL) { | 2496 if (spe->method_type() == NULL) { |
2556 spe->set_property_oop(method_type()); | 2497 spe->set_method_type(method_type()); |
2557 } | 2498 } |
2558 } | 2499 } |
2559 | 2500 |
2560 // report back to the caller with the MethodType | 2501 // report back to the caller with the MethodType |
2561 return method_type; | 2502 return method_type; |
2608 // name and signature, as interpreted relative to the given class loader. | 2549 // name and signature, as interpreted relative to the given class loader. |
2609 methodHandle SystemDictionary::find_dynamic_call_site_invoker(KlassHandle caller, | 2550 methodHandle SystemDictionary::find_dynamic_call_site_invoker(KlassHandle caller, |
2610 Handle bootstrap_specifier, | 2551 Handle bootstrap_specifier, |
2611 Symbol* name, | 2552 Symbol* name, |
2612 Symbol* type, | 2553 Symbol* type, |
2613 Handle* appendix_result, | 2554 Handle *appendix_result, |
2555 Handle *method_type_result, | |
2614 TRAPS) { | 2556 TRAPS) { |
2615 methodHandle empty; | 2557 methodHandle empty; |
2616 Handle bsm, info; | 2558 Handle bsm, info; |
2617 if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) { | 2559 if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) { |
2618 bsm = bootstrap_specifier; | 2560 bsm = bootstrap_specifier; |
2651 SystemDictionary::MethodHandleNatives_klass(), | 2593 SystemDictionary::MethodHandleNatives_klass(), |
2652 vmSymbols::linkCallSite_name(), | 2594 vmSymbols::linkCallSite_name(), |
2653 vmSymbols::linkCallSite_signature(), | 2595 vmSymbols::linkCallSite_signature(), |
2654 &args, CHECK_(empty)); | 2596 &args, CHECK_(empty)); |
2655 Handle mname(THREAD, (oop) result.get_jobject()); | 2597 Handle mname(THREAD, (oop) result.get_jobject()); |
2598 (*method_type_result) = method_type; | |
2656 return unpack_method_and_appendix(mname, appendix_box, appendix_result, THREAD); | 2599 return unpack_method_and_appendix(mname, appendix_box, appendix_result, THREAD); |
2657 } | 2600 } |
2658 | 2601 |
2659 // Since the identity hash code for symbols changes when the symbols are | 2602 // Since the identity hash code for symbols changes when the symbols are |
2660 // moved from the regular perm gen (hash in the mark word) to the shared | 2603 // moved from the regular perm gen (hash in the mark word) to the shared |
2719 guarantee(constraints() != NULL, "Verify of loader constraints failed"); | 2662 guarantee(constraints() != NULL, "Verify of loader constraints failed"); |
2720 constraints()->verify(dictionary(), placeholders()); | 2663 constraints()->verify(dictionary(), placeholders()); |
2721 } | 2664 } |
2722 | 2665 |
2723 | 2666 |
2724 void SystemDictionary::verify_obj_klass_present(Handle obj, | 2667 void SystemDictionary::verify_obj_klass_present(Symbol* class_name, |
2725 Symbol* class_name, | 2668 ClassLoaderData* loader_data) { |
2726 Handle class_loader) { | |
2727 GCMutexLocker mu(SystemDictionary_lock); | 2669 GCMutexLocker mu(SystemDictionary_lock); |
2728 Symbol* name; | 2670 Symbol* name; |
2729 | 2671 |
2730 klassOop probe = find_class(class_name, class_loader); | 2672 Klass* probe = find_class(class_name, loader_data); |
2731 if (probe == NULL) { | 2673 if (probe == NULL) { |
2732 probe = SystemDictionary::find_shared_class(class_name); | 2674 probe = SystemDictionary::find_shared_class(class_name); |
2733 if (probe == NULL) { | 2675 if (probe == NULL) { |
2734 name = find_placeholder(class_name, class_loader); | 2676 name = find_placeholder(class_name, loader_data); |
2735 } | 2677 } |
2736 } | 2678 } |
2737 guarantee(probe != NULL || name != NULL, | 2679 guarantee(probe != NULL || name != NULL, |
2738 "Loaded klasses should be in SystemDictionary"); | 2680 "Loaded klasses should be in SystemDictionary"); |
2739 } | 2681 } |
2749 static int class_size; // size of class objects in words | 2691 static int class_size; // size of class objects in words |
2750 static int method_size; // size of method objects in words | 2692 static int method_size; // size of method objects in words |
2751 static int debug_size; // size of debug info in methods | 2693 static int debug_size; // size of debug info in methods |
2752 static int methoddata_size; // size of methodData objects in words | 2694 static int methoddata_size; // size of methodData objects in words |
2753 | 2695 |
2754 static void do_class(klassOop k) { | 2696 static void do_class(Klass* k) { |
2755 nclasses++; | 2697 nclasses++; |
2756 class_size += k->size(); | 2698 class_size += k->size(); |
2757 if (k->klass_part()->oop_is_instance()) { | 2699 if (k->oop_is_instance()) { |
2758 instanceKlass* ik = (instanceKlass*)k->klass_part(); | 2700 InstanceKlass* ik = (InstanceKlass*)k; |
2759 class_size += ik->methods()->size(); | 2701 class_size += ik->methods()->size(); |
2760 class_size += ik->constants()->size(); | 2702 class_size += ik->constants()->size(); |
2761 class_size += ik->local_interfaces()->size(); | 2703 class_size += ik->local_interfaces()->size(); |
2762 class_size += ik->transitive_interfaces()->size(); | 2704 class_size += ik->transitive_interfaces()->size(); |
2763 // We do not have to count implementors, since we only store one! | 2705 // We do not have to count implementors, since we only store one! |
2764 class_size += ik->fields()->length(); | 2706 // SSS: How should these be accounted now that they have moved? |
2765 } | 2707 // class_size += ik->fields()->length(); |
2766 } | 2708 } |
2767 | 2709 } |
2768 static void do_method(methodOop m) { | 2710 |
2711 static void do_method(Method* m) { | |
2769 nmethods++; | 2712 nmethods++; |
2770 method_size += m->size(); | 2713 method_size += m->size(); |
2771 // class loader uses same objArray for empty vectors, so don't count these | 2714 // class loader uses same objArray for empty vectors, so don't count these |
2772 if (m->has_stackmap_table()) { | 2715 if (m->has_stackmap_table()) { |
2773 method_size += m->stackmap_data()->size(); | 2716 method_size += m->stackmap_data()->size(); |
2774 } | 2717 } |
2775 | 2718 |
2776 methodDataOop mdo = m->method_data(); | 2719 MethodData* mdo = m->method_data(); |
2777 if (mdo != NULL) { | 2720 if (mdo != NULL) { |
2778 nmethoddata++; | 2721 nmethoddata++; |
2779 methoddata_size += mdo->size(); | 2722 methoddata_size += mdo->size(); |
2780 } | 2723 } |
2781 } | 2724 } |
2834 _number_of_bytecodes = 0; | 2777 _number_of_bytecodes = 0; |
2835 for (int i = 0; i < max_parameter_size ; i++) _parameter_size_profile[i] = 0; | 2778 for (int i = 0; i < max_parameter_size ; i++) _parameter_size_profile[i] = 0; |
2836 for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile [j] = 0; | 2779 for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile [j] = 0; |
2837 }; | 2780 }; |
2838 | 2781 |
2839 static void do_method(methodOop m) { | 2782 static void do_method(Method* m) { |
2840 _number_of_methods++; | 2783 _number_of_methods++; |
2841 // collect flag info | 2784 // collect flag info |
2842 if (m->is_final() ) _number_of_final_methods++; | 2785 if (m->is_final() ) _number_of_final_methods++; |
2843 if (m->is_static() ) _number_of_static_methods++; | 2786 if (m->is_static() ) _number_of_static_methods++; |
2844 if (m->is_native() ) _number_of_native_methods++; | 2787 if (m->is_native() ) _number_of_native_methods++; |