1189 return NULL; 1190 } 1191 1192 // Make sure we have an entry in the SystemDictionary on success 1193 debug_only( { 1194 MutexLocker mu(THREAD, SystemDictionary_lock); 1195 1196 Klass* check = find_class(h_name, k->class_loader_data()); 1197 assert(check == k, "should be present in the dictionary"); 1198 } ); 1199 1200 return k; 1201 } 1202 1203 #if INCLUDE_CDS 1204 // Load a class for boot loader from the shared spaces. This also 1205 // forces the super class and all interfaces to be loaded. 1206 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name, 1207 PackageEntry* pkg_entry, 1208 TRAPS) { 1209 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name); 1210 if (ik != NULL && ik->is_shared_boot_class()) { 1211 return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD); 1212 } 1213 return NULL; 1214 } 1215 1216 // Check if a shared class can be loaded by the specific classloader: 1217 // 1218 // NULL classloader: 1219 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader. 1220 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must 1221 // be defined in an unnamed module. 1222 bool SystemDictionary::is_shared_class_visible(Symbol* class_name, 1223 InstanceKlass* ik, 1224 PackageEntry* pkg_entry, 1225 Handle class_loader, TRAPS) { 1226 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), 1227 "Cannot use sharing if java.base is patched"); 1228 ResourceMark rm(THREAD); 1229 int path_index = ik->shared_classpath_index(); 1230 ClassLoaderData* loader_data = class_loader_data(class_loader); 1231 if (path_index < 0) { 1232 // path_index < 0 indicates that the class is intended for a custom loader 1233 // and should not be loaded by boot/platform/app loaders 1234 if (loader_data->is_builtin_class_loader_data()) { 1235 return false; 1236 } else { 1237 return true; 1238 } 1239 } 1240 SharedClassPathEntry* ent = 1241 (SharedClassPathEntry*)FileMapInfo::shared_path(path_index); 1242 if (!Universe::is_module_initialized()) { 1243 assert(ent != NULL && ent->is_modules_image(), 1244 "Loading non-bootstrap classes before the module system is initialized"); 1245 assert(class_loader.is_null(), "sanity"); 1517 // a named package within the unnamed module. In all cases, 1518 // limit visibility to search for the class only in the boot 1519 // loader's append path. 1520 if (!ClassLoader::has_bootclasspath_append()) { 1521 // If there is no bootclasspath append entry, no need to continue 1522 // searching. 1523 return NULL; 1524 } 1525 search_only_bootloader_append = true; 1526 } 1527 } 1528 1529 // Prior to bootstrapping's module initialization, never load a class outside 1530 // of the boot loader's module path 1531 assert(Universe::is_module_initialized() || 1532 !search_only_bootloader_append, 1533 "Attempt to load a class outside of boot loader's module path"); 1534 1535 // Search for classes in the CDS archive. 1536 InstanceKlass* k = NULL; 1537 { 1538 #if INCLUDE_CDS 1539 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time()); 1540 k = load_shared_boot_class(class_name, pkg_entry, THREAD); 1541 #endif 1542 } 1543 1544 if (k == NULL) { 1545 // Use VM class loader 1546 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time()); 1547 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL); 1548 } 1549 1550 // find_or_define_instance_class may return a different InstanceKlass 1551 if (k != NULL) { 1552 InstanceKlass* defined_k = 1553 find_or_define_instance_class(class_name, class_loader, k, THREAD); 1554 if (!HAS_PENDING_EXCEPTION && defined_k != k) { 1555 // If a parallel capable class loader already defined this class, register 'k' for cleanup. 1556 assert(defined_k != NULL, "Should have a klass if there's no exception"); 1557 loader_data->add_to_deallocate_list(k); 1558 k = defined_k; 1559 } else if (HAS_PENDING_EXCEPTION) { 1560 loader_data->add_to_deallocate_list(k); 1561 return NULL; 1562 } | 1189 return NULL; 1190 } 1191 1192 // Make sure we have an entry in the SystemDictionary on success 1193 debug_only( { 1194 MutexLocker mu(THREAD, SystemDictionary_lock); 1195 1196 Klass* check = find_class(h_name, k->class_loader_data()); 1197 assert(check == k, "should be present in the dictionary"); 1198 } ); 1199 1200 return k; 1201 } 1202 1203 #if INCLUDE_CDS 1204 // Load a class for boot loader from the shared spaces. This also 1205 // forces the super class and all interfaces to be loaded. 1206 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name, 1207 PackageEntry* pkg_entry, 1208 TRAPS) { 1209 assert(UseSharedSpaces, "Sanity check"); 1210 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name); 1211 if (ik != NULL && ik->is_shared_boot_class()) { 1212 return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD); 1213 } 1214 return NULL; 1215 } 1216 1217 // For shared case, if -Xbootclasspath/a: and --module-path not specified 1218 // don't need check class visibility for builtin loaders. 1219 bool continue_check_shared_class_visibility() { 1220 static int check_continue = -1; 1221 if (check_continue == -1) { 1222 const char *classpath_append = Arguments::get_jdk_boot_class_path_append(); 1223 const char *module_path = Arguments::get_property("jdk.module.path"); 1224 log_info(cds)("-Xbootclasspath/a: = %s", classpath_append == NULL ? "nil" : classpath_append); 1225 log_info(cds)("jdk.module.path = %s", module_path == NULL ? "nil" : module_path); 1226 if ((classpath_append == NULL || strlen(classpath_append) == 0) && module_path == NULL) { 1227 check_continue = 0; 1228 } else { 1229 check_continue = 1; 1230 } 1231 } 1232 return check_continue == 1; 1233 } 1234 1235 1236 // Check if a shared class can be loaded by the specific classloader: 1237 // 1238 // NULL classloader: 1239 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader. 1240 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must 1241 // be defined in an unnamed module. 1242 bool SystemDictionary::is_shared_class_visible(Symbol* class_name, 1243 InstanceKlass* ik, 1244 PackageEntry* pkg_entry, 1245 Handle class_loader, TRAPS) { 1246 bool cont = continue_check_shared_class_visibility(); 1247 #ifdef ASSERT 1248 if (!cont) { 1249 assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD), "Sanity check"); 1250 } 1251 #endif 1252 if (!cont) { 1253 return true; 1254 } 1255 return is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD); 1256 } 1257 1258 bool SystemDictionary::is_shared_class_visible_impl(Symbol* class_name, 1259 InstanceKlass* ik, 1260 PackageEntry* pkg_entry, 1261 Handle class_loader, TRAPS) { 1262 1263 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), 1264 "Cannot use sharing if java.base is patched"); 1265 ResourceMark rm(THREAD); 1266 int path_index = ik->shared_classpath_index(); 1267 ClassLoaderData* loader_data = class_loader_data(class_loader); 1268 if (path_index < 0) { 1269 // path_index < 0 indicates that the class is intended for a custom loader 1270 // and should not be loaded by boot/platform/app loaders 1271 if (loader_data->is_builtin_class_loader_data()) { 1272 return false; 1273 } else { 1274 return true; 1275 } 1276 } 1277 SharedClassPathEntry* ent = 1278 (SharedClassPathEntry*)FileMapInfo::shared_path(path_index); 1279 if (!Universe::is_module_initialized()) { 1280 assert(ent != NULL && ent->is_modules_image(), 1281 "Loading non-bootstrap classes before the module system is initialized"); 1282 assert(class_loader.is_null(), "sanity"); 1554 // a named package within the unnamed module. In all cases, 1555 // limit visibility to search for the class only in the boot 1556 // loader's append path. 1557 if (!ClassLoader::has_bootclasspath_append()) { 1558 // If there is no bootclasspath append entry, no need to continue 1559 // searching. 1560 return NULL; 1561 } 1562 search_only_bootloader_append = true; 1563 } 1564 } 1565 1566 // Prior to bootstrapping's module initialization, never load a class outside 1567 // of the boot loader's module path 1568 assert(Universe::is_module_initialized() || 1569 !search_only_bootloader_append, 1570 "Attempt to load a class outside of boot loader's module path"); 1571 1572 // Search for classes in the CDS archive. 1573 InstanceKlass* k = NULL; 1574 1575 #if INCLUDE_CDS 1576 if (UseSharedSpaces) 1577 { 1578 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time()); 1579 k = load_shared_boot_class(class_name, pkg_entry, THREAD); 1580 } 1581 #endif 1582 1583 if (k == NULL) { 1584 // Use VM class loader 1585 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time()); 1586 k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL); 1587 } 1588 1589 // find_or_define_instance_class may return a different InstanceKlass 1590 if (k != NULL) { 1591 InstanceKlass* defined_k = 1592 find_or_define_instance_class(class_name, class_loader, k, THREAD); 1593 if (!HAS_PENDING_EXCEPTION && defined_k != k) { 1594 // If a parallel capable class loader already defined this class, register 'k' for cleanup. 1595 assert(defined_k != NULL, "Should have a klass if there's no exception"); 1596 loader_data->add_to_deallocate_list(k); 1597 k = defined_k; 1598 } else if (HAS_PENDING_EXCEPTION) { 1599 loader_data->add_to_deallocate_list(k); 1600 return NULL; 1601 } |