-
Notifications
You must be signed in to change notification settings - Fork 6.2k
JDK-8310584: GetThreadState reports blocked and runnable for pinned suspended virtual threads #14878
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
|
👋 Welcome back amenkov! A progress list of the required criteria for merging this PR into |
|
@alexmenkov The following labels 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 lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
sspitsyn
left a comment
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.
This looks good. Thank you for filing bug and fixing it!
I've one question besides this fix.
Thanks,
Serguei
|
@alexmenkov 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 63 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 |
| state &= ~java_lang_VirtualThread::RUNNING; | ||
| state |= JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_SUSPENDED; | ||
| state |= JVMTI_THREAD_STATE_SUSPENDED; | ||
| } |
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.
One question unrelated to this bug and your fix.
I wonder if any check and handling is needed for the case:
if (ext_suspended && ((state & JVMTI_THREAD_STATE_ALIVE) == 0))
Not sure this condition is even possible. But do we need to add an assert here?
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.
AFAIU it's possible in the case when we have terminated VT and JvmtiVTSuspender is requested to suspend all virtual threads
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.
So there is a window in which a VT is marked as terminated yet is still visible for actions like this? For regular threads we would always have filtered out thread in the process of exiting. Seeing terminated threads seems potentially problematic but perhaps all the VT code is prepared to handle this.
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.
I hope there is no such window in GetThreadState() case, but get_vthread_state method is also called from MultipleStackTracesCollector::fill_frames and there is a comment there:
// Note that either or both of thr and thread_oop
// may be null if the thread is new or has exited.
I keep this check for safety (though fill_frames does not care about suspend bit)
|
@alexmenkov Do you consider backporting this to 21? |
dholmes-ora
left a comment
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.
The change seems consistent with the definition of GetThreadState. But I note that the interrupt bit should also only be set if the target is alive.
maybe it makes sense. |
we get interrupt bit from Thread object, so the value is consistent with terminated state. suspend bit is a bit different - see my reply to Serguei |
Sorry I don't follow. I don't see anything that prevents the target from terminating after you have read the interrupt bit from the thread object, but before you read the actual state. |
The virtual thread state and the interrupt status are separate. That's okay for the suspended case, assuming not resumed while JVMTI GetThreadState executes. If not suspended then it looks like it could give an inconsistent view of the state. I don't know why GetThreadState defined a state flag for interrupted. |
|
So AFAIU GetThreadState for platform threads (get_thread_state_base) don't have similar issue because suspended/interrupted values are read after reading main thread state value. |
dholmes-ora
left a comment
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.
Seems fine to me, assuming all tests pass.
Thanks.
sspitsyn
left a comment
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.
The update looks good.
Need to make sure there are no new failures though.
Thanks,
Serguei
|
/integrate |
|
Going to push as commit af5bf81.
Your commit was automatically rebased without conflicts. |
|
@alexmenkov Pushed as commit af5bf81. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
The change fixes handling of "suspended" bit in VT state.
The code looks very strange.
java_lang_VirtualThread::RUNNING == 3, so line 803 clears JVMTI_THREAD_STATE_ALIVE(1) and JVMTI_THREAD_STATE_TERMINATED(2)
Per log this code came from loom repo with VT integration.
Testing: tier1-4, updated GetThreadStateMountedTest.java
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14878/head:pull/14878$ git checkout pull/14878Update a local copy of the PR:
$ git checkout pull/14878$ git pull https://git.openjdk.org/jdk.git pull/14878/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 14878View PR using the GUI difftool:
$ git pr show -t 14878Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14878.diff
Webrev
Link to Webrev Comment