< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page
rev 59477 : [mq]: cds_lambda


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()) {


1348   // If unexpected superclass or interfaces are found, we cannot
1349   // load <ik> from the shared archive.
1350 
1351   if (ik->super() != NULL &&
1352       !check_shared_class_super_type(ik, InstanceKlass::cast(ik->super()),
1353                                      class_loader, protection_domain, true, THREAD)) {
1354     return false;
1355   }
1356 
1357   Array<InstanceKlass*>* interfaces = ik->local_interfaces();
1358   int num_interfaces = interfaces->length();
1359   for (int index = 0; index < num_interfaces; index++) {
1360     if (!check_shared_class_super_type(ik, interfaces->at(index), class_loader, protection_domain, false, THREAD)) {
1361       return false;
1362     }
1363   }
1364 
1365   return true;
1366 }
1367 


























1368 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1369                                                    Handle class_loader,
1370                                                    Handle protection_domain,
1371                                                    const ClassFileStream *cfs,
1372                                                    PackageEntry* pkg_entry,
1373                                                    TRAPS) {
1374   assert(ik != NULL, "sanity");
1375   assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1376   Symbol* class_name = ik->name();
1377 
1378   bool visible = is_shared_class_visible(
1379                           class_name, ik, pkg_entry, class_loader, CHECK_NULL);
1380   if (!visible) {
1381     return NULL;
1382   }
1383 
1384   if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
1385     return NULL;
1386   }
1387 
1388   InstanceKlass* new_ik = KlassFactory::check_shared_class_file_load_hook(


1389       ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);

