Bläddra i källkod

Merge pull request #4854 from dcamper/master

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

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 11 år sedan
förälder
incheckning
8f618ab101
1 ändrade filer med 12 tillägg och 0 borttagningar
  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()