Class such as jdk.internal.math.MathUtils initialize large arrays in their <clinit>. It's beneficial to AOT-initialize them to improve start-up time:
@jdk.internal.vm.annotation.AOTInitialize
final class MathUtils {
private static final long[] g = { ... over 1200 items ...}
Note that we already have a @AOTSafeClassInitializer that works slightly differently:
@AOTInitialize class A {...}
@AOTSafeClassInitializer class B {...}
Similarity: the annotation takes effect only if the annotated class is included in an AOT cache. (E.g., the class was used in a training run).
Difference: the JVM will force A to be initialized in the AOT assembly run. A will always be cached in the aot-initialized state.
The JVM does not force B to be initialized in the AOT assembly run. B will be cached in the aot-initialized state only if it was initialized during the AOT assembly run as a side effect of Java code execution (e.g., in module bootstrap or when linking invokedynamic bytecodes).
@jdk.internal.vm.annotation.AOTInitialize
final class MathUtils {
private static final long[] g = { ... over 1200 items ...}
Note that we already have a @AOTSafeClassInitializer that works slightly differently:
@AOTInitialize class A {...}
@AOTSafeClassInitializer class B {...}
Similarity: the annotation takes effect only if the annotated class is included in an AOT cache. (E.g., the class was used in a training run).
Difference: the JVM will force A to be initialized in the AOT assembly run. A will always be cached in the aot-initialized state.
The JVM does not force B to be initialized in the AOT assembly run. B will be cached in the aot-initialized state only if it was initialized during the AOT assembly run as a side effect of Java code execution (e.g., in module bootstrap or when linking invokedynamic bytecodes).
- links to
-
Review(master) openjdk/jdk/27024