Преглед изворни кода

HPCC-10060: Improve memory and thread handling of embedded Java code

Within destructor for JavaThreadContext class, add an explicit DetachCurrentThread() call to detatch the native thred from the JVM.  This allows the JVM to more easily determine what needs to be garbaged collected.

Within the constructor and destructor for JavaEmbedImportContext class, add calls to push and pop a local reference frame in the JNI.  This collects new local references and enables them to be GC'd when the frame is popped, freeing memory somewhat faster.  Also, allow up to 64 local references to be tracked/created (up from the default of 16).
Dan S. Camper пре 11 година
родитељ
комит
dd5f62d557
1 измењених фајлова са 12 додато и 0 уклоњено
  1. 12 0
      plugins/javaembed/javaembed.cpp

+ 12 - 0
plugins/javaembed/javaembed.cpp

@@ -202,6 +202,11 @@ public:
     {
         if (javaClass)
             JNIenv->DeleteGlobalRef(javaClass);
+        
+        // According to the Java VM 1.7 docs, "A native thread attached to
+        // the VM must call DetachCurrentThread() to detach itself before
+        // exiting."
+        globalState->javaVM->DetachCurrentThread();
     }
 
     void checkException()
@@ -557,9 +562,16 @@ public:
     {
         argcount = 0;
         argsig = NULL;
+        
+        // Create a new frame for local references and increase the capacity
+        // of those references to 64 (default is 16)
+        sharedCtx->JNIenv->PushLocalFrame(64);
     }
     ~JavaEmbedImportContext()
     {
+        // Pop local reference frame; explicitly frees all local
+        // references made during that frame's lifetime
+        sharedCtx->JNIenv->PopLocalFrame(NULL);
     }
 
     virtual bool getBooleanResult()