JDK-8352394 : [CRaC] AOT class linking cannot archive jdk.internal.crac.Core$Priority
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: repo-crac
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2025-03-19
  • Updated: 2025-05-30
  • Resolved: 2025-05-27
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.
Other
repo-cracResolved
Related Reports
Relates :  
Relates :  
Description
The new CDS feature "Ahead-of-Time Class Loading & Linking" (JEP 483) fails in CRaC JDK (even when CRaC is not used):
```
[0.581s][error][cds,heap] Cannot archive object 0x00000000897046f0 of class java.util.WeakHashMap$Entry
[0.581s][error][cds,heap] [ 0] {0x00000000897007b8} java.lang.Class (jdk.internal.crac.Core$Priority::FILE_DESCRIPTORS)
[0.581s][error][cds,heap] [ 1] {0x0000000089700948} jdk.internal.crac.Core$Priority::context (offset = 24)
[0.581s][error][cds,heap] [ 2] {0x0000000089700e80} jdk.internal.crac.mirror.impl.BlockingOrderedContext::resources (offset = 12)
[0.581s][error][cds,heap] [ 3] {0x0000000089701000} java.util.WeakHashMap::table (offset = 36)
[0.581s][error][cds,heap] [ 4] {0x00000000897013f0} [Ljava.util.WeakHashMap$Entry;
[0.581s][error][cds     ] An error has occurred while writing the shared archive file.
```

This happens because of the combination of these facts:
1. CDS has problems with archiving `Reference` objects: https://github.com/openjdk/jdk/blob/82eb78069ffbaf66ae479d41d850d5999055e0e1/src/hotspot/share/classfile/javaClasses.cpp#L5466
2. AOT class linking archives enum classes in initialized state: https://bugs.openjdk.org/browse/JDK-8293187
3. In CRaC JDK `jdk.internal.crac.Core$Priority` enum class always gets initialized during VM init process, its values (contexts) have links to `Reference` objects
Thus, when AOT class linking creates an archive it always stumbles upon `jdk.internal.crac.Core$Priority` and fails.

This can be reproduced by dumping a CDS archive with `-XX:+AOTClassLinking` or by running `runtime/cds/appcds` tests (the ones that perform AOT class linking will fail).

The priority is low because there seems to be no practical reason to use CRaC and AOT class linking together.
Comments
With JDK-8344140 the issue is no longer present
27-05-2025

I've noticed that JDK-8344140 actually restricted the set of AOT-initialized enums — there is a good chance `jdk.internal.crac.Core$Priority` won't be included anymore. So, I've marked my fix PR (https://github.com/openjdk/crac/pull/213) as draft and propose to wait until JDK-8344140 makes it to CRaC to see if the issue gets resolved by it.
19-03-2025