This repository was archived by the owner on Feb 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
java.base/share/classes/java/lang
test/hotspot/jtreg/runtime/cds/appcds/cacheObject Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ static ArchivableStaticFieldInfo closed_archive_subgraph_entry_fields[] = {
9292static ArchivableStaticFieldInfo open_archive_subgraph_entry_fields[] = {
9393 {" jdk/internal/module/ArchivedModuleGraph" , " archivedModuleGraph" },
9494 {" java/util/ImmutableCollections" , " archivedObjects" },
95+ {" java/lang/ModuleLayer" , " EMPTY_LAYER" },
9596 {" java/lang/module/Configuration" , " EMPTY_CONFIGURATION" },
9697 {" jdk/internal/math/FDBigInteger" , " archivedCaches" },
9798};
Original file line number Diff line number Diff line change 4848import jdk .internal .loader .Loader ;
4949import jdk .internal .loader .LoaderPool ;
5050import jdk .internal .module .ServicesCatalog ;
51+ import jdk .internal .misc .CDS ;
52+ import jdk .internal .vm .annotation .Stable ;
5153import sun .security .util .SecurityConstants ;
5254
5355
147149
148150public final class ModuleLayer {
149151
150- // the empty layer
151- private static final ModuleLayer EMPTY_LAYER
152- = new ModuleLayer (Configuration .empty (), List .of (), null );
152+ // the empty layer (may be initialized from the CDS archive)
153+ private static @ Stable ModuleLayer EMPTY_LAYER ;
154+ static {
155+ CDS .initializeFromArchive (ModuleLayer .class );
156+ if (EMPTY_LAYER == null ) {
157+ // create a new empty layer if there is no archived version.
158+ EMPTY_LAYER = new ModuleLayer (Configuration .empty (), List .of (), null );
159+ }
160+ }
153161
154162 // the configuration from which this layer was created
155163 private final Configuration cf ;
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ public static void main(String args[]) throws Exception {
6161 checkModuleDescriptors (expectArchivedDescriptors );
6262 checkConfiguration (expectArchivedConfiguration );
6363 checkEmptyConfiguration (expectArchivedConfiguration );
64+ checkEmptyLayer ();
6465 }
6566
6667 private static void checkModuleDescriptors (boolean expectArchivedDescriptors ) {
@@ -139,4 +140,13 @@ private static void checkConfiguration(boolean expectArchivedConfiguration) {
139140 }
140141 }
141142 }
143+
144+ private static void checkEmptyLayer () {
145+ // ModuleLayer.EMPTY_FIELD returned by empty() method is singleton.
146+ // Check that with CDS there is still a single instance of EMPTY_LAYER
147+ // and boot() layer parent is THE empty layer.
148+ if (ModuleLayer .empty () != ModuleLayer .boot ().parents ().get (0 )) {
149+ throw new RuntimeException ("FAILED. Empty module layer is not singleton" );
150+ }
151+ }
142152}
You can’t perform that action at this time.
0 commit comments