< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page

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

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

  69 #include "prims/jvmtiExport.hpp"
  70 #include "prims/methodHandles.hpp"
  71 #include "runtime/arguments.hpp"
  72 #include "runtime/atomic.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/sharedRuntime.hpp"
  78 #include "runtime/signature.hpp"
  79 #include "runtime/synchronizer.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 class InvokeMethodKey : public StackObj {
  94   private:
  95     Symbol* _symbol;
  96     intptr_t _iid;

 315 
 316 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain,
 317                                          bool throw_error, TRAPS) {
 318   Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
 319   // Check for pending exception or null klass, and throw exception
 320   if (HAS_PENDING_EXCEPTION || klass == nullptr) {
 321     handle_resolution_exception(class_name, throw_error, CHECK_NULL);
 322   }
 323   return klass;
 324 }
 325 
 326 // Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
 327 
 328 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 329   if (Signature::is_array(class_name)) {
 330     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 331   } else {
 332     assert(class_name != nullptr && !Signature::is_array(class_name), "must be");
 333     if (Signature::has_envelope(class_name)) {
 334       ResourceMark rm(THREAD);
 335       // Ignore wrapping L and ;.
 336       TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 337                                                    class_name->utf8_length() - 2);
 338       return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 339     } else {
 340       return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 341     }
 342   }
 343 }
 344 
 345 // Forwards to resolve_instance_class_or_null
 346 
 347 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
 348                                                      Handle class_loader,
 349                                                      Handle protection_domain,
 350                                                      TRAPS) {
 351   assert(Signature::is_array(class_name), "must be array");
 352   ResourceMark rm(THREAD);
 353   SignatureStream ss(class_name, false);
 354   int ndims = ss.skip_array_prefix();  // skip all '['s
 355   Klass* k = nullptr;
 356   BasicType t = ss.type();
 357   if (ss.has_envelope()) {
 358     Symbol* obj_class = ss.as_symbol();
 359     k = SystemDictionary::resolve_instance_class_or_null(obj_class,
 360                                                          class_loader,
 361                                                          protection_domain,
 362                                                          CHECK_NULL);
 363     if (k != nullptr) {
 364       k = k->array_klass(ndims, CHECK_NULL);







 365     }
 366   } else {
 367     k = Universe::typeArrayKlassObj(t);
 368     k = TypeArrayKlass::cast(k)->array_klass(ndims, CHECK_NULL);
 369   }
 370   return k;
 371 }
 372 
 373 static inline void log_circularity_error(Symbol* name, PlaceholderEntry* probe) {
 374   LogTarget(Debug, class, load, placeholders) lt;
 375   if (lt.is_enabled()) {
 376     ResourceMark rm;
 377     LogStream ls(lt);
 378     ls.print("ClassCircularityError detected for placeholder entry %s", name->as_C_string());
 379     probe->print_on(&ls);
 380     ls.cr();
 381   }
 382 }
 383 
 384 // Must be called for any superclass or superinterface resolution

 471     SystemDictionary::resolve_instance_class_or_null(super_name,
 472                                                      class_loader,
 473                                                      protection_domain,
 474                                                      THREAD);
 475 
 476   // Clean up placeholder entry.
 477   {
 478     MutexLocker mu(THREAD, SystemDictionary_lock);
 479     PlaceholderTable::find_and_remove(class_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 480     SystemDictionary_lock->notify_all();
 481   }
 482 
 483   // Check for pending exception or null superk, and throw exception
 484   if (HAS_PENDING_EXCEPTION || superk == nullptr) {
 485     handle_resolution_exception(super_name, true, CHECK_NULL);
 486   }
 487 
 488   return superk;
 489 }
 490 











































 491 // If the class in is in the placeholder table, class loading is in progress.
 492 // For cases where the application changes threads to load classes, it
 493 // is critical to ClassCircularity detection that we try loading
 494 // the superclass on the new thread internally, so we do parallel
 495 // superclass loading here.  This avoids deadlock for ClassCircularity
 496 // detection for parallelCapable class loaders that lock on a per-class lock.
 497 static void handle_parallel_super_load(Symbol* name,
 498                                        Symbol* superclassname,
 499                                        Handle class_loader,
 500                                        Handle protection_domain, TRAPS) {
 501 
 502   // superk is not used; resolve_super_or_fail is called for circularity check only.
 503   Klass* superk = SystemDictionary::resolve_super_or_fail(name,
 504                                                           superclassname,
 505                                                           class_loader,
 506                                                           protection_domain,
 507                                                           true,
 508                                                           CHECK);
 509 }
 510 

 556 void SystemDictionary::post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld) {
 557   assert(event != nullptr, "invariant");
 558   assert(k != nullptr, "invariant");
 559   event->set_loadedClass(k);
 560   event->set_definingClassLoader(k->class_loader_data());
 561   event->set_initiatingClassLoader(init_cld);
 562   event->commit();
 563 }
 564 
 565 // SystemDictionary::resolve_instance_class_or_null is the main function for class name resolution.
 566 // After checking if the InstanceKlass already exists, it checks for ClassCircularityError and
 567 // whether the thread must wait for loading in parallel.  It eventually calls load_instance_class,
 568 // which will load the class via the bootstrap loader or call ClassLoader.loadClass().
 569 // This can return null, an exception or an InstanceKlass.
 570 InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
 571                                                                 Handle class_loader,
 572                                                                 Handle protection_domain,
 573                                                                 TRAPS) {
 574   // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
 575   assert(name != nullptr && !Signature::is_array(name) &&
 576          !Signature::has_envelope(name), "invalid class name");
 577 
 578   EventClassLoad class_load_start_event;
 579 
 580   HandleMark hm(THREAD);
 581 
 582   // Fix for 4474172; see evaluation for more details
 583   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 584   ClassLoaderData* loader_data = register_loader(class_loader);
 585   Dictionary* dictionary = loader_data->dictionary();
 586 
 587   // Do lookup to see if class already exists and the protection domain
 588   // has the right access.
 589   // This call uses find which checks protection domain already matches
 590   // All subsequent calls use find_class, and set loaded_class so that
 591   // before we return a result, we call out to java to check for valid protection domain.
 592   InstanceKlass* probe = dictionary->find(THREAD, name, protection_domain);
 593   if (probe != nullptr) return probe;
 594 
 595   // Non-bootstrap class loaders will call out to class loader and
 596   // define via jvm/jni_DefineClass which will acquire the

 761   Dictionary* dictionary = loader_data->dictionary();
 762   return dictionary->find(current, class_name, protection_domain);
 763 }
 764 
 765 // Look for a loaded instance or array klass by name.  Do not do any loading.
 766 // return null in case of error.
 767 Klass* SystemDictionary::find_instance_or_array_klass(Thread* current,
 768                                                       Symbol* class_name,
 769                                                       Handle class_loader,
 770                                                       Handle protection_domain) {
 771   Klass* k = nullptr;
 772   assert(class_name != nullptr, "class name must be non nullptr");
 773 
 774   if (Signature::is_array(class_name)) {
 775     // The name refers to an array.  Parse the name.
 776     // dimension and object_key in FieldArrayInfo are assigned as a
 777     // side-effect of this call
 778     SignatureStream ss(class_name, false);
 779     int ndims = ss.skip_array_prefix();  // skip all '['s
 780     BasicType t = ss.type();
 781     if (t != T_OBJECT) {
 782       k = Universe::typeArrayKlassObj(t);
 783     } else {
 784       k = SystemDictionary::find_instance_klass(current, ss.as_symbol(), class_loader, protection_domain);
 785     }
 786     if (k != nullptr) {
 787       k = k->array_klass_or_null(ndims);




 788     }
 789   } else {
 790     k = find_instance_klass(current, class_name, class_loader, protection_domain);
 791   }
 792   return k;
 793 }
 794 
 795 // Note: this method is much like resolve_class_from_stream, but
 796 // does not publish the classes in the SystemDictionary.
 797 // Handles Lookup.defineClass hidden.
 798 InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
 799                                                      ClassFileStream* st,
 800                                                      Symbol* class_name,
 801                                                      Handle class_loader,
 802                                                      const ClassLoadInfo& cl_info,
 803                                                      TRAPS) {
 804 
 805   EventClassLoad class_load_start_event;
 806   ClassLoaderData* loader_data;
 807 

1121 
1122 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1123                                                    Handle class_loader,
1124                                                    Handle protection_domain,
1125                                                    const ClassFileStream *cfs,
1126                                                    PackageEntry* pkg_entry,
1127                                                    TRAPS) {
1128   assert(ik != nullptr, "sanity");
1129   assert(!ik->is_unshareable_info_restored(), "shared class can be restored only once");
1130   assert(Atomic::add(&ik->_shared_class_load_count, 1) == 1, "shared class loaded more than once");
1131   Symbol* class_name = ik->name();
1132 
1133   if (!is_shared_class_visible(class_name, ik, pkg_entry, class_loader)) {
1134     return nullptr;
1135   }
1136 
1137   if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
1138     return nullptr;
1139   }
1140 



















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

