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