< prev index next >
src/hotspot/share/classfile/systemDictionary.cpp
Print this page
*** 1226,1242 ****
--- 1226,1264 ----
// Load a class for boot loader from the shared spaces. This also
// forces the super class and all interfaces to be loaded.
InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
PackageEntry* pkg_entry,
TRAPS) {
+ assert(UseSharedSpaces, "Sanity check");
InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
if (ik != NULL && ik->is_shared_boot_class()) {
return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD);
}
return NULL;
}
+ // Check if
+ // 1) -Xbootclasspath/a: specified or
+ // 2) --module-path at runtime
+ // so avoid checking class visibility for builtin loaders.
+ bool need_to_check_shared_class_visibility() {
+ static int check_continue = -1;
+ if (check_continue == -1) {
+ const char *classpath_append = Arguments::get_jdk_boot_class_path_append();
+ const char *module_path = Arguments::get_property("jdk.module.path");
+ log_info(cds)("-Xbootclasspath/a: = %s", classpath_append != NULL ? classpath_append : "nil");
+ log_info(cds)("--module-path = %s", module_path != NULL ? module_path : "nil");
+ if ((classpath_append == NULL || strlen(classpath_append) == 0) &&
+ (module_path == NULL || strlen(module_path) == 0)) {
+ check_continue = 0;
+ } else {
+ check_continue = 1;
+ }
+ }
+ return check_continue == 1;
+ }
+
// Check if a shared class can be loaded by the specific classloader:
//
// NULL classloader:
// - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
// - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
*** 1245,1266 ****
InstanceKlass* ik,
PackageEntry* pkg_entry,
Handle class_loader, TRAPS) {
assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
"Cannot use sharing if java.base is patched");
! ResourceMark rm(THREAD);
! int path_index = ik->shared_classpath_index();
! ClassLoaderData* loader_data = class_loader_data(class_loader);
! if (path_index < 0) {
// path_index < 0 indicates that the class is intended for a custom loader
// and should not be loaded by boot/platform/app loaders
! if (loader_data->is_builtin_class_loader_data()) {
return false;
} else {
return true;
}
}
SharedClassPathEntry* ent =
(SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
if (!Universe::is_module_initialized()) {
assert(ent != NULL && ent->is_modules_image(),
"Loading non-bootstrap classes before the module system is initialized");
--- 1267,1299 ----
InstanceKlass* ik,
PackageEntry* pkg_entry,
Handle class_loader, TRAPS) {
assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
"Cannot use sharing if java.base is patched");
! if (ik->shared_classpath_index() < 0) {
// path_index < 0 indicates that the class is intended for a custom loader
// and should not be loaded by boot/platform/app loaders
! if (is_builtin_class_loader(class_loader())) {
return false;
} else {
return true;
}
}
+ bool cont = need_to_check_shared_class_visibility();
+ if (!cont) {
+ assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD), "Sanity check");
+ return true;
+ }
+ return is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD);
+ }
+
+ bool SystemDictionary::is_shared_class_visible_impl(Symbol* class_name,
+ InstanceKlass* ik,
+ PackageEntry* pkg_entry,
+ Handle class_loader, TRAPS) {
+ ClassLoaderData* loader_data = class_loader_data(class_loader);
+ int path_index = ik->shared_classpath_index();
SharedClassPathEntry* ent =
(SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
if (!Universe::is_module_initialized()) {
assert(ent != NULL && ent->is_modules_image(),
"Loading non-bootstrap classes before the module system is initialized");
*** 1554,1569 ****
!search_only_bootloader_append,
"Attempt to load a class outside of boot loader's module path");
// Search for classes in the CDS archive.
InstanceKlass* k = NULL;
! {
#if INCLUDE_CDS
PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
k = load_shared_boot_class(class_name, pkg_entry, THREAD);
- #endif
}
if (k == NULL) {
// Use VM class loader
PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
--- 1587,1604 ----
!search_only_bootloader_append,
"Attempt to load a class outside of boot loader's module path");
// Search for classes in the CDS archive.
InstanceKlass* k = NULL;
!
#if INCLUDE_CDS
+ if (UseSharedSpaces)
+ {
PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
k = load_shared_boot_class(class_name, pkg_entry, THREAD);
}
+ #endif
if (k == NULL) {
// Use VM class loader
PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
< prev index next >