< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page

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

  59 #include "oops/instanceKlass.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/method.inline.hpp"
  62 #include "oops/objArrayKlass.hpp"
  63 #include "oops/objArrayOop.inline.hpp"
  64 #include "oops/oop.inline.hpp"
  65 #include "oops/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;

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







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

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











































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

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




 846     }
 847   } else {
 848     k = find_instance_klass(current, class_name, class_loader, protection_domain);
 849   }
 850   return k;
 851 }
 852 
 853 // Note: this method is much like resolve_class_from_stream, but
 854 // does not publish the classes in the SystemDictionary.
 855 // Handles Lookup.defineClass hidden.
 856 InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream(
 857                                                      ClassFileStream* st,
 858                                                      Symbol* class_name,
 859                                                      Handle class_loader,
 860                                                      const ClassLoadInfo& cl_info,
 861                                                      TRAPS) {
 862 
 863   EventClassLoad class_load_start_event;
 864   ClassLoaderData* loader_data;
 865 

1181 }
1182 
1183 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1184                                                    Handle class_loader,
1185                                                    Handle protection_domain,
1186                                                    const ClassFileStream *cfs,
1187                                                    PackageEntry* pkg_entry,
1188                                                    TRAPS) {
1189   assert(ik != NULL, "sanity");
1190   assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1191   Symbol* class_name = ik->name();
1192 
1193   if (!is_shared_class_visible(class_name, ik, pkg_entry, class_loader)) {
1194     return NULL;
1195   }
1196 
1197   if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
1198     return NULL;
1199   }
1200 


















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

1236   return ik;
1237 }
1238 
1239 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1240   ik->print_class_load_logging(loader_data, NULL, NULL);
1241 
1242   // For boot loader, ensure that GetSystemPackage knows that a class in this
1243   // package was loaded.
1244   if (loader_data->is_the_null_class_loader_data()) {
1245     int path_index = ik->shared_classpath_index();
1246     ik->set_classpath_index(path_index);
1247   }
1248 
1249   // notify a class loaded from shared object
1250   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1251 }
1252 
1253 #endif // INCLUDE_CDS
1254 
1255 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {

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




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

  39 #include "classfile/packageEntry.hpp"
  40 #include "classfile/placeholders.hpp"
  41 #include "classfile/protectionDomainCache.hpp"
  42 #include "classfile/resolutionErrors.hpp"
  43 #include "classfile/stringTable.hpp"
  44 #include "classfile/symbolTable.hpp"
  45 #include "classfile/systemDictionary.hpp"
  46 #include "classfile/vmClasses.hpp"
  47 #include "classfile/vmSymbols.hpp"
  48 #include "code/codeCache.hpp"
  49 #include "gc/shared/gcTraceTime.inline.hpp"
  50 #include "interpreter/bootstrapInfo.hpp"
  51 #include "jfr/jfrEvents.hpp"
  52 #include "logging/log.hpp"
  53 #include "logging/logStream.hpp"
  54 #include "memory/metaspaceClosure.hpp"
  55 #include "memory/oopFactory.hpp"
  56 #include "memory/resourceArea.hpp"
  57 #include "memory/universe.hpp"
  58 #include "oops/access.inline.hpp"
  59 #include "oops/fieldStreams.inline.hpp"
  60 #include "oops/instanceKlass.hpp"
  61 #include "oops/klass.inline.hpp"
  62 #include "oops/method.inline.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "oops/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;

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

 476     SystemDictionary::resolve_instance_class_or_null(super_name,
 477                                                      class_loader,
 478                                                      protection_domain,
 479                                                      THREAD);
 480 
 481   // Clean up placeholder entry.
 482   {
 483     MutexLocker mu(THREAD, SystemDictionary_lock);
 484     PlaceholderTable::find_and_remove(class_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
 485     SystemDictionary_lock->notify_all();
 486   }
 487 
 488   // Check for pending exception or null superk, and throw exception
 489   if (HAS_PENDING_EXCEPTION || superk == NULL) {
 490     handle_resolution_exception(super_name, true, CHECK_NULL);
 491   }
 492 
 493   return superk;
 494 }
 495 
 496 Klass* SystemDictionary::resolve_inline_type_field_or_fail(AllFieldStream* fs,
 497                                                            Handle class_loader,
 498                                                            Handle protection_domain,
 499                                                            bool throw_error,
 500                                                            TRAPS) {
 501   Symbol* class_name = fs->signature()->fundamental_name(THREAD);
 502   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 503   ClassLoaderData* loader_data = class_loader_data(class_loader);
 504   bool throw_circularity_error = false;
 505   PlaceholderEntry* oldprobe;
 506 
 507   {
 508     MutexLocker mu(THREAD, SystemDictionary_lock);
 509     oldprobe = PlaceholderTable::get_entry(class_name, loader_data);
 510     if (oldprobe != NULL &&
 511       oldprobe->check_seen_thread(THREAD, PlaceholderTable::PRIMITIVE_OBJECT_FIELD)) {
 512       throw_circularity_error = true;
 513 
 514     } else {
 515       PlaceholderTable::find_and_add(class_name, loader_data,
 516                                    PlaceholderTable::PRIMITIVE_OBJECT_FIELD, NULL, THREAD);
 517     }
 518   }
 519 
 520   Klass* klass = NULL;
 521   if (!throw_circularity_error) {
 522     klass = SystemDictionary::resolve_or_fail(class_name, class_loader,
 523                                                protection_domain, true, THREAD);
 524   } else {
 525     ResourceMark rm(THREAD);
 526     THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), class_name->as_C_string());
 527   }
 528 
 529   {
 530     MutexLocker mu(THREAD, SystemDictionary_lock);
 531     PlaceholderTable::find_and_remove(class_name, loader_data,
 532                                       PlaceholderTable::PRIMITIVE_OBJECT_FIELD, THREAD);
 533   }
 534 
 535   class_name->decrement_refcount();
 536   return klass;
 537 }
 538 
 539 // We only get here if this thread finds that another thread
 540 // has already claimed the placeholder token for the current operation,
 541 // but that other thread either never owned or gave up the
 542 // object lock
 543 // Waits on SystemDictionary_lock to indicate placeholder table updated
 544 // On return, caller must recheck placeholder table state
 545 //
 546 // We only get here if
 547 //  1) custom classLoader, i.e. not bootstrap classloader
 548 //  2) custom classLoader has broken the class loader objectLock
 549 //     so another thread got here in parallel
 550 //
 551 // lockObject must be held.
 552 // Complicated dance due to lock ordering:
 553 // Must first release the classloader object lock to
 554 // allow initial definer to complete the class definition
 555 // and to avoid deadlock
 556 // Reclaim classloader lock object with same original recursion count
 557 // Must release SystemDictionary_lock after notify, since
 558 // class loader lock must be claimed before SystemDictionary_lock

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

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

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