Skip to content

Commit 5564eff

Browse files
committed
8289763: Remove NULL check in CDSProtectionDomain::init_security_info()
Reviewed-by: ccheung, coleenp
1 parent a694e9e commit 5564eff

File tree

1 file changed

+51
-56
lines changed

1 file changed

+51
-56
lines changed

src/hotspot/share/cds/cdsProtectionDomain.cpp

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -47,66 +47,61 @@ OopHandle CDSProtectionDomain::_shared_jar_manifests;
4747
// the given InstanceKlass.
4848
// Returns the ProtectionDomain for the InstanceKlass.
4949
Handle CDSProtectionDomain::init_security_info(Handle class_loader, InstanceKlass* ik, PackageEntry* pkg_entry, TRAPS) {
50-
Handle pd;
50+
int index = ik->shared_classpath_index();
51+
assert(index >= 0, "Sanity");
52+
SharedClassPathEntry* ent = FileMapInfo::shared_path(index);
53+
Symbol* class_name = ik->name();
5154

52-
if (ik != NULL) {
53-
int index = ik->shared_classpath_index();
54-
assert(index >= 0, "Sanity");
55-
SharedClassPathEntry* ent = FileMapInfo::shared_path(index);
56-
Symbol* class_name = ik->name();
57-
58-
if (ent->is_modules_image()) {
59-
// For shared app/platform classes originated from the run-time image:
60-
// The ProtectionDomains are cached in the corresponding ModuleEntries
61-
// for fast access by the VM.
62-
// all packages from module image are already created during VM bootstrap in
63-
// Modules::define_module().
64-
assert(pkg_entry != NULL, "archived class in module image cannot be from unnamed package");
65-
ModuleEntry* mod_entry = pkg_entry->module();
66-
pd = get_shared_protection_domain(class_loader, mod_entry, CHECK_(pd));
67-
} else {
68-
// For shared app/platform classes originated from JAR files on the class path:
69-
// Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length
70-
// as the shared classpath table in the shared archive (see
71-
// FileMap::_shared_path_table in filemap.hpp for details).
72-
//
73-
// If a shared InstanceKlass k is loaded from the class path, let
74-
//
75-
// index = k->shared_classpath_index():
76-
//
77-
// FileMap::_shared_path_table[index] identifies the JAR file that contains k.
78-
//
79-
// k's protection domain is:
80-
//
81-
// ProtectionDomain pd = _shared_protection_domains[index];
82-
//
83-
// and k's Package is initialized using
84-
//
85-
// manifest = _shared_jar_manifests[index];
86-
// url = _shared_jar_urls[index];
87-
// define_shared_package(class_name, class_loader, manifest, url, CHECK_(pd));
88-
//
89-
// Note that if an element of these 3 _shared_xxx arrays is NULL, it will be initialized by
90-
// the corresponding SystemDictionaryShared::get_shared_xxx() function.
91-
Handle manifest = get_shared_jar_manifest(index, CHECK_(pd));
92-
Handle url = get_shared_jar_url(index, CHECK_(pd));
93-
int index_offset = index - ClassLoaderExt::app_class_paths_start_index();
94-
if (index_offset < PackageEntry::max_index_for_defined_in_class_path()) {
95-
if (pkg_entry == NULL || !pkg_entry->is_defined_by_cds_in_class_path(index_offset)) {
96-
// define_shared_package only needs to be called once for each package in a jar specified
97-
// in the shared class path.
98-
define_shared_package(class_name, class_loader, manifest, url, CHECK_(pd));
99-
if (pkg_entry != NULL) {
100-
pkg_entry->set_defined_by_cds_in_class_path(index_offset);
101-
}
55+
if (ent->is_modules_image()) {
56+
// For shared app/platform classes originated from the run-time image:
57+
// The ProtectionDomains are cached in the corresponding ModuleEntries
58+
// for fast access by the VM.
59+
// all packages from module image are already created during VM bootstrap in
60+
// Modules::define_module().
61+
assert(pkg_entry != NULL, "archived class in module image cannot be from unnamed package");
62+
ModuleEntry* mod_entry = pkg_entry->module();
63+
return get_shared_protection_domain(class_loader, mod_entry, THREAD);
64+
} else {
65+
// For shared app/platform classes originated from JAR files on the class path:
66+
// Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length
67+
// as the shared classpath table in the shared archive (see
68+
// FileMap::_shared_path_table in filemap.hpp for details).
69+
//
70+
// If a shared InstanceKlass k is loaded from the class path, let
71+
//
72+
// index = k->shared_classpath_index():
73+
//
74+
// FileMap::_shared_path_table[index] identifies the JAR file that contains k.
75+
//
76+
// k's protection domain is:
77+
//
78+
// ProtectionDomain pd = _shared_protection_domains[index];
79+
//
80+
// and k's Package is initialized using
81+
//
82+
// manifest = _shared_jar_manifests[index];
83+
// url = _shared_jar_urls[index];
84+
// define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
85+
//
86+
// Note that if an element of these 3 _shared_xxx arrays is NULL, it will be initialized by
87+
// the corresponding SystemDictionaryShared::get_shared_xxx() function.
88+
Handle manifest = get_shared_jar_manifest(index, CHECK_NH);
89+
Handle url = get_shared_jar_url(index, CHECK_NH);
90+
int index_offset = index - ClassLoaderExt::app_class_paths_start_index();
91+
if (index_offset < PackageEntry::max_index_for_defined_in_class_path()) {
92+
if (pkg_entry == NULL || !pkg_entry->is_defined_by_cds_in_class_path(index_offset)) {
93+
// define_shared_package only needs to be called once for each package in a jar specified
94+
// in the shared class path.
95+
define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
96+
if (pkg_entry != NULL) {
97+
pkg_entry->set_defined_by_cds_in_class_path(index_offset);
10298
}
103-
} else {
104-
define_shared_package(class_name, class_loader, manifest, url, CHECK_(pd));
10599
}
106-
pd = get_shared_protection_domain(class_loader, index, url, CHECK_(pd));
100+
} else {
101+
define_shared_package(class_name, class_loader, manifest, url, CHECK_NH);
107102
}
103+
return get_shared_protection_domain(class_loader, index, url, THREAD);
108104
}
109-
return pd;
110105
}
111106

112107
Handle CDSProtectionDomain::get_package_name(Symbol* class_name, TRAPS) {

0 commit comments

Comments
 (0)