-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
8332259: JvmtiTrace::safe_get_thread_name fails if current thread is in native state #19275
Conversation
👋 Welcome back lmesnik! A progress list of the required criteria for merging this PR into |
@lmesnik 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 142 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 |
Webrevs
|
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 have to wonder whether this solution will potentially cause problems because the code will now block for safepoints. We could fallback to Thread::name()
if the current thread is in-native.
Thanks for feedback. Here is the update. I've updated the safe_get_thread_name() to not change thread state. In "jvmtiEnter.xsl" functions the thread name is s read once before the transition happened and re-used then. |
I don't understand the additional changes because they read the current thread's name, whereas this issue is about reading an arbitrary thread's name when the current thread happens to be in the wrong state. ??? |
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.
Okay now I get it. Even once the function is made truly safe, we are always calling it from an unsafe state and so will get the default Thread::name
response. So now, after any transition to the VM the name is read again to get a good value. This seems a good enhancement though I have to wonder if the apparent changing of the thread name in the tracing might cause problems. The tracing really needs to include a unique thread identifier.
Thanks
@@ -958,7 +958,6 @@ JvmtiEventControllerPrivate::clear_to_frame_pop(JvmtiEnvThreadState *ets, JvmtiF | |||
void | |||
JvmtiEventControllerPrivate::change_field_watch(jvmtiEvent event_type, bool added) { | |||
int *count_addr; | |||
|
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: this file doesn't need to be touched.
Are there tests that run with TraceJVMTI so that this option is tested? |
There are no tests currently executed with TraceJVMTI. |
I discussed the issue with @sspitsyn and after this, I updated the function to return something more descriptive in case we can't read thread state. (Easier to understand what happens.) |
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, Posted one nit though.
if (Thread::current()->is_Java_thread()) { | ||
JavaThreadState current_state = JavaThread::cast(Thread::current())->thread_state(); | ||
if (current_state == _thread_in_native || current_state == _thread_blocked) { | ||
return "not readable"; |
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 make it more detailed, something like like this:
"" or ""
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.
Yes this would have looked better if the text was more clearly an error message with angle brackets.
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.
@sspitsyn, @dholmes-ora Thanks for the naming suggestion, looks to long in the report. Let me try to use logging and see if it makes sense to make more improvements.
The name becomes too long in the logs. |
/integrate |
Going to push as commit 03b7a85.
Your commit was automatically rebased without conflicts. |
The JvmtiTrace::safe_get_thread_name sometimes crashes when called while current thread is in native thread state.
It happens when thread_name is set for tracing from jvmti functions.
See:
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/prims/jvmtiEnter.xsl#L649
The setup is called and the thread name is used in tracing before the thread transition. There is no good location where this method could be called from vm thread_state only. Some functions like raw monitor enter/exit never transition in vm state. So sometimes it is needed to call this function from native thread state.
The change should affect JVMTI trace mode only (-XX:TraceJVMTI).
Verified by running jvmti/jdi/jdb tests with tracing enabled.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19275/head:pull/19275
$ git checkout pull/19275
Update a local copy of the PR:
$ git checkout pull/19275
$ git pull https://git.openjdk.org/jdk.git pull/19275/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19275
View PR using the GUI difftool:
$ git pr show -t 19275
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19275.diff
Webrev
Link to Webrev Comment