diff --git a/src/hotspot/share/cds/cdsProtectionDomain.cpp b/src/hotspot/share/cds/cdsProtectionDomain.cpp index a4ffeea26dc..2eb47ff2788 100644 --- a/src/hotspot/share/cds/cdsProtectionDomain.cpp +++ b/src/hotspot/share/cds/cdsProtectionDomain.cpp @@ -199,17 +199,9 @@ Handle CDSProtectionDomain::get_shared_jar_manifest(int shared_path_index, TRAPS Handle CDSProtectionDomain::get_shared_jar_url(int shared_path_index, TRAPS) { Handle url_h; if (shared_jar_url(shared_path_index) == nullptr) { - JavaValue result(T_OBJECT); const char* path = FileMapInfo::shared_path_name(shared_path_index); - Handle path_string = java_lang_String::create_from_str(path, CHECK_(url_h)); - Klass* classLoaders_klass = - vmClasses::jdk_internal_loader_ClassLoaders_klass(); - JavaCalls::call_static(&result, classLoaders_klass, - vmSymbols::toFileURL_name(), - vmSymbols::toFileURL_signature(), - path_string, CHECK_(url_h)); - - atomic_set_shared_jar_url(shared_path_index, result.get_oop()); + oop result_oop = to_file_URL(path, url_h, CHECK_(url_h)); + atomic_set_shared_jar_url(shared_path_index, result_oop); } url_h = Handle(THREAD, shared_jar_url(shared_path_index)); @@ -217,6 +209,17 @@ Handle CDSProtectionDomain::get_shared_jar_url(int shared_path_index, TRAPS) { return url_h; } +oop CDSProtectionDomain::to_file_URL(const char* path, Handle url_h, TRAPS) { + JavaValue result(T_OBJECT); + Handle path_string = java_lang_String::create_from_str(path, CHECK_NULL); + JavaCalls::call_static(&result, + vmClasses::jdk_internal_loader_ClassLoaders_klass(), + vmSymbols::toFileURL_name(), + vmSymbols::toFileURL_signature(), + path_string, CHECK_NULL); + return result.get_oop(); +} + // Get the ProtectionDomain associated with the CodeSource from the classloader. Handle CDSProtectionDomain::get_protection_domain_from_classloader(Handle class_loader, Handle url, TRAPS) { diff --git a/src/hotspot/share/cds/cdsProtectionDomain.hpp b/src/hotspot/share/cds/cdsProtectionDomain.hpp index 0e688fcfa00..baab4ab0e72 100644 --- a/src/hotspot/share/cds/cdsProtectionDomain.hpp +++ b/src/hotspot/share/cds/cdsProtectionDomain.hpp @@ -80,6 +80,7 @@ public: static Handle create_jar_manifest(const char* man, size_t size, TRAPS); static Handle get_shared_jar_manifest(int shared_path_index, TRAPS); static Handle get_shared_jar_url(int shared_path_index, TRAPS); + static oop to_file_URL(const char* path, Handle url_h, TRAPS); static Handle get_protection_domain_from_classloader(Handle class_loader, Handle url, TRAPS); static Handle get_shared_protection_domain(Handle class_loader, diff --git a/src/hotspot/share/cds/metaspaceShared.cpp b/src/hotspot/share/cds/metaspaceShared.cpp index 6f646e162ec..efd7a906a46 100644 --- a/src/hotspot/share/cds/metaspaceShared.cpp +++ b/src/hotspot/share/cds/metaspaceShared.cpp @@ -751,12 +751,21 @@ void MetaspaceShared::preload_classes(TRAPS) { } } - // Exercise the manifest processing code to ensure classes used by CDS at runtime - // are always archived + // Some classes are used at CDS runtime but are not loaded, and therefore archived, at + // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they + // are archived. + exercise_runtime_cds_code(CHECK); + + log_info(cds)("Loading classes to share: done."); +} + +void MetaspaceShared::exercise_runtime_cds_code(TRAPS) { + // Exercise the manifest processing code const char* dummy = "Manifest-Version: 1.0\n"; CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK); - log_info(cds)("Loading classes to share: done."); + // Exercise FileSystem and URL code + CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK); } void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) { @@ -799,16 +808,6 @@ void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS } #endif - // Dummy call to load classes used at CDS runtime - JavaValue result(T_OBJECT); - Handle path_string = java_lang_String::create_from_str("dummy.jar", CHECK); - JavaCalls::call_static(&result, - vmClasses::jdk_internal_loader_ClassLoaders_klass(), - vmSymbols::toFileURL_name(), - vmSymbols::toFileURL_signature(), - path_string, - CHECK); - VM_PopulateDumpSharedSpace op(builder); VMThread::execute(&op); diff --git a/src/hotspot/share/cds/metaspaceShared.hpp b/src/hotspot/share/cds/metaspaceShared.hpp index f26af21676a..ecc158cc3ef 100644 --- a/src/hotspot/share/cds/metaspaceShared.hpp +++ b/src/hotspot/share/cds/metaspaceShared.hpp @@ -75,6 +75,7 @@ class MetaspaceShared : AllStatic { #endif private: + static void exercise_runtime_cds_code(TRAPS) NOT_CDS_RETURN; static void preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) NOT_CDS_RETURN; static void preload_classes(TRAPS) NOT_CDS_RETURN; diff --git a/test/hotspot/jtreg/ProblemList-Xcomp.txt b/test/hotspot/jtreg/ProblemList-Xcomp.txt index 2e9b6da3828..1d3342f9b7e 100644 --- a/test/hotspot/jtreg/ProblemList-Xcomp.txt +++ b/test/hotspot/jtreg/ProblemList-Xcomp.txt @@ -56,6 +56,4 @@ compiler/cha/TypeProfileFinalMethod.java 8341039 generic-all gc/arguments/TestNewSizeFlags.java 8299116 macosx-aarch64 -runtime/cds/appcds/DumpRuntimeClassesTest.java 8341452 generic-all - runtime/condy/escapeAnalysis/TestEscapeCondy.java 8339694 generic-all diff --git a/test/hotspot/jtreg/runtime/cds/appcds/DumpRuntimeClassesTest.java b/test/hotspot/jtreg/runtime/cds/appcds/DumpRuntimeClassesTest.java index 2e530a8d6dd..c31d96b1c82 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/DumpRuntimeClassesTest.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/DumpRuntimeClassesTest.java @@ -27,6 +27,9 @@ * @summary Classes used by CDS at runtime should be in the archived * @bug 8324259 * @requires vm.cds + * @requires vm.compMode != "Xcomp" + * @comment Running this test with -Xcomp may load other classes which + * are not used in other modes * @library /test/lib * @compile test-classes/Hello.java * @run driver DumpRuntimeClassesTest