Browse Source

HPCC-22824 Ensure javaembed is loaded and available for HPCCUtils.log use

If HpccUtils has not previously been used, calls to hpccutils.log would fail.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 5 years ago
parent
commit
1c8eb5213a
2 changed files with 9 additions and 3 deletions
  1. 4 0
      plugins/javaembed/HpccUtils.java
  2. 5 3
      plugins/javaembed/javaembed.cpp

+ 4 - 0
plugins/javaembed/HpccUtils.java

@@ -35,6 +35,10 @@ public class HpccUtils  implements Iterator, ActivityContext
         System.load(dllname);
         handle = _handle;
     }
+    public static void load(String dllname)
+    {
+        System.load(dllname);
+    }
     public native void remove();
     public boolean hasNext()
     {

+ 5 - 3
plugins/javaembed/javaembed.cpp

@@ -695,6 +695,7 @@ static jobject getClassLoader(CheckedJNIEnv *JNIenv, jclass obj)
     return classloader;
 }
 
+static StringBuffer helperLibraryName;
 static CheckedJNIEnv *queryJNIEnv();
 
 // Some global objects setup at load time for efficiency and code readability
@@ -704,6 +705,7 @@ static jmethodID clc_newInstance;
 static jmethodID clc_getSignature;
 static jclass hpccIteratorClass;
 static jmethodID hi_constructor;
+static jmethodID hi_load;
 static jclass utilIteratorClass;
 static jclass langIterableClass;
 static jmethodID iterable_iterator;
@@ -786,6 +788,8 @@ static void setupGlobals(CheckedJNIEnv *J)
         clc_getSignature = J->GetStaticMethodID(customLoaderClass, "getSignature","(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/String;");
         hpccIteratorClass = J->FindGlobalClass("com/HPCCSystems/HpccUtils");
         hi_constructor = J->GetMethodID(hpccIteratorClass, "<init>", "(JLjava/lang/String;)V");
+        hi_load = J->GetStaticMethodID(hpccIteratorClass, "load", "(Ljava/lang/String;)V");
+        J->CallStaticVoidMethod(hpccIteratorClass, hi_load, J->NewStringUTF(helperLibraryName));
     }
     catch (IException *E)
     {
@@ -1027,15 +1031,12 @@ void JavaGlobalState::unregister(const char *key)
     globalState->doUnregister(key);
 }
 
-static StringBuffer helperLibraryName;
-
 #ifdef _WIN32
     EXTERN_C IMAGE_DOS_HEADER __ImageBase;
 #endif
 
 MODULE_INIT(INIT_PRIORITY_STANDARD)
 {
-    globalState = new JavaGlobalState;
     // Make sure we are never unloaded (as JVM does not support it)
     // we do this by doing a dynamic load of the javaembed library
 #ifdef _WIN32
@@ -1054,6 +1055,7 @@ MODULE_INIT(INIT_PRIORITY_STANDARD)
         // Deliberately leak this handle
     }
 #endif
+    globalState = new JavaGlobalState;
     return true;
 }
 MODULE_EXIT()