Skip to content

8354890: AOT-initialize j.l.i.MethodHandleImpl and inner classes #24956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

iklam
Copy link
Member

@iklam iklam commented Apr 29, 2025

This is a general fix for all the "points to a static field that may hold a different value" failures related to java/lang/invoke/MethodHandleImpl. E.g., JDK-8354840, JDK-8353330.

AOT-cached method handles quite often refer to the static fields in MethodHandleImpl or its inner classes. In the production run, if the value of these static field changes, we may have unexpected behavior related to identity of objects in these static fields. CDSHeapVerifier makes a very conservative check for such static fields, but sometimes gives false positives (as in the above two JBS issues)

In this PR, we AOT-initialize MethodHandleImpl and its inner classes. This is a more authentic snapshot of the state of java.lang.invoke during the assembly phase. We also avoid the need to add and maintain entries in the cdsHeapVerifier.cpp table.

I also added more code in MethodHandleTest.java to simulate potential usage patterns of MethodHandle by the Java core libraries. Hopefully this will reduce the likelihood for innocent core lib changes breaking the AOT assembly phase.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 2 Reviewers)

Issue

  • JDK-8354890: AOT-initialize j.l.i.MethodHandleImpl and inner classes (Enhancement - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24956

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24956.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 pr/24757 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:

8354890: AOT-initialize j.l.i.MethodHandleImpl and inner classes

Reviewed-by: liach, vlivanov

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

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-notifier openjdk-notifier bot changed the base branch from pr/24757 to master April 30, 2025 18:10
@openjdk-notifier
Copy link

The parent pull request that this pull request depends on has now been integrated and the target branch of this pull request has been updated. This means that changes from the dependent pull request can start to show up as belonging to this pull request, which may be confusing for reviewers. To remedy this situation, simply merge the latest changes from the new target branch into this pull request by running commands similar to these in the local repository for your personal fork:

git checkout 8354890-aot-init-methodhandleimpl-and-inner-classes
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# if there are conflicts, follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk
Copy link

openjdk bot commented Apr 30, 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 8354890-aot-init-methodhandleimpl-and-inner-classes
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 Apr 30, 2025
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Apr 30, 2025
// of <clinit>
initialize(CHECK);
return;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is to avoid deadlock in the previous implementation.

@iklam iklam marked this pull request as ready for review April 30, 2025 21:44
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 30, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 30, 2025

Webrevs

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

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

The tests look good to me.

@@ -1525,7 +1525,12 @@ private static NamedFunction createFunction(byte func) {
}
}

// Called from JVM when loading an AOT cache
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
// Called from JVM when loading an AOT cache

Comment on lines 1532 to 1533

private static void runtimeSetup() {
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
private static void runtimeSetup() {
// Called from JVM when loading an AOT cache
private static void runtimeSetup() {

Copy link
Member

Choose a reason for hiding this comment

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

Same problem in Reference, credit to @ExE-Boss

throw new RuntimeException("o has wrong interfaces");
}

statementEnum(MyEnum.A);
Copy link
Member

Choose a reason for hiding this comment

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

String s = statementEnum(MyEnum.A);
if (!s.equals("A")) {
    throw new RuntimeException("enum switch incorrect");
}

@adinn
Copy link
Contributor

adinn commented May 1, 2025

@iklam We have seen this problem with Red Hat deployments in jdk24 as well as jdk25-ea.

I'm saying that mostly for information. However, I do have to ask: If this is fixed for jdk25 is there any question of also fixing it in jdk24? I would be content to receive a no answer -- a similar issue with patch that could be backported from jdk26 -> jdk25 might be something to think about a bit more?

@iklam
Copy link
Member Author

iklam commented May 5, 2025

@iklam We have seen this problem with Red Hat deployments in jdk24 as well as jdk25-ea.

I'm saying that mostly for information. However, I do have to ask: If this is fixed for jdk25 is there any question of also fixing it in jdk24? I would be content to receive a no answer -- a similar issue with patch that could be backported from jdk26 -> jdk25 might be something to think about a bit more?

Backporting this to jdk 24 would require a lot of effort. I think it might be easier to update CDSHeapVerifier to add more rules to filter out the false positives. CDSHeapVerifier is too conservative and reports error for things that are actually OK.

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

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

The Java code change and the BSM coverage looks good to me. Requiring another reviewer for hotspot changes.

/reviewers 2 reviewer

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 5, 2025
@openjdk
Copy link

openjdk bot commented May 5, 2025

@liach
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 2 Reviewers).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label May 5, 2025
Copy link
Contributor

@iwanowww iwanowww 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.

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

iklam commented May 9, 2025

Thanks @liach @iwanowww for the review
/integrate

@openjdk
Copy link

openjdk bot commented May 9, 2025

Going to push as commit 591e71e.
Since your change was applied there has been 1 commit pushed to the master branch:

  • 53ad4b2: 8355364: [REDO] Missing REX2 prefix accounting in ZGC barriers leads to incorrect encoding

Your commit was automatically rebased without conflicts.

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

openjdk bot commented May 9, 2025

@iklam Pushed as commit 591e71e.

💡 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
Development

Successfully merging this pull request may close these issues.

4 participants