< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page

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

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

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

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

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







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

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












































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

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




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

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


















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







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

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




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

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

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

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

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

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

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