Skip to content

8369515: Deadlock between JVMTI and JNI ReleasePrimitiveArrayCritical#28779

Closed
dholmes-ora wants to merge 5 commits intoopenjdk:masterfrom
dholmes-ora:8369515-jni-critical
Closed

8369515: Deadlock between JVMTI and JNI ReleasePrimitiveArrayCritical#28779
dholmes-ora wants to merge 5 commits intoopenjdk:masterfrom
dholmes-ora:8369515-jni-critical

Conversation

@dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Dec 12, 2025

As discussed in JBS the deadlock occurs when the call to ReleasePrimitiveArrayCritical performs the transition from native to VM, and in the process checks for special runtime exit conditions - which includes the obj_deopt_suspend request. The simple solution is to define a custom JNI ENTRY with custom ThreadInVMfromNative that elides the exit check.

The change is limited to ReleasePrimitiveArrayCritical and ReleaseStringCritical.

UPDATE: we are now employing a much simpler solution.

There is no regression test as this has only been seen in long running stress tests.

Testing:
-tiers 1-6


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-8369515: Deadlock between JVMTI and JNI ReleasePrimitiveArrayCritical (Bug - P3)

Reviewers

Contributors

  • Richard Reingruber <rrich@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28779

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 12, 2025

👋 Welcome back dholmes! 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 Dec 12, 2025

@dholmes-ora 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:

8369515: Deadlock between JVMTI and JNI ReleasePrimitiveArrayCritical

Co-authored-by: Richard Reingruber <rrich@openjdk.org>
Reviewed-by: rrich, fbredberg, pchilanomate

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

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.

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

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Dec 12, 2025
@openjdk
Copy link

openjdk bot commented Dec 12, 2025

@dholmes-ora The following label will be automatically applied to this pull request:

  • hotspot

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

@dholmes-ora dholmes-ora marked this pull request as ready for review December 15, 2025 04:17
@dholmes-ora
Copy link
Member Author

/label add hotspot-runtime
/label add serviceability

@openjdk openjdk bot added rfr Pull request is ready for review hotspot-runtime hotspot-runtime-dev@openjdk.org labels Dec 15, 2025
@openjdk
Copy link

openjdk bot commented Dec 15, 2025

@dholmes-ora
The hotspot-runtime label was successfully added.

@openjdk openjdk bot added the serviceability serviceability-dev@openjdk.org label Dec 15, 2025
@openjdk
Copy link

openjdk bot commented Dec 15, 2025

@dholmes-ora
The serviceability label was successfully added.

@mlbridge
Copy link

mlbridge bot commented Dec 15, 2025

Webrevs

@reinrich
Copy link
Member

Thanks for providing a fix for the issue David.
I've scheduled some local testing.

@reinrich
Copy link
Member

@dholmes-ora I do think that also entering a critical region is problematic if it is nested.
I'm currently testing with reinrich@d7ce2cc where a thread doesn't suspend for EscapeBarriers while in a critical region.

@dholmes-ora
Copy link
Member Author

I do think that also entering a critical region is problematic if it is nested.

Isn't nesting critical regions against the rules of using critical regions?

@reinrich
Copy link
Member

I do think that also entering a critical region is problematic if it is nested.

Isn't nesting critical regions against the rules of using critical regions?

For arrays it's explicitly allowed in the specification. There's also an example how to do it properly :)
I'll see if I can implement a reproducer.

@dholmes-ora
Copy link
Member Author

I do think that also entering a critical region is problematic if it is nested.

Isn't nesting critical regions against the rules of using critical regions?

For arrays it's explicitly allowed in the specification. There's also an example how to do it properly :) I'll see if I can implement a reproducer.

Right I see that. It states:

Inside a critical region, native code must not call other JNI functions, ...

but then explicitly allows the critical functions themselves to be an exception. Okay.

So isn't a fix for this simply to skip blocking as per your PR:

 if (is_obj_deopt_suspend() && !in_critical()) {

irrespective of nesting and without any need for any of the changes I proposed?

@reinrich
Copy link
Member

So isn't a fix for this simply to skip blocking as per your PR:

 if (is_obj_deopt_suspend() && !in_critical()) {

irrespective of nesting and without any need for any of the changes I proposed?

Yes, I currently think so.
Testing so far is good. Don't have a reproducer yet for the deadlock.

@dholmes-ora
Copy link
Member Author

I tested tiers 1-6 with the simplified fix and nothing has turned up.

@reinrich
Copy link
Member

Thanks! Same with my testing.
I doubt that I'll find the time to write a reproducer though.

@dholmes-ora
Copy link
Member Author

/contributor add @reinrich

@openjdk
Copy link

openjdk bot commented Dec 18, 2025

@dholmes-ora
Contributor Richard Reingruber <rrich@openjdk.org> successfully added.

Copy link
Contributor

@fbredber fbredber left a comment

Choose a reason for hiding this comment

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

Fixing deadlock issues caused by suspend requests can easily become quite messy, but not this time. I think it's an elegant solution, with a good explaining source code comment. Thank you!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 18, 2025
Copy link
Contributor

@pchilano pchilano 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 to me.

@pchilano
Copy link
Contributor

FTR we are not processing this special exit condition when transitioning from _thread_blocked to _thread_in_vm already, so I would assume it should be also okay for any native->vm transition.

@dholmes-ora
Copy link
Member Author

Thanks for the reviews @fbredber and @pchilano !

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 19, 2025
@reinrich
Copy link
Member

I wonder why there are no GHA tests?

@dholmes-ora
Copy link
Member Author

I wonder why there are no GHA tests?

I don't run GHA by default.

@reinrich
Copy link
Member

A deadlock can still occur if the debugger suspends the thread in the critical region, e.g. to read a local variable. After JDK-8373839 this shouldn't be possible anymore.

Copy link
Member

@reinrich reinrich 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.
Thanks, Richard.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 19, 2025
@dholmes-ora
Copy link
Member Author

Thanks for the reviews!

/integrate

@openjdk
Copy link

openjdk bot commented Dec 22, 2025

Going to push as commit 25e8714.
Since your change was applied there have been 62 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 Dec 22, 2025
@openjdk openjdk bot closed this Dec 22, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 22, 2025
@openjdk
Copy link

openjdk bot commented Dec 22, 2025

@dholmes-ora Pushed as commit 25e8714.

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

@dholmes-ora dholmes-ora deleted the 8369515-jni-critical branch December 22, 2025 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

4 participants