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

Optimize JNIHandle::make_local thread variable usage

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 16
    • 16
    • hotspot
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: