Skip to content

Commit b18626a

Browse files
committed
8231275: Remove null check in the beginning of SystemDictionary::load_shared_class()
Reviewed-by: ccheung, coleenp
1 parent 9c92ecb commit b18626a

File tree

1 file changed

+92
-93
lines changed

1 file changed

+92
-93
lines changed

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 92 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,117 +1268,116 @@ InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
12681268
Handle protection_domain,
12691269
const ClassFileStream *cfs,
12701270
TRAPS) {
1271+
assert(ik != NULL, "sanity");
1272+
assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1273+
Symbol* class_name = ik->name();
12711274

1272-
if (ik != NULL) {
1273-
assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1274-
Symbol* class_name = ik->name();
1275+
bool visible = is_shared_class_visible(
1276+
class_name, ik, class_loader, CHECK_NULL);
1277+
if (!visible) {
1278+
return NULL;
1279+
}
12751280

1276-
bool visible = is_shared_class_visible(
1277-
class_name, ik, class_loader, CHECK_NULL);
1278-
if (!visible) {
1281+
// Resolve the superclass and interfaces. They must be the same
1282+
// as in dump time, because the layout of <ik> depends on
1283+
// the specific layout of ik->super() and ik->local_interfaces().
1284+
//
1285+
// If unexpected superclass or interfaces are found, we cannot
1286+
// load <ik> from the shared archive.
1287+
1288+
if (ik->super() != NULL) {
1289+
Symbol* cn = ik->super()->name();
1290+
Klass *s = resolve_super_or_fail(class_name, cn,
1291+
class_loader, protection_domain, true, CHECK_NULL);
1292+
if (s != ik->super()) {
1293+
// The dynamically resolved super class is not the same as the one we used during dump time,
1294+
// so we cannot use ik.
12791295
return NULL;
1296+
} else {
1297+
assert(s->is_shared(), "must be");
12801298
}
1299+
}
12811300

1282-
// Resolve the superclass and interfaces. They must be the same
1283-
// as in dump time, because the layout of <ik> depends on
1284-
// the specific layout of ik->super() and ik->local_interfaces().
1285-
//
1286-
// If unexpected superclass or interfaces are found, we cannot
1287-
// load <ik> from the shared archive.
1288-
1289-
if (ik->super() != NULL) {
1290-
Symbol* cn = ik->super()->name();
1291-
Klass *s = resolve_super_or_fail(class_name, cn,
1292-
class_loader, protection_domain, true, CHECK_NULL);
1293-
if (s != ik->super()) {
1294-
// The dynamically resolved super class is not the same as the one we used during dump time,
1295-
// so we cannot use ik.
1296-
return NULL;
1297-
} else {
1298-
assert(s->is_shared(), "must be");
1299-
}
1300-
}
1301-
1302-
Array<InstanceKlass*>* interfaces = ik->local_interfaces();
1303-
int num_interfaces = interfaces->length();
1304-
for (int index = 0; index < num_interfaces; index++) {
1305-
InstanceKlass* k = interfaces->at(index);
1306-
Symbol* name = k->name();
1307-
Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL);
1308-
if (k != i) {
1309-
// The dynamically resolved interface class is not the same as the one we used during dump time,
1310-
// so we cannot use ik.
1311-
return NULL;
1312-
} else {
1313-
assert(i->is_shared(), "must be");
1314-
}
1301+
Array<InstanceKlass*>* interfaces = ik->local_interfaces();
1302+
int num_interfaces = interfaces->length();
1303+
for (int index = 0; index < num_interfaces; index++) {
1304+
InstanceKlass* k = interfaces->at(index);
1305+
Symbol* name = k->name();
1306+
Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL);
1307+
if (k != i) {
1308+
// The dynamically resolved interface class is not the same as the one we used during dump time,
1309+
// so we cannot use ik.
1310+
return NULL;
1311+
} else {
1312+
assert(i->is_shared(), "must be");
13151313
}
1314+
}
13161315

1317-
InstanceKlass* new_ik = KlassFactory::check_shared_class_file_load_hook(
1318-
ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
1319-
if (new_ik != NULL) {
1320-
// The class is changed by CFLH. Return the new class. The shared class is
1321-
// not used.
1322-
return new_ik;
1323-
}
1316+
InstanceKlass* new_ik = KlassFactory::check_shared_class_file_load_hook(
1317+
ik, class_name, class_loader, protection_domain, cfs, CHECK_NULL);
1318+
if (new_ik != NULL) {
1319+
// The class is changed by CFLH. Return the new class. The shared class is
1320+
// not used.
1321+
return new_ik;
1322+
}
13241323

1325-
// Adjust methods to recover missing data. They need addresses for
1326-
// interpreter entry points and their default native method address
1327-
// must be reset.
1324+
// Adjust methods to recover missing data. They need addresses for
1325+
// interpreter entry points and their default native method address
1326+
// must be reset.
13281327

1329-
// Updating methods must be done under a lock so multiple
1330-
// threads don't update these in parallel
1331-
//
1332-
// Shared classes are all currently loaded by either the bootstrap or
1333-
// internal parallel class loaders, so this will never cause a deadlock
1334-
// on a custom class loader lock.
1328+
// Updating methods must be done under a lock so multiple
1329+
// threads don't update these in parallel
1330+
//
1331+
// Shared classes are all currently loaded by either the bootstrap or
1332+
// internal parallel class loaders, so this will never cause a deadlock
1333+
// on a custom class loader lock.
13351334

1336-
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1337-
{
1338-
HandleMark hm(THREAD);
1339-
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1340-
check_loader_lock_contention(lockObject, THREAD);
1341-
ObjectLocker ol(lockObject, THREAD, true);
1342-
// prohibited package check assumes all classes loaded from archive call
1343-
// restore_unshareable_info which calls ik->set_package()
1344-
ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL);
1345-
}
1335+
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1336+
{
1337+
HandleMark hm(THREAD);
1338+
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1339+
check_loader_lock_contention(lockObject, THREAD);
1340+
ObjectLocker ol(lockObject, THREAD, true);
1341+
// prohibited package check assumes all classes loaded from archive call
1342+
// restore_unshareable_info which calls ik->set_package()
1343+
ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL);
1344+
}
13461345

1347-
ik->print_class_load_logging(loader_data, NULL, NULL);
1346+
ik->print_class_load_logging(loader_data, NULL, NULL);
13481347

1349-
// For boot loader, ensure that GetSystemPackage knows that a class in this
1350-
// package was loaded.
1351-
if (class_loader.is_null()) {
1352-
int path_index = ik->shared_classpath_index();
1353-
ResourceMark rm;
1354-
ClassLoader::add_package(ik->name()->as_C_string(), path_index, THREAD);
1355-
}
1348+
// For boot loader, ensure that GetSystemPackage knows that a class in this
1349+
// package was loaded.
1350+
if (class_loader.is_null()) {
1351+
int path_index = ik->shared_classpath_index();
1352+
ResourceMark rm;
1353+
ClassLoader::add_package(ik->name()->as_C_string(), path_index, THREAD);
1354+
}
13561355

1357-
if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
1358-
// Only dump the classes that can be stored into CDS archive
1359-
if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
1360-
ResourceMark rm(THREAD);
1361-
classlist_file->print_cr("%s", ik->name()->as_C_string());
1362-
classlist_file->flush();
1363-
}
1356+
if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
1357+
// Only dump the classes that can be stored into CDS archive
1358+
if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
1359+
ResourceMark rm(THREAD);
1360+
classlist_file->print_cr("%s", ik->name()->as_C_string());
1361+
classlist_file->flush();
13641362
}
1363+
}
13651364

1366-
// notify a class loaded from shared object
1367-
ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1365+
// notify a class loaded from shared object
1366+
ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
13681367

1369-
ik->set_has_passed_fingerprint_check(false);
1370-
if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
1371-
uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
1372-
uint64_t cds_fp = ik->get_stored_fingerprint();
1373-
if (aot_fp != 0 && aot_fp == cds_fp) {
1374-
// This class matches with a class saved in an AOT library
1375-
ik->set_has_passed_fingerprint_check(true);
1376-
} else {
1377-
ResourceMark rm;
1378-
log_info(class, fingerprint)("%s : expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
1379-
}
1368+
ik->set_has_passed_fingerprint_check(false);
1369+
if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
1370+
uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
1371+
uint64_t cds_fp = ik->get_stored_fingerprint();
1372+
if (aot_fp != 0 && aot_fp == cds_fp) {
1373+
// This class matches with a class saved in an AOT library
1374+
ik->set_has_passed_fingerprint_check(true);
1375+
} else {
1376+
ResourceMark rm;
1377+
log_info(class, fingerprint)("%s : expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
13801378
}
13811379
}
1380+
13821381
return ik;
13831382
}
13841383
#endif // INCLUDE_CDS

0 commit comments

Comments
 (0)