< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page




1215     return NULL;
1216   }
1217 
1218   // Make sure we have an entry in the SystemDictionary on success
1219   debug_only( {
1220     MutexLocker mu(THREAD, SystemDictionary_lock);
1221 
1222     Klass* check = find_class(h_name, k->class_loader_data());
1223     assert(check == k, "should be present in the dictionary");
1224   } );
1225 
1226   return k;
1227 }
1228 
1229 #if INCLUDE_CDS
1230 // Load a class for boot loader from the shared spaces. This also
1231 // forces the super class and all interfaces to be loaded.
1232 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
1233                                                         PackageEntry* pkg_entry,
1234                                                         TRAPS) {

1235   InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1236   if (ik != NULL && ik->is_shared_boot_class()) {
1237     return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD);
1238   }
1239   return NULL;
1240 }
1241 
1242 // Check if a shared class can be loaded by the specific classloader:
1243 //
1244 // NULL classloader:
1245 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1246 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1247 //     be defined in an unnamed module.
1248 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1249                                                InstanceKlass* ik,
1250                                                PackageEntry* pkg_entry,
1251                                                Handle class_loader, TRAPS) {
1252   assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1253          "Cannot use sharing if java.base is patched");
1254   ResourceMark rm(THREAD);
1255   int path_index = ik->shared_classpath_index();
1256   ClassLoaderData* loader_data = class_loader_data(class_loader);
1257   if (path_index < 0) {
1258     // path_index < 0 indicates that the class is intended for a custom loader
1259     // and should not be loaded by boot/platform/app loaders
1260     if (loader_data->is_builtin_class_loader_data()) {
1261       return false;
1262     } else {
1263       return true;
1264     }
1265   }















