1234 instanceKlassHandle SystemDictionary::load_shared_class( |
1237 instanceKlassHandle SystemDictionary::load_shared_class( |
1235 Symbol* class_name, Handle class_loader, TRAPS) { |
1238 Symbol* class_name, Handle class_loader, TRAPS) { |
1236 instanceKlassHandle ik (THREAD, find_shared_class(class_name)); |
1239 instanceKlassHandle ik (THREAD, find_shared_class(class_name)); |
1237 // Make sure we only return the boot class for the NULL classloader. |
1240 // Make sure we only return the boot class for the NULL classloader. |
1238 if (ik.not_null() && |
1241 if (ik.not_null() && |
1239 SharedClassUtil::is_shared_boot_class(ik()) && class_loader.is_null()) { |
1242 ik->is_shared_boot_class() && class_loader.is_null()) { |
1240 Handle protection_domain; |
1243 Handle protection_domain; |
1241 return load_shared_class(ik, class_loader, protection_domain, THREAD); |
1244 return load_shared_class(ik, class_loader, protection_domain, THREAD); |
1242 } |
1245 } |
1243 return instanceKlassHandle(); |
1246 return instanceKlassHandle(); |
|
1247 } |
|
1248 |
|
1249 // Check if a shared class can be loaded by the specific classloader: |
|
1250 // |
|
1251 // NULL classloader: |
|
1252 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader. |
|
1253 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must |
|
1254 // be defined in an unnamed module. |
|
1255 bool SystemDictionary::is_shared_class_visible(Symbol* class_name, |
|
1256 instanceKlassHandle ik, |
|
1257 Handle class_loader, TRAPS) { |
|
1258 int path_index = ik->shared_classpath_index(); |
|
1259 SharedClassPathEntry* ent = |
|
1260 (SharedClassPathEntry*)FileMapInfo::shared_classpath(path_index); |
|
1261 if (!Universe::is_module_initialized()) { |
|
1262 assert(ent->is_jrt(), |
|
1263 "Loading non-bootstrap classes before the module system is initialized"); |
|
1264 assert(class_loader.is_null(), "sanity"); |
|
1265 return true; |
|
1266 } |
|
1267 // Get the pkg_entry from the classloader |
|
1268 TempNewSymbol pkg_name = NULL; |
|
1269 PackageEntry* pkg_entry = NULL; |
|
1270 ModuleEntry* mod_entry = NULL; |
|
1271 int length = 0; |
|
1272 ClassLoaderData* loader_data = class_loader_data(class_loader); |
|
1273 const jbyte* pkg_string = InstanceKlass::package_from_name(class_name, length); |
|
1274 if (pkg_string != NULL) { |
|
1275 pkg_name = SymbolTable::new_symbol((const char*)pkg_string, |
|
1276 length, CHECK_(false)); |
|
1277 if (loader_data != NULL) { |
|
1278 pkg_entry = loader_data->packages()->lookup_only(pkg_name); |
|
1279 } |
|
1280 if (pkg_entry != NULL) { |
|
1281 mod_entry = pkg_entry->module(); |
|
1282 } |
|
1283 } |
|
1284 |
|
1285 if (class_loader.is_null()) { |
|
1286 // The NULL classloader can load archived class originated from the |
|
1287 // "modules" jimage and the -Xbootclasspath/a. For class from the |
|
1288 // "modules" jimage, the PackageEntry/ModuleEntry must be defined |
|
1289 // by the NULL classloader. |
|
1290 if (mod_entry != NULL) { |
|
1291 // PackageEntry/ModuleEntry is found in the classloader. Check if the |
|
1292 // ModuleEntry's location agrees with the archived class' origination. |
|
1293 if (ent->is_jrt() && mod_entry->location()->starts_with("jrt:")) { |
|
1294 return true; // Module class from the "module" jimage |
|
1295 } |
|
1296 } |
|
1297 |
|
1298 // If the archived class is not from the "module" jimage, the class can be |
|
1299 // loaded by the NULL classloader if |
|
1300 // |
|
1301 // 1. the class is from the unamed package |
|
1302 // 2. or, the class is not from a module defined in the NULL classloader |
|
1303 // 3. or, the class is from an unamed module |
|
1304 if (!ent->is_jrt() && ik->is_shared_boot_class()) { |
|
1305 // the class is from the -Xbootclasspath/a |
|
1306 if (pkg_string == NULL || |
|
1307 pkg_entry == NULL || |
|
1308 pkg_entry->in_unnamed_module()) { |
|
1309 assert(mod_entry == NULL || |
|
1310 mod_entry == loader_data->modules()->unnamed_module(), |
|
1311 "the unnamed module is not defined in the classloader"); |
|
1312 return true; |
|
1313 } |
|
1314 } |
|
1315 return false; |
|
1316 } else { |
|
1317 bool res = SystemDictionaryShared::is_shared_class_visible_for_classloader( |
|
1318 ik, class_loader, pkg_string, pkg_name, |
|
1319 pkg_entry, mod_entry, CHECK_(false)); |
|
1320 return res; |
|
1321 } |
1244 } |
1322 } |
1245 |
1323 |
1246 instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik, |
1324 instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik, |
1247 Handle class_loader, |
1325 Handle class_loader, |
1248 Handle protection_domain, TRAPS) { |
1326 Handle protection_domain, TRAPS) { |
1249 if (ik.not_null()) { |
1327 if (ik.not_null()) { |
1250 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1328 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1251 Symbol* class_name = ik->name(); |
1329 Symbol* class_name = ik->name(); |
|
1330 |
|
1331 bool visible = is_shared_class_visible( |
|
1332 class_name, ik, class_loader, CHECK_(nh)); |
|
1333 if (!visible) { |
|
1334 return nh; |
|
1335 } |
1252 |
1336 |
1253 // Found the class, now load the superclass and interfaces. If they |
1337 // Found the class, now load the superclass and interfaces. If they |
1254 // are shared, add them to the main system dictionary and reset |
1338 // are shared, add them to the main system dictionary and reset |
1255 // their hierarchy references (supers, subs, and interfaces). |
1339 // their hierarchy references (supers, subs, and interfaces). |
1256 |
1340 |
1301 ObjectLocker ol(lockObject, THREAD, true); |
1385 ObjectLocker ol(lockObject, THREAD, true); |
1302 ik->restore_unshareable_info(loader_data, protection_domain, CHECK_(nh)); |
1386 ik->restore_unshareable_info(loader_data, protection_domain, CHECK_(nh)); |
1303 } |
1387 } |
1304 |
1388 |
1305 if (log_is_enabled(Info, classload)) { |
1389 if (log_is_enabled(Info, classload)) { |
1306 ik()->print_loading_log(LogLevel::Info, loader_data, NULL); |
1390 ik()->print_loading_log(LogLevel::Info, loader_data, NULL, NULL); |
1307 } |
1391 } |
1308 // No 'else' here as logging levels are not mutually exclusive |
1392 // No 'else' here as logging levels are not mutually exclusive |
1309 |
1393 |
1310 if (log_is_enabled(Debug, classload)) { |
1394 if (log_is_enabled(Debug, classload)) { |
1311 ik()->print_loading_log(LogLevel::Debug, loader_data, NULL); |
1395 ik()->print_loading_log(LogLevel::Debug, loader_data, NULL, NULL); |
|
1396 } |
|
1397 |
|
1398 // For boot loader, ensure that GetSystemPackage knows that a class in this |
|
1399 // package was loaded. |
|
1400 if (class_loader.is_null()) { |
|
1401 int path_index = ik->shared_classpath_index(); |
|
1402 ResourceMark rm; |
|
1403 ClassLoader::add_package(ik->name()->as_C_string(), path_index, THREAD); |
1312 } |
1404 } |
1313 |
1405 |
1314 if (DumpLoadedClassList != NULL && classlist_file->is_open()) { |
1406 if (DumpLoadedClassList != NULL && classlist_file->is_open()) { |
1315 // Only dump the classes that can be stored into CDS archive |
1407 // Only dump the classes that can be stored into CDS archive |
1316 if (SystemDictionaryShared::is_sharing_possible(loader_data)) { |
1408 if (SystemDictionaryShared::is_sharing_possible(loader_data)) { |
1327 } |
1419 } |
1328 #endif // INCLUDE_CDS |
1420 #endif // INCLUDE_CDS |
1329 |
1421 |
1330 instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) { |
1422 instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) { |
1331 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
1423 instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
|
1424 |
1332 if (class_loader.is_null()) { |
1425 if (class_loader.is_null()) { |
|
1426 int length = 0; |
|
1427 PackageEntry* pkg_entry = NULL; |
|
1428 bool search_only_bootloader_append = false; |
|
1429 ClassLoaderData *loader_data = class_loader_data(class_loader); |
|
1430 |
|
1431 // Find the package in the boot loader's package entry table. |
|
1432 const jbyte* pkg_string = InstanceKlass::package_from_name(class_name, length); |
|
1433 if (pkg_string != NULL) { |
|
1434 TempNewSymbol pkg_name = SymbolTable::new_symbol((const char*)pkg_string, length, CHECK_(nh)); |
|
1435 pkg_entry = loader_data->packages()->lookup_only(pkg_name); |
|
1436 } |
|
1437 |
|
1438 // Prior to attempting to load the class, enforce the boot loader's |
|
1439 // visibility boundaries. |
|
1440 if (!Universe::is_module_initialized()) { |
|
1441 // During bootstrapping, prior to module initialization, any |
|
1442 // class attempting to be loaded must be checked against the |
|
1443 // java.base packages in the boot loader's PackageEntryTable. |
|
1444 // No class outside of java.base is allowed to be loaded during |
|
1445 // this bootstrapping window. |
|
1446 if (!DumpSharedSpaces) { |
|
1447 if (pkg_entry == NULL || pkg_entry->in_unnamed_module()) { |
|
1448 // Class is either in the unnamed package or in |
|
1449 // a named package within the unnamed module. Either |
|
1450 // case is outside of java.base, do not attempt to |
|
1451 // load the class post java.base definition. If |
|
1452 // java.base has not been defined, let the class load |
|
1453 // and its package will be checked later by |
|
1454 // ModuleEntryTable::verify_javabase_packages. |
|
1455 if (ModuleEntryTable::javabase_defined()) { |
|
1456 return nh; |
|
1457 } |
|
1458 } else { |
|
1459 // Check that the class' package is defined within java.base. |
|
1460 ModuleEntry* mod_entry = pkg_entry->module(); |
|
1461 Symbol* mod_entry_name = mod_entry->name(); |
|
1462 if (mod_entry_name->fast_compare(vmSymbols::java_base()) != 0) { |
|
1463 return nh; |
|
1464 } |
|
1465 } |
|
1466 } |
|
1467 } else { |
|
1468 assert(!DumpSharedSpaces, "Archive dumped after module system initialization"); |
|
1469 // After the module system has been initialized, check if the class' |
|
1470 // package is in a module defined to the boot loader. |
|
1471 if (pkg_string == NULL || pkg_entry == NULL || pkg_entry->in_unnamed_module()) { |
|
1472 // Class is either in the unnamed package, in a named package |
|
1473 // within a module not defined to the boot loader or in a |
|
1474 // a named package within the unnamed module. In all cases, |
|
1475 // limit visibility to search for the class only in the boot |
|
1476 // loader's append path. |
|
1477 search_only_bootloader_append = true; |
|
1478 } |
|
1479 } |
|
1480 |
|
1481 // Prior to bootstrapping's module initialization, never load a class outside |
|
1482 // of the boot loader's module path |
|
1483 assert(Universe::is_module_initialized() || DumpSharedSpaces || |
|
1484 !search_only_bootloader_append, |
|
1485 "Attempt to load a class outside of boot loader's module path"); |
1333 |
1486 |
1334 // Search the shared system dictionary for classes preloaded into the |
1487 // Search the shared system dictionary for classes preloaded into the |
1335 // shared spaces. |
1488 // shared spaces. |
1336 instanceKlassHandle k; |
1489 instanceKlassHandle k; |
1337 { |
1490 { |
1938 start_id = limit_id; |
2091 start_id = limit_id; |
1939 } |
2092 } |
1940 |
2093 |
1941 void SystemDictionary::initialize_preloaded_classes(TRAPS) { |
2094 void SystemDictionary::initialize_preloaded_classes(TRAPS) { |
1942 assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once"); |
2095 assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once"); |
|
2096 |
|
2097 // Create the ModuleEntry for java.base. This call needs to be done here, |
|
2098 // after vmSymbols::initialize() is called but before any classes are pre-loaded. |
|
2099 ClassLoader::create_javabase(); |
|
2100 |
1943 // Preload commonly used klasses |
2101 // Preload commonly used klasses |
1944 WKID scan = FIRST_WKID; |
2102 WKID scan = FIRST_WKID; |
1945 // first do Object, then String, Class |
2103 // first do Object, then String, Class |
1946 if (UseSharedSpaces) { |
2104 if (UseSharedSpaces) { |
1947 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK); |
2105 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK); |