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

Optimize JNIHandle::make_local thread variable usage

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 16
    • Fix Version/s: 16
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:
      b07

      Description

      All JNI functions are declared as a JNI_ENTRY which is a wrapper that, in part, extracts the current thread:

      JavaThread* thread=JavaThread::thread_from_jni_environment(env);
      Thread* THREAD = thread;

      but many JNI methods don't take advantage of this existing variable and instead implicitly re-evaluate the current thread by passing the current JNIEnv through to internal API's. For example:

      JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
        ...
        ret = JNIHandles::make_local(env, i);
        return ret;
      JNI_END

      could instead use:

        ret = JNIHandles::make_local(THREAD, i);

      The same seems to be true of all uses of make_local(env, obj) there is always a THREAD variable available either via a specific ENTRY macro (JNI_ENTRY, JVM_ENTRY, UNSAFE_ENTRY etc) or via a TRAPS parameter. So we can change all uses and remove the "env" version.

      There is also some unnecessary use of (Java)Thread::current() in relation to these calls, as again we already have the current thread materialized as THREAD.

        Attachments

          Activity

            People

            Assignee:
            dholmes David Holmes
            Reporter:
            dholmes David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: