> This is an alternative to https://github.com/openjdk/jdk/pull/27024. Thanks > to @ashu-mehra for the suggestion. > > ### Background: > > The AOT Assembly Phase is in essence a small Java program that executes a > limited set of Java bytecodes. This program bootstraps the module system, > loads classes, and performs certain ahead-of-time optimizations such as > resolving `invokedynamic` call sites. > > As a side effect of Java program execution, a small set of Java classes are > initialized in the Assembly Phase. > > Since [JDK-8360163](https://bugs.openjdk.org/browse/JDK-8360163), if a class > `X` is annotated with `@AOTSafeClassInitializer` *and* is initialized in the > Assembly Phase, then `X` will be stored in the AOT cache in the "initialized" > state. When the AOT cache is used in the Production Run, `X::<clinit>` will > not be executed, and the static variables of `X` will be available upon JVM > bootstrap. > > ### Problem: > > The Assembly Phase doesn't touch many classes that may benefit from > `@AOTSafeClassInitializer`. For example, > `jdk.internal.math.MathUtils::<clinit>` creates a few large tables. Caching > `MathUtils` in the "initialized" state will improve start-up time. However, > since no bytecodes executed by the Assembly Phase use `MathUtils`. it will > not be initialized. > > ### Fix: > > If a class `X` has the `@AOTSafeClassInitializer` annotation *and* was > initialized in the AOT Training Run, the JVM will proactively initialize `X` > in the Assembly Phase. This will ensure that `X` will be cached in the > "initialized" state. > > As a proof of concept, `@AOTSafeClassInitializer` is added to `MathUtils`. > `@AOTSafeClassInitializer` will be added to more classes in future RFEs.
Ioi Lam has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains six additional commits since the last revision: - Exclude new test from hotspot_aot_classlinking and hotspot_appcds_dynamic test groups - @adinn and @liach comments - Merge branch 'master' into 8368174-proactive-init-aot-safe-class-initializer - updated javadoc for AOTSafeClassInitializer.java - Fix - imported ------------- Changes: - all: https://git.openjdk.org/jdk/pull/27402/files - new: https://git.openjdk.org/jdk/pull/27402/files/1fa2b1ec..774fe0ee Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=27402&range=01 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27402&range=00-01 Stats: 123813 lines in 925 files changed: 112515 ins; 7470 del; 3828 mod Patch: https://git.openjdk.org/jdk/pull/27402.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/27402/head:pull/27402 PR: https://git.openjdk.org/jdk/pull/27402