1390   if (new_ik != NULL) {
1391     // The class is changed by CFLH. Return the new class. The shared class is
1392     // not used.
1393     return new_ik;
1394   }
1395 
1396   // Adjust methods to recover missing data.  They need addresses for
1397   // interpreter entry points and their default native method address
1398   // must be reset.
1399 
1400   // Updating methods must be done under a lock so multiple
1401   // threads don't update these in parallel
1402   //
1403   // Shared classes are all currently loaded by either the bootstrap or
1404   // internal parallel class loaders, so this will never cause a deadlock
1405   // on a custom class loader lock.
1406 
1407   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1408   {
1409     HandleMark hm(THREAD);
1410     Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1411     check_loader_lock_contention(lockObject, THREAD);
1412     ObjectLocker ol(lockObject, THREAD, true);
1413     // prohibited package check assumes all classes loaded from archive call
1414     // restore_unshareable_info which calls ik->set_package()
1415     ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1416   }
1417 
1418   load_shared_class_misc(ik, loader_data, CHECK_NULL);
1419   return ik;
1420 }
1421 
1422 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data, TRAPS) {
1423   ik->print_class_load_logging(loader_data, NULL, NULL);
1424 
1425   // For boot loader, ensure that GetSystemPackage knows that a class in this
1426   // package was loaded.
1427   if (loader_data->is_the_null_class_loader_data()) {
1428     int path_index = ik->shared_classpath_index();






1429     ik->set_classpath_index(path_index, THREAD);
1430   }
1431 
1432   if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
1433     // Only dump the classes that can be stored into CDS archive
1434     if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
1435       ResourceMark rm(THREAD);
1436       classlist_file->print_cr("%s", ik->name()->as_C_string());
1437       classlist_file->flush();
1438     }
1439   }
1440 
1441   // notify a class loaded from shared object
1442   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1443 
1444   ik->set_has_passed_fingerprint_check(false);
1445   if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
1446     uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
1447     uint64_t cds_fp = ik->get_stored_fingerprint();
1448     if (aot_fp != 0 && aot_fp == cds_fp) {




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
1255     // 1) the class is intended for a custom loader and should not be loaded by boot/platform/app loaders
1256     // or
1257     // 2) the class is a hidden lambda proxy class which would be loaded by boot/platform/app loaders
1258     if (loader_data->is_builtin_class_loader_data()) {
1259       if (!SystemDictionaryShared::is_hidden_lambda_proxy(ik)) {
1260         return false;
1261       } else {
1262         return true;
1263       }
1264     } else {
1265       return true;
1266     }
1267   }
1268   SharedClassPathEntry* ent =
1269             (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
1270   if (!Universe::is_module_initialized()) {
1271     assert(ent != NULL && ent->is_modules_image(),
1272            "Loading non-bootstrap classes before the module system is initialized");
1273     assert(class_loader.is_null(), "sanity");
1274     return true;
1275   }
1276   // Get the pkg_entry from the classloader
1277   ModuleEntry* mod_entry = NULL;
1278   TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() :
1279                                                ClassLoader::package_from_class_name(class_name);
1280   if (pkg_name != NULL) {
1281     if (loader_data != NULL) {
1282       if (pkg_entry != NULL) {
1283         mod_entry = pkg_entry->module();
1284         // If the archived class is from a module that has been patched at runtime,
1285         // the class cannot be loaded from the archive.
1286         if (mod_entry != NULL && mod_entry->is_patched()) {


1354   // If unexpected superclass or interfaces are found, we cannot
1355   // load <ik> from the shared archive.
1356 
1357   if (ik->super() != NULL &&
1358       !check_shared_class_super_type(ik, InstanceKlass::cast(ik->super()),
1359                                      class_loader, protection_domain, true, THREAD)) {
1360     return false;
1361   }
1362 
1363   Array<InstanceKlass*>* interfaces = ik->local_interfaces();
1364   int num_interfaces = interfaces->length();
1365   for (int index = 0; index < num_interfaces; index++) {
1366     if (!check_shared_class_super_type(ik, interfaces->at(index), class_loader, protection_domain, false, THREAD)) {
1367       return false;
1368     }
1369   }
1370 
1371   return true;
1372 }
1373 
1374 InstanceKlass* SystemDictionary::load_shared_lambda_proxy_class(InstanceKlass* ik,
1375                                                                 Handle class_loader,
1376                                                                 Handle protection_domain,
1377                                                                 PackageEntry* pkg_entry,
1378                                                                 TRAPS) {
1379   InstanceKlass* shared_n_h = SystemDictionaryShared::get_shared_nest_host(ik);
1380   assert(shared_n_h->is_shared(), "nest host must be in CDS archive");
1381   Symbol* cn = shared_n_h->name();
1382   Klass *s = resolve_or_fail(cn, class_loader, protection_domain, true, CHECK_NULL);
1383   if (s != shared_n_h) {
1384     // The dynamically resolved nest_host is not the same as the one we used during dump time,
1385     // so we cannot use ik.
1386     return NULL;
1387   } else {
1388     assert(s->is_shared(), "must be");
1389   }
1390 
1391   // The lambda proxy class and its nest host have the same class loader and class loader data,
1392   // as verified in SystemDictionaryShared::add_lambda_proxy_class()
1393   assert(shared_n_h->class_loader() == class_loader(), "mismatched class loader");
1394   assert(shared_n_h->class_loader_data() == ClassLoaderData::class_loader_data(class_loader()), "mismatched class loader data");
1395   ik->set_nest_host(shared_n_h, THREAD);
1396 
1397   return load_shared_class(ik, class_loader, protection_domain, NULL, pkg_entry, CHECK_NULL);
1398 }
1399 
1400 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1401                                                    Handle class_loader,
1402                                                    Handle protection_domain,
1403                                                    const ClassFileStream *cfs,
1404                                                    PackageEntry* pkg_entry,
1405                                                    TRAPS) {
1406   assert(ik != NULL, "sanity");
1407   assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1408   Symbol* class_name = ik->name();
1409 
1410   bool visible = is_shared_class_visible(
1411                           class_name, ik, pkg_entry, class_loader, CHECK_NULL);
1412   if (!visible) {
1413     return NULL;
1414   }
1415 
1416   if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
1417     return NULL;
1418   }
1419 
1420   InstanceKlass* new_ik = NULL;
1421   if (!SystemDictionaryShared::is_hidden_lambda_proxy(ik)) {
1422     new_ik = KlassFactory::check_shared_class_file_load_hook(
1423       ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
1424   }
1425   if (new_ik != NULL) {
1426     // The class is changed by CFLH. Return the new class. The shared class is
1427     // not used.
1428     return new_ik;
1429   }
1430 
1431   // Adjust methods to recover missing data.  They need addresses for
1432   // interpreter entry points and their default native method address
1433   // must be reset.
1434 
1435   // Updating methods must be done under a lock so multiple
1436   // threads don't update these in parallel
1437   //
1438   // Shared classes are all currently loaded by either the bootstrap or
1439   // internal parallel class loaders, so this will never cause a deadlock
1440   // on a custom class loader lock.
1441 
1442   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1443   {
1444     HandleMark hm(THREAD);
1445     Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1446     check_loader_lock_contention(lockObject, THREAD);
1447     ObjectLocker ol(lockObject, THREAD, true);
1448     // prohibited package check assumes all classes loaded from archive call
1449     // restore_unshareable_info which calls ik->set_package()
1450     ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1451   }
1452 
1453   load_shared_class_misc(ik, loader_data, CHECK_NULL);
1454   return ik;
1455 }
1456 
1457 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data, TRAPS) {
1458   ik->print_class_load_logging(loader_data, NULL, NULL);
1459 
1460   // For boot loader, ensure that GetSystemPackage knows that a class in this
1461   // package was loaded.
1462   if (loader_data->is_the_null_class_loader_data()) {
1463     int path_index = ik->shared_classpath_index();
1464     if (path_index < 0) {
1465       if (SystemDictionaryShared::is_hidden_lambda_proxy(ik)) {
1466         InstanceKlass* nest_host = SystemDictionaryShared::get_shared_nest_host(ik);
1467         path_index = nest_host->shared_classpath_index();
1468       }
1469     }
1470     ik->set_classpath_index(path_index, THREAD);
1471   }
1472 
1473   if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
1474     // Only dump the classes that can be stored into CDS archive
1475     if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
1476       ResourceMark rm(THREAD);
1477       classlist_file->print_cr("%s", ik->name()->as_C_string());
1478       classlist_file->flush();
1479     }
1480   }
1481 
1482   // notify a class loaded from shared object
1483   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1484 
1485   ik->set_has_passed_fingerprint_check(false);
1486   if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
1487     uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
1488     uint64_t cds_fp = ik->get_stored_fingerprint();
1489     if (aot_fp != 0 && aot_fp == cds_fp) {


< prev index next >