RFR: 8367387: Add @AOTInitialize annotation

Ioi Lam iklam at openjdk.org
Thu Sep 11 04:43:48 UTC 2025


This PR adds a new annotation, `@AOTInitialize` that forces a class to be (a) initialized in the AOT assembly phase, and (b) stored in the AOT cache in an already initialized state. This means that all the static fields in this class will be immediately available upon JVM bootstrap when the AOT cache is used in an application's production run.

This PR annotates a single class, `jdk.internal.math.MathUtils`. More classes will be added in future PRs.

If a class `K` has the `@AOTInitialize` annotation, the same annotation must be also added to
- All of `K`'s super classes
- All of `K`'s super interfaces that require to be initialized when `K` is initialized (see JVMS 5.5. Initialization, step 7; also C++ function `InstanceKlass::interface_needs_clinit_execution_as_super()`

Note, the check of the above requirement has been moved to `AOTClassInitializer::check_aot_annotations()`. The previous check in `ClassFileParser` was not executed because the class is loaded in the AOT training run, where `CDSConfig::is_initing_classes_at_dump_time()` returns `false` (this function returns `true` only in the AOT assembly phase).

This annotation is awfully similar to `@AOTSafeAnnotation`, and I am not sure if we need both. Please see the javadoc in `@AOTInitialize` to see the difference between the two annotations.

-------------

Commit messages:
 - Added javadoc; added test case; code clean up
 - Merge branch 'master' into aot-initialize-math-utils
 - cleanup
 - Merge branch 'master' into aot-initialize-math-utils
 - Merge branch '8366477-refactor-aot-related-flag-bits-in-klass-hpp' into aot-initialize-math-utils
 - Merge branch 'master' into 8366477-refactor-aot-related-flag-bits-in-klass-hpp
 - @liach and @ashu-mehra comment: Renamed Klass::_is_generated_shared_class -> _is_aot_generated_class
 - Merge branch 'master' into 8366477-refactor-aot-related-flag-bits-in-klass-hpp.saved
 - Move annotation validation to AOTClassInitializer::check_aot_annotations()
 - Force AOT initialization of MathUtils in assembly phase
 - ... and 8 more: https://git.openjdk.org/jdk/compare/134c3ef4...5b71ce80

Changes: https://git.openjdk.org/jdk/pull/27024/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27024&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8367387
  Stats: 316 lines in 10 files changed: 263 ins; 49 del; 4 mod
  Patch: https://git.openjdk.org/jdk/pull/27024.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27024/head:pull/27024

PR: https://git.openjdk.org/jdk/pull/27024


More information about the core-libs-dev mailing list