Skip to content

Conversation

@tzezula
Copy link
Contributor

@tzezula tzezula commented Jul 17, 2024

The HotSpotJVMCIRuntime#getJObjectValue method returns a real JNI local handle instead of a JVMCI handle to prevent random crashes on ZGC.


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-8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getJObjectValue (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20219

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

Using diff file

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

Webrev

Link to Webrev Comment

…ned by HotSpotJVMCIRuntime#getConstantValue.
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 17, 2024

👋 Welcome back tzezula! 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 Jul 17, 2024

@tzezula 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:

8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getJObjectValue

Reviewed-by: dnsimon, never

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 106 new commits pushed to the master branch:

  • 5ff7c57: 8337168: Optimize LocalDateTime.toString
  • 374fca0: 8335967: "text-decoration: none" does not work with "A" HTML tags
  • 2aeb12e: 8334482: Shenandoah: Deadlock when safepoint is pending during nmethods iteration
  • d10afa2: 8336245: AArch64: remove extra register copy when converting from long to pointer
  • 7f11935: 8337167: StringSize deduplication
  • 487450c: 8216471: GTK LnF: Frame is clipped and does not show JTable,Tooltip and JTree demo in SwingSet2 demo
  • 29f0f17: 8336879: Always true condition 'img != null' in GTKPainter.paintPopupMenuBackground
  • ee839b7: 8337239: Fix simple -Wzero-as-null-pointer-constant warnings in classfile code
  • 0584af2: 8336685: Shenandoah: Remove experimental incremental update mode
  • 8c28f25: 8337124: (fs) sun.nio.fs.WindowsSecurity.enablePrivilege should pin when continuations supported
  • ... and 96 more: https://git.openjdk.org/jdk/compare/6df7acbc74922d297852044596045a8b32636423...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@tkrodriguez, @dougxc) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot changed the title JDK-8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getConstantValue. 8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getConstantValue. Jul 17, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 17, 2024
@openjdk
Copy link

openjdk bot commented Jul 17, 2024

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

  • graal
  • hotspot-compiler

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 graal graal-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org labels Jul 17, 2024
@mlbridge
Copy link

mlbridge bot commented Jul 17, 2024

Webrevs

@tzezula tzezula changed the title 8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getConstantValue. 8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getJObjectValue. Jul 17, 2024
@tzezula tzezula changed the title 8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getJObjectValue. 8336663: [JVMCI] VM Crash on ZGC due to incompatible handle returned by HotSpotJVMCIRuntime#getJObjectValue Jul 17, 2024
@fisk
Copy link
Contributor

fisk commented Jul 17, 2024

Would you mind explaining on a higher level what this code tries to do? If I understand the fix correctly, we are creating a hotspot JNI local from some Graal constant with getJObjectValue and expose a raw pointer to the HotSpot JNI handle to the caller. Looking at the only use I can find for this API, that raw pointer is then used to create yet another JNI local by calling NewLocalRef in some JNI environment. That seems either redundant, if it's the HotSpot JNI environment (as we just created a JNI local handle), or possibly dangerous if this is some libgraal JNI environment instead, as resolving the JNI local handle is only allowed when the thread is in the in_vm state. Otherwise the reference might become invalid between creating the JNI handle and resolving it in libgraal which is running in_native from HotSpot point of view. What am I missing?

@dean-long
Copy link
Member

Does "JVMCI shared library" mean libgraal? I thought it was its own separate logical VM and used it's own internal GC, not ZGC. How is Truffle shared library compiler different from libgraal?

@tzezula
Copy link
Contributor Author

tzezula commented Jul 18, 2024

I believe there is a misunderstanding regarding the method's usage. I need to extend the Javadoc, as the current documentation only states that the method can be called when IS_IN_NATIVE_IMAGE is true, which is insufficient. All calls to getJObjectValue are made from the JVMCI shared library. From HotSpot's perspective, the call to getJObjectValue represents a native-to-VM transition, which does not affect JNI local frames. The returned jlong is converted into the nativeimage PointerBase type and becomes a jobject pointing to an object in the HotSpot heap. The method cannot return a jobject directly because it is called within the JVMCI shared library but returns a pointer to an object in the HotSpot heap.

The method is used to "unwrap" the object held by the IndirectHotSpotObjectConstantImpl in the JVMCI shared library. The unwrapped object resides in the HotSpot heap, and the JVMCI shared library is considered native code from HotSpot's perspective. The overall usage is as follows:

  1. A Java thread in the HotSpot heap calls the native compile method, causing HotSpot Java-to-native transition.
  2. In the JVMCI shared library, we call getJObjectValue, causing HotSpot native-to-VM transition.
  3. getJObjectValue returns a jobject as a jlong, resulting in HotSpot VM-to-native transition.
  4. We create a nativeimage pointer type from the jlong and use it as a receiver or parameter while making JNI calls to objects in the HotSpot heap.
  5. The native compile method ends, causing HotSpot native-to-Java transition, and local handles, including the handle returned by getJObjectValue, are freed.

@tzezula
Copy link
Contributor Author

tzezula commented Jul 18, 2024

@fisk

Looking at the only use I can find for this API, that raw pointer is then used to create yet another JNI local by calling NewLocalRef in some JNI environment. That seems either redundant,

Yes, it's now redundant. The original getJObjectValue method returned a JVMCI handle, whose lifecycle was tied to the lifecycle of given IndirectHotSpotObjectConstantImpl. To remove this limitation, we created a new JNI local reference. With the changes introduced in this pull request, the NewLocalRef call should be removed.

@tzezula
Copy link
Contributor Author

tzezula commented Jul 18, 2024

@dean-long

Does "JVMCI shared library" mean libgraal?

Yes

I thought it was its own separate logical VM and used it's own internal GC, not ZGC.

Yes, the JVMCI shared library uses its own serial GC. However, the JVMCI shared library interacts with objects in the HotSpot heap through IndirectHotSpotObjectConstantImpl. The updated getJObjectValue method unwraps the IndirectHotSpotObjectConstantImpl to a jobject that points to an object in the HotSpot heap.

How is Truffle shared library compiler different from libgraal?

It's basically the same thing. Truffle compiler is a part of JVMCI shared library. The only difference is the entry point.

@fisk
Copy link
Contributor

fisk commented Jul 18, 2024

@fisk

Looking at the only use I can find for this API, that raw pointer is then used to create yet another JNI local by calling NewLocalRef in some JNI environment. That seems either redundant,

Yes, it's now redundant. The original getJObjectValue method returned a JVMCI handle, whose lifecycle was tied to the lifecycle of given IndirectHotSpotObjectConstantImpl. To remove this limitation, we created a new JNI local reference. With the changes introduced in this pull request, the NewLocalRef call should be removed.

Ah, okay. I guess you will fix that separately in the Graal repo. Good.

Copy link
Contributor

@tkrodriguez tkrodriguez left a comment

Choose a reason for hiding this comment

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

The latest version looks ok to me.

@openjdk
Copy link

openjdk bot commented Jul 24, 2024

⚠️ @tzezula the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout JDK-8336663
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 24, 2024
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jul 25, 2024
@tzezula
Copy link
Contributor Author

tzezula commented Jul 26, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Jul 26, 2024

@tzezula This pull request has not yet been marked as ready for integration.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 26, 2024
@tzezula
Copy link
Contributor Author

tzezula commented Jul 26, 2024

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jul 26, 2024
@openjdk
Copy link

openjdk bot commented Jul 26, 2024

@tzezula
Your change (at version 4738569) is now ready to be sponsored by a Committer.

@dougxc
Copy link
Member

dougxc commented Jul 26, 2024

/sponsor

@openjdk
Copy link

openjdk bot commented Jul 26, 2024

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

  • 5ff7c57: 8337168: Optimize LocalDateTime.toString
  • 374fca0: 8335967: "text-decoration: none" does not work with "A" HTML tags
  • 2aeb12e: 8334482: Shenandoah: Deadlock when safepoint is pending during nmethods iteration
  • d10afa2: 8336245: AArch64: remove extra register copy when converting from long to pointer
  • 7f11935: 8337167: StringSize deduplication
  • 487450c: 8216471: GTK LnF: Frame is clipped and does not show JTable,Tooltip and JTree demo in SwingSet2 demo
  • 29f0f17: 8336879: Always true condition 'img != null' in GTKPainter.paintPopupMenuBackground
  • ee839b7: 8337239: Fix simple -Wzero-as-null-pointer-constant warnings in classfile code
  • 0584af2: 8336685: Shenandoah: Remove experimental incremental update mode
  • 8c28f25: 8337124: (fs) sun.nio.fs.WindowsSecurity.enablePrivilege should pin when continuations supported
  • ... and 96 more: https://git.openjdk.org/jdk/compare/6df7acbc74922d297852044596045a8b32636423...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 26, 2024
@openjdk openjdk bot closed this Jul 26, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jul 26, 2024
@openjdk
Copy link

openjdk bot commented Jul 26, 2024

@dougxc @tzezula Pushed as commit 3abe8a6.

💡 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

graal graal-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants