< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page

  39 #include "classfile/packageEntry.hpp"
  40 #include "classfile/placeholders.hpp"
  41 #include "classfile/protectionDomainCache.hpp"
  42 #include "classfile/resolutionErrors.hpp"
  43 #include "classfile/stringTable.hpp"
  44 #include "classfile/symbolTable.hpp"
  45 #include "classfile/systemDictionary.hpp"
  46 #include "classfile/vmClasses.hpp"
  47 #include "classfile/vmSymbols.hpp"
  48 #include "code/codeCache.hpp"
  49 #include "gc/shared/gcTraceTime.inline.hpp"
  50 #include "interpreter/bootstrapInfo.hpp"
  51 #include "jfr/jfrEvents.hpp"
  52 #include "logging/log.hpp"
  53 #include "logging/logStream.hpp"
  54 #include "memory/metaspaceClosure.hpp"
  55 #include "memory/oopFactory.hpp"
  56 #include "memory/resourceArea.hpp"
  57 #include "memory/universe.hpp"
  58 #include "oops/access.inline.hpp"

  59 #include "oops/instanceKlass.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/method.inline.hpp"
  62 #include "oops/objArrayKlass.hpp"
  63 #include "oops/objArrayOop.inline.hpp"
  64 #include "oops/oop.inline.hpp"
  65 #include "oops/oopHandle.inline.hpp"
  66 #include "oops/symbol.hpp"
  67 #include "oops/typeArrayKlass.hpp"

  68 #include "prims/jvmtiExport.hpp"
  69 #include "prims/methodHandles.hpp"
  70 #include "runtime/arguments.hpp"
  71 #include "runtime/handles.inline.hpp"
  72 #include "runtime/java.hpp"
  73 #include "runtime/javaCalls.hpp"
  74 #include "runtime/mutexLocker.hpp"

  75 #include "runtime/sharedRuntime.hpp"
  76 #include "runtime/signature.hpp"
  77 #include "services/classLoadingService.hpp"
  78 #include "services/diagnosticCommand.hpp"
  79 #include "services/finalizerService.hpp"
  80 #include "services/threadService.hpp"
  81 #include "utilities/macros.hpp"
  82 #include "utilities/utf8.hpp"
  83 #if INCLUDE_CDS
  84 #include "classfile/systemDictionaryShared.hpp"
  85 #endif
  86 #if INCLUDE_JFR
  87 #include "jfr/jfr.hpp"
  88 #endif
  89 
  90 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
  91 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
  92 ProtectionDomainCacheTable*   SystemDictionary::_pd_cache_table = NULL;
  93 
  94 OopHandle   SystemDictionary::_java_system_loader;

 269 }
 270 
 271 // Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
 272 
 273 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 274   if (Signature::is_array(class_name)) {
 275     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 276   } else {
 277     return resolve_instance_class_or_null_helper(class_name, class_loader, protection_domain, THREAD);
 278   }
 279 }
 280 
 281 // name may be in the form of "java/lang/Object" or "Ljava/lang/Object;"
 282 InstanceKlass* SystemDictionary::resolve_instance_class_or_null_helper(Symbol* class_name,
 283                                                                        Handle class_loader,
 284                                                                        Handle protection_domain,
 285                                                                        TRAPS) {
 286   assert(class_name != NULL && !Signature::is_array(class_name), "must be");
 287   if (Signature::has_envelope(class_name)) {
 288     ResourceMark rm(THREAD);
 289     // Ignore wrapping L and ;.
 290     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 291                                                  class_name->utf8_length() - 2);
 292     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 293   } else {
 294     return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 295   }
 296 }
 297 
 298 // Forwards to resolve_instance_class_or_null
 299 
 300 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
 301                                                      Handle class_loader,
 302                                                      Handle protection_domain,
 303                                                      TRAPS) {
 304   assert(Signature::is_array(class_name), "must be array");
 305   ResourceMark rm(THREAD);
 306   SignatureStream ss(class_name, false);
 307   int ndims = ss.skip_array_prefix();  // skip all '['s
 308   Klass* k = NULL;
 309   BasicType t = ss.type();
 310   if (ss.has_envelope()) {
 311     Symbol* obj_class = ss.as_symbol();
 312     k = SystemDictionary::resolve_instance_class_or_null(obj_class,
 313                                                          class_loader,
 314                                                          protection_domain,
 315                                                          CHECK_NULL);
 316     if (k != NULL) {
 317       k = k->array_klass(ndims, CHECK_NULL);







 318     }
 319   } else {
 320     k = Universe::typeArrayKlassObj(t);
 321     k = TypeArrayKlass::cast(k)->array_klass(ndims, CHECK_NULL);
 322   }
 323   return k;
 324 }
 325 
 326 static inline void log_circularity_error(Thread* thread, PlaceholderEntry* probe) {
 327   LogTarget(Debug, class, load, placeholders) lt;
 328   if (lt.is_enabled()) {
 329     ResourceMark rm(thread);
 330     LogStream ls(lt);
 331     ls.print("ClassCircularityError detected for placeholder ");
 332     probe->print_entry(&ls);
 333     ls.cr();
 334   }
 335 }
 336 
 337 // Must be called for any superclass or superinterface resolution

 427     SystemDictionary::resolve_instance_class_or_null_helper(super_name,
 428                                                             class_loader,
 429                                                             protection_domain,
 430                                                             THREAD);
 431 
 432   // Clean up placeholder entry.
 433   {
 434     MutexLocker mu(THREAD, SystemDictionary_lock);
 435     placeholders()->find_and_remove(name_hash, class_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 436     SystemDictionary_lock->notify_all();
 437   }
 438 
 439   // Check for pending exception or null superk, and throw exception
 440   if (HAS_PENDING_EXCEPTION || superk == NULL) {
 441     handle_resolution_exception(super_name, true, CHECK_NULL);
 442   }
 443 
 444   return superk;
 445 }
 446 












































 447 // We only get here if this thread finds that another thread
 448 // has already claimed the placeholder token for the current operation,
 449 // but that other thread either never owned or gave up the
 450 // object lock
 451 // Waits on SystemDictionary_lock to indicate placeholder table updated
 452 // On return, caller must recheck placeholder table state
 453 //
 454 // We only get here if
 455 //  1) custom classLoader, i.e. not bootstrap classloader
 456 //  2) custom classLoader has broken the class loader objectLock
 457 //     so another thread got here in parallel
 458 //
 459 // lockObject must be held.
 460 // Complicated dance due to lock ordering:
 461 // Must first release the classloader object lock to
 462 // allow initial definer to complete the class definition
 463 // and to avoid deadlock
 464 // Reclaim classloader lock object with same original recursion count
 465 // Must release SystemDictionary_lock after notify, since
 466 // class loader lock must be claimed before SystemDictionary_lock

 784   Dictionary* dictionary = loader_data->dictionary();
 785   unsigned int name_hash = dictionary->compute_hash(class_name);
 786   return dictionary->find(name_hash, class_name, protection_domain);
 787 }
 788 
 789 // Look for a loaded instance or array klass by name.  Do not do any loading.
 790 // return NULL in case of error.
 791 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
 792                                                       Handle class_loader,
 793                                                       Handle protection_domain) {
 794   Klass* k = NULL;
 795   assert(class_name != NULL, "class name must be non NULL");
 796 
 797   if (Signature::is_array(class_name)) {
 798     // The name refers to an array.  Parse the name.
 799     // dimension and object_key in FieldArrayInfo are assigned as a
 800     // side-effect of this call
 801     SignatureStream ss(class_name, false);
 802     int ndims = ss.skip_array_prefix();  // skip all '['s
 803     BasicType t = ss.type();
 804     if (t != T_OBJECT) {
 805       k = Universe::typeArrayKlassObj(t);
 806     } else {
 807       k = SystemDictionary::find_instance_klass(ss.as_symbol(), class_loader, protection_domain);
 808     }
 809     if (k != NULL) {
 810       k = k->array_klass_or_null(ndims);




 811     }
 812   } else {
 813     k = find_instance_klass(class_name, class_loader, protection_domain);
 814   }
 815   return k;
 816 }
 817 
 818 // Note: this method is much like resolve_class_from_stream, but
 819 // does not publish the classes in the SystemDictionary.
 820 // Handles Lookup.defineClass hidden.
 821 InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
 822                                                      ClassFileStream* st,
 823                                                      Symbol* class_name,
 824                                                      Handle class_loader,
 825                                                      const ClassLoadInfo& cl_info,
 826                                                      TRAPS) {
 827 
 828   EventClassLoad class_load_start_event;
 829   ClassLoaderData* loader_data;
 830 

1132 }
1133 
1134 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1135                                                    Handle class_loader,
1136                                                    Handle protection_domain,
1137                                                    const ClassFileStream *cfs,
1138                                                    PackageEntry* pkg_entry,
1139                                                    TRAPS) {
1140   assert(ik != NULL, "sanity");
1141   assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1142   Symbol* class_name = ik->name();
1143 
1144   if (!is_shared_class_visible(class_name, ik, pkg_entry, class_loader)) {
1145     return NULL;
1146   }
1147 
1148   if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
1149     return NULL;
1150   }
1151 


















