JDK-8369742 : Link AOT-linked classes at JVM bootstrap
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-10-14
  • Updated: 2025-10-20
  • Resolved: 2025-10-17
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 26
26 masterFixed
Related Reports
Relates :  
Relates :  
Description
BACKGROUND:

After JDK-8350550, all AOT-linked classes are loaded during VM bootstrap, before any Java bytecodes. They are initially in the "loaded" state, not "linked"

After we starting executing Java bytecodes, some of these classes are linked as a side effect of executing the invokestatic/getstatic/putstatic/new bytecodes.

Later, when AOTLinkedClassBulkLoader::link_or_init_javabase_classe() is called (after about 48,000 bytecodes have been executed), all AOT-linked classes in java.base are linked.

The remaining AOT-linked classes will be linked when AOTLinkedClassBulkLoader::link_or_init_non_javabase_classes() is called (after about 70,000 bytecodes have been executed).

PROBLEM:

If we have an AOT-initialized Java like this in java.base

@AOTSafeClassInitializer
class Foo {
    static Bar b = new Bar(); // AOT-cached
    static void doit() {
        b.toString();  /// invokevirtual Bar::toString()Ljava/lang/String;
    }
}

If Foo.doit() is called before link_or_init_javabase_classe(), it's possible for the Bar class to be not yet linked. The "invokevirtual" bytecode will crash because the vtable of the object "b" is not yet initialized.

SOLUTION:

Before we execute the first Java bytecode, unconditionally link all AOT-linked classes. This will ensure that the Bar class will have an initialized vtable for the above example.



Comments
Changeset: 6cd7f30d Branch: master Author: Ioi Lam <iklam@openjdk.org> Date: 2025-10-17 19:50:04 +0000 URL: https://git.openjdk.org/jdk/commit/6cd7f30d8d4118787401693b8628c72679d37a6a
17-10-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/27783 Date: 2025-10-14 04:13:40 +0000
14-10-2025

Note: the scenario in the "Bar" example in Description does not affect JDK 24, 25 or the current JDK mainline (26). We are lucky that in all the bytecode execution up to AOTLinkedClassBulkLoader::link_or_init_javabase_classe(), whenever we do a vtable/itable dispatch on an AOT-cached heap object, we happen to have already linked its class (either by explict calls from the JVM, or as side effect of invokestatic/getstatic/putstatic/new). However, this is a potential problem that should be fixed. I have run into the "Bar" problem when implementing JDK-8368199, which changes the bytecodes that are executed in early VM bootstrap.
14-10-2025