This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] JNI performance improvements


graydon hoare wrote:

this patch implements two JNI optimizations:

 - avoidance of the malloc/free on each JNI call, when the call only
   uses the "bottom", non-reentrant frame (this is the majority of JNI
   traffic).

 - a fast path which avoids clearing the frame when leaving it, if
   no local references have been made. most JNI functions do not make
   any local references.


Graydon,

Great patch! But... are you sure that caching only the bottom-most frame is always sufficient? Its easy to imagine cases where nested JNI calls will be common. For example, won't the AWT JNI code be re-entered frequently now that we have a single event dispatch thread? ie: gtk_main_iteration called from event thread via JNI, an event is dispatched back to application which then makes another JNI call? Seems that we could end up popping up and down different levels of the stack frequently, which will eliminate much of the benefit of this optimization as frames will keep getting freed and re-allocated just as before.

We could avoid this by maintaining a chain of bottom frames which get re-used. Then again, if profiling shows that this really doesn't happen in practice then I'm prepared to trust that.

+// Destroy the env's reusable resources. This is called from the thread
+// destructor "finalize_native" in natThread.cc
+void +_Jv_FreeJNIEnv (_Jv_JNIEnv *env)
+{
+ if (env == NULL)
+ return;
+
+ if (env->bottom_locals != NULL)
+ _Jv_Free (env->bottom_locals);
+
+ _Jv_Free (env);
+}


Why don't we just GC-allocate these - ie _Jv_AllocBytes() ? Then we wouldn't need _Jv_FreeJNIEnv.

Regards

Bryce



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]