src/hotspot/share/classfile/systemDictionary.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54847 59ea39bb2809
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    45 #include "classfile/vmSymbols.hpp"
    45 #include "classfile/vmSymbols.hpp"
    46 #include "code/codeCache.hpp"
    46 #include "code/codeCache.hpp"
    47 #include "compiler/compileBroker.hpp"
    47 #include "compiler/compileBroker.hpp"
    48 #include "gc/shared/gcTraceTime.inline.hpp"
    48 #include "gc/shared/gcTraceTime.inline.hpp"
    49 #include "gc/shared/oopStorage.inline.hpp"
    49 #include "gc/shared/oopStorage.inline.hpp"
       
    50 #include "gc/shared/oopStorageSet.hpp"
    50 #include "interpreter/bytecodeStream.hpp"
    51 #include "interpreter/bytecodeStream.hpp"
    51 #include "interpreter/interpreter.hpp"
    52 #include "interpreter/interpreter.hpp"
    52 #include "jfr/jfrEvents.hpp"
    53 #include "jfr/jfrEvents.hpp"
    53 #include "logging/log.hpp"
    54 #include "logging/log.hpp"
    54 #include "logging/logStream.hpp"
    55 #include "logging/logStream.hpp"
    96 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
    97 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
    97 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
    98 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
    98 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
    99 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
    99 ProtectionDomainCacheTable*   SystemDictionary::_pd_cache_table = NULL;
   100 ProtectionDomainCacheTable*   SystemDictionary::_pd_cache_table = NULL;
   100 
   101 
   101 int         SystemDictionary::_number_of_modifications = 0;
       
   102 oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
   102 oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
   103 
   103 
   104 InstanceKlass*      SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
   104 InstanceKlass*      SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
   105                                                           =  { NULL /*, NULL...*/ };
   105                                                           =  { NULL /*, NULL...*/ };
   106 
   106 
   112 bool        SystemDictionary::_has_checkPackageAccess     =  false;
   112 bool        SystemDictionary::_has_checkPackageAccess     =  false;
   113 
   113 
   114 // Default ProtectionDomainCacheSize value
   114 // Default ProtectionDomainCacheSize value
   115 
   115 
   116 const int defaultProtectionDomainCacheSize = 1009;
   116 const int defaultProtectionDomainCacheSize = 1009;
   117 
       
   118 OopStorage* SystemDictionary::_vm_weak_oop_storage = NULL;
       
   119 
       
   120 
   117 
   121 // ----------------------------------------------------------------------------
   118 // ----------------------------------------------------------------------------
   122 // Java-level SystemLoader and PlatformLoader
   119 // Java-level SystemLoader and PlatformLoader
   123 
   120 
   124 oop SystemDictionary::java_system_loader() {
   121 oop SystemDictionary::java_system_loader() {
   178 bool SystemDictionary::is_system_class_loader(oop class_loader) {
   175 bool SystemDictionary::is_system_class_loader(oop class_loader) {
   179   if (class_loader == NULL) {
   176   if (class_loader == NULL) {
   180     return false;
   177     return false;
   181   }
   178   }
   182   return (class_loader->klass() == SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass() ||
   179   return (class_loader->klass() == SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass() ||
   183          oopDesc::equals(class_loader, _java_system_loader));
   180          class_loader == _java_system_loader);
   184 }
   181 }
   185 
   182 
   186 // Returns true if the passed class loader is the platform class loader.
   183 // Returns true if the passed class loader is the platform class loader.
   187 bool SystemDictionary::is_platform_class_loader(oop class_loader) {
   184 bool SystemDictionary::is_platform_class_loader(oop class_loader) {
   188   if (class_loader == NULL) {
   185   if (class_loader == NULL) {
   394     // so we don't throw an exception here.
   391     // so we don't throw an exception here.
   395     // see: nsk redefclass014 & java.lang.instrument Instrument032
   392     // see: nsk redefclass014 & java.lang.instrument Instrument032
   396     if ((childk != NULL ) && (is_superclass) &&
   393     if ((childk != NULL ) && (is_superclass) &&
   397         ((quicksuperk = childk->java_super()) != NULL) &&
   394         ((quicksuperk = childk->java_super()) != NULL) &&
   398          ((quicksuperk->name() == super_name) &&
   395          ((quicksuperk->name() == super_name) &&
   399             (oopDesc::equals(quicksuperk->class_loader(), class_loader())))) {
   396             (quicksuperk->class_loader() == class_loader()))) {
   400            return quicksuperk;
   397            return quicksuperk;
   401     } else {
   398     } else {
   402       PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data);
   399       PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data);
   403       if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
   400       if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
   404           throw_circularity_error = true;
   401           throw_circularity_error = true;
   543   assert_lock_strong(SystemDictionary_lock);
   540   assert_lock_strong(SystemDictionary_lock);
   544 
   541 
   545   bool calledholdinglock
   542   bool calledholdinglock
   546       = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
   543       = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
   547   assert(calledholdinglock,"must hold lock for notify");
   544   assert(calledholdinglock,"must hold lock for notify");
   548   assert((!oopDesc::equals(lockObject(), _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
   545   assert((lockObject() != _system_loader_lock_obj && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
   549   ObjectSynchronizer::notifyall(lockObject, THREAD);
   546   ObjectSynchronizer::notifyall(lockObject, THREAD);
   550   intptr_t recursions =  ObjectSynchronizer::complete_exit(lockObject, THREAD);
   547   intptr_t recursions =  ObjectSynchronizer::complete_exit(lockObject, THREAD);
   551   SystemDictionary_lock->wait();
   548   SystemDictionary_lock->wait();
   552   SystemDictionary_lock->unlock();
   549   SystemDictionary_lock->unlock();
   553   ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
   550   ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
   851       k = load_instance_class(name, class_loader, THREAD);
   848       k = load_instance_class(name, class_loader, THREAD);
   852 
   849 
   853       // If everything was OK (no exceptions, no null return value), and
   850       // If everything was OK (no exceptions, no null return value), and
   854       // class_loader is NOT the defining loader, do a little more bookkeeping.
   851       // class_loader is NOT the defining loader, do a little more bookkeeping.
   855       if (!HAS_PENDING_EXCEPTION && k != NULL &&
   852       if (!HAS_PENDING_EXCEPTION && k != NULL &&
   856         !oopDesc::equals(k->class_loader(), class_loader())) {
   853         k->class_loader() != class_loader()) {
   857 
   854 
   858         check_constraints(d_hash, k, class_loader, false, THREAD);
   855         check_constraints(d_hash, k, class_loader, false, THREAD);
   859 
   856 
   860         // Need to check for a PENDING_EXCEPTION again; check_constraints
   857         // Need to check for a PENDING_EXCEPTION again; check_constraints
   861         // can throw but we may have to remove entry from the placeholder table below.
   858         // can throw but we may have to remove entry from the placeholder table below.
  1004 
  1001 
  1005   ClassLoaderData* loader_data;
  1002   ClassLoaderData* loader_data;
  1006   if (unsafe_anonymous_host != NULL) {
  1003   if (unsafe_anonymous_host != NULL) {
  1007     // Create a new CLD for an unsafe anonymous class, that uses the same class loader
  1004     // Create a new CLD for an unsafe anonymous class, that uses the same class loader
  1008     // as the unsafe_anonymous_host
  1005     // as the unsafe_anonymous_host
  1009     guarantee(oopDesc::equals(unsafe_anonymous_host->class_loader(), class_loader()), "should be the same");
  1006     guarantee(unsafe_anonymous_host->class_loader() == class_loader(), "should be the same");
  1010     loader_data = ClassLoaderData::unsafe_anonymous_class_loader_data(class_loader);
  1007     loader_data = ClassLoaderData::unsafe_anonymous_class_loader_data(class_loader);
  1011   } else {
  1008   } else {
  1012     loader_data = ClassLoaderData::class_loader_data(class_loader());
  1009     loader_data = ClassLoaderData::class_loader_data(class_loader());
  1013   }
  1010   }
  1014 
  1011 
  1037       MutexLocker mu_r(Compile_lock, THREAD);
  1034       MutexLocker mu_r(Compile_lock, THREAD);
  1038 
  1035 
  1039       // Add to class hierarchy, initialize vtables, and do possible
  1036       // Add to class hierarchy, initialize vtables, and do possible
  1040       // deoptimizations.
  1037       // deoptimizations.
  1041       add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
  1038       add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
  1042 
       
  1043       // But, do not add to dictionary.
  1039       // But, do not add to dictionary.
  1044 
       
  1045       // compiled code dependencies need to be validated anyway
       
  1046       notice_modification();
       
  1047     }
  1040     }
  1048 
  1041 
  1049     // Rewrite and patch constant pool here.
  1042     // Rewrite and patch constant pool here.
  1050     k->link_class(CHECK_NULL);
  1043     k->link_class(CHECK_NULL);
  1051     if (cp_patches != NULL) {
  1044     if (cp_patches != NULL) {
  1210   }
  1203   }
  1211   // Get the pkg_entry from the classloader
  1204   // Get the pkg_entry from the classloader
  1212   TempNewSymbol pkg_name = NULL;
  1205   TempNewSymbol pkg_name = NULL;
  1213   PackageEntry* pkg_entry = NULL;
  1206   PackageEntry* pkg_entry = NULL;
  1214   ModuleEntry* mod_entry = NULL;
  1207   ModuleEntry* mod_entry = NULL;
  1215   const char* pkg_string = NULL;
       
  1216   pkg_name = InstanceKlass::package_from_name(class_name, CHECK_false);
  1208   pkg_name = InstanceKlass::package_from_name(class_name, CHECK_false);
  1217   if (pkg_name != NULL) {
  1209   if (pkg_name != NULL) {
  1218     pkg_string = pkg_name->as_C_string();
       
  1219     if (loader_data != NULL) {
  1210     if (loader_data != NULL) {
  1220       pkg_entry = loader_data->packages()->lookup_only(pkg_name);
  1211       pkg_entry = loader_data->packages()->lookup_only(pkg_name);
  1221     }
  1212     }
  1222     if (pkg_entry != NULL) {
  1213     if (pkg_entry != NULL) {
  1223       mod_entry = pkg_entry->module();
  1214       mod_entry = pkg_entry->module();
  1250     // 1. the class is from the unamed package
  1241     // 1. the class is from the unamed package
  1251     // 2. or, the class is not from a module defined in the NULL classloader
  1242     // 2. or, the class is not from a module defined in the NULL classloader
  1252     // 3. or, the class is from an unamed module
  1243     // 3. or, the class is from an unamed module
  1253     if (!ent->is_modules_image() && ik->is_shared_boot_class()) {
  1244     if (!ent->is_modules_image() && ik->is_shared_boot_class()) {
  1254       // the class is from the -Xbootclasspath/a
  1245       // the class is from the -Xbootclasspath/a
  1255       if (pkg_string == NULL ||
  1246       if (pkg_name == NULL ||
  1256           pkg_entry == NULL ||
  1247           pkg_entry == NULL ||
  1257           pkg_entry->in_unnamed_module()) {
  1248           pkg_entry->in_unnamed_module()) {
  1258         assert(mod_entry == NULL ||
  1249         assert(mod_entry == NULL ||
  1259                mod_entry == loader_data->unnamed_module(),
  1250                mod_entry == loader_data->unnamed_module(),
  1260                "the unnamed module is not defined in the classloader");
  1251                "the unnamed module is not defined in the classloader");
  1262       }
  1253       }
  1263     }
  1254     }
  1264     return false;
  1255     return false;
  1265   } else {
  1256   } else {
  1266     bool res = SystemDictionaryShared::is_shared_class_visible_for_classloader(
  1257     bool res = SystemDictionaryShared::is_shared_class_visible_for_classloader(
  1267               ik, class_loader, pkg_string, pkg_name,
  1258               ik, class_loader, pkg_name, pkg_entry, mod_entry, CHECK_(false));
  1268               pkg_entry, mod_entry, CHECK_(false));
       
  1269     return res;
  1259     return res;
  1270   }
  1260   }
  1271 }
  1261 }
  1272 
  1262 
  1273 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
  1263 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
  1274                                                    Handle class_loader,
  1264                                                    Handle class_loader,
  1275                                                    Handle protection_domain,
  1265                                                    Handle protection_domain,
  1276                                                    const ClassFileStream *cfs,
  1266                                                    const ClassFileStream *cfs,
  1277                                                    TRAPS) {
  1267                                                    TRAPS) {
  1278 
  1268   assert(ik != NULL, "sanity");
  1279   if (ik != NULL) {
  1269   assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
  1280     Symbol* class_name = ik->name();
  1270   Symbol* class_name = ik->name();
  1281 
  1271 
  1282     bool visible = is_shared_class_visible(
  1272   bool visible = is_shared_class_visible(
  1283                             class_name, ik, class_loader, CHECK_NULL);
  1273                           class_name, ik, class_loader, CHECK_NULL);
  1284     if (!visible) {
  1274   if (!visible) {
       
  1275     return NULL;
       
  1276   }
       
  1277 
       
  1278   // Resolve the superclass and interfaces. They must be the same
       
  1279   // as in dump time, because the layout of <ik> depends on
       
  1280   // the specific layout of ik->super() and ik->local_interfaces().
       
  1281   //
       
  1282   // If unexpected superclass or interfaces are found, we cannot
       
  1283   // load <ik> from the shared archive.
       
  1284 
       
  1285   if (ik->super() != NULL) {
       
  1286     Symbol*  cn = ik->super()->name();
       
  1287     Klass *s = resolve_super_or_fail(class_name, cn,
       
  1288                                      class_loader, protection_domain, true, CHECK_NULL);
       
  1289     if (s != ik->super()) {
       
  1290       // The dynamically resolved super class is not the same as the one we used during dump time,
       
  1291       // so we cannot use ik.
  1285       return NULL;
  1292       return NULL;
  1286     }
  1293     } else {
  1287 
  1294       assert(s->is_shared(), "must be");
  1288     // Resolve the superclass and interfaces. They must be the same
  1295     }
  1289     // as in dump time, because the layout of <ik> depends on
  1296   }
  1290     // the specific layout of ik->super() and ik->local_interfaces().
  1297 
  1291     //
  1298   Array<InstanceKlass*>* interfaces = ik->local_interfaces();
  1292     // If unexpected superclass or interfaces are found, we cannot
  1299   int num_interfaces = interfaces->length();
  1293     // load <ik> from the shared archive.
  1300   for (int index = 0; index < num_interfaces; index++) {
  1294 
  1301     InstanceKlass* k = interfaces->at(index);
  1295     if (ik->super() != NULL) {
  1302     Symbol* name  = k->name();
  1296       Symbol*  cn = ik->super()->name();
  1303     Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL);
  1297       Klass *s = resolve_super_or_fail(class_name, cn,
  1304     if (k != i) {
  1298                                        class_loader, protection_domain, true, CHECK_NULL);
  1305       // The dynamically resolved interface class is not the same as the one we used during dump time,
  1299       if (s != ik->super()) {
  1306       // so we cannot use ik.
  1300         // The dynamically resolved super class is not the same as the one we used during dump time,
  1307       return NULL;
  1301         // so we cannot use ik.
  1308     } else {
  1302         return NULL;
  1309       assert(i->is_shared(), "must be");
  1303       } else {
  1310     }
  1304         assert(s->is_shared(), "must be");
  1311   }
  1305       }
  1312 
  1306     }
  1313   InstanceKlass* new_ik = KlassFactory::check_shared_class_file_load_hook(
  1307 
  1314       ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
  1308     Array<InstanceKlass*>* interfaces = ik->local_interfaces();
  1315   if (new_ik != NULL) {
  1309     int num_interfaces = interfaces->length();
  1316     // The class is changed by CFLH. Return the new class. The shared class is
  1310     for (int index = 0; index < num_interfaces; index++) {
  1317     // not used.
  1311       InstanceKlass* k = interfaces->at(index);
  1318     return new_ik;
  1312       Symbol* name  = k->name();
  1319   }
  1313       Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL);
  1320 
  1314       if (k != i) {
  1321   // Adjust methods to recover missing data.  They need addresses for
  1315         // The dynamically resolved interface class is not the same as the one we used during dump time,
  1322   // interpreter entry points and their default native method address
  1316         // so we cannot use ik.
  1323   // must be reset.
  1317         return NULL;
  1324 
  1318       } else {
  1325   // Updating methods must be done under a lock so multiple
  1319         assert(i->is_shared(), "must be");
  1326   // threads don't update these in parallel
  1320       }
  1327   //
  1321     }
  1328   // Shared classes are all currently loaded by either the bootstrap or
  1322 
  1329   // internal parallel class loaders, so this will never cause a deadlock
  1323     InstanceKlass* new_ik = KlassFactory::check_shared_class_file_load_hook(
  1330   // on a custom class loader lock.
  1324         ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
  1331 
  1325     if (new_ik != NULL) {
  1332   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
  1326       // The class is changed by CFLH. Return the new class. The shared class is
  1333   {
  1327       // not used.
  1334     HandleMark hm(THREAD);
  1328       return new_ik;
  1335     Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
  1329     }
  1336     check_loader_lock_contention(lockObject, THREAD);
  1330 
  1337     ObjectLocker ol(lockObject, THREAD, true);
  1331     // Adjust methods to recover missing data.  They need addresses for
  1338     // prohibited package check assumes all classes loaded from archive call
  1332     // interpreter entry points and their default native method address
  1339     // restore_unshareable_info which calls ik->set_package()
  1333     // must be reset.
  1340     ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL);
  1334 
  1341   }
  1335     // Updating methods must be done under a lock so multiple
  1342 
  1336     // threads don't update these in parallel
  1343   ik->print_class_load_logging(loader_data, NULL, NULL);
  1337     //
  1344 
  1338     // Shared classes are all currently loaded by either the bootstrap or
  1345   // For boot loader, ensure that GetSystemPackage knows that a class in this
  1339     // internal parallel class loaders, so this will never cause a deadlock
  1346   // package was loaded.
  1340     // on a custom class loader lock.
  1347   if (class_loader.is_null()) {
  1341 
  1348     int path_index = ik->shared_classpath_index();
  1342     ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
  1349     ResourceMark rm;
  1343     {
  1350     ClassLoader::add_package(ik->name()->as_C_string(), path_index, THREAD);
  1344       HandleMark hm(THREAD);
  1351   }
  1345       Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
  1352 
  1346       check_loader_lock_contention(lockObject, THREAD);
  1353   if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
  1347       ObjectLocker ol(lockObject, THREAD, true);
  1354     // Only dump the classes that can be stored into CDS archive
  1348       // prohibited package check assumes all classes loaded from archive call
  1355     if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
  1349       // restore_unshareable_info which calls ik->set_package()
  1356       ResourceMark rm(THREAD);
  1350       ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL);
  1357       classlist_file->print_cr("%s", ik->name()->as_C_string());
  1351     }
  1358       classlist_file->flush();
  1352 
  1359     }
  1353     ik->print_class_load_logging(loader_data, NULL, NULL);
  1360   }
  1354 
  1361 
  1355     // For boot loader, ensure that GetSystemPackage knows that a class in this
  1362   // notify a class loaded from shared object
  1356     // package was loaded.
  1363   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
  1357     if (class_loader.is_null()) {
  1364 
  1358       int path_index = ik->shared_classpath_index();
  1365   ik->set_has_passed_fingerprint_check(false);
       
  1366   if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
       
  1367     uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
       
  1368     uint64_t cds_fp = ik->get_stored_fingerprint();
       
  1369     if (aot_fp != 0 && aot_fp == cds_fp) {
       
  1370       // This class matches with a class saved in an AOT library
       
  1371       ik->set_has_passed_fingerprint_check(true);
       
  1372     } else {
  1359       ResourceMark rm;
  1373       ResourceMark rm;
  1360       ClassLoader::add_package(ik->name()->as_C_string(), path_index, THREAD);
  1374       log_info(class, fingerprint)("%s :  expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
  1361     }
  1375     }
  1362 
  1376   }
  1363     if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
  1377 
  1364       // Only dump the classes that can be stored into CDS archive
       
  1365       if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
       
  1366         ResourceMark rm(THREAD);
       
  1367         classlist_file->print_cr("%s", ik->name()->as_C_string());
       
  1368         classlist_file->flush();
       
  1369       }
       
  1370     }
       
  1371 
       
  1372     // notify a class loaded from shared object
       
  1373     ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
       
  1374 
       
  1375     ik->set_has_passed_fingerprint_check(false);
       
  1376     if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
       
  1377       uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
       
  1378       uint64_t cds_fp = ik->get_stored_fingerprint();
       
  1379       if (aot_fp != 0 && aot_fp == cds_fp) {
       
  1380         // This class matches with a class saved in an AOT library
       
  1381         ik->set_has_passed_fingerprint_check(true);
       
  1382       } else {
       
  1383         ResourceMark rm;
       
  1384         log_info(class, fingerprint)("%s :  expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
       
  1385       }
       
  1386     }
       
  1387   }
       
  1388   return ik;
  1378   return ik;
  1389 }
  1379 }
  1390 #endif // INCLUDE_CDS
  1380 #endif // INCLUDE_CDS
  1391 
  1381 
  1392 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
  1382 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
  1437         // Class is either in the unnamed package, in a named package
  1427         // Class is either in the unnamed package, in a named package
  1438         // within a module not defined to the boot loader or in a
  1428         // within a module not defined to the boot loader or in a
  1439         // a named package within the unnamed module.  In all cases,
  1429         // a named package within the unnamed module.  In all cases,
  1440         // limit visibility to search for the class only in the boot
  1430         // limit visibility to search for the class only in the boot
  1441         // loader's append path.
  1431         // loader's append path.
       
  1432         if (!ClassLoader::has_bootclasspath_append()) {
       
  1433            // If there is no bootclasspath append entry, no need to continue
       
  1434            // searching.
       
  1435            return NULL;
       
  1436         }
  1442         search_only_bootloader_append = true;
  1437         search_only_bootloader_append = true;
  1443       }
  1438       }
  1444     }
  1439     }
  1445 
  1440 
  1446     // Prior to bootstrapping's module initialization, never load a class outside
  1441     // Prior to bootstrapping's module initialization, never load a class outside
  1734 
  1729 
  1735   if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
  1730   if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
  1736       == ObjectSynchronizer::owner_other) {
  1731       == ObjectSynchronizer::owner_other) {
  1737     // contention will likely happen, so increment the corresponding
  1732     // contention will likely happen, so increment the corresponding
  1738     // contention counter.
  1733     // contention counter.
  1739     if (oopDesc::equals(loader_lock(), _system_loader_lock_obj)) {
  1734     if (loader_lock() == _system_loader_lock_obj) {
  1740       ClassLoader::sync_systemLoaderLockContentionRate()->inc();
  1735       ClassLoader::sync_systemLoaderLockContentionRate()->inc();
  1741     } else {
  1736     } else {
  1742       ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
  1737       ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
  1743     }
  1738     }
  1744   }
  1739   }
  1847   }
  1842   }
  1848 
  1843 
  1849   return unloading_occurred;
  1844   return unloading_occurred;
  1850 }
  1845 }
  1851 
  1846 
  1852 void SystemDictionary::oops_do(OopClosure* f) {
  1847 void SystemDictionary::oops_do(OopClosure* f, bool include_handles) {
  1853   f->do_oop(&_java_system_loader);
  1848   f->do_oop(&_java_system_loader);
  1854   f->do_oop(&_java_platform_loader);
  1849   f->do_oop(&_java_platform_loader);
  1855   f->do_oop(&_system_loader_lock_obj);
  1850   f->do_oop(&_system_loader_lock_obj);
  1856   CDS_ONLY(SystemDictionaryShared::oops_do(f);)
  1851   CDS_ONLY(SystemDictionaryShared::oops_do(f);)
  1857 
  1852 
  1858   // Visit extra methods
  1853   // Visit extra methods
  1859   invoke_method_table()->oops_do(f);
  1854   invoke_method_table()->oops_do(f);
       
  1855 
       
  1856   if (include_handles) {
       
  1857     OopStorageSet::vm_global()->oops_do(f);
       
  1858   }
  1860 }
  1859 }
  1861 
  1860 
  1862 // CDS: scan and relocate all classes referenced by _well_known_klasses[].
  1861 // CDS: scan and relocate all classes referenced by _well_known_klasses[].
  1863 void SystemDictionary::well_known_klasses_do(MetaspaceClosure* it) {
  1862 void SystemDictionary::well_known_klasses_do(MetaspaceClosure* it) {
  1864   for (int id = FIRST_WKID; id < WKID_LIMIT; id++) {
  1863   for (int id = FIRST_WKID; id < WKID_LIMIT; id++) {
  1878 // Initialization
  1877 // Initialization
  1879 
  1878 
  1880 void SystemDictionary::initialize(TRAPS) {
  1879 void SystemDictionary::initialize(TRAPS) {
  1881   // Allocate arrays
  1880   // Allocate arrays
  1882   _placeholders        = new PlaceholderTable(_placeholder_table_size);
  1881   _placeholders        = new PlaceholderTable(_placeholder_table_size);
  1883   _number_of_modifications = 0;
       
  1884   _loader_constraints  = new LoaderConstraintTable(_loader_constraint_size);
  1882   _loader_constraints  = new LoaderConstraintTable(_loader_constraint_size);
  1885   _resolution_errors   = new ResolutionErrorTable(_resolution_error_size);
  1883   _resolution_errors   = new ResolutionErrorTable(_resolution_error_size);
  1886   _invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
  1884   _invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
  1887   _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
  1885   _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
  1888 
  1886 
  2140     MutexLocker mu1(SystemDictionary_lock, THREAD);
  2138     MutexLocker mu1(SystemDictionary_lock, THREAD);
  2141 
  2139 
  2142     // See whether biased locking is enabled and if so set it for this
  2140     // See whether biased locking is enabled and if so set it for this
  2143     // klass.
  2141     // klass.
  2144     // Note that this must be done past the last potential blocking
  2142     // Note that this must be done past the last potential blocking
  2145     // point / safepoint. We enable biased locking lazily using a
  2143     // point / safepoint. We might enable biased locking lazily using a
  2146     // VM_Operation to iterate the SystemDictionary and installing the
  2144     // VM_Operation to iterate the SystemDictionary and installing the
  2147     // biasable mark word into each InstanceKlass's prototype header.
  2145     // biasable mark word into each InstanceKlass's prototype header.
  2148     // To avoid race conditions where we accidentally miss enabling the
  2146     // To avoid race conditions where we accidentally miss enabling the
  2149     // optimization for one class in the process of being added to the
  2147     // optimization for one class in the process of being added to the
  2150     // dictionary, we must not safepoint after the test of
  2148     // dictionary, we must not safepoint after the test of
  2152     if (UseBiasedLocking && BiasedLocking::enabled()) {
  2150     if (UseBiasedLocking && BiasedLocking::enabled()) {
  2153       // Set biased locking bit for all loaded classes; it will be
  2151       // Set biased locking bit for all loaded classes; it will be
  2154       // cleared if revocation occurs too often for this type
  2152       // cleared if revocation occurs too often for this type
  2155       // NOTE that we must only do this when the class is initally
  2153       // NOTE that we must only do this when the class is initally
  2156       // defined, not each time it is referenced from a new class loader
  2154       // defined, not each time it is referenced from a new class loader
  2157       if (oopDesc::equals(k->class_loader(), class_loader())) {
  2155       if (k->class_loader() == class_loader()) {
  2158         k->set_prototype_header(markOopDesc::biased_locking_prototype());
  2156         k->set_prototype_header(markWord::biased_locking_prototype());
  2159       }
  2157       }
  2160     }
  2158     }
  2161 
  2159 
  2162     // Make a new dictionary entry.
  2160     // Make a new dictionary entry.
  2163     Dictionary* dictionary = loader_data->dictionary();
  2161     Dictionary* dictionary = loader_data->dictionary();
  2164     InstanceKlass* sd_check = find_class(d_hash, name, dictionary);
  2162     InstanceKlass* sd_check = find_class(d_hash, name, dictionary);
  2165     if (sd_check == NULL) {
  2163     if (sd_check == NULL) {
  2166       dictionary->add_klass(d_hash, name, k);
  2164       dictionary->add_klass(d_hash, name, k);
  2167 
       
  2168       notice_modification();
       
  2169     }
  2165     }
  2170   #ifdef ASSERT
  2166   #ifdef ASSERT
  2171     sd_check = find_class(d_hash, name, dictionary);
  2167     sd_check = find_class(d_hash, name, dictionary);
  2172     assert (sd_check != NULL, "should have entry in dictionary");
  2168     assert (sd_check != NULL, "should have entry in dictionary");
  2173     // Note: there may be a placeholder entry: for circularity testing
  2169     // Note: there may be a placeholder entry: for circularity testing
  2347 // Arrays are not added to the loader constraint table, their elements are.
  2343 // Arrays are not added to the loader constraint table, their elements are.
  2348 Symbol* SystemDictionary::check_signature_loaders(Symbol* signature,
  2344 Symbol* SystemDictionary::check_signature_loaders(Symbol* signature,
  2349                                                Handle loader1, Handle loader2,
  2345                                                Handle loader1, Handle loader2,
  2350                                                bool is_method, TRAPS)  {
  2346                                                bool is_method, TRAPS)  {
  2351   // Nothing to do if loaders are the same.
  2347   // Nothing to do if loaders are the same.
  2352   if (oopDesc::equals(loader1(), loader2())) {
  2348   if (loader1() == loader2()) {
  2353     return NULL;
  2349     return NULL;
  2354   }
  2350   }
  2355 
  2351 
  2356   SignatureStream sig_strm(signature, is_method);
  2352   SignatureStream sig_strm(signature, is_method);
  2357   while (!sig_strm.is_done()) {
  2353   while (!sig_strm.is_done()) {
  2859     pd_cache_table()->print_table_statistics(st, "ProtectionDomainCache Table");
  2855     pd_cache_table()->print_table_statistics(st, "ProtectionDomainCache Table");
  2860   }
  2856   }
  2861 }
  2857 }
  2862 
  2858 
  2863 TableStatistics SystemDictionary::placeholders_statistics() {
  2859 TableStatistics SystemDictionary::placeholders_statistics() {
       
  2860   MutexLocker ml(SystemDictionary_lock);
  2864   return placeholders()->statistics_calculate();
  2861   return placeholders()->statistics_calculate();
  2865 }
  2862 }
  2866 
  2863 
  2867 TableStatistics SystemDictionary::loader_constraints_statistics() {
  2864 TableStatistics SystemDictionary::loader_constraints_statistics() {
       
  2865   MutexLocker ml(SystemDictionary_lock);
  2868   return constraints()->statistics_calculate();
  2866   return constraints()->statistics_calculate();
  2869 }
  2867 }
  2870 
  2868 
  2871 TableStatistics SystemDictionary::protection_domain_cache_statistics() {
  2869 TableStatistics SystemDictionary::protection_domain_cache_statistics() {
       
  2870   MutexLocker ml(SystemDictionary_lock);
  2872   return pd_cache_table()->statistics_calculate();
  2871   return pd_cache_table()->statistics_calculate();
  2873 }
  2872 }
  2874 
  2873 
  2875 // Utility for dumping dictionaries.
  2874 // Utility for dumping dictionaries.
  2876 SystemDictionaryDCmd::SystemDictionaryDCmd(outputStream* output, bool heap) :
  2875 SystemDictionaryDCmd::SystemDictionaryDCmd(outputStream* output, bool heap) :
  2894     return dcmd->_dcmdparser.num_arguments();
  2893     return dcmd->_dcmdparser.num_arguments();
  2895   } else {
  2894   } else {
  2896     return 0;
  2895     return 0;
  2897   }
  2896   }
  2898 }
  2897 }
  2899 
       
  2900 void SystemDictionary::initialize_oop_storage() {
       
  2901   _vm_weak_oop_storage =
       
  2902     new OopStorage("VM Weak Oop Handles",
       
  2903                    VMWeakAlloc_lock,
       
  2904                    VMWeakActive_lock);
       
  2905 }
       
  2906 
       
  2907 OopStorage* SystemDictionary::vm_weak_oop_storage() {
       
  2908   assert(_vm_weak_oop_storage != NULL, "Uninitialized");
       
  2909   return _vm_weak_oop_storage;
       
  2910 }