< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page

  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 "code/codeCache.hpp"
  48 #include "gc/shared/gcTraceTime.inline.hpp"
  49 #include "interpreter/bootstrapInfo.hpp"
  50 #include "jfr/jfrEvents.hpp"
  51 #include "jvm.h"
  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/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 "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/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 == NULL) {
 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 != NULL && !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 = NULL;
 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 != NULL) {
 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 == NULL) {
 485     handle_resolution_exception(super_name, true, CHECK_NULL);
 486   }
 487 
 488   return superk;
 489 }
 490 











































 491 // We only get here if this thread finds that another thread
 492 // has already claimed the placeholder token for the current operation,
 493 // but that other thread either never owned or gave up the
 494 // object lock
 495 // Waits on SystemDictionary_lock to indicate placeholder table updated
 496 // On return, caller must recheck placeholder table state
 497 //
 498 // We only get here if
 499 //  1) custom classLoader, i.e. not bootstrap classloader
 500 //  2) custom classLoader has broken the class loader objectLock
 501 //     so another thread got here in parallel
 502 //
 503 // lockObject must be held.
 504 // Complicated dance due to lock ordering:
 505 // Must first release the classloader object lock to
 506 // allow initial definer to complete the class definition
 507 // and to avoid deadlock
 508 // Reclaim classloader lock object with same original recursion count
 509 // Must release SystemDictionary_lock after notify, since
 510 // class loader lock must be claimed before SystemDictionary_lock

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

 830   Dictionary* dictionary = loader_data->dictionary();
 831   return dictionary->find(current, class_name, protection_domain);
 832 }
 833 
 834 // Look for a loaded instance or array klass by name.  Do not do any loading.
 835 // return NULL in case of error.
 836 Klass* SystemDictionary::find_instance_or_array_klass(Thread* current,
 837                                                       Symbol* class_name,
 838                                                       Handle class_loader,
 839                                                       Handle protection_domain) {
 840   Klass* k = NULL;
 841   assert(class_name != NULL, "class name must be non NULL");
 842 
 843   if (Signature::is_array(class_name)) {
 844     // The name refers to an array.  Parse the name.
 845     // dimension and object_key in FieldArrayInfo are assigned as a
 846     // side-effect of this call
 847     SignatureStream ss(class_name, false);
 848     int ndims = ss.skip_array_prefix();  // skip all '['s
 849     BasicType t = ss.type();
 850     if (t != T_OBJECT) {
 851       k = Universe::typeArrayKlassObj(t);
 852     } else {
 853       k = SystemDictionary::find_instance_klass(current, ss.as_symbol(), class_loader, protection_domain);
 854     }
 855     if (k != NULL) {
 856       k = k->array_klass_or_null(ndims);




 857     }
 858   } else {
 859     k = find_instance_klass(current, class_name, class_loader, protection_domain);
 860   }
 861   return k;
 862 }
 863 
 864 // Note: this method is much like resolve_class_from_stream, but
 865 // does not publish the classes in the SystemDictionary.
 866 // Handles Lookup.defineClass hidden.
 867 InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
 868                                                      ClassFileStream* st,
 869                                                      Symbol* class_name,
 870                                                      Handle class_loader,
 871                                                      const ClassLoadInfo& cl_info,
 872                                                      TRAPS) {
 873 
 874   EventClassLoad class_load_start_event;
 875   ClassLoaderData* loader_data;
 876 

1192 }
1193 
1194 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1195                                                    Handle class_loader,
1196                                                    Handle protection_domain,
1197                                                    const ClassFileStream *cfs,
1198                                                    PackageEntry* pkg_entry,
1199                                                    TRAPS) {
1200   assert(ik != NULL, "sanity");
1201   assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1202   Symbol* class_name = ik->name();
1203 
1204   if (!is_shared_class_visible(class_name, ik, pkg_entry, class_loader)) {
1205     return NULL;
1206   }
1207 
1208   if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
1209     return NULL;
1210   }
1211 


















