Skip to content

Commit e958670

Browse files
authored
feat: support setting jsdk library file path for jit manager (#117)
* Support setting jsdk library file path for jit manager * Remove the log * Add java doc for checkstyle
1 parent d038cbd commit e958670

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

java/hybridse-sdk/src/main/java/com/_4paradigm/hybridse/HybridSeLibrary.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
*/
2525
public class HybridSeLibrary {
2626
private static final Logger logger = LoggerFactory.getLogger(HybridSeLibrary.class.getName());
27-
private static final String HybridSE_JSDK_CORE_NAME = "hybridse_jsdk_core";
27+
private static final String DEFAULT_HYBRIDSE_JSDK_CORE_NAME = "hybridse_jsdk_core";
28+
2829
private static boolean initialized = false;
2930

3031
/**
@@ -34,7 +35,18 @@ public static synchronized void initCore() {
3435
if (initialized) {
3536
return;
3637
}
37-
LibraryLoader.loadLibrary(HybridSE_JSDK_CORE_NAME);
38+
LibraryLoader.loadLibrary(DEFAULT_HYBRIDSE_JSDK_CORE_NAME);
39+
initialized = true;
40+
}
41+
42+
/**
43+
* Load hybridse jsdk core if it hasn't loaded before.
44+
*/
45+
public static synchronized void initCore(String jsdkCoreLibraryPath) {
46+
if (initialized) {
47+
return;
48+
}
49+
LibraryLoader.loadLibrary(jsdkCoreLibraryPath);
3850
initialized = true;
3951
}
4052

java/hybridse-sdk/src/main/java/com/_4paradigm/hybridse/sdk/JitManager.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ public class JitManager {
3838

3939
private static Logger logger = LoggerFactory.getLogger(JitManager.class);
4040

41-
static {
42-
HybridSeLibrary.initCore();
43-
Engine.InitializeGlobalLLVM();
44-
}
4541

4642
// One jit currently only take one llvm module, since symbol may duplicate
4743
private static Map<String, HybridSeJitWrapper> jits = new HashMap<>();
@@ -112,17 +108,43 @@ private static synchronized void initModule(String tag, ByteBuffer moduleBuffer)
112108
initializedModuleTags.add(tag);
113109
}
114110

111+
public static synchronized void initCore() {
112+
HybridSeLibrary.initCore();
113+
Engine.InitializeGlobalLLVM();
114+
}
115+
116+
public static synchronized void initCore(String jsdkCoreLibraryPath) {
117+
HybridSeLibrary.initCore(jsdkCoreLibraryPath);
118+
Engine.InitializeGlobalLLVM();
119+
}
120+
115121
/**
116122
* Init llvm module specified by tag. Init native module with module byte buffer.
117123
*
118124
* @param tag tag specified a jit
119125
* @param moduleBuffer ByteBuffer used to initialize native module
120126
*/
121127
public static synchronized void initJitModule(String tag, ByteBuffer moduleBuffer) {
122-
123128
// ensure worker native
124129
HybridSeLibrary.initCore();
125130

131+
// ensure worker side module
132+
if (!JitManager.hasModule(tag)) {
133+
JitManager.initModule(tag, moduleBuffer);
134+
}
135+
}
136+
137+
/**
138+
* Init llvm module specified by tag. Init native module with module byte buffer.
139+
*
140+
* @param tag tag specified a jit
141+
* @param moduleBuffer ByteBuffer used to initialize native module
142+
* @param jsdkCoreLibraryPath the file path of jsdk core library
143+
*/
144+
public static synchronized void initJitModule(String tag, ByteBuffer moduleBuffer, String jsdkCoreLibraryPath) {
145+
// ensure worker native
146+
HybridSeLibrary.initCore(jsdkCoreLibraryPath);
147+
126148
// ensure worker side module
127149
if (!JitManager.hasModule(tag)) {
128150
JitManager.initModule(tag, moduleBuffer);

0 commit comments

Comments
 (0)