$ javac HelloWorld.java
$ jar cf HelloWorld.jar HelloWorld.class
$ java -Xshare:off -XX:DumpLoadedClassList=hw.classlist -cp HelloWorld.jar HelloWorld
$ java -Xshare:dump -XX:SharedArchiveFile=hw.jsa -XX:SharedClassListFile=hw.classlist -cp HelloWorld.jar
$ java -cp HelloWorld.jar -XX:SharedArchiveFile=hw.jsa -Xlog:class+load HelloWorld | grep class.load | grep -v shared.objects
[0.248s][info][class,load] java.nio.file.FileSystems source: jrt:/java.base loader: boot_loader
[0.248s][info][class,load] java.nio.file.FileSystems$DefaultFileSystemHolder source: jrt:/java.base loader: boot_loader
[0.249s][info][class,load] java.nio.file.FileSystems$DefaultFileSystemHolder$1 source: jrt:/java.base loader: boot_loader
[0.254s][info][class,load] java.net.URI$Parser source: jrt:/java.base loader: boot_loader
===================
The above 4 classes are not loaded during the -XX:DumpLoadedClassList run. Instead, they are used only when the hw.jsa is loaded at runtime (when the CDS initialization code calls ClassLoaders::toFileURL()
https://github.com/openjdk/jdk/blob/a474b37212da5edbd5868c9157aff90aae00ca50/src/hotspot/share/cds/cdsProtectionDomain.cpp#L207-L210
->
https://github.com/openjdk/jdk/blame/a474b37212da5edbd5868c9157aff90aae00ca50/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java#L228C24-L237
private static URL toFileURL(String s) {
try {
// Use an intermediate File object to construct a URI/URL without
// authority component as URLClassPath can't handle URLs with a UNC
// server name in the authority component.
return Path.of(s).toRealPath().toFile().toURI().toURL();
} catch (InvalidPathException | IOException ignore) {
// malformed path string or class path element does not exist
return null;
}
=====================
Suggested fix:
When dumping the CDS archive, the CDS code should make a dummy call to ClassLoaders::toFileURL(). This would ensure that all classes used by that method will be added to the CDS archive.
$ jar cf HelloWorld.jar HelloWorld.class
$ java -Xshare:off -XX:DumpLoadedClassList=hw.classlist -cp HelloWorld.jar HelloWorld
$ java -Xshare:dump -XX:SharedArchiveFile=hw.jsa -XX:SharedClassListFile=hw.classlist -cp HelloWorld.jar
$ java -cp HelloWorld.jar -XX:SharedArchiveFile=hw.jsa -Xlog:class+load HelloWorld | grep class.load | grep -v shared.objects
[0.248s][info][class,load] java.nio.file.FileSystems source: jrt:/java.base loader: boot_loader
[0.248s][info][class,load] java.nio.file.FileSystems$DefaultFileSystemHolder source: jrt:/java.base loader: boot_loader
[0.249s][info][class,load] java.nio.file.FileSystems$DefaultFileSystemHolder$1 source: jrt:/java.base loader: boot_loader
[0.254s][info][class,load] java.net.URI$Parser source: jrt:/java.base loader: boot_loader
===================
The above 4 classes are not loaded during the -XX:DumpLoadedClassList run. Instead, they are used only when the hw.jsa is loaded at runtime (when the CDS initialization code calls ClassLoaders::toFileURL()
https://github.com/openjdk/jdk/blob/a474b37212da5edbd5868c9157aff90aae00ca50/src/hotspot/share/cds/cdsProtectionDomain.cpp#L207-L210
->
https://github.com/openjdk/jdk/blame/a474b37212da5edbd5868c9157aff90aae00ca50/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java#L228C24-L237
private static URL toFileURL(String s) {
try {
// Use an intermediate File object to construct a URI/URL without
// authority component as URLClassPath can't handle URLs with a UNC
// server name in the authority component.
return Path.of(s).toRealPath().toFile().toURI().toURL();
} catch (InvalidPathException | IOException ignore) {
// malformed path string or class path element does not exist
return null;
}
=====================
Suggested fix:
When dumping the CDS archive, the CDS code should make a dummy call to ClassLoaders::toFileURL(). This would ensure that all classes used by that method will be added to the CDS archive.
- relates to
-
JDK-8252689 Classes are loaded from jrt:/java.base even when CDS is used
-
- Resolved
-
-
JDK-8341452 Test runtime/cds/appcds/DumpRuntimeClassesTest.java from JDK-8324259 is failing
-
- Resolved
-
- links to
-
Commit(master) openjdk/jdk/88380484
-
Review(master) openjdk/jdk/21232