RFR: 8262376: ReplaceCriticalClassesForSubgraphs.java fails if --with-build-jdk is used
Ioi Lam
iklam at openjdk.java.net
Thu Apr 29 00:49:00 UTC 2021
When CDS tries to load sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo from the classlist, the VM has already finished the "early" bootup phase. To load this class, the module system tries to create an instance of jdk.internal.module.SystemModuleFinders$SystemModuleReader and store that into the ArchivedBootLayer. However, the SystemModuleReader class is also not yet loaded, so the VM loads it on demand. As a result, SystemModuleReader is treated as a "non-early class".
The problem is now ArchivedBootLayer refers to a non-early class. At runtime, if JVMTI ClassLoadHook is enabled, HeapShared will refuse to load ArchivedBootLayer from the archived heap. The reason is explained by this in heapShared.cpp:
// Note: if a ArchivedKlassSubGraphInfoRecord contains non-early classes, and JVMTI
// ClassFileLoadHook is enabled, it's possible for this class to be dynamically replaced. In
// this case, we will not load the ArchivedKlassSubGraphInfoRecord and will clear its roots.
However, this doesn't make sense for ArchivedBootLayer -- it's loaded in the early phase at runtime, so any classes referenced by ArchivedBootLayer will also be loaded in the early phase. This means JVMTI ClassLoadHook cannot replace SystemModuleReader.
Hence, the fix is simple -- for any classes referenced by the 3 "full-module-graph" subgraphs, we always treat them as "early" classes, regardless of when they are loaded during dump time.
// Entry fields for subgraphs archived in the open archive heap region (full module graph).
static ArchivableStaticFieldInfo fmg_open_archive_subgraph_entry_fields[] = {
{"jdk/internal/loader/ArchivedClassLoaders", "archivedClassLoaders"},
{"jdk/internal/module/ArchivedBootLayer", "archivedBootLayer"},
{"java/lang/Module$ArchivedData", "archivedData"},
};
The validate the fix, I modified the test case to always load CLDRLocaleDataMetaInfo during dump time. The test failed without the fix and passed with the fix.
-------------
Commit messages:
- 8262376: ReplaceCriticalClassesForSubgraphs.java fails if --with-build-jdk is used
Changes: https://git.openjdk.java.net/jdk/pull/3780/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3780&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8262376
Stats: 19 lines in 2 files changed: 12 ins; 3 del; 4 mod
Patch: https://git.openjdk.java.net/jdk/pull/3780.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/3780/head:pull/3780
PR: https://git.openjdk.java.net/jdk/pull/3780
More information about the hotspot-runtime-dev
mailing list