--- old/src/hotspot/share/classfile/systemDictionary.cpp 2020-05-21 23:00:22.538586425 -0700 +++ new/src/hotspot/share/classfile/systemDictionary.cpp 2020-05-21 23:00:22.246575433 -0700 @@ -1206,6 +1206,7 @@ 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); @@ -1213,6 +1214,25 @@ return NULL; } +// For shared case, if -Xbootclasspath/a: and --module-path not specified +// don't need check class visibility for builtin loaders. +bool continue_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 ? "nil" : classpath_append); + log_info(cds)("jdk.module.path = %s", module_path == NULL ? "nil" : module_path); + if ((classpath_append == NULL || strlen(classpath_append) == 0) && module_path == NULL) { + 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: @@ -1223,6 +1243,23 @@ InstanceKlass* ik, PackageEntry* pkg_entry, Handle class_loader, TRAPS) { + bool cont = continue_check_shared_class_visibility(); +#ifdef ASSERT + if (!cont) { + assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD), "Sanity check"); + } +#endif + if (!cont) { + 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) { + assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), "Cannot use sharing if java.base is patched"); ResourceMark rm(THREAD); @@ -1534,12 +1571,14 @@ // 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 } +#endif if (k == NULL) { // Use VM class loader --- old/src/hotspot/share/classfile/systemDictionary.hpp 2020-05-21 23:00:23.118608257 -0700 +++ new/src/hotspot/share/classfile/systemDictionary.hpp 2020-05-21 23:00:22.814596814 -0700 @@ -631,6 +631,9 @@ static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik, PackageEntry* pkg_entry, Handle class_loader, TRAPS); + static bool is_shared_class_visible_impl(Symbol* class_name, InstanceKlass* ik, + PackageEntry* pkg_entry, + Handle class_loader, TRAPS); static bool check_shared_class_super_type(InstanceKlass* child, InstanceKlass* super, Handle class_loader, Handle protection_domain, bool is_superclass, TRAPS);