431 if (HAS_PENDING_EXCEPTION || superk == NULL) {
432 // can null superk
433 Klass* k = handle_resolution_exception(super_name, true, superk, THREAD);
434 assert(k == NULL || k == superk, "must be");
435 if (k == NULL) {
436 superk = NULL;
437 }
438 }
439
440 return superk;
441 }
442
443 void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
444 Handle class_loader,
445 Handle protection_domain,
446 TRAPS) {
447 // Now we have to call back to java to check if the initating class has access
448 JavaValue result(T_VOID);
449 LogTarget(Debug, protectiondomain) lt;
450 if (lt.is_enabled()) {
451 ResourceMark rm;
452 // Print out trace information
453 LogStream ls(lt);
454 ls.print_cr("Checking package access");
455 if (class_loader() != NULL) {
456 ls.print("class loader: ");
457 class_loader()->print_value_on(&ls);
458 } else {
459 ls.print_cr("class loader: NULL");
460 }
461 if (protection_domain() != NULL) {
462 ls.print(" protection domain: ");
463 protection_domain()->print_value_on(&ls);
464 } else {
465 ls.print_cr(" protection domain: NULL");
466 }
467 ls.print(" loading: "); klass->print_value_on(&ls);
468 ls.cr();
469 }
470
471 // This handle and the class_loader handle passed in keeps this class from
1159 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
1160 TRAPS) {
1161 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1162 if (ik != NULL && ik->is_shared_boot_class()) {
1163 return load_shared_class(ik, Handle(), Handle(), NULL, THREAD);
1164 }
1165 return NULL;
1166 }
1167
1168 // Check if a shared class can be loaded by the specific classloader:
1169 //
1170 // NULL classloader:
1171 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1172 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1173 // be defined in an unnamed module.
1174 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1175 InstanceKlass* ik,
1176 Handle class_loader, TRAPS) {
1177 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1178 "Cannot use sharing if java.base is patched");
1179 ResourceMark rm;
1180 int path_index = ik->shared_classpath_index();
1181 ClassLoaderData* loader_data = class_loader_data(class_loader);
1182 if (path_index < 0) {
1183 // path_index < 0 indicates that the class is intended for a custom loader
1184 // and should not be loaded by boot/platform/app loaders
1185 if (loader_data->is_builtin_class_loader_data()) {
1186 return false;
1187 } else {
1188 return true;
1189 }
1190 }
1191 SharedClassPathEntry* ent =
1192 (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
1193 if (!Universe::is_module_initialized()) {
1194 assert(ent != NULL && ent->is_modules_image(),
1195 "Loading non-bootstrap classes before the module system is initialized");
1196 assert(class_loader.is_null(), "sanity");
1197 return true;
1198 }
1199 // Get the pkg_entry from the classloader
1324 // internal parallel class loaders, so this will never cause a deadlock
1325 // on a custom class loader lock.
1326
1327 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1328 {
1329 HandleMark hm(THREAD);
1330 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1331 check_loader_lock_contention(lockObject, THREAD);
1332 ObjectLocker ol(lockObject, THREAD, true);
1333 // prohibited package check assumes all classes loaded from archive call
1334 // restore_unshareable_info which calls ik->set_package()
1335 ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL);
1336 }
1337
1338 ik->print_class_load_logging(loader_data, NULL, NULL);
1339
1340 // For boot loader, ensure that GetSystemPackage knows that a class in this
1341 // package was loaded.
1342 if (class_loader.is_null()) {
1343 int path_index = ik->shared_classpath_index();
1344 ResourceMark rm;
1345 ClassLoader::add_package(ik->name()->as_C_string(), path_index, THREAD);
1346 }
1347
1348 if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
1349 // Only dump the classes that can be stored into CDS archive
1350 if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
1351 ResourceMark rm(THREAD);
1352 classlist_file->print_cr("%s", ik->name()->as_C_string());
1353 classlist_file->flush();
1354 }
1355 }
1356
1357 // notify a class loaded from shared object
1358 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1359
1360 ik->set_has_passed_fingerprint_check(false);
1361 if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
1362 uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
1363 uint64_t cds_fp = ik->get_stored_fingerprint();
1364 if (aot_fp != 0 && aot_fp == cds_fp) {
1365 // This class matches with a class saved in an AOT library
1366 ik->set_has_passed_fingerprint_check(true);
1367 } else {
1368 ResourceMark rm;
1369 log_info(class, fingerprint)("%s : expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
1370 }
1371 }
1372
1373 return ik;
1374 }
1375 #endif // INCLUDE_CDS
1376
1377 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
1378
1379 if (class_loader.is_null()) {
1380 ResourceMark rm;
1381 PackageEntry* pkg_entry = NULL;
1382 bool search_only_bootloader_append = false;
1383 ClassLoaderData *loader_data = class_loader_data(class_loader);
1384
1385 // Find the package in the boot loader's package entry table.
1386 TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK_NULL);
1387 if (pkg_name != NULL) {
1388 pkg_entry = loader_data->packages()->lookup_only(pkg_name);
1389 }
1390
1391 // Prior to attempting to load the class, enforce the boot loader's
1392 // visibility boundaries.
1393 if (!Universe::is_module_initialized()) {
1394 // During bootstrapping, prior to module initialization, any
1395 // class attempting to be loaded must be checked against the
1396 // java.base packages in the boot loader's PackageEntryTable.
1397 // No class outside of java.base is allowed to be loaded during
1398 // this bootstrapping window.
1399 if (pkg_entry == NULL || pkg_entry->in_unnamed_module()) {
1400 // Class is either in the unnamed package or in
|
431 if (HAS_PENDING_EXCEPTION || superk == NULL) {
432 // can null superk
433 Klass* k = handle_resolution_exception(super_name, true, superk, THREAD);
434 assert(k == NULL || k == superk, "must be");
435 if (k == NULL) {
436 superk = NULL;
437 }
438 }
439
440 return superk;
441 }
442
443 void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
444 Handle class_loader,
445 Handle protection_domain,
446 TRAPS) {
447 // Now we have to call back to java to check if the initating class has access
448 JavaValue result(T_VOID);
449 LogTarget(Debug, protectiondomain) lt;
450 if (lt.is_enabled()) {
451 ResourceMark rm(THREAD);
452 // Print out trace information
453 LogStream ls(lt);
454 ls.print_cr("Checking package access");
455 if (class_loader() != NULL) {
456 ls.print("class loader: ");
457 class_loader()->print_value_on(&ls);
458 } else {
459 ls.print_cr("class loader: NULL");
460 }
461 if (protection_domain() != NULL) {
462 ls.print(" protection domain: ");
463 protection_domain()->print_value_on(&ls);
464 } else {
465 ls.print_cr(" protection domain: NULL");
466 }
467 ls.print(" loading: "); klass->print_value_on(&ls);
468 ls.cr();
469 }
470
471 // This handle and the class_loader handle passed in keeps this class from
1159 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
1160 TRAPS) {
1161 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1162 if (ik != NULL && ik->is_shared_boot_class()) {
1163 return load_shared_class(ik, Handle(), Handle(), NULL, THREAD);
1164 }
1165 return NULL;
1166 }
1167
1168 // Check if a shared class can be loaded by the specific classloader:
1169 //
1170 // NULL classloader:
1171 // - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1172 // - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1173 // be defined in an unnamed module.
1174 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1175 InstanceKlass* ik,
1176 Handle class_loader, TRAPS) {
1177 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1178 "Cannot use sharing if java.base is patched");
1179 ResourceMark rm(THREAD);
1180 int path_index = ik->shared_classpath_index();
1181 ClassLoaderData* loader_data = class_loader_data(class_loader);
1182 if (path_index < 0) {
1183 // path_index < 0 indicates that the class is intended for a custom loader
1184 // and should not be loaded by boot/platform/app loaders
1185 if (loader_data->is_builtin_class_loader_data()) {
1186 return false;
1187 } else {
1188 return true;
1189 }
1190 }
1191 SharedClassPathEntry* ent =
1192 (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
1193 if (!Universe::is_module_initialized()) {
1194 assert(ent != NULL && ent->is_modules_image(),
1195 "Loading non-bootstrap classes before the module system is initialized");
1196 assert(class_loader.is_null(), "sanity");
1197 return true;
1198 }
1199 // Get the pkg_entry from the classloader
1324 // internal parallel class loaders, so this will never cause a deadlock
1325 // on a custom class loader lock.
1326
1327 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1328 {
1329 HandleMark hm(THREAD);
1330 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1331 check_loader_lock_contention(lockObject, THREAD);
1332 ObjectLocker ol(lockObject, THREAD, true);
1333 // prohibited package check assumes all classes loaded from archive call
1334 // restore_unshareable_info which calls ik->set_package()
1335 ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL);
1336 }
1337
1338 ik->print_class_load_logging(loader_data, NULL, NULL);
1339
1340 // For boot loader, ensure that GetSystemPackage knows that a class in this
1341 // package was loaded.
1342 if (class_loader.is_null()) {
1343 int path_index = ik->shared_classpath_index();
1344 ResourceMark rm(THREAD);
1345 ClassLoader::add_package(ik->name()->as_C_string(), path_index, THREAD);
1346 }
1347
1348 if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
1349 // Only dump the classes that can be stored into CDS archive
1350 if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
1351 ResourceMark rm(THREAD);
1352 classlist_file->print_cr("%s", ik->name()->as_C_string());
1353 classlist_file->flush();
1354 }
1355 }
1356
1357 // notify a class loaded from shared object
1358 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1359
1360 ik->set_has_passed_fingerprint_check(false);
1361 if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
1362 uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
1363 uint64_t cds_fp = ik->get_stored_fingerprint();
1364 if (aot_fp != 0 && aot_fp == cds_fp) {
1365 // This class matches with a class saved in an AOT library
1366 ik->set_has_passed_fingerprint_check(true);
1367 } else {
1368 if (log_is_enabled(Info, class, fingerprint)) {
1369 ResourceMark rm(THREAD);
1370 log_info(class, fingerprint)("%s : expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
1371 }
1372 }
1373 }
1374
1375 return ik;
1376 }
1377 #endif // INCLUDE_CDS
1378
1379 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
1380
1381 if (class_loader.is_null()) {
1382 ResourceMark rm(THREAD);
1383 PackageEntry* pkg_entry = NULL;
1384 bool search_only_bootloader_append = false;
1385 ClassLoaderData *loader_data = class_loader_data(class_loader);
1386
1387 // Find the package in the boot loader's package entry table.
1388 TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK_NULL);
1389 if (pkg_name != NULL) {
1390 pkg_entry = loader_data->packages()->lookup_only(pkg_name);
1391 }
1392
1393 // Prior to attempting to load the class, enforce the boot loader's
1394 // visibility boundaries.
1395 if (!Universe::is_module_initialized()) {
1396 // During bootstrapping, prior to module initialization, any
1397 // class attempting to be loaded must be checked against the
1398 // java.base packages in the boot loader's PackageEntryTable.
1399 // No class outside of java.base is allowed to be loaded during
1400 // this bootstrapping window.
1401 if (pkg_entry == NULL || pkg_entry->in_unnamed_module()) {
1402 // Class is either in the unnamed package or in
|