-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8361103: java_lang_Thread::async_get_stack_trace does not properly protect JavaThread #26119
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 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 166 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 |
|
@alexmenkov 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. |
Webrevs
|
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.
Generally looks good. A couple of minor nits/queries.
Thanks
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.
Looks good. Thanks
|
I'm also unclear if this code in the handshake is sufficient for dealing with the case where we have a mounted virtual thread initially, but it is unmounted before the handshake gets to execute: The commented line seems an inaccurate characterization as we could be executing a completely different virtual thread on this carrier now - which is not related to |
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.
Revoking my approval as there may be further issues.
I suppose the comment is obsolete. I don't see |
I suspect it dates back to when there were temporary transitions and where the thread identity had to be temporarily changed to the carrier thread. We've been able to remove that complexity, which eliminates complexity from JVMTI, and maybe here too. |
|
@alexmenkov I think we need a separate JBS issue for this and have runtime fix it. I want to be sure we are fixing it in the right/best way. I don't think we need the extra argument, but need to examine the existing usages. Chances are that any code trying to deal with virtual thread's via the API is actually doing it wrong and will need fixing anyway. I will file a bug. |
|
Filed JDK-8361912 |
I think just update the method to use carrier is error prone and callers should explicitly request the functionality. |
|
@alexmenkov Alex, the form of this fix will be determined by whatever we end up doing for JDK-8361912. I don't see any point in re-doing this fix later, so I suggest just putting this on hold for now. I will ensure the other issue is fixed within the next week. |
|
I've created JDK-8364343 with a stress test that tickles several asserts that we can use for follow-on issues. |
| class GetStackTraceHandshakeClosure : public HandshakeClosure { | ||
| public: | ||
| const Handle _java_thread; | ||
| const Handle _thread_oop; |
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 making this change! Very confusing otherwise.
|
|
||
| bool carrier = false; | ||
| if (java_lang_VirtualThread::is_instance(_java_thread())) { | ||
| // if (thread->vthread() != _java_thread()) // We might be inside a System.executeOnCarrierThread |
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.
Need to check with @AlanBateman whether this check is also needed (he does both in his draft PR).
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.
ThreadSnapshotFactory::get_thread_snapshot needs to fail (and the caller retry) if called while the target virtual thread is in transition. This is because it captures the thread state in addition to the stack trace, and several other properties. So this is why (in the draft changes) it checks that thread identity is set and that the continuation is mounted.
java_lang_Thread::async_get_stack_trace just needs to walk the continuation stack so checking that the continuation is mounted should be enough here.
| if (ce == nullptr || ce->cont_oop(java_thread) != java_lang_VirtualThread::continuation(_thread_oop())) { | ||
| // Target thread has been unmounted. | ||
| return; | ||
| } |
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.
Shouldn't we set carrier = true if we don't return here? Or am I misunderstanding what "carrier" means 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.
"carrier" means target is a platform thread with mounted virtual thread.
When carrier == true vframeStream skips frames of the mounted virtual thread.
Here target is a virtual thread, so we need frames starting from the last frame
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.
Looks good (a couple of typos). Thanks.
Co-authored-by: David Holmes <62092539+dholmes-ora@users.noreply.github.com>
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 to me. I've posted one nit though.
|
|
||
| GetStackTraceHandshakeClosure(Handle java_thread) : | ||
| HandshakeClosure("GetStackTraceHandshakeClosure"), _java_thread(java_thread), _depth(0), _retry_handshake(false), | ||
| GetStackTraceHandshakeClosure(Handle thread_oop) : |
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.
Nit: I'd suggest to rename: thread_oop => thread_h
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.
Done (thread_oop => thread_h and _thread_oop => _thread_h)
|
Thank you for the review @dholmes-ora and @sspitsyn |
|
Going to push as commit ecbdd34.
Your commit was automatically rebased without conflicts. |
|
@alexmenkov Pushed as commit ecbdd34. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
The fix updates
java_lang_Thread::async_get_stack_trace()(used byjava.lang.Thread.getStackTrace()to get stack trace for platform and mounted virtual threads) to correctly useThreadListHandlefor thread protection.Testing: tier1..5
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26119/head:pull/26119$ git checkout pull/26119Update a local copy of the PR:
$ git checkout pull/26119$ git pull https://git.openjdk.org/jdk.git pull/26119/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26119View PR using the GUI difftool:
$ git pr show -t 26119Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26119.diff
Using Webrev
Link to Webrev Comment