-
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
8280422: thread_from_jni_environment can never return NULL #7193
Conversation
👋 Welcome back dholmes! A progress list of the required criteria for merging this PR into |
@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. |
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.
Looks sensible to me.
@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 33 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 |
Thanks for the review @shipilev ! |
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.
return NULL; | ||
} else { | ||
return thread_from_jni_env; | ||
JavaThread* current = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset())); |
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.
[pre-existing] If I were writing this I would have used char*
rather than intptr_t
.
Thanks @kimbarrett ! /integrate |
Going to push as commit f35df5b.
Your commit was automatically rebased without conflicts. |
@dholmes-ora Pushed as commit f35df5b. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This seems to break I run into this rather often when running a profiler on the dacapo benchmark suite with an debug build of the JDK. |
I would suggest to add a method for checking the termination status in cases where it might happen: // Returns whether current thread as indicated by the given JNIEnv
// is terminated.
// We don't assert it is Thread::current here as that is done at the
// external JNI entry points where the JNIEnv is passed into the VM.
static bool is_thread_from_jni_environment_terminated(JNIEnv* env) {
JavaThread* current = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
// We can't get here in a thread that has completed its execution and so
// "is_terminated", but a thread is also considered terminated if the VM
// has exited, so we have to check this and block in case this is a daemon
// thread returning to the VM (the JNI DirectBuffer entry points rely on
// this).
return current->is_terminated();
} |
Can you please provide further information. As a correctly used JNIEnv can never produce a NULL thread as the JNIEnv is a sub-object of the JavaThread instance. |
AsyncGetCallTrace is implemented in forte.cpp: void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {
JavaThread* thread;
if (trace->env_id == NULL ||
(thread = JavaThread::thread_from_jni_environment(trace->env_id)) == NULL ||
thread->is_exiting()) {
// bad env_id, thread has exited or thread is exiting
trace->num_frames = ticks_thread_exit; // -8
return;
} I'm going to create a separate issue with a PR for the discussion. |
That condition should just be:
|
That does not address the issue, as |
Correct but this PR did not introduce that behaviour. I only changed the name of the local variable and added the comment. |
// this). | ||
if (current->is_terminated()) { | ||
current->block_if_vm_exited(); | ||
ShouldNotReachHere(); |
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 breaks AsyncGetCallTrace
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.
If we reach that code then the VM aborts. It should be impossible to reach that statement and thus impossible to actually return NULL in the old code. Please elaborate under what conditions you think this code can be reached.
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.
AsyncProfiler on a debug build of OpenJDK profiling the dacapo tomcat benchmark.
It seems to me that this commit introduces the |
I've created a PR with a fix at #7559 |
Analysing the code and its use (see JBS issue for gory details) we can see that
thread_from_jni_environment
can never actually return NULL, so we change it to not appear to do so and thus keep static analysis tools happy. We also always validate the incoming JNIEnv for debug builds and scrap the unusedVerifyJNIEnvThread
flag.Testing: tiers 1-5
Thanks,
David
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7193/head:pull/7193
$ git checkout pull/7193
Update a local copy of the PR:
$ git checkout pull/7193
$ git pull https://git.openjdk.java.net/jdk pull/7193/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7193
View PR using the GUI difftool:
$ git pr show -t 7193
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7193.diff