< 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;

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







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

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











































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

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

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




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

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



















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

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

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




1736     }
1737   } else {
1738     MutexLocker mu(current, SystemDictionary_lock);
1739     // Non-array classes are easy: simply check the constraint table.
1740     klass = LoaderConstraintTable::find_constrained_klass(class_name, class_loader_data(class_loader));
1741   }
1742 
1743   return klass;
1744 }
1745 
1746 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
1747                                              Klass* klass_being_linked,
1748                                              Handle class_loader1,
1749                                              Handle class_loader2) {
1750   ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
1751   ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
1752 
1753   Symbol* constraint_name = nullptr;
1754 
1755   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;

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

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

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

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

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

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