1211 return NULL; 1212 } 1213 1214 // Make sure we have an entry in the SystemDictionary on success 1215 debug_only( { 1216 MutexLocker mu(THREAD, SystemDictionary_lock); 1217 1218 Klass* check = find_class(h_name, k->class_loader_data()); 1219 assert(check == k, "should be present in the dictionary"); 1220 } ); 1221 1222 return k; 1223 } 1224 1225 #if INCLUDE_CDS 1226 // Load a class for boot loader from the shared spaces. This also 1227 // forces the super class and all interfaces to be loaded. 1228 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name, 1229 PackageEntry* pkg_entry, 1230 TRAPS) { 1231 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name); 1232 if (ik != NULL && ik->is_shared_boot_class()) { 1233 return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD); 1234 } 1235 return NULL; 1236 } 1237 1238 // Check if a shared class can be loaded by the specific classloader: 1239 // 1240 // NULL classloader: 1241 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader. 1242 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must 1243 // be defined in an unnamed module. 1244 bool SystemDictionary::is_shared_class_visible(Symbol* class_name, 1245 InstanceKlass* ik, 1246 PackageEntry* pkg_entry, 1247 Handle class_loader, TRAPS) { 1248 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), 1249 "Cannot use sharing if java.base is patched"); 1250 ResourceMark rm(THREAD); 1251 int path_index = ik->shared_classpath_index(); 1252 ClassLoaderData* loader_data = class_loader_data(class_loader); 1253 if (path_index < 0) { 1254 // path_index < 0 indicates that the class is intended for a custom loader 1255 // and should not be loaded by boot/platform/app loaders 1256 if (loader_data->is_builtin_class_loader_data()) { 1257 return false; 1258 } else { 1259 return true; 1260 } 1261 } 1262 SharedClassPathEntry* ent = 1263 (SharedClassPathEntry*)FileMapInfo::shared_path(path_index); 1264 if (!Universe::is_module_initialized()) { 1265 assert(ent != NULL && ent->is_modules_image(), 1266 "Loading non-bootstrap classes before the module system is initialized"); 1267 assert(class_loader.is_null(), "sanity"); 1268 return true; 1269 } 1270 // Get the pkg_entry from the classloader 1271 ModuleEntry* mod_entry = NULL; 1272 TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() : 1273 ClassLoader::package_from_class_name(class_name); 1274 if (pkg_name != NULL) { 1275 if (loader_data != NULL) { 1276 if (pkg_entry != NULL) { 1277 mod_entry = pkg_entry->module(); 1278 // If the archived class is from a module that has been patched at runtime, 1279 // the class cannot be loaded from the archive. 1280 if (mod_entry != NULL && mod_entry->is_patched()) { 1281 return false; 1539 // a named package within the unnamed module. In all cases, 1540 // limit visibility to search for the class only in the boot 1541 // loader's append path. 1542 if (!ClassLoader::has_bootclasspath_append()) { 1543 // If there is no bootclasspath append entry, no need to continue 1544 // searching. 1545 return NULL; 1546 } 1547 search_only_bootloader_append = true; 1548 } 1549 } 1550 1551 // Prior to bootstrapping's module initialization, never load a class outside 1552 // of the boot loader's module path 1553 assert(Universe::is_module_initialized() || 1554 !search_only_bootloader_append, 1555 "Attempt to load a class outside of boot loader's module path"); 1556 1557 // Search for classes in the CDS archive. 1558 InstanceKlass* k = NULL; 1559 { 1560 #if INCLUDE_CDS 1561 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time()); 1562 k = load_shared_boot_class(class_name, pkg_entry, THREAD); 1563 #endif 1564 } 1565 1566 if (k == NULL) { 1567 // Use VM class loader 1568 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time()); 1569 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL); 1570 } 1571 1572 // find_or_define_instance_class may return a different InstanceKlass 1573 if (k != NULL) { 1574 InstanceKlass* defined_k = 1575 find_or_define_instance_class(class_name, class_loader, k, THREAD); 1576 if (!HAS_PENDING_EXCEPTION && defined_k != k) { 1577 // If a parallel capable class loader already defined this class, register 'k' for cleanup. 1578 assert(defined_k != NULL, "Should have a klass if there's no exception"); 1579 loader_data->add_to_deallocate_list(k); 1580 k = defined_k; 1581 } else if (HAS_PENDING_EXCEPTION) { 1582 loader_data->add_to_deallocate_list(k); 1583 return NULL; 1584 } | 1211 return NULL; 1212 } 1213 1214 // Make sure we have an entry in the SystemDictionary on success 1215 debug_only( { 1216 MutexLocker mu(THREAD, SystemDictionary_lock); 1217 1218 Klass* check = find_class(h_name, k->class_loader_data()); 1219 assert(check == k, "should be present in the dictionary"); 1220 } ); 1221 1222 return k; 1223 } 1224 1225 #if INCLUDE_CDS 1226 // Load a class for boot loader from the shared spaces. This also 1227 // forces the super class and all interfaces to be loaded. 1228 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name, 1229 PackageEntry* pkg_entry, 1230 TRAPS) { 1231 assert(UseSharedSpaces, "Sanity check"); 1232 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name); 1233 if (ik != NULL && ik->is_shared_boot_class()) { 1234 return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD); 1235 } 1236 return NULL; 1237 } 1238 1239 // Check if a shared class can be loaded by the specific classloader: 1240 // 1241 // NULL classloader: 1242 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader. 1243 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must 1244 // be defined in an unnamed module. 1245 bool SystemDictionary::is_shared_class_visible(Symbol* class_name, 1246 InstanceKlass* ik, 1247 PackageEntry* pkg_entry, 1248 Handle class_loader, TRAPS) { 1249 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), 1250 "Cannot use sharing if java.base is patched"); 1251 if (ik->shared_classpath_index() < 0) { 1252 // path_index < 0 indicates that the class is intended for a custom loader 1253 // and should not be loaded by boot/platform/app loaders 1254 if (is_builtin_class_loader(class_loader())) { 1255 return false; 1256 } else { 1257 return true; 1258 } 1259 } 1260 1261 // skip class visibility check 1262 if (MetaspaceShared::use_optimized_module_handling()) { 1263 assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD), "Sanity check"); 1264 return true; 1265 } 1266 return is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD); 1267 } 1268 1269 bool SystemDictionary::is_shared_class_visible_impl(Symbol* class_name, 1270 InstanceKlass* ik, 1271 PackageEntry* pkg_entry, 1272 Handle class_loader, TRAPS) { 1273 int path_index = ik->shared_classpath_index(); 1274 ClassLoaderData* loader_data = class_loader_data(class_loader); 1275 SharedClassPathEntry* ent = 1276 (SharedClassPathEntry*)FileMapInfo::shared_path(path_index); 1277 if (!Universe::is_module_initialized()) { 1278 assert(ent != NULL && ent->is_modules_image(), 1279 "Loading non-bootstrap classes before the module system is initialized"); 1280 assert(class_loader.is_null(), "sanity"); 1281 return true; 1282 } 1283 // Get the pkg_entry from the classloader 1284 ModuleEntry* mod_entry = NULL; 1285 TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() : 1286 ClassLoader::package_from_class_name(class_name); 1287 if (pkg_name != NULL) { 1288 if (loader_data != NULL) { 1289 if (pkg_entry != NULL) { 1290 mod_entry = pkg_entry->module(); 1291 // If the archived class is from a module that has been patched at runtime, 1292 // the class cannot be loaded from the archive. 1293 if (mod_entry != NULL && mod_entry->is_patched()) { 1294 return false; 1552 // a named package within the unnamed module. In all cases, 1553 // limit visibility to search for the class only in the boot 1554 // loader's append path. 1555 if (!ClassLoader::has_bootclasspath_append()) { 1556 // If there is no bootclasspath append entry, no need to continue 1557 // searching. 1558 return NULL; 1559 } 1560 search_only_bootloader_append = true; 1561 } 1562 } 1563 1564 // Prior to bootstrapping's module initialization, never load a class outside 1565 // of the boot loader's module path 1566 assert(Universe::is_module_initialized() || 1567 !search_only_bootloader_append, 1568 "Attempt to load a class outside of boot loader's module path"); 1569 1570 // Search for classes in the CDS archive. 1571 InstanceKlass* k = NULL; 1572 1573 #if INCLUDE_CDS 1574 if (UseSharedSpaces) 1575 { 1576 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time()); 1577 k = load_shared_boot_class(class_name, pkg_entry, THREAD); 1578 } 1579 #endif 1580 1581 if (k == NULL) { 1582 // Use VM class loader 1583 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time()); 1584 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL); 1585 } 1586 1587 // find_or_define_instance_class may return a different InstanceKlass 1588 if (k != NULL) { 1589 InstanceKlass* defined_k = 1590 find_or_define_instance_class(class_name, class_loader, k, THREAD); 1591 if (!HAS_PENDING_EXCEPTION && defined_k != k) { 1592 // If a parallel capable class loader already defined this class, register 'k' for cleanup. 1593 assert(defined_k != NULL, "Should have a klass if there's no exception"); 1594 loader_data->add_to_deallocate_list(k); 1595 k = defined_k; 1596 } else if (HAS_PENDING_EXCEPTION) { 1597 loader_data->add_to_deallocate_list(k); 1598 return NULL; 1599 } |