src/java.base/share/classes/java/util/ImmutableCollections.java
changeset 51371 3ab8b84e93cd
parent 50809 6ff774d73176
child 52427 3c6aa484536c
--- a/src/java.base/share/classes/java/util/ImmutableCollections.java	Thu Aug 09 15:52:23 2018 -0700
+++ b/src/java.base/share/classes/java/util/ImmutableCollections.java	Fri Aug 10 00:35:57 2018 -0400
@@ -36,6 +36,7 @@
 import java.util.function.Predicate;
 import java.util.function.UnaryOperator;
 import jdk.internal.misc.SharedSecrets;
+import jdk.internal.misc.VM;
 import jdk.internal.vm.annotation.Stable;
 
 /**
@@ -409,7 +410,15 @@
     static final class ListN<E> extends AbstractImmutableList<E>
             implements Serializable {
 
-        static final List<?> EMPTY_LIST = new ListN<>();
+        // EMPTY_LIST may be initialized from the CDS archive.
+        static @Stable List<?> EMPTY_LIST;
+
+        static {
+            VM.initializeFromArchive(ListN.class);
+            if (EMPTY_LIST == null) {
+                EMPTY_LIST = new ListN<>();
+            }
+        }
 
         @Stable
         private final E[] elements;
@@ -567,7 +576,15 @@
     static final class SetN<E> extends AbstractImmutableSet<E>
             implements Serializable {
 
-        static final Set<?> EMPTY_SET = new SetN<>();
+        // EMPTY_SET may be initialized from the CDS archive.
+        static @Stable Set<?> EMPTY_SET;
+
+        static {
+            VM.initializeFromArchive(SetN.class);
+            if (EMPTY_SET == null) {
+                EMPTY_SET = new SetN<>();
+            }
+        }
 
         @Stable
         final E[] elements;
@@ -772,7 +789,15 @@
      */
     static final class MapN<K,V> extends AbstractImmutableMap<K,V> {
 
-        static final Map<?,?> EMPTY_MAP = new MapN<>();
+        // EMPTY_MAP may be initialized from the CDS archive.
+        static @Stable Map<?,?> EMPTY_MAP;
+
+        static {
+            VM.initializeFromArchive(MapN.class);
+            if (EMPTY_MAP == null) {
+                EMPTY_MAP = new MapN<>();
+            }
+        }
 
         @Stable
         final Object[] table; // pairs of key, value