This RFE is a prerequisite of JDK-8293336 (Store LambdaForms in CDS archive heap) because LambdaForm objects transitively point to sun.invoke.util.Wrapper objects.
sun.invoke.util.Wrapper is a more complex form of Enum that is not yet supported by the CDS archive heap. There are 2 issues:
[1] A Wrapper instance may reference java.lang.Class objects, which currently cannot be stored in the CDS archive heap. E.g.,
public enum Wrapper {
...
private final Class<?> wrapperType;
...
}
Fix: allow archived heap objects to point to the java.lang.Classes for primitive types (e.g., boolean.class) and box types (e.g., Boolean.class). These Classes are easy to support, and they are the only kind of Classes referenced by Wrapper.
[2] The Wrapper class has user-defined static fields:
public enum Wrapper {
...
public static final int COUNT = 10;
private static final Object DOUBLE_ZERO = (Double)(double)0;
...
}
These static fields are initialized using <clinit>. The identity of some of the object fields (such as Wrapper.DOUBLE_ZERO) may be significant. We cannot re-execute the <clinit> method in the production run. Otherwise, some objects in the archived heap may refer to the archived version of Wrapper.DOUBLE_ZERO which is not the same object as the runtime version of Wrapper.DOUBLE_ZERO.
To ensure that we don't violate any (unexpressed) requirements of object identity, we need to archive the mirror of Wrapper in its initialized state. The mirror contains all of the static fields that are initialized during AOTCache creation. This ensures that Wrapper.DOUBLE_ZERO is always the same object instance during dump time and run time.
====
Not all Enum classes can be stored in the initialized state. E.g., some Enums might have static fields that depend on the environment:
enum Foo {
[....]
static final long TIME = System.currentTimeMillis();
}
Therefore, this RFE does not expose this capability for general usage. Currently, only a small set of Enums are stored in the archived heap, whose contents are carefully limited by tables in heapShared.cpp. We assume that none of the archived Enums have environment dependencies.
Obviously a better mechanism (AOT object creation API, static analysis, etc) will be needed before this capability can be opened up.