Skip to content

Conversation

@iklam
Copy link
Member

@iklam iklam commented Apr 29, 2025

This is the implementation of the draft JEP: Ahead-of-time Command Line Ergonomics

  • Implemented new flag AOTCacheOutput, which can be used to create an AOT cache using the "one-command workflow"
  • Added processing of the JDK_AOT_VM_OPTIONS environment variable that can supply extra VM options when creating an AOT cache
  • Added %p substitution for AOTCache, AOTCacheOutput, and AOTConfiguration options

Please see the JEP and CSR for detailed specification.

Examples:

# Create an AOT cache with a single command:
$ java -cp HelloWorld.jar -XX:AOTMode=record -XX:AOTCacheOutput=foo.aot HelloWorld
Hello World
Temporary AOTConfiguration recorded: foo.aot.config
Launching child process /usr/bin/java to assemble AOT cache foo.aot using configuration foo.aot.config
[...]
Reading AOTConfiguration foo.aot.config and writing AOTCache foo.aot
AOTCache creation is complete: foo.aot 10240000 bytes

# Create logging file for the AOT cache assembly phase
$ export AOT_TOOL_COMMAND=-Xlog:cds:file=log.txt
$ java -cp HelloWorld.jar -XX:AOTMode=record -XX:AOTCacheOutput=foo.aot HelloWorld

Note: the child process is launched with Java API because the HotSpot native APIs are not sufficient (no way to set env vars for child process).


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Change requires CSR request JDK-8356010 to be approved
  • Commit message must refer to an issue

Issues

  • JDK-8355798: Implement JEP 514: Ahead-of-Time Command Line Ergonomics (Sub-task - P4)
  • JDK-8356010: Implement JEP 514: Ahead-of-Time Command Line Ergonomics (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24942/head:pull/24942
$ git checkout pull/24942

Update a local copy of the PR:
$ git checkout pull/24942
$ git pull https://git.openjdk.org/jdk.git pull/24942/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24942

View PR using the GUI difftool:
$ git pr show -t 24942

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24942.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 29, 2025

👋 Welcome back iklam! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 29, 2025

@iklam This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8355798: Implement JEP 514: Ahead-of-Time Command Line Ergonomics

Reviewed-by: erikj, kvn, asmehra

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Apr 29, 2025

@iklam The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added hotspot-runtime hotspot-runtime-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Apr 29, 2025
@vnkozlov
Copy link
Contributor

JEP and CSR call env var :JAVA_AOT_OPTIONS. This description and changes call it AOT_TOOL_OPTIONS. Please, fix.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments.

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Apr 30, 2025
@openjdk
Copy link

openjdk bot commented May 1, 2025

@iklam this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout 8355798-implement-leyden-ergo-jep-8350022
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label May 1, 2025
@iklam iklam changed the title 8355798: Implement JEP-JDK-8350022: Ahead-of-time Command Line Ergonomics 8355798: Implement JEP-512: Ahead-of-Time Command Line Ergonomics May 4, 2025
@iklam iklam changed the title 8355798: Implement JEP-512: Ahead-of-Time Command Line Ergonomics 8355798: Implement JEP-514: Ahead-of-Time Command Line Ergonomics May 4, 2025
@iklam iklam changed the title 8355798: Implement JEP-514: Ahead-of-Time Command Line Ergonomics 8355798: Implement JEP 514: Ahead-of-Time Command Line Ergonomics May 4, 2025
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label May 4, 2025
@iklam iklam marked this pull request as ready for review May 5, 2025 00:24
@openjdk openjdk bot added the rfr Pull request is ready for review label May 5, 2025
@mlbridge
Copy link

mlbridge bot commented May 5, 2025

@iklam
Copy link
Member Author

iklam commented May 5, 2025

JEP and CSR call env var :JAVA_AOT_OPTIONS. This description and changes call it AOT_TOOL_OPTIONS. Please, fix.

Fixed.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments.

Comment on lines 122 to 123
"Write AOT cache into this file (overrides AOTCache when " \
"writing)") \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks not complete description. And "override AOTCache .." is confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to "Specifies the file name for writing the AOT cache". Since the behavior is complex, I don't know how much detail I should put here.

stringStream ss;
print_java_launcher(&ss);
const char* cmd = ss.freeze();
tty->print_cr("Launching child process %s to assemble AOT cache %s using configuration %s", cmd, AOTCacheOutput, AOTConfiguration);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that AOT produces outputs on TTY like this unconditionally. I think it is fine for development but for production we should use UL I think.
Was this discussed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we print things that are important to the user. The other examples are:

