with CDS and G1, JCK test api/java_lang/ModuleLayer/Boot.html fails in JDK 16:
Testcase "parent" failed with message: Expected same as : "", was given: ""
at com.sun.tck.lib.Assert.fail(Assert.java:494)
at com.sun.tck.lib.Assert.assertSame(Assert.java:439)
at com.sun.tck.lib.Assert.assertSame(Assert.java:426)
at javasoft.sqe.tests.api.java.lang.ModuleLayer.Boot.parent(Boot.java:108)
Testcase "parent" is based on the following statements:
- "Its parent is the empty layer"
-- from source: "ModuleLayer.boot()"
parent: Failed. Expected same as : "", was given: ""
Bisecting has indicated this started failing since JDK-8253081 integration.
The root cause of the problem is that after unpacking the CDS archive there appear to be two instances of empty layer (another one comes from CDS archive). Because of that there is a mismatch between ModuleLayer.empty() (which returns java/lang/ModuleLayer.EMPTY_LAYER) and ModuleLayer.boot().parents().get(0) (which with CDS returns the CDS instance). The spec says [1] that boot() parent for java.base must return THE empty layer, with a link to empty() method.
One solution is to make java/lang/ModuleLayer.EMPTY_LAYER a singleton similar to java/lang/module/Configuration.EMPTY_CONFIGURATION and initialize this field from CDS archive if CDS is on.
[1] https://download.java.net/java/early_access/jdk16/docs/api/java.base/java/lang/ModuleLayer.html#boot()