1212   InstanceKlass* new_ik = NULL;
1213   // CFLH check is skipped for VM hidden classes (see KlassFactory::create_from_stream).
1214   // It will be skipped for shared VM hidden lambda proxy classes.
1215   if (!SystemDictionaryShared::is_hidden_lambda_proxy(ik)) {
1216     new_ik = KlassFactory::check_shared_class_file_load_hook(
1217       ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
1218   }
1219   if (new_ik != NULL) {
1220     // The class is changed by CFLH. Return the new class. The shared class is
1221     // not used.
1222     return new_ik;
1223   }
1224 
1225   // Adjust methods to recover missing data.  They need addresses for
1226   // interpreter entry points and their default native method address
1227   // must be reset.
1228 
1229   // Shared classes are all currently loaded by either the bootstrap or
1230   // internal parallel class loaders, so this will never cause a deadlock
1231   // on a custom class loader lock.
1232   // Since this class is already locked with parallel capable class
1233   // loaders, including the bootstrap loader via the placeholder table,
1234   // this lock is currently a nop.
1235 
1236   ClassLoaderData* loader_data = class_loader_data(class_loader);
1237   {
1238     HandleMark hm(THREAD);
1239     Handle lockObject = get_loader_lock_or_null(class_loader);
1240     ObjectLocker ol(lockObject, THREAD);
1241     // prohibited package check assumes all classes loaded from archive call
1242     // restore_unshareable_info which calls ik->set_package()
1243     ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1244   }
1245 
1246   load_shared_class_misc(ik, loader_data);

1247   return ik;
1248 }
1249 
1250 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1251   ik->print_class_load_logging(loader_data, NULL, NULL);
1252 
1253   // For boot loader, ensure that GetSystemPackage knows that a class in this
1254   // package was loaded.
1255   if (loader_data->is_the_null_class_loader_data()) {
1256     int path_index = ik->shared_classpath_index();
1257     ik->set_classpath_index(path_index);
1258   }
1259 
1260   // notify a class loaded from shared object
1261   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1262 }
1263 
1264 #endif // INCLUDE_CDS
1265 
1266 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {

1808 Klass* SystemDictionary::find_constrained_instance_or_array_klass(
1809                     Thread* current, Symbol* class_name, Handle class_loader) {
1810 
1811   // First see if it has been loaded directly.
1812   // Force the protection domain to be null.  (This removes protection checks.)
1813   Handle no_protection_domain;
1814   Klass* klass = find_instance_or_array_klass(current, class_name, class_loader,
1815                                               no_protection_domain);
1816   if (klass != NULL)
1817     return klass;
1818 
1819   // Now look to see if it has been loaded elsewhere, and is subject to
1820   // a loader constraint that would require this loader to return the
1821   // klass that is already loaded.
1822   if (Signature::is_array(class_name)) {
1823     // For array classes, their Klass*s are not kept in the
1824     // constraint table. The element Klass*s are.
1825     SignatureStream ss(class_name, false);
1826     int ndims = ss.skip_array_prefix();  // skip all '['s
1827     BasicType t = ss.type();
1828     if (t != T_OBJECT) {
1829       klass = Universe::typeArrayKlassObj(t);
1830     } else {
1831       MutexLocker mu(current, SystemDictionary_lock);
1832       klass = LoaderConstraintTable::find_constrained_klass(ss.as_symbol(), class_loader_data(class_loader));
1833     }
1834     // If element class already loaded, allocate array klass
1835     if (klass != NULL) {
1836       klass = klass->array_klass_or_null(ndims);




1837     }
1838   } else {
1839     MutexLocker mu(current, SystemDictionary_lock);
1840     // Non-array classes are easy: simply check the constraint table.
1841     klass = LoaderConstraintTable::find_constrained_klass(class_name, class_loader_data(class_loader));
1842   }
1843 
1844   return klass;
1845 }
1846 
1847 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
1848                                              Klass* klass_being_linked,
1849                                              Handle class_loader1,
1850                                              Handle class_loader2) {
1851   ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
1852   ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
1853 
1854   Symbol* constraint_name = NULL;
1855 
1856   if (!Signature::is_array(class_name)) {

  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 "code/codeCache.hpp"
  48 #include "gc/shared/gcTraceTime.inline.hpp"
  49 #include "interpreter/bootstrapInfo.hpp"
  50 #include "jfr/jfrEvents.hpp"
  51 #include "jvm.h"
  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/oop.hpp"
  67 #include "oops/oopHandle.hpp"
  68 #include "oops/oopHandle.inline.hpp"
  69 #include "oops/symbol.hpp"
  70 #include "oops/typeArrayKlass.hpp"
  71 #include "oops/inlineKlass.inline.hpp"
  72 #include "prims/jvmtiExport.hpp"
  73 #include "prims/methodHandles.hpp"
  74 #include "runtime/arguments.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 == NULL) {
 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 != NULL && !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 = NULL;
 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 != NULL) {
 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 == NULL) {
 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(AllFieldStream* fs,
 502                                                            Handle class_loader,
 503                                                            Handle protection_domain,
 504                                                            bool throw_error,
 505                                                            TRAPS) {
 506   Symbol* class_name = fs->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 != NULL &&
 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, NULL, THREAD);
 522     }
 523   }
 524 
 525   Klass* klass = NULL;
 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 // We only get here if this thread finds that another thread
 545 // has already claimed the placeholder token for the current operation,
 546 // but that other thread either never owned or gave up the
 547 // object lock
 548 // Waits on SystemDictionary_lock to indicate placeholder table updated
 549 // On return, caller must recheck placeholder table state
 550 //
 551 // We only get here if
 552 //  1) custom classLoader, i.e. not bootstrap classloader
 553 //  2) custom classLoader has broken the class loader objectLock
 554 //     so another thread got here in parallel
 555 //
 556 // lockObject must be held.
 557 // Complicated dance due to lock ordering:
 558 // Must first release the classloader object lock to
 559 // allow initial definer to complete the class definition
 560 // and to avoid deadlock
 561 // Reclaim classloader lock object with same original recursion count
 562 // Must release SystemDictionary_lock after notify, since
 563 // class loader lock must be claimed before SystemDictionary_lock

 672 void SystemDictionary::post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld) {
 673   assert(event != NULL, "invariant");
 674   assert(k != NULL, "invariant");
 675   event->set_loadedClass(k);
 676   event->set_definingClassLoader(k->class_loader_data());
 677   event->set_initiatingClassLoader(init_cld);
 678   event->commit();
 679 }
 680 
 681 // SystemDictionary::resolve_instance_class_or_null is the main function for class name resolution.
 682 // After checking if the InstanceKlass already exists, it checks for ClassCircularityError and
 683 // whether the thread must wait for loading in parallel.  It eventually calls load_instance_class,
 684 // which will load the class via the bootstrap loader or call ClassLoader.loadClass().
 685 // This can return NULL, an exception or an InstanceKlass.
 686 InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
 687                                                                 Handle class_loader,
 688                                                                 Handle protection_domain,
 689                                                                 TRAPS) {
 690   // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
 691   assert(name != NULL && !Signature::is_array(name) &&
 692          !Signature::has_envelope(name), "invalid class name: %s", name == NULL ? "NULL" : name->as_C_string());
 693 
 694   EventClassLoad class_load_start_event;
 695 
 696   HandleMark hm(THREAD);
 697 
 698   // Fix for 4474172; see evaluation for more details
 699   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 700   ClassLoaderData* loader_data = register_loader(class_loader);
 701   Dictionary* dictionary = loader_data->dictionary();
 702 
 703   // Do lookup to see if class already exists and the protection domain
 704   // has the right access.
 705   // This call uses find which checks protection domain already matches
 706   // All subsequent calls use find_class, and set loaded_class so that
 707   // before we return a result, we call out to java to check for valid protection domain.
 708   InstanceKlass* probe = dictionary->find(THREAD, name, protection_domain);
 709   if (probe != NULL) return probe;
 710 
 711   // Non-bootstrap class loaders will call out to class loader and
 712   // define via jvm/jni_DefineClass which will acquire the

 883   Dictionary* dictionary = loader_data->dictionary();
 884   return dictionary->find(current, class_name, protection_domain);
 885 }
 886 
 887 // Look for a loaded instance or array klass by name.  Do not do any loading.
 888 // return NULL in case of error.
 889 Klass* SystemDictionary::find_instance_or_array_klass(Thread* current,
 890                                                       Symbol* class_name,
 891                                                       Handle class_loader,
 892                                                       Handle protection_domain) {
 893   Klass* k = NULL;
 894   assert(class_name != NULL, "class name must be non NULL");
 895 
 896   if (Signature::is_array(class_name)) {
 897     // The name refers to an array.  Parse the name.
 898     // dimension and object_key in FieldArrayInfo are assigned as a
 899     // side-effect of this call
 900     SignatureStream ss(class_name, false);
 901     int ndims = ss.skip_array_prefix();  // skip all '['s
 902     BasicType t = ss.type();
 903     if (t != T_OBJECT && t != T_PRIMITIVE_OBJECT) {
 904       k = Universe::typeArrayKlassObj(t);
 905     } else {
 906       k = SystemDictionary::find_instance_klass(current, ss.as_symbol(), class_loader, protection_domain);
 907     }
 908     if (k != NULL) {
 909       if (class_name->is_Q_array_signature()) {
 910         k = InlineKlass::cast(k)->value_array_klass_or_null(ndims);
 911       } else {
 912         k = k->array_klass_or_null(ndims);
 913       }
 914     }
 915   } else {
 916     k = find_instance_klass(current, class_name, class_loader, protection_domain);
 917   }
 918   return k;
 919 }
 920 
 921 // Note: this method is much like resolve_class_from_stream, but
 922 // does not publish the classes in the SystemDictionary.
 923 // Handles Lookup.defineClass hidden.
 924 InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
 925                                                      ClassFileStream* st,
 926                                                      Symbol* class_name,
 927                                                      Handle class_loader,
 928                                                      const ClassLoadInfo& cl_info,
 929                                                      TRAPS) {
 930 
 931   EventClassLoad class_load_start_event;
 932   ClassLoaderData* loader_data;
 933 

1249 }
1250 
1251 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1252                                                    Handle class_loader,
1253                                                    Handle protection_domain,
1254                                                    const ClassFileStream *cfs,
1255                                                    PackageEntry* pkg_entry,
1256                                                    TRAPS) {
1257   assert(ik != NULL, "sanity");
1258   assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1259   Symbol* class_name = ik->name();
1260 
1261   if (!is_shared_class_visible(class_name, ik, pkg_entry, class_loader)) {
1262     return NULL;
1263   }
1264 
1265   if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
1266     return NULL;
1267   }
1268 
1269 
1270   if (ik->has_inline_type_fields()) {
1271     for (AllFieldStream fs(ik->fields(), ik->constants()); !fs.done(); fs.next()) {
1272       if (Signature::basic_type(fs.signature()) == T_PRIMITIVE_OBJECT) {
1273         if (!fs.access_flags().is_static()) {
1274           // Pre-load inline class
1275           Klass* real_k = SystemDictionary::resolve_inline_type_field_or_fail(&fs,
1276             class_loader, protection_domain, true, CHECK_NULL);
1277           Klass* k = ik->get_inline_type_field_klass_or_null(fs.index());
1278           if (real_k != k) {
1279             // oops, the app has substituted a different version of k!
1280             return NULL;
1281           }
1282         }
1283       }
1284     }
1285   }
1286 
1287   InstanceKlass* new_ik = NULL;
1288   // CFLH check is skipped for VM hidden classes (see KlassFactory::create_from_stream).
1289   // It will be skipped for shared VM hidden lambda proxy classes.
1290   if (!SystemDictionaryShared::is_hidden_lambda_proxy(ik)) {
1291     new_ik = KlassFactory::check_shared_class_file_load_hook(
1292       ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
1293   }
1294   if (new_ik != NULL) {
1295     // The class is changed by CFLH. Return the new class. The shared class is
1296     // not used.
1297     return new_ik;
1298   }
1299 
1300   // Adjust methods to recover missing data.  They need addresses for
1301   // interpreter entry points and their default native method address
1302   // must be reset.
1303 
1304   // Shared classes are all currently loaded by either the bootstrap or
1305   // internal parallel class loaders, so this will never cause a deadlock
1306   // on a custom class loader lock.
1307   // Since this class is already locked with parallel capable class
1308   // loaders, including the bootstrap loader via the placeholder table,
1309   // this lock is currently a nop.
1310 
1311   ClassLoaderData* loader_data = class_loader_data(class_loader);
1312   {
1313     HandleMark hm(THREAD);
1314     Handle lockObject = get_loader_lock_or_null(class_loader);
1315     ObjectLocker ol(lockObject, THREAD);
1316     // prohibited package check assumes all classes loaded from archive call
1317     // restore_unshareable_info which calls ik->set_package()
1318     ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1319   }
1320 
1321   load_shared_class_misc(ik, loader_data);
1322 
1323   return ik;
1324 }
1325 
1326 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1327   ik->print_class_load_logging(loader_data, NULL, NULL);
1328 
1329   // For boot loader, ensure that GetSystemPackage knows that a class in this
1330   // package was loaded.
1331   if (loader_data->is_the_null_class_loader_data()) {
1332     int path_index = ik->shared_classpath_index();
1333     ik->set_classpath_index(path_index);
1334   }
1335 
1336   // notify a class loaded from shared object
1337   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1338 }
1339 
1340 #endif // INCLUDE_CDS
1341 
1342 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {

1884 Klass* SystemDictionary::find_constrained_instance_or_array_klass(
1885                     Thread* current, Symbol* class_name, Handle class_loader) {
1886 
1887   // First see if it has been loaded directly.
1888   // Force the protection domain to be null.  (This removes protection checks.)
1889   Handle no_protection_domain;
1890   Klass* klass = find_instance_or_array_klass(current, class_name, class_loader,
1891                                               no_protection_domain);
1892   if (klass != NULL)
1893     return klass;
1894 
1895   // Now look to see if it has been loaded elsewhere, and is subject to
1896   // a loader constraint that would require this loader to return the
1897   // klass that is already loaded.
1898   if (Signature::is_array(class_name)) {
1899     // For array classes, their Klass*s are not kept in the
1900     // constraint table. The element Klass*s are.
1901     SignatureStream ss(class_name, false);
1902     int ndims = ss.skip_array_prefix();  // skip all '['s
1903     BasicType t = ss.type();
1904     if (t != T_OBJECT && t != T_PRIMITIVE_OBJECT) {
1905       klass = Universe::typeArrayKlassObj(t);
1906     } else {
1907       MutexLocker mu(current, SystemDictionary_lock);
1908       klass = LoaderConstraintTable::find_constrained_klass(ss.as_symbol(), class_loader_data(class_loader));
1909     }
1910     // If element class already loaded, allocate array klass
1911     if (klass != NULL) {
1912       if (class_name->is_Q_array_signature()) {
1913         klass = InlineKlass::cast(klass)->value_array_klass_or_null(ndims);
1914       } else {
1915         klass = klass->array_klass_or_null(ndims);
1916       }
1917     }
1918   } else {
1919     MutexLocker mu(current, SystemDictionary_lock);
1920     // Non-array classes are easy: simply check the constraint table.
1921     klass = LoaderConstraintTable::find_constrained_klass(class_name, class_loader_data(class_loader));
1922   }
1923 
1924   return klass;
1925 }
1926 
1927 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
1928                                              Klass* klass_being_linked,
1929                                              Handle class_loader1,
1930                                              Handle class_loader2) {
1931   ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
1932   ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
1933 
1934   Symbol* constraint_name = NULL;
1935 
1936   if (!Signature::is_array(class_name)) {
< prev index next >