Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8320658

ThreadInfo.isInNative needs to be updated to say what executing native code means

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • core-svc
    • None
    • minimal
    • Docs only clarification, no compatibility impact
    • Java API
    • SE

      Summary

      Update the specification of java.lang.management.ThreadInfo::isInNative to make it clearer when it returns true.

      Problem

      The method description (which dates from Java 5) is a bit confusing as it speaks of "executing native code via the JNI". It also predates the introduction of the java.lang.foreign API and the ability to invoke native code using a method handle obtained from the native linker.

      Solution

      Update method description to make it clear that it returns true when the thread is executing a native method or when it is executing native code via a method handle obtained from the native linker.

      Specification

      Update the specification of java.lang.management.ThreadInfo::isInNative as follows:

           /**
      -     * Tests if the thread associated with this {@code ThreadInfo}
      -     * is executing native code via the Java Native Interface (JNI).
      -     * The JNI native code does not include
      -     * the virtual machine support code or the compiled native
      -     * code generated by the virtual machine.
      +     * Tests if the thread associated with this {@code ThreadInfo} is executing
      +     * 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
      +     * Linker#downcallHandle(java.lang.foreign.FunctionDescriptor, Linker.Option...)
      +     * method handle} obtained from the {@linkplain Linker native linker}, or is
      +     * <a href="{@docRoot}/../specs/jni/invocation.html#attachcurrentthread">
      +     * attached</a> to the VM with the <a href="{@docRoot}/../specs/jni/index.html">
      +     * Java Native Interface</a> with no Java frames on its stack.
      +     *
      +     * <p> Native code does not include Java virtual machine support code,
      +     * compiled code generated by the Java virtual machine, or special cases
      +     * such as a thread blocked on a <a href="{@docRoot}/../specs/jvmti.html#RawMonitors">
      +     * JVM TI raw monitor</a>.
            *
            * @return {@code true} if the thread is executing native code;
            *         {@code false} otherwise

            alanb Alan Bateman
            alanb Alan Bateman
            Mandy Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: