-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8327743: JVM crash in hotspot/share/runtime/javaThread.cpp - failed: held monitor count should be equal to jni: 0 != 1 #18445
8327743: JVM crash in hotspot/share/runtime/javaThread.cpp - failed: held monitor count should be equal to jni: 0 != 1 #18445
Conversation
…held monitor count should be equal to jni: 0 != 1
👋 Welcome back dholmes! A progress list of the required criteria for merging this PR into |
@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:
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 66 new commits pushed to the
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 |
@dholmes-ora The following label will be automatically applied to this pull request:
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. |
Move the warning code prior to any values being pushed to the carrier thread.
… zero when mounting a new vthread. Fix the termination logic - the zeroing of the JNI count should not have been under the CheckJNICalls guard.
…ease builds unless CheckJNICalls is set.
terminates. The faulting conditions are emulated using a custom scheduler.
Add missing @requires, as the logging only happens from continuation code
/contributor add @fbredber |
@dholmes-ora |
Webrevs
|
@robehn the comment isn't saying that we are missing anything. Only JNI DetachThread specifies that it will release all held monitors. When a thread terminates (platform or virtual) there is no specification to say it should also release any still held monitors - so we don't. We find all locked monitors from the in-use monitor list, we don't rely on the counters for that. Thanks for the testing and review. I just pushed a small update for RISC |
Isn't continuation_enter_cleanup() also used by yield()? How does monitorEnter(); Thread.yield(); monitorExit() not result in the JNI lock count going to -1? |
@dean-long In general yes but in this case the virtual thread is pinned so the cleanup is skipped. These monitor counts only exist to force pinning. |
The tests expect an exit value of 0, but for some reason why I run it they are returning 1. |
Nevermind, user error. |
I've done basic smoke testing on PowerPC using QEMU. |
Thanks for the pin. We will do that. |
There was a problem hiding this 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, thanks for working this one out David.
Thanks for the review @pchilano . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing didn't bring up any issue. I've only got a few minor comments.
Thanks, Richard.
Thanks for the review comments and testing of PPC @reinrich ! |
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this and taking care of ppc.
Thanks for all the reviews. /integrate |
Going to push as commit 274c805.
Your commit was automatically rebased without conflicts. |
@dholmes-ora Pushed as commit 274c805. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
The crux of the problem here is that the virtual thread code was not keeping the held-monitor-count and jni-monitor-count in sync under all conditions. So if a vthread acquired a monitor via JNI but failed to unlock it before terminating, the underlying platform thread's counts were out of sync and if it terminated we would trigger the assertion that checks for such things.
The actual fix is very simple: we zero the platform thread's jni-monitor-count in
continuation_enter_cleanup
the same way we zero the held-monitor-count. In addition we apply the sameCheckJNICalls
check for this unbalanced locking and issue a warning in the virtual thread case. That fact this happens in asm code complicates matters.The existing
JNIMonitor.java
test is greatly expanded to test these scenarios and check the unified logging output.Other minor changes involve expanding some of the other assertions relating to the two counts so we can detected a mismatch earlier without a need for the thread to terminate. And the test that original uncovered the problem (
GetOwnedMonitorInfoTest.java
) has some minor adjustments to enhance diagnostics.I've provided the fix for all architectures that support continuations: x64, aarch64, riscv and ppc. The latter both build okay in GHA but I can't actually test them with the updated test. So some assistance from RISCV folk (@robehn ?) and PPC folk (??) would be appreciated (otherwise any issues will have to be handled as follow up fixes
The changes are structured so that there is no extra code executed in product builds unless
CheckJNICalls
is set. This means that product builds will not keep the JNI count in sync with the held count, unlessCheckJNICalls
is set. This could trip up a future logging entry or explicit check of the JNI count, but it is expected that these counts will be removed once ObjectMonitor usage will not force virtual thread pinning.Testing:
Thanks to @pchilano for help working out the best form of the fix and the initial asm for x64.
Thanks to @fbredber for the Aarch64 and RISCV asm code.
Thanks
Progress
Issue
Reviewers
Contributors
<fbredberg@openjdk.org>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18445/head:pull/18445
$ git checkout pull/18445
Update a local copy of the PR:
$ git checkout pull/18445
$ git pull https://git.openjdk.org/jdk.git pull/18445/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18445
View PR using the GUI difftool:
$ git pr show -t 18445
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18445.diff
Webrev
Link to Webrev Comment