1176   return ik;
1177 }
1178 
1179 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1180   ik->print_class_load_logging(loader_data, nullptr, nullptr);
1181 
1182   // For boot loader, ensure that GetSystemPackage knows that a class in this
1183   // package was loaded.
1184   if (loader_data->is_the_null_class_loader_data()) {
1185     int path_index = ik->shared_classpath_index();
1186     ik->set_classpath_index(path_index);
1187   }
1188 
1189   // notify a class loaded from shared object
1190   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1191 }
1192 
1193 #endif // INCLUDE_CDS
1194 
1195 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {

1700 Klass* SystemDictionary::find_constrained_instance_or_array_klass(
1701                     Thread* current, Symbol* class_name, Handle class_loader) {
1702 
1703   // First see if it has been loaded directly.
1704   // Force the protection domain to be null.  (This removes protection checks.)
1705   Handle no_protection_domain;
1706   Klass* klass = find_instance_or_array_klass(current, class_name, class_loader,
1707                                               no_protection_domain);
1708   if (klass != nullptr)
1709     return klass;
1710 
1711   // Now look to see if it has been loaded elsewhere, and is subject to
1712   // a loader constraint that would require this loader to return the
1713   // klass that is already loaded.
1714   if (Signature::is_array(class_name)) {
1715     // For array classes, their Klass*s are not kept in the
1716     // constraint table. The element Klass*s are.
1717     SignatureStream ss(class_name, false);
1718     int ndims = ss.skip_array_prefix();  // skip all '['s
1719     BasicType t = ss.type();
1720     if (t != T_OBJECT) {
1721       klass = Universe::typeArrayKlassObj(t);
1722     } else {
1723       MutexLocker mu(current, SystemDictionary_lock);
1724       klass = LoaderConstraintTable::find_constrained_klass(ss.as_symbol(), class_loader_data(class_loader));
1725     }
1726     // If element class already loaded, allocate array klass
1727     if (klass != nullptr) {
1728       klass = klass->array_klass_or_null(ndims);




1729     }
1730   } else {
1731     MutexLocker mu(current, SystemDictionary_lock);
1732     // Non-array classes are easy: simply check the constraint table.
1733     klass = LoaderConstraintTable::find_constrained_klass(class_name, class_loader_data(class_loader));
1734   }
1735 
1736   return klass;
1737 }
1738 
1739 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
1740                                              Klass* klass_being_linked,
1741                                              Handle class_loader1,
1742                                              Handle class_loader2) {
1743   ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
1744   ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
1745 
1746   Symbol* constraint_name = nullptr;
1747 
1748   if (!Signature::is_array(class_name)) {

  38 #include "classfile/packageEntry.hpp"
  39 #include "classfile/placeholders.hpp"
  40 #include "classfile/protectionDomainCache.hpp"
  41 #include "classfile/resolutionErrors.hpp"
  42 #include "classfile/stringTable.hpp"
  43 #include "classfile/symbolTable.hpp"
  44 #include "classfile/systemDictionary.hpp"
  45 #include "classfile/vmClasses.hpp"
  46 #include "classfile/vmSymbols.hpp"
  47 #include "gc/shared/gcTraceTime.inline.hpp"
  48 #include "interpreter/bootstrapInfo.hpp"
  49 #include "jfr/jfrEvents.hpp"
  50 #include "jvm.h"
  51 #include "logging/log.hpp"
  52 #include "logging/logStream.hpp"
  53 #include "memory/metaspaceClosure.hpp"
  54 #include "memory/oopFactory.hpp"
  55 #include "memory/resourceArea.hpp"
  56 #include "memory/universe.hpp"
  57 #include "oops/access.inline.hpp"
  58 #include "oops/fieldStreams.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/oop.hpp"
  66 #include "oops/oopHandle.hpp"
  67 #include "oops/oopHandle.inline.hpp"
  68 #include "oops/symbol.hpp"
  69 #include "oops/typeArrayKlass.hpp"
  70 #include "oops/inlineKlass.inline.hpp"
  71 #include "prims/jvmtiExport.hpp"
  72 #include "prims/methodHandles.hpp"
  73 #include "runtime/arguments.hpp"
  74 #include "runtime/atomic.hpp"
  75 #include "runtime/handles.inline.hpp"
  76 #include "runtime/java.hpp"
  77 #include "runtime/javaCalls.hpp"
  78 #include "runtime/mutexLocker.hpp"
  79 #include "runtime/os.hpp"
  80 #include "runtime/sharedRuntime.hpp"
  81 #include "runtime/signature.hpp"
  82 #include "runtime/synchronizer.hpp"
  83 #include "services/classLoadingService.hpp"
  84 #include "services/diagnosticCommand.hpp"
  85 #include "services/finalizerService.hpp"
  86 #include "services/threadService.hpp"
  87 #include "utilities/macros.hpp"
  88 #include "utilities/utf8.hpp"
  89 #if INCLUDE_CDS
  90 #include "classfile/systemDictionaryShared.hpp"
  91 #endif
  92 #if INCLUDE_JFR
  93 #include "jfr/jfr.hpp"
  94 #endif
  95 
  96 class InvokeMethodKey : public StackObj {
  97   private:
  98     Symbol* _symbol;
  99     intptr_t _iid;

 318 
 319 Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain,
 320                                          bool throw_error, TRAPS) {
 321   Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
 322   // Check for pending exception or null klass, and throw exception
 323   if (HAS_PENDING_EXCEPTION || klass == nullptr) {
 324     handle_resolution_exception(class_name, throw_error, CHECK_NULL);
 325   }
 326   return klass;
 327 }
 328 
 329 // Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
 330 
 331 Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
 332   if (Signature::is_array(class_name)) {
 333     return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
 334   } else {
 335     assert(class_name != nullptr && !Signature::is_array(class_name), "must be");
 336     if (Signature::has_envelope(class_name)) {
 337       ResourceMark rm(THREAD);
 338       // Ignore wrapping L and ; (and Q and ; for value types).
 339       TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
 340                                                    class_name->utf8_length() - 2);
 341       return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
 342     } else {
 343       return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
 344     }
 345   }
 346 }
 347 
 348 // Forwards to resolve_instance_class_or_null
 349 
 350 Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
 351                                                      Handle class_loader,
 352                                                      Handle protection_domain,
 353                                                      TRAPS) {
 354   assert(Signature::is_array(class_name), "must be array");
 355   ResourceMark rm(THREAD);
 356   SignatureStream ss(class_name, false);
 357   int ndims = ss.skip_array_prefix();  // skip all '['s
 358   Klass* k = nullptr;
 359   BasicType t = ss.type();
 360   if (ss.has_envelope()) {
 361     Symbol* obj_class = ss.as_symbol();
 362     k = SystemDictionary::resolve_instance_class_or_null(obj_class,
 363                                                          class_loader,
 364                                                          protection_domain,
 365                                                          CHECK_NULL);
 366     if (k != nullptr) {
 367       if (class_name->is_Q_array_signature()) {
 368         if (!k->is_inline_klass()) {
 369           THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), "L/Q mismatch on bottom type");
 370         }
 371         k = InlineKlass::cast(k)->value_array_klass(ndims, CHECK_NULL);
 372       } else {
 373         k = k->array_klass(ndims, CHECK_NULL);
 374       }
 375     }
 376   } else {
 377     k = Universe::typeArrayKlassObj(t);
 378     k = TypeArrayKlass::cast(k)->array_klass(ndims, CHECK_NULL);
 379   }
 380   return k;
 381 }
 382 
 383 static inline void log_circularity_error(Symbol* name, PlaceholderEntry* probe) {
 384   LogTarget(Debug, class, load, placeholders) lt;
 385   if (lt.is_enabled()) {
 386     ResourceMark rm;
 387     LogStream ls(lt);
 388     ls.print("ClassCircularityError detected for placeholder entry %s", name->as_C_string());
 389     probe->print_on(&ls);
 390     ls.cr();
 391   }
 392 }
 393 
 394 // Must be called for any superclass or superinterface resolution

 481     SystemDictionary::resolve_instance_class_or_null(super_name,
 482                                                      class_loader,
 483                                                      protection_domain,
 484                                                      THREAD);
 485 
 486   // Clean up placeholder entry.
 487   {
 488     MutexLocker mu(THREAD, SystemDictionary_lock);
 489     PlaceholderTable::find_and_remove(class_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 490     SystemDictionary_lock->notify_all();
 491   }
 492 
 493   // Check for pending exception or null superk, and throw exception
 494   if (HAS_PENDING_EXCEPTION || superk == nullptr) {
 495     handle_resolution_exception(super_name, true, CHECK_NULL);
 496   }
 497 
 498   return superk;
 499 }
 500 
 501 Klass* SystemDictionary::resolve_inline_type_field_or_fail(Symbol* signature,
 502                                                            Handle class_loader,
 503                                                            Handle protection_domain,
 504                                                            bool throw_error,
 505                                                            TRAPS) {
 506   Symbol* class_name = signature->fundamental_name(THREAD);
 507   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 508   ClassLoaderData* loader_data = class_loader_data(class_loader);
 509   bool throw_circularity_error = false;
 510   PlaceholderEntry* oldprobe;
 511 
 512   {
 513     MutexLocker mu(THREAD, SystemDictionary_lock);
 514     oldprobe = PlaceholderTable::get_entry(class_name, loader_data);
 515     if (oldprobe != nullptr &&
 516       oldprobe->check_seen_thread(THREAD, PlaceholderTable::PRIMITIVE_OBJECT_FIELD)) {
 517       throw_circularity_error = true;
 518 
 519     } else {
 520       PlaceholderTable::find_and_add(class_name, loader_data,
 521                                    PlaceholderTable::PRIMITIVE_OBJECT_FIELD, nullptr, THREAD);
 522     }
 523   }
 524 
 525   Klass* klass = nullptr;
 526   if (!throw_circularity_error) {
 527     klass = SystemDictionary::resolve_or_fail(class_name, class_loader,
 528                                                protection_domain, true, THREAD);
 529   } else {
 530     ResourceMark rm(THREAD);
 531     THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), class_name->as_C_string());
 532   }
 533 
 534   {
 535     MutexLocker mu(THREAD, SystemDictionary_lock);
 536     PlaceholderTable::find_and_remove(class_name, loader_data,
 537                                       PlaceholderTable::PRIMITIVE_OBJECT_FIELD, THREAD);
 538   }
 539 
 540   class_name->decrement_refcount();
 541   return klass;
 542 }
 543 
 544 // If the class in is in the placeholder table, class loading is in progress.
 545 // For cases where the application changes threads to load classes, it
 546 // is critical to ClassCircularity detection that we try loading
 547 // the superclass on the new thread internally, so we do parallel
 548 // superclass loading here.  This avoids deadlock for ClassCircularity
 549 // detection for parallelCapable class loaders that lock on a per-class lock.
 550 static void handle_parallel_super_load(Symbol* name,
 551                                        Symbol* superclassname,
 552                                        Handle class_loader,
 553                                        Handle protection_domain, TRAPS) {
 554 
 555   // superk is not used; resolve_super_or_fail is called for circularity check only.
 556   Klass* superk = SystemDictionary::resolve_super_or_fail(name,
 557                                                           superclassname,
 558                                                           class_loader,
 559                                                           protection_domain,
 560                                                           true,
 561                                                           CHECK);
 562 }
 563 

 609 void SystemDictionary::post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld) {
 610   assert(event != nullptr, "invariant");
 611   assert(k != nullptr, "invariant");
 612   event->set_loadedClass(k);
 613   event->set_definingClassLoader(k->class_loader_data());
 614   event->set_initiatingClassLoader(init_cld);
 615   event->commit();
 616 }
 617 
 618 // SystemDictionary::resolve_instance_class_or_null is the main function for class name resolution.
 619 // After checking if the InstanceKlass already exists, it checks for ClassCircularityError and
 620 // whether the thread must wait for loading in parallel.  It eventually calls load_instance_class,
 621 // which will load the class via the bootstrap loader or call ClassLoader.loadClass().
 622 // This can return null, an exception or an InstanceKlass.
 623 InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
 624                                                                 Handle class_loader,
 625                                                                 Handle protection_domain,
 626                                                                 TRAPS) {
 627   // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
 628   assert(name != nullptr && !Signature::is_array(name) &&
 629          !Signature::has_envelope(name), "invalid class name: %s", name == nullptr ? "nullptr" : name->as_C_string());
 630 
 631   EventClassLoad class_load_start_event;
 632 
 633   HandleMark hm(THREAD);
 634 
 635   // Fix for 4474172; see evaluation for more details
 636   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 637   ClassLoaderData* loader_data = register_loader(class_loader);
 638   Dictionary* dictionary = loader_data->dictionary();
 639 
 640   // Do lookup to see if class already exists and the protection domain
 641   // has the right access.
 642   // This call uses find which checks protection domain already matches
 643   // All subsequent calls use find_class, and set loaded_class so that
 644   // before we return a result, we call out to java to check for valid protection domain.
 645   InstanceKlass* probe = dictionary->find(THREAD, name, protection_domain);
 646   if (probe != nullptr) return probe;
 647 
 648   // Non-bootstrap class loaders will call out to class loader and
 649   // define via jvm/jni_DefineClass which will acquire the

 814   Dictionary* dictionary = loader_data->dictionary();
 815   return dictionary->find(current, class_name, protection_domain);
 816 }
 817 
 818 // Look for a loaded instance or array klass by name.  Do not do any loading.
 819 // return null in case of error.
 820 Klass* SystemDictionary::find_instance_or_array_klass(Thread* current,
 821                                                       Symbol* class_name,
 822                                                       Handle class_loader,
 823                                                       Handle protection_domain) {
 824   Klass* k = nullptr;
 825   assert(class_name != nullptr, "class name must be non nullptr");
 826 
 827   if (Signature::is_array(class_name)) {
 828     // The name refers to an array.  Parse the name.
 829     // dimension and object_key in FieldArrayInfo are assigned as a
 830     // side-effect of this call
 831     SignatureStream ss(class_name, false);
 832     int ndims = ss.skip_array_prefix();  // skip all '['s
 833     BasicType t = ss.type();
 834     if (t != T_OBJECT && t != T_PRIMITIVE_OBJECT) {
 835       k = Universe::typeArrayKlassObj(t);
 836     } else {
 837       k = SystemDictionary::find_instance_klass(current, ss.as_symbol(), class_loader, protection_domain);
 838     }
 839     if (k != nullptr) {
 840       if (class_name->is_Q_array_signature()) {
 841         k = InlineKlass::cast(k)->value_array_klass_or_null(ndims);
 842       } else {
 843         k = k->array_klass_or_null(ndims);
 844       }
 845     }
 846   } else {
 847     k = find_instance_klass(current, class_name, class_loader, protection_domain);
 848   }
 849   return k;
 850 }
 851 
 852 // Note: this method is much like resolve_class_from_stream, but
 853 // does not publish the classes in the SystemDictionary.
 854 // Handles Lookup.defineClass hidden.
 855 InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
 856                                                      ClassFileStream* st,
 857                                                      Symbol* class_name,
 858                                                      Handle class_loader,
 859                                                      const ClassLoadInfo& cl_info,
 860                                                      TRAPS) {
 861 
 862   EventClassLoad class_load_start_event;
 863   ClassLoaderData* loader_data;
 864 

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

1777 Klass* SystemDictionary::find_constrained_instance_or_array_klass(
1778                     Thread* current, Symbol* class_name, Handle class_loader) {
1779 
1780   // First see if it has been loaded directly.
1781   // Force the protection domain to be null.  (This removes protection checks.)
1782   Handle no_protection_domain;
1783   Klass* klass = find_instance_or_array_klass(current, class_name, class_loader,
1784                                               no_protection_domain);
1785   if (klass != nullptr)
1786     return klass;
1787 
1788   // Now look to see if it has been loaded elsewhere, and is subject to
1789   // a loader constraint that would require this loader to return the
1790   // klass that is already loaded.
1791   if (Signature::is_array(class_name)) {
1792     // For array classes, their Klass*s are not kept in the
1793     // constraint table. The element Klass*s are.
1794     SignatureStream ss(class_name, false);
1795     int ndims = ss.skip_array_prefix();  // skip all '['s
1796     BasicType t = ss.type();
1797     if (t != T_OBJECT && t != T_PRIMITIVE_OBJECT) {
1798       klass = Universe::typeArrayKlassObj(t);
1799     } else {
1800       MutexLocker mu(current, SystemDictionary_lock);
1801       klass = LoaderConstraintTable::find_constrained_klass(ss.as_symbol(), class_loader_data(class_loader));
1802     }
1803     // If element class already loaded, allocate array klass
1804     if (klass != nullptr) {
1805       if (class_name->is_Q_array_signature()) {
1806         klass = InlineKlass::cast(klass)->value_array_klass_or_null(ndims);
1807       } else {
1808         klass = klass->array_klass_or_null(ndims);
1809       }
1810     }
1811   } else {
1812     MutexLocker mu(current, SystemDictionary_lock);
1813     // Non-array classes are easy: simply check the constraint table.
1814     klass = LoaderConstraintTable::find_constrained_klass(class_name, class_loader_data(class_loader));
1815   }
1816 
1817   return klass;
1818 }
1819 
1820 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
1821                                              Klass* klass_being_linked,
1822                                              Handle class_loader1,
1823                                              Handle class_loader2) {
1824   ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
1825   ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
1826 
1827   Symbol* constraint_name = nullptr;
1828 
1829   if (!Signature::is_array(class_name)) {
< prev index next >