1266   SharedClassPathEntry* ent =
1267             (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
1268   if (!Universe::is_module_initialized()) {
1269     assert(ent != NULL && ent->is_modules_image(),
1270            "Loading non-bootstrap classes before the module system is initialized");
1271     assert(class_loader.is_null(), "sanity");
1272     return true;
1273   }
1274   // Get the pkg_entry from the classloader
1275   ModuleEntry* mod_entry = NULL;
1276   TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() :
1277                                                ClassLoader::package_from_class_name(class_name);
1278   if (pkg_name != NULL) {
1279     if (loader_data != NULL) {
1280       if (pkg_entry != NULL) {
1281         mod_entry = pkg_entry->module();
1282         // If the archived class is from a module that has been patched at runtime,
1283         // the class cannot be loaded from the archive.
1284         if (mod_entry != NULL && mod_entry->is_patched()) {
1285           return false;


1543         // a named package within the unnamed module.  In all cases,
1544         // limit visibility to search for the class only in the boot
1545         // loader's append path.
1546         if (!ClassLoader::has_bootclasspath_append()) {
1547            // If there is no bootclasspath append entry, no need to continue
1548            // searching.
1549            return NULL;
1550         }
1551         search_only_bootloader_append = true;
1552       }
1553     }
1554 
1555     // Prior to bootstrapping's module initialization, never load a class outside
1556     // of the boot loader's module path
1557     assert(Universe::is_module_initialized() ||
1558            !search_only_bootloader_append,
1559            "Attempt to load a class outside of boot loader's module path");
1560 
1561     // Search for classes in the CDS archive.
1562     InstanceKlass* k = NULL;
1563     {
1564 #if INCLUDE_CDS


1565       PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1566       k = load_shared_boot_class(class_name, pkg_entry, THREAD);
1567 #endif
1568     }

1569 
1570     if (k == NULL) {
1571       // Use VM class loader
1572       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1573       k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
1574     }
1575 
1576     // find_or_define_instance_class may return a different InstanceKlass
1577     if (k != NULL) {
1578       InstanceKlass* defined_k =
1579         find_or_define_instance_class(class_name, class_loader, k, THREAD);
1580       if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1581         // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1582         assert(defined_k != NULL, "Should have a klass if there's no exception");
1583         loader_data->add_to_deallocate_list(k);
1584         k = defined_k;
1585       } else if (HAS_PENDING_EXCEPTION) {
1586         loader_data->add_to_deallocate_list(k);
1587         return NULL;
1588       }




1215     return NULL;
1216   }
1217 
1218   // Make sure we have an entry in the SystemDictionary on success
1219   debug_only( {
1220     MutexLocker mu(THREAD, SystemDictionary_lock);
1221 
1222     Klass* check = find_class(h_name, k->class_loader_data());
1223     assert(check == k, "should be present in the dictionary");
1224   } );
1225 
1226   return k;
1227 }
1228 
1229 #if INCLUDE_CDS
1230 // Load a class for boot loader from the shared spaces. This also
1231 // forces the super class and all interfaces to be loaded.
1232 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
1233                                                         PackageEntry* pkg_entry,
1234                                                         TRAPS) {
1235   assert(UseSharedSpaces, "Sanity check");
1236   InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1237   if (ik != NULL && ik->is_shared_boot_class()) {
1238     return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD);
1239   }
1240   return NULL;
1241 }
1242 
1243 // Check if a shared class can be loaded by the specific classloader:
1244 //
1245 // NULL classloader:
1246 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1247 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1248 //     be defined in an unnamed module.
1249 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1250                                                InstanceKlass* ik,
1251                                                PackageEntry* pkg_entry,
1252                                                Handle class_loader, TRAPS) {
1253   assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1254          "Cannot use sharing if java.base is patched");
1255   if (ik->shared_classpath_index() < 0) {



1256     // path_index < 0 indicates that the class is intended for a custom loader
1257     // and should not be loaded by boot/platform/app loaders
1258     if (is_builtin_class_loader(class_loader())) {
1259       return false;
1260     } else {
1261       return true;
1262     }
1263   }
1264 
1265   // skip class visibility check
1266   if (MetaspaceShared::use_optimized_module_handling()) {
1267     assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD), "Optimizing module handling failed.");
1268     return true;
1269   }
1270   return is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD);
1271 }
1272 
1273 bool SystemDictionary::is_shared_class_visible_impl(Symbol* class_name,
1274                                                InstanceKlass* ik,
1275                                                PackageEntry* pkg_entry,
1276                                                Handle class_loader, TRAPS) {
1277   int path_index = ik->shared_classpath_index();
1278   ClassLoaderData* loader_data = class_loader_data(class_loader);
1279   SharedClassPathEntry* ent =
1280             (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
1281   if (!Universe::is_module_initialized()) {
1282     assert(ent != NULL && ent->is_modules_image(),
1283            "Loading non-bootstrap classes before the module system is initialized");
1284     assert(class_loader.is_null(), "sanity");
1285     return true;
1286   }
1287   // Get the pkg_entry from the classloader
1288   ModuleEntry* mod_entry = NULL;
1289   TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() :
1290                                                ClassLoader::package_from_class_name(class_name);
1291   if (pkg_name != NULL) {
1292     if (loader_data != NULL) {
1293       if (pkg_entry != NULL) {
1294         mod_entry = pkg_entry->module();
1295         // If the archived class is from a module that has been patched at runtime,
1296         // the class cannot be loaded from the archive.
1297         if (mod_entry != NULL && mod_entry->is_patched()) {
1298           return false;


1556         // a named package within the unnamed module.  In all cases,
1557         // limit visibility to search for the class only in the boot
1558         // loader's append path.
1559         if (!ClassLoader::has_bootclasspath_append()) {
1560            // If there is no bootclasspath append entry, no need to continue
1561            // searching.
1562            return NULL;
1563         }
1564         search_only_bootloader_append = true;
1565       }
1566     }
1567 
1568     // Prior to bootstrapping's module initialization, never load a class outside
1569     // of the boot loader's module path
1570     assert(Universe::is_module_initialized() ||
1571            !search_only_bootloader_append,
1572            "Attempt to load a class outside of boot loader's module path");
1573 
1574     // Search for classes in the CDS archive.
1575     InstanceKlass* k = NULL;
1576 
1577 #if INCLUDE_CDS
1578     if (UseSharedSpaces) 
1579     {
1580       PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1581       k = load_shared_boot_class(class_name, pkg_entry, THREAD);

1582     }
1583 #endif
1584 
1585     if (k == NULL) {
1586       // Use VM class loader
1587       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1588       k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
1589     }
1590 
1591     // find_or_define_instance_class may return a different InstanceKlass
1592     if (k != NULL) {
1593       InstanceKlass* defined_k =
1594         find_or_define_instance_class(class_name, class_loader, k, THREAD);
1595       if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1596         // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1597         assert(defined_k != NULL, "Should have a klass if there's no exception");
1598         loader_data->add_to_deallocate_list(k);
1599         k = defined_k;
1600       } else if (HAS_PENDING_EXCEPTION) {
1601         loader_data->add_to_deallocate_list(k);
1602         return NULL;
1603       }


< prev index next >