JDK-8293187 : Store initialized Enum classes in AOTCache
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2022-08-31
  • Updated: 2024-11-15
  • Resolved: 2024-11-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 24
24Resolved
Related Reports
Blocks :  
Duplicate :  
Sub Tasks
JDK-8312125 :  
Description
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.
Comments
Fixed as part of JDK-8331497: Implement JEP 483: Ahead-of-Time Class Loading & Linking
15-11-2024

A pull request was submitted for review. Branch: pr/20843 URL: https://git.openjdk.org/jdk/pull/20958 Date: 2024-09-12 00:42:01 +0000
12-09-2024