RFR: 8374639: Static archive with AOTClassLinking breaks dynamic archive
Ioi Lam
iklam at openjdk.org
Wed Jan 7 20:14:00 UTC 2026
**Bug fix**
The assert happens because [JDK-8309240](https://bugs.openjdk.org/browse/JDK-8309240) (Array classes should be stored in dynamic CDS archive) is not compatible with `AOTClassLinking` since JDK 26.
Since the benefit of [JDK-8309240](https://bugs.openjdk.org/browse/JDK-8309240) is small (obj array classes can be quickly created at run time), we should remove [JDK-8309240](https://bugs.openjdk.org/browse/JDK-8309240).
**Background**
The incompatibility is caused by [JDK-8350550](https://bugs.openjdk.org/browse/JDK-8350550) (Preload classes from AOT cache during VM bootstrap) added in JDK 26.
[JDK-8309240](https://bugs.openjdk.org/browse/JDK-8309240) adds support for scenarios like this:
- class `Foo` is in the static archive, but `Foo[]` is not in the static archive
- class `Foo[]` is in the dynamic archive
There's a pointer from the InstanceKlass of `Foo` to its array class `Foo[]` (`InstanceKlass::_array_klasses`). With [JDK-8309240](https://bugs.openjdk.org/browse/JDK-8309240), we update this pointer to point to `Foo[]` right after the CDS archives are mapped. This happens before `vmClasses::resolve_all()`:
https://github.com/openjdk/jdk/blob/dd20e9150666f247af61dfa524a170ef7dd96c03/src/hotspot/share/cds/aotMetaspace.cpp#L2162
With [JDK-8350550](https://bugs.openjdk.org/browse/JDK-8350550), if the static archive has AOT-linked classes, we will restore all of its classes inside `vmClasses::resolve_all()` -- see the callstack in the Description of [JDK-8374639](https://bugs.openjdk.org/browse/JDK-8374639).
The class restoration requires that all the classes (both instance classes and their array classes) must have a Java mirror. In this example, `Foo` is from the static archive and has an archived Java mirror, so we are OK. However, `Foo[]` is from the dynamic archive and doesn't have an archived mirror. Also, we are too early in the bootstrap process so we are unable to allocate a Java mirror from the heap yet. Hence the assert.
-------------
Commit messages:
- 8374639: Static archive with AOTClassLinking breaks dynamic archive
Changes: https://git.openjdk.org/jdk/pull/29078/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29078&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8374639
Stats: 486 lines in 10 files changed: 95 ins; 380 del; 11 mod
Patch: https://git.openjdk.org/jdk/pull/29078.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/29078/head:pull/29078
PR: https://git.openjdk.org/jdk/pull/29078
More information about the hotspot-runtime-dev
mailing list