Background:
An application should have the exact same behavior whether running in AOT training mode (-XX:AOTCacheOutput=xxx.aot) or not. This will allow us to capture a profile that closely approximates what the application will do in the production run. (As an extreme example, if the app is unable to connect to the network in the AOT training run, then we can't capture profiles related network messaging ...).
----------
When using AOT cache with JFR, the same set of JFR options should be specified in both the training run and production run.
However, the xxx.jfr file is not recorded in the training run, because JFR is disabled in the AOT training run:
https://github.com/openjdk/jdk/blob/c69275ddfe8c1769ae82b4ba64b2d6d80bbd8683/src/hotspot/share/jfr/recorder/jfrRecorder.cpp#L202-L204
$ java -XX:StartFlightRecording:dumponexit=false -cp HelloWorld.jar -XX:AOTCacheOutput=hw.aot HelloWorld
Java HotSpot(TM) 64-Bit Server VM warning: JFR will be disabled during CDS dumping
Hello World
Temporary AOTConfiguration recorded: hw.aot.config
Launching child process java to assemble AOT cache hw.aot using configuration hw.aot.config
Picked up JAVA_TOOL_OPTIONS: -Djava.class.path=HelloWorld.jar -XX:StartFlightRecording:dumponexit=false -XX:AOTCacheOutput=hw.aot -XX:AOTConfiguration=hw.aot.config -XX:AOTMode=create
Java HotSpot(TM) 64-Bit Server VM warning: JFR will be disabled during CDS dumping
Reading AOTConfiguration hw.aot.config and writing AOTCache hw.aot
AOTCache creation is complete: hw.aot 10715136 bytes
Removed temporary AOT configuration file hw.aot.config
$ ls -l *.jfr
ls: cannot access '*.jfr': No such file or directory
The xxx.jfr file is recorded with an AOT production run:
$ java -XX:StartFlightRecording:dumponexit=false -cp HelloWorld.jar -XX:AOTCache=hw.aot HelloWorld
[0.165s][info][jfr,startup] Started recording 1. No limit specified, using maxsize=250MB as default.
[0.165s][info][jfr,startup]
[0.165s][info][jfr,startup] Use jcmd 383838 JFR.dump name=1 filename=FILEPATH to copy recording data to file.
Hello World
$ ls -l *.jfr
-rw-rw-r-- 1 iklam iklam 230618 Jan 15 09:10 hotspot-pid-399748-id-1-2026_01_15_09_10_13.jfr
An application should have the exact same behavior whether running in AOT training mode (-XX:AOTCacheOutput=xxx.aot) or not. This will allow us to capture a profile that closely approximates what the application will do in the production run. (As an extreme example, if the app is unable to connect to the network in the AOT training run, then we can't capture profiles related network messaging ...).
----------
When using AOT cache with JFR, the same set of JFR options should be specified in both the training run and production run.
However, the xxx.jfr file is not recorded in the training run, because JFR is disabled in the AOT training run:
https://github.com/openjdk/jdk/blob/c69275ddfe8c1769ae82b4ba64b2d6d80bbd8683/src/hotspot/share/jfr/recorder/jfrRecorder.cpp#L202-L204
$ java -XX:StartFlightRecording:dumponexit=false -cp HelloWorld.jar -XX:AOTCacheOutput=hw.aot HelloWorld
Java HotSpot(TM) 64-Bit Server VM warning: JFR will be disabled during CDS dumping
Hello World
Temporary AOTConfiguration recorded: hw.aot.config
Launching child process java to assemble AOT cache hw.aot using configuration hw.aot.config
Picked up JAVA_TOOL_OPTIONS: -Djava.class.path=HelloWorld.jar -XX:StartFlightRecording:dumponexit=false -XX:AOTCacheOutput=hw.aot -XX:AOTConfiguration=hw.aot.config -XX:AOTMode=create
Java HotSpot(TM) 64-Bit Server VM warning: JFR will be disabled during CDS dumping
Reading AOTConfiguration hw.aot.config and writing AOTCache hw.aot
AOTCache creation is complete: hw.aot 10715136 bytes
Removed temporary AOT configuration file hw.aot.config
$ ls -l *.jfr
ls: cannot access '*.jfr': No such file or directory
The xxx.jfr file is recorded with an AOT production run:
$ java -XX:StartFlightRecording:dumponexit=false -cp HelloWorld.jar -XX:AOTCache=hw.aot HelloWorld
[0.165s][info][jfr,startup] Started recording 1. No limit specified, using maxsize=250MB as default.
[0.165s][info][jfr,startup]
[0.165s][info][jfr,startup] Use jcmd 383838 JFR.dump name=1 filename=FILEPATH to copy recording data to file.
Hello World
$ ls -l *.jfr
-rw-rw-r-- 1 iklam iklam 230618 Jan 15 09:10 hotspot-pid-399748-id-1-2026_01_15_09_10_13.jfr