Do we need all the calls to DeleteLocalRef in the C++ JavaHL code after
a method has completed and for it to clean up after itself. We have a
ton of this kind of code:
// No need to check for an exception here, because we return anyway.
Why can't we just return after calling env->CallVoidMethod?
I'm not saying we get rid of this call everywhere, such as utility
functions that set up Java objects, but for calls that return directly
to the JVM.
The JVM cleans up local references already when the JNI call completes.
So wouldn't it be faster for the JVM to do this then for us to have to
call through env->DeleteLocalRef all the time? Then we also have to
check for exceptions, which doesn't seem particular light to me either:
JNIEnv *env = getEnv();
// Retrieving the exception removes it so we rethrow it here.
jthrowable exp = env->ExceptionOccurred();
From this page:
"The overhead of field access using the JNI lies in the cost of calling
through the JNIEnv. Rather than directly dereferencing objects, the
native code has to perform a C function call which in turn dereferences
the object. The function call is necessary because it isolates the
native code from the internal object representation maintained by the
virtual machine implementation. The JNI field access overhead is
typically negligible because a function call takes only a few cycles."
Also, what about adding a new
bool JNIUtil::isJavaExceptionThrown(JNIEnv *env);
function that takes the JNIEnv from the caller, which presumably already
has one? How expensive is the getEnv() call?
To unsubscribe, e-mail: firstname.lastname@example.org
For additional commands, e-mail: email@example.com
Received on Thu Apr 19 00:15:58 2007