1152   InstanceKlass* new_ik = NULL;
1153   // CFLH check is skipped for VM hidden classes (see KlassFactory::create_from_stream).
1154   // It will be skipped for shared VM hidden lambda proxy classes.
1155   if (!SystemDictionaryShared::is_hidden_lambda_proxy(ik)) {
1156     new_ik = KlassFactory::check_shared_class_file_load_hook(
1157       ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
1158   }
1159   if (new_ik != NULL) {
1160     // The class is changed by CFLH. Return the new class. The shared class is
1161     // not used.
1162     return new_ik;
1163   }
1164 
1165   // Adjust methods to recover missing data.  They need addresses for
1166   // interpreter entry points and their default native method address
1167   // must be reset.
1168 
1169   // Shared classes are all currently loaded by either the bootstrap or
1170   // internal parallel class loaders, so this will never cause a deadlock
1171   // on a custom class loader lock.
1172   // Since this class is already locked with parallel capable class
1173   // loaders, including the bootstrap loader via the placeholder table,
1174   // this lock is currently a nop.
1175 
1176   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1177   {
1178     HandleMark hm(THREAD);
1179     Handle lockObject = get_loader_lock_or_null(class_loader);
1180     ObjectLocker ol(lockObject, THREAD);
1181     // prohibited package check assumes all classes loaded from archive call
1182     // restore_unshareable_info which calls ik->set_package()
1183     ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1184   }
1185 
1186   load_shared_class_misc(ik, loader_data);

1187   return ik;
1188 }
1189 
1190 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1191   ik->print_class_load_logging(loader_data, NULL, NULL);
1192 
1193   // For boot loader, ensure that GetSystemPackage knows that a class in this
1194   // package was loaded.
1195   if (loader_data->is_the_null_class_loader_data()) {
1196     int path_index = ik->shared_classpath_index();
1197     ik->set_classpath_index(path_index);
1198   }
1199 
1200   // notify a class loaded from shared object
1201   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1202 }
1203 
1204 #endif // INCLUDE_CDS
1205 
1206 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {

1754 Klass* SystemDictionary::find_constrained_instance_or_array_klass(
1755                     Thread* current, Symbol* class_name, Handle class_loader) {
1756 
1757   // First see if it has been loaded directly.
1758   // Force the protection domain to be null.  (This removes protection checks.)
1759   Handle no_protection_domain;
1760   Klass* klass = find_instance_or_array_klass(class_name, class_loader,
1761                                               no_protection_domain);
1762   if (klass != NULL)
1763     return klass;
1764 
1765   // Now look to see if it has been loaded elsewhere, and is subject to
1766   // a loader constraint that would require this loader to return the
1767   // klass that is already loaded.
1768   if (Signature::is_array(class_name)) {
1769     // For array classes, their Klass*s are not kept in the
1770     // constraint table. The element Klass*s are.
1771     SignatureStream ss(class_name, false);
1772     int ndims = ss.skip_array_prefix();  // skip all '['s
1773     BasicType t = ss.type();
1774     if (t != T_OBJECT) {
1775       klass = Universe::typeArrayKlassObj(t);
1776     } else {
1777       MutexLocker mu(current, SystemDictionary_lock);
1778       klass = constraints()->find_constrained_klass(ss.as_symbol(), class_loader);
1779     }
1780     // If element class already loaded, allocate array klass
1781     if (klass != NULL) {
1782       klass = klass->array_klass_or_null(ndims);




1783     }
1784   } else {
1785     MutexLocker mu(current, SystemDictionary_lock);
1786     // Non-array classes are easy: simply check the constraint table.
1787     klass = constraints()->find_constrained_klass(class_name, class_loader);
1788   }
1789 
1790   return klass;
1791 }
1792 
1793 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
1794                                              Klass* klass_being_linked,
1795                                              Handle class_loader1,
1796                                              Handle class_loader2) {
1797   ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
1798   ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
1799 
1800   Symbol* constraint_name = NULL;
1801 
1802   if (!Signature::is_array(class_name)) {

  39 #include "classfile/packageEntry.hpp"
  40 #include "classfile/placeholders.hpp"
  41 #include "classfile/protectionDomainCache.hpp"
  42 #include "classfile/resolutionErrors.hpp"
  43 #include "classfile/stringTable.hpp"
  44 #include "classfile/symbolTable.hpp"
  45 #include "classfile/systemDictionary.hpp"
  46 #include "classfile/vmClasses.hpp"
  47 #include "classfile/vmSymbols.hpp"
  48 #include "code/codeCache.hpp"
  49 #include "gc/shared/gcTraceTime.inline.hpp"
  50 #include "interpreter/bootstrapInfo.hpp"
  51 #include "jfr/jfrEvents.hpp"
  52 #include "logging/log.hpp"
  53 #include "logging/logStream.hpp"
  54 #include "memory/metaspaceClosure.hpp"
  55 #include "memory/oopFactory.hpp"
  56 #include "memory/resourceArea.hpp"
  57 #include "memory/universe.hpp"
  58 #include "oops/access.inline.hpp"
  59 #include "oops/fieldStreams.inline.hpp"
  60 #include "oops/instanceKlass.hpp"
  61 #include "oops/klass.inline.hpp"
  62 #include "oops/method.inline.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "oops/oopHandle.inline.hpp"
  67 #include "oops/symbol.hpp"
  68 #include "oops/typeArrayKlass.hpp"
  69 #include "oops/inlineKlass.inline.hpp"
  70 #include "prims/jvmtiExport.hpp"
  71 #include "prims/methodHandles.hpp"
  72 #include "runtime/arguments.hpp"
  73 #include "runtime/handles.inline.hpp"
  74 #include "runtime/java.hpp"
  75 #include "runtime/javaCalls.hpp"
  76 #include "runtime/mutexLocker.hpp"
  77 #include "runtime/os.hpp"
  78 #include "runtime/sharedRuntime.hpp"
  79 #include "runtime/signature.hpp"
  80 #include "services/classLoadingService.hpp"
  81 #include "services/diagnosticCommand.hpp"
  82 #include "services/finalizerService.hpp"
  83 #include "services/threadService.hpp"
  84 #include "utilities/macros.hpp"
  85 #include "utilities/utf8.hpp"
  86 #if INCLUDE_CDS
  87 #include "classfile/systemDictionaryShared.hpp"
  88 #endif
  89 #if INCLUDE_JFR
  90 #include "jfr/jfr.hpp"
  91 #endif
  92 
  93 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
  94 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
  95 ProtectionDomainCacheTable*   SystemDictionary::_pd_cache_table = NULL;
  96 
  97 OopHandle   SystemDictionary::_java_system_loader;

 272 }
 273 
 274 // Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
 275 
 276 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 277   if (Signature::is_array(class_name)) {
 278     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 279   } else {
 280     return resolve_instance_class_or_null_helper(class_name, class_loader, protection_domain, THREAD);
 281   }
 282 }
 283 
 284 // name may be in the form of "java/lang/Object" or "Ljava/lang/Object;"
 285 InstanceKlass* SystemDictionary::resolve_instance_class_or_null_helper(Symbol* class_name,
 286                                                                        Handle class_loader,
 287                                                                        Handle protection_domain,
 288                                                                        TRAPS) {
 289   assert(class_name != NULL && !Signature::is_array(class_name), "must be");
 290   if (Signature::has_envelope(class_name)) {
 291     ResourceMark rm(THREAD);
 292     // Ignore wrapping L and ;. (and Q and ; for value types);
 293     TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 294                                                  class_name->utf8_length() - 2);
 295     return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 296   } else {
 297     return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 298   }
 299 }
 300 
 301 // Forwards to resolve_instance_class_or_null
 302 
 303 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
 304                                                      Handle class_loader,
 305                                                      Handle protection_domain,
 306                                                      TRAPS) {
 307   assert(Signature::is_array(class_name), "must be array");
 308   ResourceMark rm(THREAD);
 309   SignatureStream ss(class_name, false);
 310   int ndims = ss.skip_array_prefix();  // skip all '['s
 311   Klass* k = NULL;
 312   BasicType t = ss.type();
 313   if (ss.has_envelope()) {
 314     Symbol* obj_class = ss.as_symbol();
 315     k = SystemDictionary::resolve_instance_class_or_null(obj_class,
 316                                                          class_loader,
 317                                                          protection_domain,
 318                                                          CHECK_NULL);
 319     if (k != NULL) {
 320       if (class_name->is_Q_array_signature()) {
 321         if (!k->is_inline_klass()) {
 322           THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), "L/Q mismatch on bottom type");
 323         }
 324         k = InlineKlass::cast(k)->value_array_klass(ndims, CHECK_NULL);
 325       } else {
 326         k = k->array_klass(ndims, CHECK_NULL);
 327       }
 328     }
 329   } else {
 330     k = Universe::typeArrayKlassObj(t);
 331     k = TypeArrayKlass::cast(k)->array_klass(ndims, CHECK_NULL);
 332   }
 333   return k;
 334 }
 335 
 336 static inline void log_circularity_error(Thread* thread, PlaceholderEntry* probe) {
 337   LogTarget(Debug, class, load, placeholders) lt;
 338   if (lt.is_enabled()) {
 339     ResourceMark rm(thread);
 340     LogStream ls(lt);
 341     ls.print("ClassCircularityError detected for placeholder ");
 342     probe->print_entry(&ls);
 343     ls.cr();
 344   }
 345 }
 346 
 347 // Must be called for any superclass or superinterface resolution

 437     SystemDictionary::resolve_instance_class_or_null_helper(super_name,
 438                                                             class_loader,
 439                                                             protection_domain,
 440                                                             THREAD);
 441 
 442   // Clean up placeholder entry.
 443   {
 444     MutexLocker mu(THREAD, SystemDictionary_lock);
 445     placeholders()->find_and_remove(name_hash, class_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 446     SystemDictionary_lock->notify_all();
 447   }
 448 
 449   // Check for pending exception or null superk, and throw exception
 450   if (HAS_PENDING_EXCEPTION || superk == NULL) {
 451     handle_resolution_exception(super_name, true, CHECK_NULL);
 452   }
 453 
 454   return superk;
 455 }
 456 
 457 Klass* SystemDictionary::resolve_inline_type_field_or_fail(AllFieldStream* fs,
 458                                                            Handle class_loader,
 459                                                            Handle protection_domain,
 460                                                            bool throw_error,
 461                                                            TRAPS) {
 462   Symbol* class_name = fs->signature()->fundamental_name(THREAD);
 463   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 464   ClassLoaderData* loader_data = class_loader_data(class_loader);
 465   unsigned int p_hash = placeholders()->compute_hash(class_name);
 466   bool throw_circularity_error = false;
 467   PlaceholderEntry* oldprobe;
 468 
 469   {
 470     MutexLocker mu(THREAD, SystemDictionary_lock);
 471     oldprobe = placeholders()->get_entry(p_hash, class_name, loader_data);
 472     if (oldprobe != NULL &&
 473       oldprobe->check_seen_thread(THREAD, PlaceholderTable::PRIMITIVE_OBJECT_FIELD)) {
 474       throw_circularity_error = true;
 475 
 476     } else {
 477       placeholders()->find_and_add(p_hash, class_name, loader_data,
 478                                    PlaceholderTable::PRIMITIVE_OBJECT_FIELD, NULL, THREAD);
 479     }
 480   }
 481 
 482   Klass* klass = NULL;
 483   if (!throw_circularity_error) {
 484     klass = SystemDictionary::resolve_or_fail(class_name, class_loader,
 485                                                protection_domain, true, THREAD);
 486   } else {
 487     ResourceMark rm(THREAD);
 488     THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), class_name->as_C_string());
 489   }
 490 
 491   {
 492     MutexLocker mu(THREAD, SystemDictionary_lock);
 493     placeholders()->find_and_remove(p_hash, class_name, loader_data,
 494                                     PlaceholderTable::PRIMITIVE_OBJECT_FIELD, THREAD);
 495   }
 496 
 497   class_name->decrement_refcount();
 498   return klass;
 499 }
 500 
 501 // We only get here if this thread finds that another thread
 502 // has already claimed the placeholder token for the current operation,
 503 // but that other thread either never owned or gave up the
 504 // object lock
 505 // Waits on SystemDictionary_lock to indicate placeholder table updated
 506 // On return, caller must recheck placeholder table state
 507 //
 508 // We only get here if
 509 //  1) custom classLoader, i.e. not bootstrap classloader
 510 //  2) custom classLoader has broken the class loader objectLock
 511 //     so another thread got here in parallel
 512 //
 513 // lockObject must be held.
 514 // Complicated dance due to lock ordering:
 515 // Must first release the classloader object lock to
 516 // allow initial definer to complete the class definition
 517 // and to avoid deadlock
 518 // Reclaim classloader lock object with same original recursion count
 519 // Must release SystemDictionary_lock after notify, since
 520 // class loader lock must be claimed before SystemDictionary_lock

 838   Dictionary* dictionary = loader_data->dictionary();
 839   unsigned int name_hash = dictionary->compute_hash(class_name);
 840   return dictionary->find(name_hash, class_name, protection_domain);
 841 }
 842 
 843 // Look for a loaded instance or array klass by name.  Do not do any loading.
 844 // return NULL in case of error.
 845 Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
 846                                                       Handle class_loader,
 847                                                       Handle protection_domain) {
 848   Klass* k = NULL;
 849   assert(class_name != NULL, "class name must be non NULL");
 850 
 851   if (Signature::is_array(class_name)) {
 852     // The name refers to an array.  Parse the name.
 853     // dimension and object_key in FieldArrayInfo are assigned as a
 854     // side-effect of this call
 855     SignatureStream ss(class_name, false);
 856     int ndims = ss.skip_array_prefix();  // skip all '['s
 857     BasicType t = ss.type();
 858     if (t != T_OBJECT && t != T_PRIMITIVE_OBJECT) {
 859       k = Universe::typeArrayKlassObj(t);
 860     } else {
 861       k = SystemDictionary::find_instance_klass(ss.as_symbol(), class_loader, protection_domain);
 862     }
 863     if (k != NULL) {
 864       if (class_name->is_Q_array_signature()) {
 865         k = InlineKlass::cast(k)->value_array_klass_or_null(ndims);
 866       } else {
 867         k = k->array_klass_or_null(ndims);
 868       }
 869     }
 870   } else {
 871     k = find_instance_klass(class_name, class_loader, protection_domain);
 872   }
 873   return k;
 874 }
 875 
 876 // Note: this method is much like resolve_class_from_stream, but
 877 // does not publish the classes in the SystemDictionary.
 878 // Handles Lookup.defineClass hidden.
 879 InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
 880                                                      ClassFileStream* st,
 881                                                      Symbol* class_name,
 882                                                      Handle class_loader,
 883                                                      const ClassLoadInfo& cl_info,
 884                                                      TRAPS) {
 885 
 886   EventClassLoad class_load_start_event;
 887   ClassLoaderData* loader_data;
 888 

1190 }
1191 
1192 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1193                                                    Handle class_loader,
1194                                                    Handle protection_domain,
1195                                                    const ClassFileStream *cfs,
1196                                                    PackageEntry* pkg_entry,
1197                                                    TRAPS) {
1198   assert(ik != NULL, "sanity");
1199   assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1200   Symbol* class_name = ik->name();
1201 
1202   if (!is_shared_class_visible(class_name, ik, pkg_entry, class_loader)) {
1203     return NULL;
1204   }
1205 
1206   if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
1207     return NULL;
1208   }
1209 
1210 
1211   if (ik->has_inline_type_fields()) {
1212     for (AllFieldStream fs(ik->fields(), ik->constants()); !fs.done(); fs.next()) {
1213       if (Signature::basic_type(fs.signature()) == T_PRIMITIVE_OBJECT) {
1214         if (!fs.access_flags().is_static()) {
1215           // Pre-load inline class
1216           Klass* real_k = SystemDictionary::resolve_inline_type_field_or_fail(&fs,
1217             class_loader, protection_domain, true, CHECK_NULL);
1218           Klass* k = ik->get_inline_type_field_klass_or_null(fs.index());
1219           if (real_k != k) {
1220             // oops, the app has substituted a different version of k!
1221             return NULL;
1222           }
1223         }
1224       }
1225     }
1226   }
1227 
1228   InstanceKlass* new_ik = NULL;
1229   // CFLH check is skipped for VM hidden classes (see KlassFactory::create_from_stream).
1230   // It will be skipped for shared VM hidden lambda proxy classes.
1231   if (!SystemDictionaryShared::is_hidden_lambda_proxy(ik)) {
1232     new_ik = KlassFactory::check_shared_class_file_load_hook(
1233       ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
1234   }
1235   if (new_ik != NULL) {
1236     // The class is changed by CFLH. Return the new class. The shared class is
1237     // not used.
1238     return new_ik;
1239   }
1240 
1241   // Adjust methods to recover missing data.  They need addresses for
1242   // interpreter entry points and their default native method address
1243   // must be reset.
1244 
1245   // Shared classes are all currently loaded by either the bootstrap or
1246   // internal parallel class loaders, so this will never cause a deadlock
1247   // on a custom class loader lock.
1248   // Since this class is already locked with parallel capable class
1249   // loaders, including the bootstrap loader via the placeholder table,
1250   // this lock is currently a nop.
1251 
1252   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1253   {
1254     HandleMark hm(THREAD);
1255     Handle lockObject = get_loader_lock_or_null(class_loader);
1256     ObjectLocker ol(lockObject, THREAD);
1257     // prohibited package check assumes all classes loaded from archive call
1258     // restore_unshareable_info which calls ik->set_package()
1259     ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1260   }
1261 
1262   load_shared_class_misc(ik, loader_data);
1263 
1264   return ik;
1265 }
1266 
1267 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1268   ik->print_class_load_logging(loader_data, NULL, NULL);
1269 
1270   // For boot loader, ensure that GetSystemPackage knows that a class in this
1271   // package was loaded.
1272   if (loader_data->is_the_null_class_loader_data()) {
1273     int path_index = ik->shared_classpath_index();
1274     ik->set_classpath_index(path_index);
1275   }
1276 
1277   // notify a class loaded from shared object
1278   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1279 }
1280 
1281 #endif // INCLUDE_CDS
1282 
1283 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {

1831 Klass* SystemDictionary::find_constrained_instance_or_array_klass(
1832                     Thread* current, Symbol* class_name, Handle class_loader) {
1833 
1834   // First see if it has been loaded directly.
1835   // Force the protection domain to be null.  (This removes protection checks.)
1836   Handle no_protection_domain;
1837   Klass* klass = find_instance_or_array_klass(class_name, class_loader,
1838                                               no_protection_domain);
1839   if (klass != NULL)
1840     return klass;
1841 
1842   // Now look to see if it has been loaded elsewhere, and is subject to
1843   // a loader constraint that would require this loader to return the
1844   // klass that is already loaded.
1845   if (Signature::is_array(class_name)) {
1846     // For array classes, their Klass*s are not kept in the
1847     // constraint table. The element Klass*s are.
1848     SignatureStream ss(class_name, false);
1849     int ndims = ss.skip_array_prefix();  // skip all '['s
1850     BasicType t = ss.type();
1851     if (t != T_OBJECT && t != T_PRIMITIVE_OBJECT) {
1852       klass = Universe::typeArrayKlassObj(t);
1853     } else {
1854       MutexLocker mu(current, SystemDictionary_lock);
1855       klass = constraints()->find_constrained_klass(ss.as_symbol(), class_loader);
1856     }
1857     // If element class already loaded, allocate array klass
1858     if (klass != NULL) {
1859       if (class_name->is_Q_array_signature()) {
1860         klass = InlineKlass::cast(klass)->value_array_klass_or_null(ndims);
1861       } else {
1862         klass = klass->array_klass_or_null(ndims);
1863       }
1864     }
1865   } else {
1866     MutexLocker mu(current, SystemDictionary_lock);
1867     // Non-array classes are easy: simply check the constraint table.
1868     klass = constraints()->find_constrained_klass(class_name, class_loader);
1869   }
1870 
1871   return klass;
1872 }
1873 
1874 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
1875                                              Klass* klass_being_linked,
1876                                              Handle class_loader1,
1877                                              Handle class_loader2) {
1878   ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
1879   ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
1880 
1881   Symbol* constraint_name = NULL;
1882 
1883   if (!Signature::is_array(class_name)) {
< prev index next >