Mercurial > hg > truffle
comparison src/share/vm/classfile/systemDictionary.cpp @ 2181:d25d4ca69222
Merge.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Wed, 16 Feb 2011 13:47:20 +0100 |
parents | 06f017f7daa7 3582bf76420e |
children | 2ab52cda08e5 |
comparison
equal
deleted
inserted
replaced
2108:50b45e2d9725 | 2181:d25d4ca69222 |
---|---|
91 void SystemDictionary::compute_java_system_loader(TRAPS) { | 91 void SystemDictionary::compute_java_system_loader(TRAPS) { |
92 KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass)); | 92 KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass)); |
93 JavaValue result(T_OBJECT); | 93 JavaValue result(T_OBJECT); |
94 JavaCalls::call_static(&result, | 94 JavaCalls::call_static(&result, |
95 KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)), | 95 KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)), |
96 vmSymbolHandles::getSystemClassLoader_name(), | 96 vmSymbols::getSystemClassLoader_name(), |
97 vmSymbolHandles::void_classloader_signature(), | 97 vmSymbols::void_classloader_signature(), |
98 CHECK); | 98 CHECK); |
99 | 99 |
100 _java_system_loader = (oop)result.get_jobject(); | 100 _java_system_loader = (oop)result.get_jobject(); |
101 } | 101 } |
102 | 102 |
105 // debugging | 105 // debugging |
106 | 106 |
107 #ifdef ASSERT | 107 #ifdef ASSERT |
108 | 108 |
109 // return true if class_name contains no '.' (internal format is '/') | 109 // return true if class_name contains no '.' (internal format is '/') |
110 bool SystemDictionary::is_internal_format(symbolHandle class_name) { | 110 bool SystemDictionary::is_internal_format(Symbol* class_name) { |
111 if (class_name.not_null()) { | 111 if (class_name != NULL) { |
112 ResourceMark rm; | 112 ResourceMark rm; |
113 char* name = class_name->as_C_string(); | 113 char* name = class_name->as_C_string(); |
114 return strchr(name, '.') == NULL; | 114 return strchr(name, '.') == NULL; |
115 } else { | 115 } else { |
116 return true; | 116 return true; |
139 // ---------------------------------------------------------------------------- | 139 // ---------------------------------------------------------------------------- |
140 // Resolving of classes | 140 // Resolving of classes |
141 | 141 |
142 // Forwards to resolve_or_null | 142 // Forwards to resolve_or_null |
143 | 143 |
144 klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { | 144 klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { |
145 klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); | 145 klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); |
146 if (HAS_PENDING_EXCEPTION || klass == NULL) { | 146 if (HAS_PENDING_EXCEPTION || klass == NULL) { |
147 KlassHandle k_h(THREAD, klass); | 147 KlassHandle k_h(THREAD, klass); |
148 // can return a null klass | 148 // can return a null klass |
149 klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD); | 149 klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD); |
150 } | 150 } |
151 return klass; | 151 return klass; |
152 } | 152 } |
153 | 153 |
154 klassOop SystemDictionary::handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) { | 154 klassOop SystemDictionary::handle_resolution_exception(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) { |
155 if (HAS_PENDING_EXCEPTION) { | 155 if (HAS_PENDING_EXCEPTION) { |
156 // If we have a pending exception we forward it to the caller, unless throw_error is true, | 156 // If we have a pending exception we forward it to the caller, unless throw_error is true, |
157 // in which case we have to check whether the pending exception is a ClassNotFoundException, | 157 // in which case we have to check whether the pending exception is a ClassNotFoundException, |
158 // and if so convert it to a NoClassDefFoundError | 158 // and if so convert it to a NoClassDefFoundError |
159 // And chain the original ClassNotFoundException | 159 // And chain the original ClassNotFoundException |
178 } | 178 } |
179 return (klassOop)klass_h(); | 179 return (klassOop)klass_h(); |
180 } | 180 } |
181 | 181 |
182 | 182 |
183 klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, | 183 klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, |
184 bool throw_error, TRAPS) | 184 bool throw_error, TRAPS) |
185 { | 185 { |
186 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD); | 186 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD); |
187 } | 187 } |
188 | 188 |
189 | 189 |
190 // Forwards to resolve_instance_class_or_null | 190 // Forwards to resolve_instance_class_or_null |
191 | 191 |
192 klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) { | 192 klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) { |
193 // (tw) May we do this? | 193 // (tw) May we do this? |
194 // assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread"); | 194 //assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread"); |
195 if (FieldType::is_array(class_name())) { | 195 if (FieldType::is_array(class_name)) { |
196 return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); | 196 return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); |
197 } else if (FieldType::is_obj(class_name)) { | |
198 ResourceMark rm(THREAD); | |
199 // Ignore wrapping L and ;. | |
200 TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1, | |
201 class_name->utf8_length() - 2, CHECK_NULL); | |
202 return resolve_instance_class_or_null(name, class_loader, protection_domain, CHECK_NULL); | |
197 } else { | 203 } else { |
198 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); | 204 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); |
199 } | 205 } |
200 } | 206 } |
201 | 207 |
202 klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, TRAPS) { | 208 klassOop SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) { |
203 return resolve_or_null(class_name, Handle(), Handle(), THREAD); | 209 return resolve_or_null(class_name, Handle(), Handle(), THREAD); |
204 } | 210 } |
205 | 211 |
206 // Forwards to resolve_instance_class_or_null | 212 // Forwards to resolve_instance_class_or_null |
207 | 213 |
208 klassOop SystemDictionary::resolve_array_class_or_null(symbolHandle class_name, | 214 klassOop SystemDictionary::resolve_array_class_or_null(Symbol* class_name, |
209 Handle class_loader, | 215 Handle class_loader, |
210 Handle protection_domain, | 216 Handle protection_domain, |
211 TRAPS) { | 217 TRAPS) { |
212 assert(FieldType::is_array(class_name()), "must be array"); | 218 assert(FieldType::is_array(class_name), "must be array"); |
213 jint dimension; | |
214 symbolOop object_key; | |
215 klassOop k = NULL; | 219 klassOop k = NULL; |
216 // dimension and object_key are assigned as a side-effect of this call | 220 FieldArrayInfo fd; |
217 BasicType t = FieldType::get_array_info(class_name(), | 221 // dimension and object_key in FieldArrayInfo are assigned as a side-effect |
218 &dimension, | 222 // of this call |
219 &object_key, | 223 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL); |
220 CHECK_NULL); | |
221 | |
222 if (t == T_OBJECT) { | 224 if (t == T_OBJECT) { |
223 symbolHandle h_key(THREAD, object_key); | |
224 // naked oop "k" is OK here -- we assign back into it | 225 // naked oop "k" is OK here -- we assign back into it |
225 k = SystemDictionary::resolve_instance_class_or_null(h_key, | 226 k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(), |
226 class_loader, | 227 class_loader, |
227 protection_domain, | 228 protection_domain, |
228 CHECK_NULL); | 229 CHECK_NULL); |
229 if (k != NULL) { | 230 if (k != NULL) { |
230 k = Klass::cast(k)->array_klass(dimension, CHECK_NULL); | 231 k = Klass::cast(k)->array_klass(fd.dimension(), CHECK_NULL); |
231 } | 232 } |
232 } else { | 233 } else { |
233 k = Universe::typeArrayKlassObj(t); | 234 k = Universe::typeArrayKlassObj(t); |
234 k = typeArrayKlass::cast(k)->array_klass(dimension, CHECK_NULL); | 235 k = typeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL); |
235 } | 236 } |
236 return k; | 237 return k; |
237 } | 238 } |
238 | 239 |
239 | 240 |
270 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2 | 271 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2 |
271 // 4.4 finds T2, Super -> throws class circularity | 272 // 4.4 finds T2, Super -> throws class circularity |
272 // Must be called, even if superclass is null, since this is | 273 // Must be called, even if superclass is null, since this is |
273 // where the placeholder entry is created which claims this | 274 // where the placeholder entry is created which claims this |
274 // thread is loading this class/classloader. | 275 // thread is loading this class/classloader. |
275 klassOop SystemDictionary::resolve_super_or_fail(symbolHandle child_name, | 276 klassOop SystemDictionary::resolve_super_or_fail(Symbol* child_name, |
276 symbolHandle class_name, | 277 Symbol* class_name, |
277 Handle class_loader, | 278 Handle class_loader, |
278 Handle protection_domain, | 279 Handle protection_domain, |
279 bool is_superclass, | 280 bool is_superclass, |
280 TRAPS) { | 281 TRAPS) { |
281 | 282 |
282 // Try to get one of the well-known klasses. | 283 // Try to get one of the well-known klasses. |
283 // They are trusted, and do not participate in circularities. | 284 // They are trusted, and do not participate in circularities. |
284 if (LinkWellKnownClasses) { | 285 if (LinkWellKnownClasses) { |
285 klassOop k = find_well_known_klass(class_name()); | 286 klassOop k = find_well_known_klass(class_name); |
286 if (k != NULL) { | 287 if (k != NULL) { |
287 return k; | 288 return k; |
288 } | 289 } |
289 } | 290 } |
290 | 291 |
322 // so we don't throw an exception here. | 323 // so we don't throw an exception here. |
323 // see: nsk redefclass014 & java.lang.instrument Instrument032 | 324 // see: nsk redefclass014 & java.lang.instrument Instrument032 |
324 if ((childk != NULL ) && (is_superclass) && | 325 if ((childk != NULL ) && (is_superclass) && |
325 ((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) && | 326 ((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) && |
326 | 327 |
327 ((Klass::cast(quicksuperk)->name() == class_name()) && | 328 ((Klass::cast(quicksuperk)->name() == class_name) && |
328 (Klass::cast(quicksuperk)->class_loader() == class_loader()))) { | 329 (Klass::cast(quicksuperk)->class_loader() == class_loader()))) { |
329 return quicksuperk; | 330 return quicksuperk; |
330 } else { | 331 } else { |
331 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); | 332 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); |
332 if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) { | 333 if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) { |
341 ResourceMark rm(THREAD); | 342 ResourceMark rm(THREAD); |
342 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); | 343 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); |
343 } | 344 } |
344 | 345 |
345 // java.lang.Object should have been found above | 346 // java.lang.Object should have been found above |
346 assert(class_name() != NULL, "null super class for resolving"); | 347 assert(class_name != NULL, "null super class for resolving"); |
347 // Resolve the super class or interface, check results on return | 348 // Resolve the super class or interface, check results on return |
348 klassOop superk = NULL; | 349 klassOop superk = NULL; |
349 superk = SystemDictionary::resolve_or_null(class_name, | 350 superk = SystemDictionary::resolve_or_null(class_name, |
350 class_loader, | 351 class_loader, |
351 protection_domain, | 352 protection_domain, |
391 | 392 |
392 KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass()); | 393 KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass()); |
393 JavaCalls::call_special(&result, | 394 JavaCalls::call_special(&result, |
394 class_loader, | 395 class_loader, |
395 system_loader, | 396 system_loader, |
396 vmSymbolHandles::checkPackageAccess_name(), | 397 vmSymbols::checkPackageAccess_name(), |
397 vmSymbolHandles::class_protectiondomain_signature(), | 398 vmSymbols::class_protectiondomain_signature(), |
398 Handle(THREAD, klass->java_mirror()), | 399 Handle(THREAD, klass->java_mirror()), |
399 protection_domain, | 400 protection_domain, |
400 THREAD); | 401 THREAD); |
401 | 402 |
402 if (TraceProtectionDomainVerification) { | 403 if (TraceProtectionDomainVerification) { |
413 // If no exception has been thrown, we have validated the protection domain | 414 // If no exception has been thrown, we have validated the protection domain |
414 // Insert the protection domain of the initiating class into the set. | 415 // Insert the protection domain of the initiating class into the set. |
415 { | 416 { |
416 // We recalculate the entry here -- we've called out to java since | 417 // We recalculate the entry here -- we've called out to java since |
417 // the last time it was calculated. | 418 // the last time it was calculated. |
418 symbolHandle kn(THREAD, klass->name()); | 419 Symbol* kn = klass->name(); |
419 unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); | 420 unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); |
420 int d_index = dictionary()->hash_to_index(d_hash); | 421 int d_index = dictionary()->hash_to_index(d_hash); |
421 | 422 |
422 MutexLocker mu(SystemDictionary_lock, THREAD); | 423 MutexLocker mu(SystemDictionary_lock, THREAD); |
423 { | 424 { |
488 // Caller must check for pending exception | 489 // Caller must check for pending exception |
489 // Returns non-null klassOop if other thread has completed load | 490 // Returns non-null klassOop if other thread has completed load |
490 // and we are done, | 491 // and we are done, |
491 // If return null klassOop and no pending exception, the caller must load the class | 492 // If return null klassOop and no pending exception, the caller must load the class |
492 instanceKlassHandle SystemDictionary::handle_parallel_super_load( | 493 instanceKlassHandle SystemDictionary::handle_parallel_super_load( |
493 symbolHandle name, symbolHandle superclassname, Handle class_loader, | 494 Symbol* name, Symbol* superclassname, Handle class_loader, |
494 Handle protection_domain, Handle lockObject, TRAPS) { | 495 Handle protection_domain, Handle lockObject, TRAPS) { |
495 | 496 |
496 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | 497 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
497 unsigned int d_hash = dictionary()->compute_hash(name, class_loader); | 498 unsigned int d_hash = dictionary()->compute_hash(name, class_loader); |
498 int d_index = dictionary()->hash_to_index(d_hash); | 499 int d_index = dictionary()->hash_to_index(d_hash); |
577 } | 578 } |
578 return (nh); | 579 return (nh); |
579 } | 580 } |
580 | 581 |
581 | 582 |
582 klassOop SystemDictionary::resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) { | 583 klassOop SystemDictionary::resolve_instance_class_or_null(Symbol* name, Handle class_loader, Handle protection_domain, TRAPS) { |
583 assert(class_name.not_null() && !FieldType::is_array(class_name()), "invalid class name"); | 584 assert(name != NULL && !FieldType::is_array(name) && |
584 // First check to see if we should remove wrapping L and ; | 585 !FieldType::is_obj(name), "invalid class name"); |
585 symbolHandle name; | |
586 if (FieldType::is_obj(class_name())) { | |
587 ResourceMark rm(THREAD); | |
588 // Ignore wrapping L and ;. | |
589 name = oopFactory::new_symbol_handle(class_name()->as_C_string() + 1, class_name()->utf8_length() - 2, CHECK_NULL); | |
590 } else { | |
591 name = class_name; | |
592 } | |
593 | 586 |
594 // UseNewReflection | 587 // UseNewReflection |
595 // Fix for 4474172; see evaluation for more details | 588 // Fix for 4474172; see evaluation for more details |
596 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); | 589 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
597 | 590 |
631 bool class_has_been_loaded = false; | 624 bool class_has_been_loaded = false; |
632 bool super_load_in_progress = false; | 625 bool super_load_in_progress = false; |
633 bool havesupername = false; | 626 bool havesupername = false; |
634 instanceKlassHandle k; | 627 instanceKlassHandle k; |
635 PlaceholderEntry* placeholder; | 628 PlaceholderEntry* placeholder; |
636 symbolHandle superclassname; | 629 Symbol* superclassname = NULL; |
637 | 630 |
638 { | 631 { |
639 MutexLocker mu(SystemDictionary_lock, THREAD); | 632 MutexLocker mu(SystemDictionary_lock, THREAD); |
640 klassOop check = find_class(d_index, d_hash, name, class_loader); | 633 klassOop check = find_class(d_index, d_hash, name, class_loader); |
641 if (check != NULL) { | 634 if (check != NULL) { |
645 } else { | 638 } else { |
646 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); | 639 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
647 if (placeholder && placeholder->super_load_in_progress()) { | 640 if (placeholder && placeholder->super_load_in_progress()) { |
648 super_load_in_progress = true; | 641 super_load_in_progress = true; |
649 if (placeholder->havesupername() == true) { | 642 if (placeholder->havesupername() == true) { |
650 superclassname = symbolHandle(THREAD, placeholder->supername()); | 643 superclassname = placeholder->supername(); |
651 havesupername = true; | 644 havesupername = true; |
652 } | 645 } |
653 } | 646 } |
654 } | 647 } |
655 } | 648 } |
690 // This classloader supports parallelism at the classloader level, | 683 // This classloader supports parallelism at the classloader level, |
691 // but only allows a single load of a class/classloader pair. | 684 // but only allows a single load of a class/classloader pair. |
692 // No performance benefit and no deadlock issues. | 685 // No performance benefit and no deadlock issues. |
693 // case 5. parallelCapable user level classloaders - without objectLocker | 686 // case 5. parallelCapable user level classloaders - without objectLocker |
694 // Allow parallel classloading of a class/classloader pair | 687 // Allow parallel classloading of a class/classloader pair |
695 symbolHandle nullsymbolHandle; | |
696 bool throw_circularity_error = false; | 688 bool throw_circularity_error = false; |
697 { | 689 { |
698 MutexLocker mu(SystemDictionary_lock, THREAD); | 690 MutexLocker mu(SystemDictionary_lock, THREAD); |
699 if (class_loader.is_null() || !is_parallelCapable(class_loader)) { | 691 if (class_loader.is_null() || !is_parallelCapable(class_loader)) { |
700 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); | 692 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
732 // All cases: add LOAD_INSTANCE | 724 // All cases: add LOAD_INSTANCE |
733 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try | 725 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try |
734 // LOAD_INSTANCE in parallel | 726 // LOAD_INSTANCE in parallel |
735 // add placeholder entry even if error - callers will remove on error | 727 // add placeholder entry even if error - callers will remove on error |
736 if (!throw_circularity_error && !class_has_been_loaded) { | 728 if (!throw_circularity_error && !class_has_been_loaded) { |
737 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, nullsymbolHandle, THREAD); | 729 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD); |
738 // For class loaders that do not acquire the classloader object lock, | 730 // For class loaders that do not acquire the classloader object lock, |
739 // if they did not catch another thread holding LOAD_INSTANCE, | 731 // if they did not catch another thread holding LOAD_INSTANCE, |
740 // need a check analogous to the acquire ObjectLocker/find_class | 732 // need a check analogous to the acquire ObjectLocker/find_class |
741 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL | 733 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL |
742 // one final check if the load has already completed | 734 // one final check if the load has already completed |
836 | 828 |
837 #ifdef ASSERT | 829 #ifdef ASSERT |
838 { | 830 { |
839 Handle loader (THREAD, k->class_loader()); | 831 Handle loader (THREAD, k->class_loader()); |
840 MutexLocker mu(SystemDictionary_lock, THREAD); | 832 MutexLocker mu(SystemDictionary_lock, THREAD); |
841 oop kk = find_class_or_placeholder(name, loader); | 833 oop kk = find_class(name, loader); |
842 assert(kk == k(), "should be present in dictionary"); | 834 assert(kk == k(), "should be present in dictionary"); |
843 } | 835 } |
844 #endif | 836 #endif |
845 | 837 |
846 // return if the protection domain in NULL | 838 // return if the protection domain in NULL |
879 // | 871 // |
880 // Callers should be aware that an entry could be added just after | 872 // Callers should be aware that an entry could be added just after |
881 // _dictionary->bucket(index) is read here, so the caller will not see | 873 // _dictionary->bucket(index) is read here, so the caller will not see |
882 // the new entry. | 874 // the new entry. |
883 | 875 |
884 klassOop SystemDictionary::find(symbolHandle class_name, | 876 klassOop SystemDictionary::find(Symbol* class_name, |
885 Handle class_loader, | 877 Handle class_loader, |
886 Handle protection_domain, | 878 Handle protection_domain, |
887 TRAPS) { | 879 TRAPS) { |
888 | 880 |
889 // UseNewReflection | 881 // UseNewReflection |
909 } | 901 } |
910 | 902 |
911 | 903 |
912 // Look for a loaded instance or array klass by name. Do not do any loading. | 904 // Look for a loaded instance or array klass by name. Do not do any loading. |
913 // return NULL in case of error. | 905 // return NULL in case of error. |
914 klassOop SystemDictionary::find_instance_or_array_klass(symbolHandle class_name, | 906 klassOop SystemDictionary::find_instance_or_array_klass(Symbol* class_name, |
915 Handle class_loader, | 907 Handle class_loader, |
916 Handle protection_domain, | 908 Handle protection_domain, |
917 TRAPS) { | 909 TRAPS) { |
918 klassOop k = NULL; | 910 klassOop k = NULL; |
919 assert(class_name() != NULL, "class name must be non NULL"); | 911 assert(class_name != NULL, "class name must be non NULL"); |
920 | 912 |
921 // Try to get one of the well-known klasses. | 913 // Try to get one of the well-known klasses. |
922 if (LinkWellKnownClasses) { | 914 if (LinkWellKnownClasses) { |
923 k = find_well_known_klass(class_name()); | 915 k = find_well_known_klass(class_name); |
924 if (k != NULL) { | 916 if (k != NULL) { |
925 return k; | 917 return k; |
926 } | 918 } |
927 } | 919 } |
928 | 920 |
929 if (FieldType::is_array(class_name())) { | 921 if (FieldType::is_array(class_name)) { |
930 // The name refers to an array. Parse the name. | 922 // The name refers to an array. Parse the name. |
931 jint dimension; | 923 // dimension and object_key in FieldArrayInfo are assigned as a |
932 symbolOop object_key; | 924 // side-effect of this call |
933 | 925 FieldArrayInfo fd; |
934 // dimension and object_key are assigned as a side-effect of this call | 926 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL)); |
935 BasicType t = FieldType::get_array_info(class_name(), &dimension, | |
936 &object_key, CHECK_(NULL)); | |
937 if (t != T_OBJECT) { | 927 if (t != T_OBJECT) { |
938 k = Universe::typeArrayKlassObj(t); | 928 k = Universe::typeArrayKlassObj(t); |
939 } else { | 929 } else { |
940 symbolHandle h_key(THREAD, object_key); | 930 k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD); |
941 k = SystemDictionary::find(h_key, class_loader, protection_domain, THREAD); | |
942 } | 931 } |
943 if (k != NULL) { | 932 if (k != NULL) { |
944 k = Klass::cast(k)->array_klass_or_null(dimension); | 933 k = Klass::cast(k)->array_klass_or_null(fd.dimension()); |
945 } | 934 } |
946 } else { | 935 } else { |
947 k = find(class_name, class_loader, protection_domain, THREAD); | 936 k = find(class_name, class_loader, protection_domain, THREAD); |
948 } | 937 } |
949 return k; | 938 return k; |
950 } | 939 } |
951 | 940 |
952 // Quick range check for names of well-known classes: | 941 // Quick range check for names of well-known classes: |
953 static symbolOop wk_klass_name_limits[2] = {NULL, NULL}; | 942 static Symbol* wk_klass_name_limits[2] = {NULL, NULL}; |
954 | 943 |
955 #ifndef PRODUCT | 944 #ifndef PRODUCT |
956 static int find_wkk_calls, find_wkk_probes, find_wkk_wins; | 945 static int find_wkk_calls, find_wkk_probes, find_wkk_wins; |
957 // counts for "hello world": 3983, 1616, 1075 | 946 // counts for "hello world": 3983, 1616, 1075 |
958 // => 60% hit after limit guard, 25% total win rate | 947 // => 60% hit after limit guard, 25% total win rate |
959 #endif | 948 #endif |
960 | 949 |
961 klassOop SystemDictionary::find_well_known_klass(symbolOop class_name) { | 950 klassOop SystemDictionary::find_well_known_klass(Symbol* class_name) { |
962 // A bounds-check on class_name will quickly get a negative result. | 951 // A bounds-check on class_name will quickly get a negative result. |
963 NOT_PRODUCT(find_wkk_calls++); | 952 NOT_PRODUCT(find_wkk_calls++); |
964 if (class_name >= wk_klass_name_limits[0] && | 953 if (class_name >= wk_klass_name_limits[0] && |
965 class_name <= wk_klass_name_limits[1]) { | 954 class_name <= wk_klass_name_limits[1]) { |
966 NOT_PRODUCT(find_wkk_probes++); | 955 NOT_PRODUCT(find_wkk_probes++); |
982 } | 971 } |
983 | 972 |
984 // Note: this method is much like resolve_from_stream, but | 973 // Note: this method is much like resolve_from_stream, but |
985 // updates no supplemental data structures. | 974 // updates no supplemental data structures. |
986 // TODO consolidate the two methods with a helper routine? | 975 // TODO consolidate the two methods with a helper routine? |
987 klassOop SystemDictionary::parse_stream(symbolHandle class_name, | 976 klassOop SystemDictionary::parse_stream(Symbol* class_name, |
988 Handle class_loader, | 977 Handle class_loader, |
989 Handle protection_domain, | 978 Handle protection_domain, |
990 ClassFileStream* st, | 979 ClassFileStream* st, |
991 KlassHandle host_klass, | 980 KlassHandle host_klass, |
992 GrowableArray<Handle>* cp_patches, | 981 GrowableArray<Handle>* cp_patches, |
993 TRAPS) { | 982 TRAPS) { |
994 symbolHandle parsed_name; | 983 TempNewSymbol parsed_name = NULL; |
995 | 984 |
996 // Parse the stream. Note that we do this even though this klass might | 985 // Parse the stream. Note that we do this even though this klass might |
997 // already be present in the SystemDictionary, otherwise we would not | 986 // already be present in the SystemDictionary, otherwise we would not |
998 // throw potential ClassFormatErrors. | 987 // throw potential ClassFormatErrors. |
999 // | 988 // |
1010 cp_patches, | 999 cp_patches, |
1011 parsed_name, | 1000 parsed_name, |
1012 true, | 1001 true, |
1013 THREAD); | 1002 THREAD); |
1014 | 1003 |
1015 | |
1016 // We don't redefine the class, so we just need to clean up whether there | 1004 // We don't redefine the class, so we just need to clean up whether there |
1017 // was an error or not (don't want to modify any system dictionary | 1005 // was an error or not (don't want to modify any system dictionary |
1018 // data structures). | 1006 // data structures). |
1019 // Parsed name could be null if we threw an error before we got far | 1007 // Parsed name could be null if we threw an error before we got far |
1020 // enough along to parse it -- in that case, there is nothing to clean up. | 1008 // enough along to parse it -- in that case, there is nothing to clean up. |
1021 if (!parsed_name.is_null()) { | 1009 if (parsed_name != NULL) { |
1022 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | 1010 unsigned int p_hash = placeholders()->compute_hash(parsed_name, |
1023 class_loader); | 1011 class_loader); |
1024 int p_index = placeholders()->hash_to_index(p_hash); | 1012 int p_index = placeholders()->hash_to_index(p_hash); |
1025 { | 1013 { |
1026 MutexLocker mu(SystemDictionary_lock, THREAD); | 1014 MutexLocker mu(SystemDictionary_lock, THREAD); |
1059 // Add a klass to the system from a stream (called by jni_DefineClass and | 1047 // Add a klass to the system from a stream (called by jni_DefineClass and |
1060 // JVM_DefineClass). | 1048 // JVM_DefineClass). |
1061 // Note: class_name can be NULL. In that case we do not know the name of | 1049 // Note: class_name can be NULL. In that case we do not know the name of |
1062 // the class until we have parsed the stream. | 1050 // the class until we have parsed the stream. |
1063 | 1051 |
1064 klassOop SystemDictionary::resolve_from_stream(symbolHandle class_name, | 1052 klassOop SystemDictionary::resolve_from_stream(Symbol* class_name, |
1065 Handle class_loader, | 1053 Handle class_loader, |
1066 Handle protection_domain, | 1054 Handle protection_domain, |
1067 ClassFileStream* st, | 1055 ClassFileStream* st, |
1068 bool verify, | 1056 bool verify, |
1069 TRAPS) { | 1057 TRAPS) { |
1078 // Make sure we are synchronized on the class loader before we proceed | 1066 // Make sure we are synchronized on the class loader before we proceed |
1079 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); | 1067 Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
1080 check_loader_lock_contention(lockObject, THREAD); | 1068 check_loader_lock_contention(lockObject, THREAD); |
1081 ObjectLocker ol(lockObject, THREAD, DoObjectLock); | 1069 ObjectLocker ol(lockObject, THREAD, DoObjectLock); |
1082 | 1070 |
1083 symbolHandle parsed_name; | 1071 TempNewSymbol parsed_name = NULL; |
1084 | 1072 |
1085 // Parse the stream. Note that we do this even though this klass might | 1073 // Parse the stream. Note that we do this even though this klass might |
1086 // already be present in the SystemDictionary, otherwise we would not | 1074 // already be present in the SystemDictionary, otherwise we would not |
1087 // throw potential ClassFormatErrors. | 1075 // throw potential ClassFormatErrors. |
1088 // | 1076 // |
1100 THREAD); | 1088 THREAD); |
1101 | 1089 |
1102 const char* pkg = "java/"; | 1090 const char* pkg = "java/"; |
1103 if (!HAS_PENDING_EXCEPTION && | 1091 if (!HAS_PENDING_EXCEPTION && |
1104 !class_loader.is_null() && | 1092 !class_loader.is_null() && |
1105 !parsed_name.is_null() && | 1093 parsed_name != NULL && |
1106 !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) { | 1094 !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) { |
1107 // It is illegal to define classes in the "java." package from | 1095 // It is illegal to define classes in the "java." package from |
1108 // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader | 1096 // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader |
1109 ResourceMark rm(THREAD); | 1097 ResourceMark rm(THREAD); |
1110 char* name = parsed_name->as_C_string(); | 1098 char* name = parsed_name->as_C_string(); |
1120 Exceptions::_throw_msg(THREAD_AND_LOCATION, | 1108 Exceptions::_throw_msg(THREAD_AND_LOCATION, |
1121 vmSymbols::java_lang_SecurityException(), message); | 1109 vmSymbols::java_lang_SecurityException(), message); |
1122 } | 1110 } |
1123 | 1111 |
1124 if (!HAS_PENDING_EXCEPTION) { | 1112 if (!HAS_PENDING_EXCEPTION) { |
1125 assert(!parsed_name.is_null(), "Sanity"); | 1113 assert(parsed_name != NULL, "Sanity"); |
1126 assert(class_name.is_null() || class_name() == parsed_name(), | 1114 assert(class_name == NULL || class_name == parsed_name, "name mismatch"); |
1127 "name mismatch"); | |
1128 // Verification prevents us from creating names with dots in them, this | 1115 // Verification prevents us from creating names with dots in them, this |
1129 // asserts that that's the case. | 1116 // asserts that that's the case. |
1130 assert(is_internal_format(parsed_name), | 1117 assert(is_internal_format(parsed_name), |
1131 "external class name format used internally"); | 1118 "external class name format used internally"); |
1132 | 1119 |
1143 // If parsing the class file or define_instance_class failed, we | 1130 // If parsing the class file or define_instance_class failed, we |
1144 // need to remove the placeholder added on our behalf. But we | 1131 // need to remove the placeholder added on our behalf. But we |
1145 // must make sure parsed_name is valid first (it won't be if we had | 1132 // must make sure parsed_name is valid first (it won't be if we had |
1146 // a format error before the class was parsed far enough to | 1133 // a format error before the class was parsed far enough to |
1147 // find the name). | 1134 // find the name). |
1148 if (HAS_PENDING_EXCEPTION && !parsed_name.is_null()) { | 1135 if (HAS_PENDING_EXCEPTION && parsed_name != NULL) { |
1149 unsigned int p_hash = placeholders()->compute_hash(parsed_name, | 1136 unsigned int p_hash = placeholders()->compute_hash(parsed_name, |
1150 class_loader); | 1137 class_loader); |
1151 int p_index = placeholders()->hash_to_index(p_hash); | 1138 int p_index = placeholders()->hash_to_index(p_hash); |
1152 { | 1139 { |
1153 MutexLocker mu(SystemDictionary_lock, THREAD); | 1140 MutexLocker mu(SystemDictionary_lock, THREAD); |
1159 | 1146 |
1160 // Make sure that we didn't leave a place holder in the | 1147 // Make sure that we didn't leave a place holder in the |
1161 // SystemDictionary; this is only done on success | 1148 // SystemDictionary; this is only done on success |
1162 debug_only( { | 1149 debug_only( { |
1163 if (!HAS_PENDING_EXCEPTION) { | 1150 if (!HAS_PENDING_EXCEPTION) { |
1164 assert(!parsed_name.is_null(), "parsed_name is still null?"); | 1151 assert(parsed_name != NULL, "parsed_name is still null?"); |
1165 symbolHandle h_name (THREAD, k->name()); | 1152 Symbol* h_name = k->name(); |
1166 Handle h_loader (THREAD, k->class_loader()); | 1153 Handle h_loader (THREAD, k->class_loader()); |
1167 | 1154 |
1168 MutexLocker mu(SystemDictionary_lock, THREAD); | 1155 MutexLocker mu(SystemDictionary_lock, THREAD); |
1169 | 1156 |
1170 oop check = find_class_or_placeholder(parsed_name, class_loader); | 1157 klassOop check = find_class(parsed_name, class_loader); |
1171 assert(check == k(), "should be present in the dictionary"); | 1158 assert(check == k(), "should be present in the dictionary"); |
1172 | 1159 |
1173 oop check2 = find_class_or_placeholder(h_name, h_loader); | 1160 klassOop check2 = find_class(h_name, h_loader); |
1174 assert(check == check2, "name inconsistancy in SystemDictionary"); | 1161 assert(check == check2, "name inconsistancy in SystemDictionary"); |
1175 } | 1162 } |
1176 } ); | 1163 } ); |
1177 | 1164 |
1178 return k(); | 1165 return k(); |
1188 | 1175 |
1189 | 1176 |
1190 // If there is a shared dictionary, then find the entry for the | 1177 // If there is a shared dictionary, then find the entry for the |
1191 // given shared system class, if any. | 1178 // given shared system class, if any. |
1192 | 1179 |
1193 klassOop SystemDictionary::find_shared_class(symbolHandle class_name) { | 1180 klassOop SystemDictionary::find_shared_class(Symbol* class_name) { |
1194 if (shared_dictionary() != NULL) { | 1181 if (shared_dictionary() != NULL) { |
1195 unsigned int d_hash = dictionary()->compute_hash(class_name, Handle()); | 1182 unsigned int d_hash = dictionary()->compute_hash(class_name, Handle()); |
1196 int d_index = dictionary()->hash_to_index(d_hash); | 1183 int d_index = dictionary()->hash_to_index(d_hash); |
1197 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); | 1184 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); |
1198 } else { | 1185 } else { |
1206 // Update the class definition to include sibling classes and no | 1193 // Update the class definition to include sibling classes and no |
1207 // subclasses (yet). [Classes in the shared space are not part of the | 1194 // subclasses (yet). [Classes in the shared space are not part of the |
1208 // object hierarchy until loaded.] | 1195 // object hierarchy until loaded.] |
1209 | 1196 |
1210 instanceKlassHandle SystemDictionary::load_shared_class( | 1197 instanceKlassHandle SystemDictionary::load_shared_class( |
1211 symbolHandle class_name, Handle class_loader, TRAPS) { | 1198 Symbol* class_name, Handle class_loader, TRAPS) { |
1212 instanceKlassHandle ik (THREAD, find_shared_class(class_name)); | 1199 instanceKlassHandle ik (THREAD, find_shared_class(class_name)); |
1213 return load_shared_class(ik, class_loader, THREAD); | 1200 return load_shared_class(ik, class_loader, THREAD); |
1214 } | 1201 } |
1215 | 1202 |
1216 // Note well! Changes to this method may affect oop access order | 1203 // Note well! Changes to this method may affect oop access order |
1221 instanceKlassHandle SystemDictionary::load_shared_class( | 1208 instanceKlassHandle SystemDictionary::load_shared_class( |
1222 instanceKlassHandle ik, Handle class_loader, TRAPS) { | 1209 instanceKlassHandle ik, Handle class_loader, TRAPS) { |
1223 assert(class_loader.is_null(), "non-null classloader for shared class?"); | 1210 assert(class_loader.is_null(), "non-null classloader for shared class?"); |
1224 if (ik.not_null()) { | 1211 if (ik.not_null()) { |
1225 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | 1212 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1226 symbolHandle class_name(THREAD, ik->name()); | 1213 Symbol* class_name = ik->name(); |
1227 | 1214 |
1228 // Found the class, now load the superclass and interfaces. If they | 1215 // Found the class, now load the superclass and interfaces. If they |
1229 // are shared, add them to the main system dictionary and reset | 1216 // are shared, add them to the main system dictionary and reset |
1230 // their hierarchy references (supers, subs, and interfaces). | 1217 // their hierarchy references (supers, subs, and interfaces). |
1231 | 1218 |
1232 if (ik->super() != NULL) { | 1219 if (ik->super() != NULL) { |
1233 symbolHandle cn(THREAD, ik->super()->klass_part()->name()); | 1220 Symbol* cn = ik->super()->klass_part()->name(); |
1234 resolve_super_or_fail(class_name, cn, | 1221 resolve_super_or_fail(class_name, cn, |
1235 class_loader, Handle(), true, CHECK_(nh)); | 1222 class_loader, Handle(), true, CHECK_(nh)); |
1236 } | 1223 } |
1237 | 1224 |
1238 objArrayHandle interfaces (THREAD, ik->local_interfaces()); | 1225 objArrayHandle interfaces (THREAD, ik->local_interfaces()); |
1242 | 1229 |
1243 // Note: can not use instanceKlass::cast here because | 1230 // Note: can not use instanceKlass::cast here because |
1244 // interfaces' instanceKlass's C++ vtbls haven't been | 1231 // interfaces' instanceKlass's C++ vtbls haven't been |
1245 // reinitialized yet (they will be once the interface classes | 1232 // reinitialized yet (they will be once the interface classes |
1246 // are loaded) | 1233 // are loaded) |
1247 symbolHandle name (THREAD, k->klass_part()->name()); | 1234 Symbol* name = k->klass_part()->name(); |
1248 resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh)); | 1235 resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh)); |
1249 } | 1236 } |
1250 | 1237 |
1251 // Adjust methods to recover missing data. They need addresses for | 1238 // Adjust methods to recover missing data. They need addresses for |
1252 // interpreter entry points and their default native method address | 1239 // interpreter entry points and their default native method address |
1289 // system yet. Call the DownloadManager method to make them appear in the | 1276 // system yet. Call the DownloadManager method to make them appear in the |
1290 // bootstrap class path and try again to load the named class. | 1277 // bootstrap class path and try again to load the named class. |
1291 // Note that with delegation class loaders all classes in another loader will | 1278 // Note that with delegation class loaders all classes in another loader will |
1292 // first try to call this so it'd better be fast!! | 1279 // first try to call this so it'd better be fast!! |
1293 static instanceKlassHandle download_and_retry_class_load( | 1280 static instanceKlassHandle download_and_retry_class_load( |
1294 symbolHandle class_name, | 1281 Symbol* class_name, |
1295 TRAPS) { | 1282 TRAPS) { |
1296 | 1283 |
1297 klassOop dlm = SystemDictionary::sun_jkernel_DownloadManager_klass(); | 1284 klassOop dlm = SystemDictionary::sun_jkernel_DownloadManager_klass(); |
1298 instanceKlassHandle nk; | 1285 instanceKlassHandle nk; |
1299 | 1286 |
1312 // multiple classes could be not found and downloaded at the same time. | 1299 // multiple classes could be not found and downloaded at the same time. |
1313 // class sun.misc.DownloadManager; | 1300 // class sun.misc.DownloadManager; |
1314 // public static String getBootClassPathEntryForClass(String className); | 1301 // public static String getBootClassPathEntryForClass(String className); |
1315 JavaCalls::call_static(&result, | 1302 JavaCalls::call_static(&result, |
1316 KlassHandle(THREAD, dlm), | 1303 KlassHandle(THREAD, dlm), |
1317 vmSymbolHandles::getBootClassPathEntryForClass_name(), | 1304 vmSymbols::getBootClassPathEntryForClass_name(), |
1318 vmSymbolHandles::string_string_signature(), | 1305 vmSymbols::string_string_signature(), |
1319 class_string, | 1306 class_string, |
1320 CHECK_(nk)); | 1307 CHECK_(nk)); |
1321 | 1308 |
1322 // Get result.string and add to bootclasspath | 1309 // Get result.string and add to bootclasspath |
1323 assert(result.get_type() == T_OBJECT, "just checking"); | 1310 assert(result.get_type() == T_OBJECT, "just checking"); |
1343 return ClassLoader::load_classfile(class_name, CHECK_(nk)); | 1330 return ClassLoader::load_classfile(class_name, CHECK_(nk)); |
1344 } | 1331 } |
1345 #endif // KERNEL | 1332 #endif // KERNEL |
1346 | 1333 |
1347 | 1334 |
1348 instanceKlassHandle SystemDictionary::load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS) { | 1335 instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) { |
1349 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | 1336 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1350 if (class_loader.is_null()) { | 1337 if (class_loader.is_null()) { |
1351 | 1338 |
1352 // Search the shared system dictionary for classes preloaded into the | 1339 // Search the shared system dictionary for classes preloaded into the |
1353 // shared spaces. | 1340 // shared spaces. |
1418 // a customer that counts on this call | 1405 // a customer that counts on this call |
1419 if (MustCallLoadClassInternal && has_loadClassInternal()) { | 1406 if (MustCallLoadClassInternal && has_loadClassInternal()) { |
1420 JavaCalls::call_special(&result, | 1407 JavaCalls::call_special(&result, |
1421 class_loader, | 1408 class_loader, |
1422 spec_klass, | 1409 spec_klass, |
1423 vmSymbolHandles::loadClassInternal_name(), | 1410 vmSymbols::loadClassInternal_name(), |
1424 vmSymbolHandles::string_class_signature(), | 1411 vmSymbols::string_class_signature(), |
1425 string, | 1412 string, |
1426 CHECK_(nh)); | 1413 CHECK_(nh)); |
1427 } else { | 1414 } else { |
1428 JavaCalls::call_virtual(&result, | 1415 JavaCalls::call_virtual(&result, |
1429 class_loader, | 1416 class_loader, |
1430 spec_klass, | 1417 spec_klass, |
1431 vmSymbolHandles::loadClass_name(), | 1418 vmSymbols::loadClass_name(), |
1432 vmSymbolHandles::string_class_signature(), | 1419 vmSymbols::string_class_signature(), |
1433 string, | 1420 string, |
1434 CHECK_(nh)); | 1421 CHECK_(nh)); |
1435 } | 1422 } |
1436 | 1423 |
1437 assert(result.get_type() == T_OBJECT, "just checking"); | 1424 assert(result.get_type() == T_OBJECT, "just checking"); |
1443 instanceKlassHandle k = | 1430 instanceKlassHandle k = |
1444 instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj)); | 1431 instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj)); |
1445 // For user defined Java class loaders, check that the name returned is | 1432 // For user defined Java class loaders, check that the name returned is |
1446 // the same as that requested. This check is done for the bootstrap | 1433 // the same as that requested. This check is done for the bootstrap |
1447 // loader when parsing the class file. | 1434 // loader when parsing the class file. |
1448 if (class_name() == k->name()) { | 1435 if (class_name == k->name()) { |
1449 return k; | 1436 return k; |
1450 } | 1437 } |
1451 } | 1438 } |
1452 // Class is not found or has the wrong name, return NULL | 1439 // Class is not found or has the wrong name, return NULL |
1453 return nh; | 1440 return nh; |
1476 // define two different instanceKlasses for that class/classloader pair. | 1463 // define two different instanceKlasses for that class/classloader pair. |
1477 // Existing classloaders will call define_instance_class with the | 1464 // Existing classloaders will call define_instance_class with the |
1478 // classloader lock held | 1465 // classloader lock held |
1479 // Parallel classloaders will call find_or_define_instance_class | 1466 // Parallel classloaders will call find_or_define_instance_class |
1480 // which will require a token to perform the define class | 1467 // which will require a token to perform the define class |
1481 symbolHandle name_h(THREAD, k->name()); | 1468 Symbol* name_h = k->name(); |
1482 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h); | 1469 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h); |
1483 int d_index = dictionary()->hash_to_index(d_hash); | 1470 int d_index = dictionary()->hash_to_index(d_hash); |
1484 check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK); | 1471 check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK); |
1485 | 1472 |
1486 // Register class just loaded with class loader (placed in Vector) | 1473 // Register class just loaded with class loader (placed in Vector) |
1535 // False is the requested default. | 1522 // False is the requested default. |
1536 // For better performance, the class loaders should synchronize | 1523 // For better performance, the class loaders should synchronize |
1537 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they | 1524 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they |
1538 // potentially waste time reading and parsing the bytestream. | 1525 // potentially waste time reading and parsing the bytestream. |
1539 // Note: VM callers should ensure consistency of k/class_name,class_loader | 1526 // Note: VM callers should ensure consistency of k/class_name,class_loader |
1540 instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { | 1527 instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { |
1541 | 1528 |
1542 instanceKlassHandle nh = instanceKlassHandle(); // null Handle | 1529 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1543 symbolHandle name_h(THREAD, k->name()); // passed in class_name may be null | 1530 Symbol* name_h = k->name(); // passed in class_name may be null |
1544 | 1531 |
1545 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader); | 1532 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader); |
1546 int d_index = dictionary()->hash_to_index(d_hash); | 1533 int d_index = dictionary()->hash_to_index(d_hash); |
1547 | 1534 |
1548 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS | 1535 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS |
1559 return(instanceKlassHandle(THREAD, check)); | 1546 return(instanceKlassHandle(THREAD, check)); |
1560 } | 1547 } |
1561 } | 1548 } |
1562 | 1549 |
1563 // Acquire define token for this class/classloader | 1550 // Acquire define token for this class/classloader |
1564 symbolHandle nullsymbolHandle; | 1551 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, NULL, THREAD); |
1565 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD); | |
1566 // Wait if another thread defining in parallel | 1552 // Wait if another thread defining in parallel |
1567 // All threads wait - even those that will throw duplicate class: otherwise | 1553 // All threads wait - even those that will throw duplicate class: otherwise |
1568 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails | 1554 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails |
1569 // if other thread has not finished updating dictionary | 1555 // if other thread has not finished updating dictionary |
1570 while (probe->definer() != NULL) { | 1556 while (probe->definer() != NULL) { |
1652 | 1638 |
1653 // ---------------------------------------------------------------------------- | 1639 // ---------------------------------------------------------------------------- |
1654 // Lookup | 1640 // Lookup |
1655 | 1641 |
1656 klassOop SystemDictionary::find_class(int index, unsigned int hash, | 1642 klassOop SystemDictionary::find_class(int index, unsigned int hash, |
1657 symbolHandle class_name, | 1643 Symbol* class_name, |
1658 Handle class_loader) { | 1644 Handle class_loader) { |
1659 assert_locked_or_safepoint(SystemDictionary_lock); | 1645 assert_locked_or_safepoint(SystemDictionary_lock); |
1660 assert (index == dictionary()->index_for(class_name, class_loader), | 1646 assert (index == dictionary()->index_for(class_name, class_loader), |
1661 "incorrect index?"); | 1647 "incorrect index?"); |
1662 | 1648 |
1664 return k; | 1650 return k; |
1665 } | 1651 } |
1666 | 1652 |
1667 | 1653 |
1668 // Basic find on classes in the midst of being loaded | 1654 // Basic find on classes in the midst of being loaded |
1669 symbolOop SystemDictionary::find_placeholder(int index, unsigned int hash, | 1655 Symbol* SystemDictionary::find_placeholder(Symbol* class_name, |
1670 symbolHandle class_name, | 1656 Handle class_loader) { |
1671 Handle class_loader) { | |
1672 assert_locked_or_safepoint(SystemDictionary_lock); | 1657 assert_locked_or_safepoint(SystemDictionary_lock); |
1673 | 1658 unsigned int p_hash = placeholders()->compute_hash(class_name, class_loader); |
1674 return placeholders()->find_entry(index, hash, class_name, class_loader); | 1659 int p_index = placeholders()->hash_to_index(p_hash); |
1660 return placeholders()->find_entry(p_index, p_hash, class_name, class_loader); | |
1675 } | 1661 } |
1676 | 1662 |
1677 | 1663 |
1678 // Used for assertions and verification only | 1664 // Used for assertions and verification only |
1679 oop SystemDictionary::find_class_or_placeholder(symbolHandle class_name, | 1665 klassOop SystemDictionary::find_class(Symbol* class_name, Handle class_loader) { |
1680 Handle class_loader) { | |
1681 #ifndef ASSERT | 1666 #ifndef ASSERT |
1682 guarantee(VerifyBeforeGC || | 1667 guarantee(VerifyBeforeGC || |
1683 VerifyDuringGC || | 1668 VerifyDuringGC || |
1684 VerifyBeforeExit || | 1669 VerifyBeforeExit || |
1685 VerifyAfterGC, "too expensive"); | 1670 VerifyAfterGC, "too expensive"); |
1686 #endif | 1671 #endif |
1687 assert_locked_or_safepoint(SystemDictionary_lock); | 1672 assert_locked_or_safepoint(SystemDictionary_lock); |
1688 symbolOop class_name_ = class_name(); | |
1689 oop class_loader_ = class_loader(); | |
1690 | 1673 |
1691 // First look in the loaded class array | 1674 // First look in the loaded class array |
1692 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); | 1675 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); |
1693 int d_index = dictionary()->hash_to_index(d_hash); | 1676 int d_index = dictionary()->hash_to_index(d_hash); |
1694 oop lookup = find_class(d_index, d_hash, class_name, class_loader); | 1677 return find_class(d_index, d_hash, class_name, class_loader); |
1695 | |
1696 if (lookup == NULL) { | |
1697 // Next try the placeholders | |
1698 unsigned int p_hash = placeholders()->compute_hash(class_name,class_loader); | |
1699 int p_index = placeholders()->hash_to_index(p_hash); | |
1700 lookup = find_placeholder(p_index, p_hash, class_name, class_loader); | |
1701 } | |
1702 | |
1703 return lookup; | |
1704 } | 1678 } |
1705 | 1679 |
1706 | 1680 |
1707 // Get the next class in the diictionary. | 1681 // Get the next class in the diictionary. |
1708 klassOop SystemDictionary::try_get_next_class() { | 1682 klassOop SystemDictionary::try_get_next_class() { |
1756 // represent classes we're actively loading. | 1730 // represent classes we're actively loading. |
1757 placeholders_do(blk); | 1731 placeholders_do(blk); |
1758 | 1732 |
1759 // Visit extra methods | 1733 // Visit extra methods |
1760 invoke_method_table()->oops_do(blk); | 1734 invoke_method_table()->oops_do(blk); |
1761 | |
1762 // Loader constraints. We must keep the symbolOop used in the name alive. | |
1763 constraints()->always_strong_classes_do(blk); | |
1764 | |
1765 // Resolution errors keep the symbolOop for the error alive | |
1766 resolution_errors()->always_strong_classes_do(blk); | |
1767 } | 1735 } |
1768 | 1736 |
1769 | 1737 |
1770 void SystemDictionary::placeholders_do(OopClosure* blk) { | 1738 void SystemDictionary::placeholders_do(OopClosure* blk) { |
1771 placeholders()->oops_do(blk); | 1739 placeholders()->oops_do(blk); |
1807 resolution_errors()->oops_do(f); | 1775 resolution_errors()->oops_do(f); |
1808 } | 1776 } |
1809 | 1777 |
1810 | 1778 |
1811 void SystemDictionary::preloaded_oops_do(OopClosure* f) { | 1779 void SystemDictionary::preloaded_oops_do(OopClosure* f) { |
1812 f->do_oop((oop*) &wk_klass_name_limits[0]); | |
1813 f->do_oop((oop*) &wk_klass_name_limits[1]); | |
1814 | |
1815 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) { | 1780 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) { |
1816 f->do_oop((oop*) &_well_known_klasses[k]); | 1781 f->do_oop((oop*) &_well_known_klasses[k]); |
1817 } | 1782 } |
1818 | 1783 |
1819 { | 1784 { |
1861 // Don't iterate over placeholders | 1826 // Don't iterate over placeholders |
1862 void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) { | 1827 void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) { |
1863 dictionary()->classes_do(f, CHECK); | 1828 dictionary()->classes_do(f, CHECK); |
1864 } | 1829 } |
1865 | 1830 |
1866 void SystemDictionary::placeholders_do(void f(symbolOop, oop)) { | 1831 void SystemDictionary::placeholders_do(void f(Symbol*, oop)) { |
1867 placeholders()->entries_do(f); | 1832 placeholders()->entries_do(f); |
1868 } | 1833 } |
1869 | 1834 |
1870 void SystemDictionary::methods_do(void f(methodOop)) { | 1835 void SystemDictionary::methods_do(void f(methodOop)) { |
1871 dictionary()->methods_do(f); | 1836 dictionary()->methods_do(f); |
1881 // if multiple threads calling this function, only one thread will load | 1846 // if multiple threads calling this function, only one thread will load |
1882 // the class. The other threads will find the loaded version once the | 1847 // the class. The other threads will find the loaded version once the |
1883 // class is loaded. | 1848 // class is loaded. |
1884 klassOop aos = _abstract_ownable_synchronizer_klass; | 1849 klassOop aos = _abstract_ownable_synchronizer_klass; |
1885 if (aos == NULL) { | 1850 if (aos == NULL) { |
1886 klassOop k = resolve_or_fail(vmSymbolHandles::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK); | 1851 klassOop k = resolve_or_fail(vmSymbols::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK); |
1887 // Force a fence to prevent any read before the write completes | 1852 // Force a fence to prevent any read before the write completes |
1888 OrderAccess::fence(); | 1853 OrderAccess::fence(); |
1889 _abstract_ownable_synchronizer_klass = k; | 1854 _abstract_ownable_synchronizer_klass = k; |
1890 } | 1855 } |
1891 } | 1856 } |
1923 | 1888 |
1924 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { | 1889 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { |
1925 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); | 1890 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); |
1926 int info = wk_init_info[id - FIRST_WKID]; | 1891 int info = wk_init_info[id - FIRST_WKID]; |
1927 int sid = (info >> CEIL_LG_OPTION_LIMIT); | 1892 int sid = (info >> CEIL_LG_OPTION_LIMIT); |
1928 symbolHandle symbol = vmSymbolHandles::symbol_handle_at((vmSymbols::SID)sid); | 1893 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid); |
1929 klassOop* klassp = &_well_known_klasses[id]; | 1894 klassOop* klassp = &_well_known_klasses[id]; |
1930 bool must_load = (init_opt < SystemDictionary::Opt); | 1895 bool must_load = (init_opt < SystemDictionary::Opt); |
1931 bool try_load = true; | 1896 bool try_load = true; |
1932 if (init_opt == SystemDictionary::Opt_Kernel) { | 1897 if (init_opt == SystemDictionary::Opt_Kernel) { |
1933 #ifndef KERNEL | 1898 #ifndef KERNEL |
1953 int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT)); | 1918 int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT)); |
1954 | 1919 |
1955 initialize_wk_klass((WKID)id, opt, CHECK); | 1920 initialize_wk_klass((WKID)id, opt, CHECK); |
1956 | 1921 |
1957 // Update limits, so find_well_known_klass can be very fast: | 1922 // Update limits, so find_well_known_klass can be very fast: |
1958 symbolOop s = vmSymbols::symbol_at((vmSymbols::SID)sid); | 1923 Symbol* s = vmSymbols::symbol_at((vmSymbols::SID)sid); |
1959 if (wk_klass_name_limits[1] == NULL) { | 1924 if (wk_klass_name_limits[1] == NULL) { |
1960 wk_klass_name_limits[0] = wk_klass_name_limits[1] = s; | 1925 wk_klass_name_limits[0] = wk_klass_name_limits[1] = s; |
1961 } else if (wk_klass_name_limits[1] < s) { | 1926 } else if (wk_klass_name_limits[1] < s) { |
1962 wk_klass_name_limits[1] = s; | 1927 wk_klass_name_limits[1] = s; |
1963 } else if (wk_klass_name_limits[0] > s) { | 1928 } else if (wk_klass_name_limits[0] > s) { |
2080 instanceKlassHandle k, | 2045 instanceKlassHandle k, |
2081 Handle class_loader, bool defining, | 2046 Handle class_loader, bool defining, |
2082 TRAPS) { | 2047 TRAPS) { |
2083 const char *linkage_error = NULL; | 2048 const char *linkage_error = NULL; |
2084 { | 2049 { |
2085 symbolHandle name (THREAD, k->name()); | 2050 Symbol* name = k->name(); |
2086 MutexLocker mu(SystemDictionary_lock, THREAD); | 2051 MutexLocker mu(SystemDictionary_lock, THREAD); |
2087 | 2052 |
2088 klassOop check = find_class(d_index, d_hash, name, class_loader); | 2053 klassOop check = find_class(d_index, d_hash, name, class_loader); |
2089 if (check != (klassOop)NULL) { | 2054 if (check != (klassOop)NULL) { |
2090 // if different instanceKlass - duplicate class definition, | 2055 // if different instanceKlass - duplicate class definition, |
2101 return; | 2066 return; |
2102 } | 2067 } |
2103 } | 2068 } |
2104 | 2069 |
2105 #ifdef ASSERT | 2070 #ifdef ASSERT |
2106 unsigned int p_hash = placeholders()->compute_hash(name, class_loader); | 2071 Symbol* ph_check = find_placeholder(name, class_loader); |
2107 int p_index = placeholders()->hash_to_index(p_hash); | 2072 assert(ph_check == NULL || ph_check == name, "invalid symbol"); |
2108 symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader); | |
2109 assert(ph_check == NULL || ph_check == name(), "invalid symbol"); | |
2110 #endif | 2073 #endif |
2111 | 2074 |
2112 if (linkage_error == NULL) { | 2075 if (linkage_error == NULL) { |
2113 if (constraints()->check_or_update(k, class_loader, name) == false) { | 2076 if (constraints()->check_or_update(k, class_loader, name) == false) { |
2114 linkage_error = "loader constraint violation: loader (instance of %s)" | 2077 linkage_error = "loader constraint violation: loader (instance of %s)" |
2140 instanceKlassHandle k, | 2103 instanceKlassHandle k, |
2141 Handle class_loader, | 2104 Handle class_loader, |
2142 TRAPS) { | 2105 TRAPS) { |
2143 // Compile_lock prevents systemDictionary updates during compilations | 2106 // Compile_lock prevents systemDictionary updates during compilations |
2144 assert_locked_or_safepoint(Compile_lock); | 2107 assert_locked_or_safepoint(Compile_lock); |
2145 symbolHandle name (THREAD, k->name()); | 2108 Symbol* name = k->name(); |
2146 | 2109 |
2147 { | 2110 { |
2148 MutexLocker mu1(SystemDictionary_lock, THREAD); | 2111 MutexLocker mu1(SystemDictionary_lock, THREAD); |
2149 | 2112 |
2150 // See whether biased locking is enabled and if so set it for this | 2113 // See whether biased locking is enabled and if so set it for this |
2180 assert (sd_check != NULL, "should have entry in system dictionary"); | 2143 assert (sd_check != NULL, "should have entry in system dictionary"); |
2181 // Changed to allow PH to remain to complete class circularity checking | 2144 // Changed to allow PH to remain to complete class circularity checking |
2182 // while only one thread can define a class at one time, multiple | 2145 // while only one thread can define a class at one time, multiple |
2183 // classes can resolve the superclass for a class at one time, | 2146 // classes can resolve the superclass for a class at one time, |
2184 // and the placeholder is used to track that | 2147 // and the placeholder is used to track that |
2185 // symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader); | 2148 // Symbol* ph_check = find_placeholder(name, class_loader); |
2186 // assert (ph_check == NULL, "should not have a placeholder entry"); | 2149 // assert (ph_check == NULL, "should not have a placeholder entry"); |
2187 #endif | 2150 #endif |
2188 SystemDictionary_lock->notify_all(); | 2151 SystemDictionary_lock->notify_all(); |
2189 } | 2152 } |
2190 } | 2153 } |
2191 | 2154 |
2192 | 2155 |
2193 klassOop SystemDictionary::find_constrained_instance_or_array_klass( | 2156 klassOop SystemDictionary::find_constrained_instance_or_array_klass( |
2194 symbolHandle class_name, Handle class_loader, TRAPS) { | 2157 Symbol* class_name, Handle class_loader, TRAPS) { |
2195 | 2158 |
2196 // First see if it has been loaded directly. | 2159 // First see if it has been loaded directly. |
2197 // Force the protection domain to be null. (This removes protection checks.) | 2160 // Force the protection domain to be null. (This removes protection checks.) |
2198 Handle no_protection_domain; | 2161 Handle no_protection_domain; |
2199 klassOop klass = find_instance_or_array_klass(class_name, class_loader, | 2162 klassOop klass = find_instance_or_array_klass(class_name, class_loader, |
2202 return klass; | 2165 return klass; |
2203 | 2166 |
2204 // Now look to see if it has been loaded elsewhere, and is subject to | 2167 // Now look to see if it has been loaded elsewhere, and is subject to |
2205 // a loader constraint that would require this loader to return the | 2168 // a loader constraint that would require this loader to return the |
2206 // klass that is already loaded. | 2169 // klass that is already loaded. |
2207 if (FieldType::is_array(class_name())) { | 2170 if (FieldType::is_array(class_name)) { |
2208 // For array classes, their klassOops are not kept in the | 2171 // For array classes, their klassOops are not kept in the |
2209 // constraint table. The element klassOops are. | 2172 // constraint table. The element klassOops are. |
2210 jint dimension; | 2173 FieldArrayInfo fd; |
2211 symbolOop object_key; | 2174 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL)); |
2212 BasicType t = FieldType::get_array_info(class_name(), &dimension, | |
2213 &object_key, CHECK_(NULL)); | |
2214 if (t != T_OBJECT) { | 2175 if (t != T_OBJECT) { |
2215 klass = Universe::typeArrayKlassObj(t); | 2176 klass = Universe::typeArrayKlassObj(t); |
2216 } else { | 2177 } else { |
2217 symbolHandle elem_name(THREAD, object_key); | |
2218 MutexLocker mu(SystemDictionary_lock, THREAD); | 2178 MutexLocker mu(SystemDictionary_lock, THREAD); |
2219 klass = constraints()->find_constrained_klass(elem_name, class_loader); | 2179 klass = constraints()->find_constrained_klass(fd.object_key(), class_loader); |
2220 } | 2180 } |
2221 // If element class already loaded, allocate array klass | 2181 // If element class already loaded, allocate array klass |
2222 if (klass != NULL) { | 2182 if (klass != NULL) { |
2223 klass = Klass::cast(klass)->array_klass_or_null(dimension); | 2183 klass = Klass::cast(klass)->array_klass_or_null(fd.dimension()); |
2224 } | 2184 } |
2225 } else { | 2185 } else { |
2226 MutexLocker mu(SystemDictionary_lock, THREAD); | 2186 MutexLocker mu(SystemDictionary_lock, THREAD); |
2227 // Non-array classes are easy: simply check the constraint table. | 2187 // Non-array classes are easy: simply check the constraint table. |
2228 klass = constraints()->find_constrained_klass(class_name, class_loader); | 2188 klass = constraints()->find_constrained_klass(class_name, class_loader); |
2230 | 2190 |
2231 return klass; | 2191 return klass; |
2232 } | 2192 } |
2233 | 2193 |
2234 | 2194 |
2235 bool SystemDictionary::add_loader_constraint(symbolHandle class_name, | 2195 bool SystemDictionary::add_loader_constraint(Symbol* class_name, |
2236 Handle class_loader1, | 2196 Handle class_loader1, |
2237 Handle class_loader2, | 2197 Handle class_loader2, |
2238 Thread* THREAD) { | 2198 Thread* THREAD) { |
2239 symbolHandle constraint_name; | 2199 Symbol* constraint_name = NULL; |
2240 if (!FieldType::is_array(class_name())) { | 2200 if (!FieldType::is_array(class_name)) { |
2241 constraint_name = class_name; | 2201 constraint_name = class_name; |
2242 } else { | 2202 } else { |
2243 // For array classes, their klassOops are not kept in the | 2203 // For array classes, their klassOops are not kept in the |
2244 // constraint table. The element classes are. | 2204 // constraint table. The element classes are. |
2245 jint dimension; | 2205 FieldArrayInfo fd; |
2246 symbolOop object_key; | 2206 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false)); |
2247 BasicType t = FieldType::get_array_info(class_name(), &dimension, | |
2248 &object_key, CHECK_(false)); | |
2249 // primitive types always pass | 2207 // primitive types always pass |
2250 if (t != T_OBJECT) { | 2208 if (t != T_OBJECT) { |
2251 return true; | 2209 return true; |
2252 } else { | 2210 } else { |
2253 constraint_name = symbolHandle(THREAD, object_key); | 2211 constraint_name = fd.object_key(); |
2254 } | 2212 } |
2255 } | 2213 } |
2256 unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, class_loader1); | 2214 unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, class_loader1); |
2257 int d_index1 = dictionary()->hash_to_index(d_hash1); | 2215 int d_index1 = dictionary()->hash_to_index(d_hash1); |
2258 | 2216 |
2271 } | 2229 } |
2272 } | 2230 } |
2273 | 2231 |
2274 // Add entry to resolution error table to record the error when the first | 2232 // Add entry to resolution error table to record the error when the first |
2275 // attempt to resolve a reference to a class has failed. | 2233 // attempt to resolve a reference to a class has failed. |
2276 void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, symbolHandle error) { | 2234 void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, Symbol* error) { |
2277 unsigned int hash = resolution_errors()->compute_hash(pool, which); | 2235 unsigned int hash = resolution_errors()->compute_hash(pool, which); |
2278 int index = resolution_errors()->hash_to_index(hash); | 2236 int index = resolution_errors()->hash_to_index(hash); |
2279 { | 2237 { |
2280 MutexLocker ml(SystemDictionary_lock, Thread::current()); | 2238 MutexLocker ml(SystemDictionary_lock, Thread::current()); |
2281 resolution_errors()->add_entry(index, hash, pool, which, error); | 2239 resolution_errors()->add_entry(index, hash, pool, which, error); |
2282 } | 2240 } |
2283 } | 2241 } |
2284 | 2242 |
2285 // Lookup resolution error table. Returns error if found, otherwise NULL. | 2243 // Lookup resolution error table. Returns error if found, otherwise NULL. |
2286 symbolOop SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) { | 2244 Symbol* SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) { |
2287 unsigned int hash = resolution_errors()->compute_hash(pool, which); | 2245 unsigned int hash = resolution_errors()->compute_hash(pool, which); |
2288 int index = resolution_errors()->hash_to_index(hash); | 2246 int index = resolution_errors()->hash_to_index(hash); |
2289 { | 2247 { |
2290 MutexLocker ml(SystemDictionary_lock, Thread::current()); | 2248 MutexLocker ml(SystemDictionary_lock, Thread::current()); |
2291 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which); | 2249 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which); |
2292 return (entry != NULL) ? entry->error() : (symbolOop)NULL; | 2250 return (entry != NULL) ? entry->error() : (Symbol*)NULL; |
2293 } | 2251 } |
2294 } | 2252 } |
2295 | 2253 |
2296 | 2254 |
2297 // Signature constraints ensure that callers and callees agree about | 2255 // Signature constraints ensure that callers and callees agree about |
2343 // signature will be resolved to the same class in both loaders. | 2301 // signature will be resolved to the same class in both loaders. |
2344 // Returns the name of the type that failed a loader constraint check, or | 2302 // Returns the name of the type that failed a loader constraint check, or |
2345 // NULL if no constraint failed. The returned C string needs cleaning up | 2303 // NULL if no constraint failed. The returned C string needs cleaning up |
2346 // with a ResourceMark in the caller. No exception except OOME is thrown. | 2304 // with a ResourceMark in the caller. No exception except OOME is thrown. |
2347 // Arrays are not added to the loader constraint table, their elements are. | 2305 // Arrays are not added to the loader constraint table, their elements are. |
2348 char* SystemDictionary::check_signature_loaders(symbolHandle signature, | 2306 char* SystemDictionary::check_signature_loaders(Symbol* signature, |
2349 Handle loader1, Handle loader2, | 2307 Handle loader1, Handle loader2, |
2350 bool is_method, TRAPS) { | 2308 bool is_method, TRAPS) { |
2351 // Nothing to do if loaders are the same. | 2309 // Nothing to do if loaders are the same. |
2352 if (loader1() == loader2()) { | 2310 if (loader1() == loader2()) { |
2353 return NULL; | 2311 return NULL; |
2354 } | 2312 } |
2355 | 2313 |
2314 ResourceMark rm(THREAD); | |
2356 SignatureStream sig_strm(signature, is_method); | 2315 SignatureStream sig_strm(signature, is_method); |
2357 while (!sig_strm.is_done()) { | 2316 while (!sig_strm.is_done()) { |
2358 if (sig_strm.is_object()) { | 2317 if (sig_strm.is_object()) { |
2359 symbolOop s = sig_strm.as_symbol(CHECK_NULL); | 2318 Symbol* s = sig_strm.as_symbol(CHECK_NULL); |
2360 symbolHandle sig (THREAD, s); | 2319 Symbol* sig = s; |
2361 if (!add_loader_constraint(sig, loader1, loader2, THREAD)) { | 2320 if (!add_loader_constraint(sig, loader1, loader2, THREAD)) { |
2362 return sig()->as_C_string(); | 2321 return sig->as_C_string(); |
2363 } | 2322 } |
2364 } | 2323 } |
2365 sig_strm.next(); | 2324 sig_strm.next(); |
2366 } | 2325 } |
2367 return NULL; | 2326 return NULL; |
2368 } | 2327 } |
2369 | 2328 |
2370 | 2329 |
2371 methodOop SystemDictionary::find_method_handle_invoke(symbolHandle name, | 2330 methodOop SystemDictionary::find_method_handle_invoke(Symbol* name, |
2372 symbolHandle signature, | 2331 Symbol* signature, |
2373 KlassHandle accessing_klass, | 2332 KlassHandle accessing_klass, |
2374 TRAPS) { | 2333 TRAPS) { |
2375 if (!EnableMethodHandles) return NULL; | 2334 if (!EnableMethodHandles) return NULL; |
2376 vmSymbols::SID name_id = vmSymbols::find_sid(name()); | 2335 vmSymbols::SID name_id = vmSymbols::find_sid(name); |
2377 assert(name_id != vmSymbols::NO_SID, "must be a known name"); | 2336 assert(name_id != vmSymbols::NO_SID, "must be a known name"); |
2378 unsigned int hash = invoke_method_table()->compute_hash(signature, name_id); | 2337 unsigned int hash = invoke_method_table()->compute_hash(signature, name_id); |
2379 int index = invoke_method_table()->hash_to_index(hash); | 2338 int index = invoke_method_table()->hash_to_index(hash); |
2380 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, name_id); | 2339 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, name_id); |
2381 methodHandle non_cached_result; | 2340 methodHandle non_cached_result; |
2385 // (tw) May we do this? | 2344 // (tw) May we do this? |
2386 //if (THREAD->is_Compiler_thread()) | 2345 //if (THREAD->is_Compiler_thread()) |
2387 // return NULL; // do not attempt from within compiler | 2346 // return NULL; // do not attempt from within compiler |
2388 bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name)); | 2347 bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name)); |
2389 bool found_on_bcp = false; | 2348 bool found_on_bcp = false; |
2390 Handle mt = find_method_handle_type(signature(), accessing_klass, | 2349 Handle mt = find_method_handle_type(signature, accessing_klass, |
2391 for_invokeGeneric, | 2350 for_invokeGeneric, |
2392 found_on_bcp, CHECK_NULL); | 2351 found_on_bcp, CHECK_NULL); |
2393 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass(); | 2352 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass(); |
2394 methodHandle m = methodOopDesc::make_invoke_method(mh_klass, name, signature, | 2353 methodHandle m = methodOopDesc::make_invoke_method(mh_klass, name, signature, |
2395 mt, CHECK_NULL); | 2354 mt, CHECK_NULL); |
2416 | 2375 |
2417 // Ask Java code to find or construct a java.dyn.MethodType for the given | 2376 // Ask Java code to find or construct a java.dyn.MethodType for the given |
2418 // signature, as interpreted relative to the given class loader. | 2377 // signature, as interpreted relative to the given class loader. |
2419 // Because of class loader constraints, all method handle usage must be | 2378 // Because of class loader constraints, all method handle usage must be |
2420 // consistent with this loader. | 2379 // consistent with this loader. |
2421 Handle SystemDictionary::find_method_handle_type(symbolHandle signature, | 2380 Handle SystemDictionary::find_method_handle_type(Symbol* signature, |
2422 KlassHandle accessing_klass, | 2381 KlassHandle accessing_klass, |
2423 bool for_invokeGeneric, | 2382 bool for_invokeGeneric, |
2424 bool& return_bcp_flag, | 2383 bool& return_bcp_flag, |
2425 TRAPS) { | 2384 TRAPS) { |
2426 Handle class_loader, protection_domain; | 2385 Handle class_loader, protection_domain; |
2427 bool is_on_bcp = true; // keep this true as long as we can materialize from the boot classloader | 2386 bool is_on_bcp = true; // keep this true as long as we can materialize from the boot classloader |
2428 Handle empty; | 2387 Handle empty; |
2429 int npts = ArgumentCount(signature()).size(); | 2388 int npts = ArgumentCount(signature).size(); |
2430 objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty)); | 2389 objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty)); |
2431 int arg = 0; | 2390 int arg = 0; |
2432 Handle rt; // the return type from the signature | 2391 Handle rt; // the return type from the signature |
2433 for (SignatureStream ss(signature()); !ss.is_done(); ss.next()) { | 2392 ResourceMark rm(THREAD); |
2393 for (SignatureStream ss(signature); !ss.is_done(); ss.next()) { | |
2434 oop mirror = NULL; | 2394 oop mirror = NULL; |
2435 if (is_on_bcp) { | 2395 if (is_on_bcp) { |
2436 mirror = ss.as_java_mirror(class_loader, protection_domain, | 2396 mirror = ss.as_java_mirror(class_loader, protection_domain, |
2437 SignatureStream::ReturnNull, CHECK_(empty)); | 2397 SignatureStream::ReturnNull, CHECK_(empty)); |
2438 if (mirror == NULL) { | 2398 if (mirror == NULL) { |
2500 | 2460 |
2501 // Ask Java code to find or construct a method handle constant. | 2461 // Ask Java code to find or construct a method handle constant. |
2502 Handle SystemDictionary::link_method_handle_constant(KlassHandle caller, | 2462 Handle SystemDictionary::link_method_handle_constant(KlassHandle caller, |
2503 int ref_kind, //e.g., JVM_REF_invokeVirtual | 2463 int ref_kind, //e.g., JVM_REF_invokeVirtual |
2504 KlassHandle callee, | 2464 KlassHandle callee, |
2505 symbolHandle name_sym, | 2465 Symbol* name_sym, |
2506 symbolHandle signature, | 2466 Symbol* signature, |
2507 TRAPS) { | 2467 TRAPS) { |
2508 Handle empty; | 2468 Handle empty; |
2509 Handle name = java_lang_String::create_from_symbol(name_sym(), CHECK_(empty)); | 2469 Handle name = java_lang_String::create_from_symbol(name_sym, CHECK_(empty)); |
2510 Handle type; | 2470 Handle type; |
2511 if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') { | 2471 if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') { |
2512 bool ignore_is_on_bcp = false; | 2472 bool ignore_is_on_bcp = false; |
2513 type = find_method_handle_type(signature, caller, false, ignore_is_on_bcp, CHECK_(empty)); | 2473 type = find_method_handle_type(signature, caller, false, ignore_is_on_bcp, CHECK_(empty)); |
2514 } else { | 2474 } else { |
2515 SignatureStream ss(signature(), false); | 2475 ResourceMark rm(THREAD); |
2476 SignatureStream ss(signature, false); | |
2516 if (!ss.is_done()) { | 2477 if (!ss.is_done()) { |
2517 oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(), | 2478 oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(), |
2518 SignatureStream::NCDFError, CHECK_(empty)); | 2479 SignatureStream::NCDFError, CHECK_(empty)); |
2519 type = Handle(THREAD, mirror); | 2480 type = Handle(THREAD, mirror); |
2520 ss.next(); | 2481 ss.next(); |
2542 } | 2503 } |
2543 | 2504 |
2544 // Ask Java code to find or construct a java.dyn.CallSite for the given | 2505 // Ask Java code to find or construct a java.dyn.CallSite for the given |
2545 // name and signature, as interpreted relative to the given class loader. | 2506 // name and signature, as interpreted relative to the given class loader. |
2546 Handle SystemDictionary::make_dynamic_call_site(Handle bootstrap_method, | 2507 Handle SystemDictionary::make_dynamic_call_site(Handle bootstrap_method, |
2547 symbolHandle name, | 2508 Symbol* name, |
2548 methodHandle signature_invoker, | 2509 methodHandle signature_invoker, |
2549 Handle info, | 2510 Handle info, |
2550 methodHandle caller_method, | 2511 methodHandle caller_method, |
2551 int caller_bci, | 2512 int caller_bci, |
2552 TRAPS) { | 2513 TRAPS) { |
2557 | 2518 |
2558 Handle caller_mname = MethodHandles::new_MemberName(CHECK_(empty)); | 2519 Handle caller_mname = MethodHandles::new_MemberName(CHECK_(empty)); |
2559 MethodHandles::init_MemberName(caller_mname(), caller_method()); | 2520 MethodHandles::init_MemberName(caller_mname(), caller_method()); |
2560 | 2521 |
2561 // call sun.dyn.MethodHandleNatives::makeDynamicCallSite(bootm, name, mtype, info, caller_mname, caller_pos) | 2522 // call sun.dyn.MethodHandleNatives::makeDynamicCallSite(bootm, name, mtype, info, caller_mname, caller_pos) |
2562 oop name_str_oop = StringTable::intern(name(), CHECK_(empty)); // not a handle! | 2523 oop name_str_oop = StringTable::intern(name, CHECK_(empty)); // not a handle! |
2563 JavaCallArguments args(Handle(THREAD, bootstrap_method())); | 2524 JavaCallArguments args(Handle(THREAD, bootstrap_method())); |
2564 args.push_oop(name_str_oop); | 2525 args.push_oop(name_str_oop); |
2565 args.push_oop(signature_invoker->method_handle_type()); | 2526 args.push_oop(signature_invoker->method_handle_type()); |
2566 args.push_oop(info()); | 2527 args.push_oop(info()); |
2567 args.push_oop(caller_mname()); | 2528 args.push_oop(caller_mname()); |
2740 constraints()->verify(dictionary(), placeholders()); | 2701 constraints()->verify(dictionary(), placeholders()); |
2741 } | 2702 } |
2742 | 2703 |
2743 | 2704 |
2744 void SystemDictionary::verify_obj_klass_present(Handle obj, | 2705 void SystemDictionary::verify_obj_klass_present(Handle obj, |
2745 symbolHandle class_name, | 2706 Symbol* class_name, |
2746 Handle class_loader) { | 2707 Handle class_loader) { |
2747 GCMutexLocker mu(SystemDictionary_lock); | 2708 GCMutexLocker mu(SystemDictionary_lock); |
2748 oop probe = find_class_or_placeholder(class_name, class_loader); | 2709 Symbol* name; |
2710 | |
2711 klassOop probe = find_class(class_name, class_loader); | |
2749 if (probe == NULL) { | 2712 if (probe == NULL) { |
2750 probe = SystemDictionary::find_shared_class(class_name); | 2713 probe = SystemDictionary::find_shared_class(class_name); |
2751 } | 2714 if (probe == NULL) { |
2752 guarantee(probe != NULL && | 2715 name = find_placeholder(class_name, class_loader); |
2753 (!probe->is_klass() || probe == obj()), | 2716 } |
2754 "Loaded klasses should be in SystemDictionary"); | 2717 } |
2718 guarantee(probe != NULL || name != NULL, | |
2719 "Loaded klasses should be in SystemDictionary"); | |
2755 } | 2720 } |
2756 | 2721 |
2757 #ifndef PRODUCT | 2722 #ifndef PRODUCT |
2758 | 2723 |
2759 // statistics code | 2724 // statistics code |