Details
-
Enhancement
-
Resolution: Fixed
-
P4
-
16
-
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.
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.