$ java -XX:AOTMode=record ....
AOTConfiguration recorded: hw.aotconfig

$ java -XX:AOTMode=create ....
Reading AOTConfiguration hw.aotconfig and writing AOTCache hw.aot
AOTCache creation is complete: hw.aot 10498048 bytes

I think AOT is still a new feature so a small number of TTY prints would be helpful. If people complain about the verbosity we can change them to UL logs.

return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args);
}

static JavaVMOption* get_last_aotmode_arg(const JavaVMInitArgs* args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we pollute Arguments code with AOT specific flags processing.
Can we move this into CDSConfig? Both these 2 new methods.

But I will agree if you want to keep it here. It is not critical.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two functions are for parsing JDK_AOT_VM_OPTIONS, so I think they belong to arguments.cpp. cdsConfig.cpp is a consumer of the options parsed by arguments.cpp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

mode should be used only as a "fail-fast" debugging aid to check if your command-line
options are compatible with the AOT cache. An alternative is to run your application with
`-XX:AOTMode=auto -Xlog:cds` to see if the AOT cache can be used or not.
`-XX:AOTMode=auto -Xlog:cds,aot` to see if the AOT cache can be used or not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Xlog:aot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Xlog:cds,aot is correct for the current state of this PR. I'll change it after JDK-8356595 is integrated into the mainline.

"-XX:AOTMode=record",
"-XX:-AOTClassLinking",
"-XX:AOTConfiguration=" + aotConfigFile,
"-Xlog:cds=debug",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Xlog:aot
I assume JDK-8356595: "Convert -Xlog:cds to -Xlog:aot " will be pushed first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Xlog:cds=debug is correct for the current state of this PR (otherwise the test will fail). I'll change it after JDK-8356595 is integrated into the mainline.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 15, 2025
Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

One way to improve test coverage of ahead-of-time (AOT) optimizations in the JDK is to
run existing jtreg test cases in a special "AOT_JDK" mode. Example:


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this extra newline intentional?

doc/testing.md Outdated

Also, test cases that were written specifically to test AOT, such as the tests
under [test/hotspot/jtreg/runtime/cds](../test/hotspot/jtreg/runtime/cds/), cannot
be execute with the AOT_JDK mode.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
be execute with the AOT_JDK mode.
be executed with the AOT_JDK mode.

doc/testing.md Outdated
under [test/hotspot/jtreg/runtime/cds](../test/hotspot/jtreg/runtime/cds/), cannot
be execute with the AOT_JDK mode.

Valid values for `AOT_JDK` are `one_step` and `two_step`. These control how
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the values are onestep and twostep in the makefile.

doc/testing.md Outdated
Comment on lines 624 to 629
In this testing mode, we first perform an AOT training run (see https://openjdk.org/jeps/483)
of a special test program ([test/setup_aot/TestSetupAOT.java](../test/setup_aot/TestSetupAOT.java))
that accesses about 5,0000 classes in the JDK core libraries. Optimization artifacts for
these classes (such as pre-linked lambda expressions, execution profiles, and pre-generated native code)
are stored into an AOT cache file, which will be used by all the JVMs launched by the selected jtreg
test cases.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these lines are >80 chars. Can you try to format line lengths in this file to stay under where reasonably feasible? It's ok if long markups such as links go over, just try to keep the normal text adhering to this.

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels May 19, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label May 20, 2025
$$($1_AOT_JDK_CACHE): $$(JDK_IMAGE_DIR)/release
$$(call MakeDir, $$($1_AOT_JDK_OUTPUT_DIR))

ifeq ($$($1_TRAINING), onestep)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not noticing this earlier. This is a conditional within a recipe. The preferred style for those are to align the ifeq, else and endif with the recipe itself, using spaces (as it's not a recipe line), and then indent the body with 2 extra spaces for logical indentation. See points 5 and 6 in https://openjdk.org/groups/build/doc/code-conventions.html. You can find an example of this in make/Bundles.gmk.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 23, 2025
@iklam
Copy link
Member Author

iklam commented May 28, 2025

/integrate

@openjdk
Copy link

openjdk bot commented May 28, 2025

Going to push as commit dede353.
Since your change was applied there have been 4 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 28, 2025
@openjdk openjdk bot closed this May 28, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 28, 2025
@openjdk
Copy link

openjdk bot commented May 28, 2025

@iklam Pushed as commit dede353.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build build-dev@openjdk.org core-libs core-libs-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

6 participants