-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8320652: ThreadInfo.isInNative needs to be updated to say what executing native code means #16791
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
/csr |
👋 Welcome back alanb! A progress list of the required criteria for merging this PR into |
@AlanBateman has indicated that a compatibility and specification (CSR) request is needed for this pull request. @AlanBateman please create a CSR request for issue JDK-8320652 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
@AlanBateman 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
|
* native code. This method returns {@code true} if the thread is executing | ||
* a native method or if executing native code invoked using a {@linkplain | ||
* java.lang.invoke.MethodHandle method handle} obtained from the | ||
* {@linkplain java.lang.foreign.Linker native linker}. | ||
* |
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 area is new to me, but I happened to be in this code few days back. I'm mostly curious on what the actual definition of a thread being in native means.
When a thread is executing any of the following, does it end up being considered as being in a "native method":
- A syscall (for example,
write()
) - A C function exposed by a platform specific library
- A JNI method (either part of the JDK or the application) which then may or may not do any syscall or C function call on a platform specific library
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 would agree, it should state if runtime functions (including those doing a syscall) will be counted here. (For JNi i would not need it to be spelled out, on the other hand it would help, since it makes clear we don’t mean c2 code)
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 isInNative
method intends to provide a way to tell if the thread has transitioned from executing Java method to a native method. JVM interpreter and compiler provide the support for Java language which is why I think such clarification might not be highly necessary.
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.
FWIW I would not remove the "does not include ..." information otherwise people may wrongly infer that in the past this method would not return true for VM code or generated code, but that now it does.
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.
Note that there is no answer for the "syscall" case mentioned as it depends on the code that makes the syscall: if from a native method then yes; if from the VM then no.
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.
Well.. it has to do in so far, that those threads are not hidden - the ThreadInfo sees it and says "isNative". But ok if this is not expected, then indeed it does not need to be documented.
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 to be no java method marked "native" on the stack, what case is that?
A native thread that is attached to the VM but is not currently executing any Java code.
funfact: its not in the list
JDWP filters its own internal threads out of any thread lists it returns, so this may be a case of using two different API's with different views of the set of threads running.
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.
JDWP filters its own internal threads out of any thread lists it returns, so this may be a case of using two different API's with different views of the set of threads running.
I think the issue that Bernd is running into is a long standing anomaly between ThreadMXBean.getAllThreadIds() and the ThreadMXBean.getThreadInfo methods. The former uses a ThreadsListEnumerator with include_jvmti_agent_threads=false so it filters out the JVMTI agent threads. The latter doesn't do the filtering so if you have threadId of a JVMTI agent thread then you can get its thread info.
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've created JDK-8321095 to track the inconsistency that Bernd brought up on whether JVMTI agent threads are hidden or not by ThreadMXBean. It seems this inconsistency goes back a long way, to JDK 8 at least.
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.
funfact: its not in the list
JDWP filters its own internal threads out of any thread lists it returns, so this may be a case of using two different API's with different views of the set of threads running.
JDWP does filter out its own threads (but not other JVMTI agent threads), but are we talking about JDWP here? It looks like Thread.print dcmd is producing the thread list that includes the JDWP threads, and as pointed out, ThreadMXBean.getAllThreadIds() does not include the JDWP threads (this is due to ThreadMXBean doing the filtering of JVMTI agent threads, not JDWP).
Note that threadId
is clearly specified by ThreadMXBean, but there is no specification for the Thread.print output, so using unlabeled values from Thread.print as an argument to ThreadMXBean.getThreadInfo() seems somewhat presumptuous.
It's ok to drop the sentence about "native code" does not include runtime or compiled code. I can see why you left out the detail of a downcall handle. Maybe better to link the text "method handle" to |
That's a good idea, I've changed it to link to downcallHandle instead. |
Thank you Alan for this latest update in commit |
* native code. | ||
* | ||
* <p> A thread is considered to be executing native code when it is executing a | ||
* native method, executing native code invoked using a {@linkplain |
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 - should "native method" be "{@code native} method"?
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 updated spec change looks good.
@AlanBateman 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 16 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 |
/integrate |
Going to push as commit 4fbf22b.
Your commit was automatically rebased without conflicts. |
@AlanBateman Pushed as commit 4fbf22b. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This is a docs only change to j.l.management.ThreadInfo::isInNative.
The method currently specifies that it tests if the thread is "executing native code via the Java Native Interface (JNI)". It would be clearer to say that it tests if the thread is executing a native method, and expand it to include native code invoked using the new foreign linker APIs. For now, I've left out the detail of a downcall handle created with the "critical" linker option.
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16791/head:pull/16791
$ git checkout pull/16791
Update a local copy of the PR:
$ git checkout pull/16791
$ git pull https://git.openjdk.org/jdk.git pull/16791/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 16791
View PR using the GUI difftool:
$ git pr show -t 16791
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16791.diff
Webrev
Link to Webrev Comment