--- old/src/hotspot/share/classfile/moduleEntry.cpp 2020-06-23 12:35:20.819198806 -0700 +++ new/src/hotspot/share/classfile/moduleEntry.cpp 2020-06-23 12:35:20.639192031 -0700 @@ -57,7 +57,7 @@ if (location != NULL) { location->increment_refcount(); CDS_ONLY(if (UseSharedSpaces) { - _shared_path_index = FileMapInfo::get_module_shared_path_index(_location); + _shared_path_index = FileMapInfo::get_module_shared_path_index(location); }); } } --- old/src/hotspot/share/classfile/moduleEntry.hpp 2020-06-23 12:35:21.655230276 -0700 +++ new/src/hotspot/share/classfile/moduleEntry.hpp 2020-06-23 12:35:21.411221091 -0700 @@ -69,7 +69,7 @@ GrowableArray* _reads; // list of modules that are readable by this module Symbol* _version; // module version number Symbol* _location; // module location - CDS_ONLY(int _shared_path_index;) // >0 if this classes in this module are in CDS archive + CDS_ONLY(int _shared_path_index;) // >=0 if classes in this module are in CDS archive bool _can_read_all_unnamed; bool _has_default_read_edges; // JVMTI redefine/retransform support bool _must_walk_reads; // walk module's reads list at GC safepoints to purge out dead modules @@ -156,6 +156,7 @@ void set_is_patched() { _is_patched = true; + CDS_ONLY(_shared_path_index = -1); // Mark all shared classes in this module invisible. } bool is_patched() { return _is_patched; --- old/src/hotspot/share/classfile/systemDictionary.cpp 2020-06-23 12:35:22.335255874 -0700 +++ new/src/hotspot/share/classfile/systemDictionary.cpp 2020-06-23 12:35:22.107247291 -0700 @@ -1353,10 +1353,11 @@ } bool SystemDictionary::is_shared_class_visible_impl(Symbol* class_name, - InstanceKlass* ik, - PackageEntry* pkg_entry, - Handle class_loader, TRAPS) { + InstanceKlass* ik, + PackageEntry* pkg_entry, + Handle class_loader, TRAPS) { int scp_index = ik->shared_classpath_index(); + assert(!ik->is_shared_unregistered_class(), "this function should be called for built-in classes only"); assert(scp_index >= 0, "must be"); SharedClassPathEntry* scp_entry = FileMapInfo::shared_path(scp_index); if (!Universe::is_module_initialized()) { @@ -1375,6 +1376,9 @@ if (should_be_in_named_module) { // Is the module loaded from the same location as during dump time? visible = mod_entry->shared_path_index() == scp_index; + if (visible) { + assert(!mod_entry->is_patched(), "cannot load archived classes for patched module"); + } } else { // During dump time, this class was in a named module, but at run time, this class should be // in an unnamed module. --- old/src/hotspot/share/classfile/systemDictionary.hpp 2020-06-23 12:35:23.195288247 -0700 +++ new/src/hotspot/share/classfile/systemDictionary.hpp 2020-06-23 12:35:22.943278761 -0700 @@ -629,9 +629,10 @@ 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 is_shared_class_visible_impl(Symbol* class_name, + InstanceKlass* ik, + PackageEntry* pkg_entry, + Handle class_loader, TRAPS); static bool is_shared_class_visible_impl_old(Symbol* class_name, InstanceKlass* ik, PackageEntry* pkg_entry, Handle class_loader, --- old/src/hotspot/share/memory/filemap.cpp 2020-06-23 12:35:23.995318361 -0700 +++ new/src/hotspot/share/memory/filemap.cpp 2020-06-23 12:35:23.763309628 -0700 @@ -380,6 +380,7 @@ } } + void SharedClassPathEntry::metaspace_pointers_do(MetaspaceClosure* it) { it->push(&_name); it->push(&_manifest); --- old/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/PatchModule/Simple.java 2020-06-23 12:35:24.807348927 -0700 +++ new/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/PatchModule/Simple.java 2020-06-23 12:35:24.591340796 -0700 @@ -76,5 +76,20 @@ "-Xlog:class+path=info", "PatchMain", "javax.naming.spi.NamingManager") .assertSilentlyDisabledCDS(0, "I pass!"); + + // ======================================== + System.out.println("Dump again without --patch-module"); + output = + TestCommon.dump(null, + TestCommon.list("javax/naming/spi/NamingManager")); + output.shouldHaveExitValue(0); + + TestCommon.run( + "-XX:+UnlockDiagnosticVMOptions", + "--patch-module=java.naming=" + moduleJar, + "-Xlog:class+load", + "-Xlog:class+path=info", + "PatchMain", "javax.naming.spi.NamingManager") + .assertSilentlyDisabledCDS(0, "I pass!"); } }