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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

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 be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

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

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

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@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?

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.

3 participants