Avoid to load native library twice even if SnappyNativeLoader injected to an ancestor class loader is discared
This commit is contained in:
parent
0f75526c85
commit
7931742179
|
@ -139,7 +139,7 @@ public class SnappyLoader
|
||||||
preloadClassByteCode.add(getByteCode(String.format("/%s.class", each.replaceAll("\\.", "/"))));
|
preloadClassByteCode.add(getByteCode(String.format("/%s.class", each.replaceAll("\\.", "/"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new class from a byte code
|
// Create SnappyNative class from a byte code
|
||||||
Class< ? > classLoader = Class.forName("java.lang.ClassLoader");
|
Class< ? > classLoader = Class.forName("java.lang.ClassLoader");
|
||||||
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
|
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
|
||||||
byte[].class, int.class, int.class, ProtectionDomain.class });
|
byte[].class, int.class, int.class, ProtectionDomain.class });
|
||||||
|
@ -168,16 +168,24 @@ public class SnappyLoader
|
||||||
Class< ? > loaderClass = systemClassLoader.loadClass(nativeLoaderClassName);
|
Class< ? > loaderClass = systemClassLoader.loadClass(nativeLoaderClassName);
|
||||||
if (loaderClass != null) {
|
if (loaderClass != null) {
|
||||||
|
|
||||||
File nativeLib = findNativeLibrary();
|
final String KEY_SNAPPY_NATIVE_LOAD_FLAG = "org.xerial.snappy.native_is_loaded";
|
||||||
if (nativeLib != null) {
|
boolean isNativeLibLoaded = Boolean.parseBoolean(System.getProperty(KEY_SNAPPY_NATIVE_LOAD_FLAG,
|
||||||
// Load extracted or specified snappyjava native library.
|
"false"));
|
||||||
Method loadMethod = loaderClass.getDeclaredMethod("load", new Class[] { String.class });
|
if (!isNativeLibLoaded) {
|
||||||
loadMethod.invoke(null, nativeLib.getAbsolutePath());
|
File nativeLib = findNativeLibrary();
|
||||||
}
|
if (nativeLib != null) {
|
||||||
else {
|
// Load extracted or specified snappyjava native library.
|
||||||
// Load preinstalled snappyjava (in the path -Djava.library.path)
|
Method loadMethod = loaderClass.getDeclaredMethod("load", new Class[] { String.class });
|
||||||
Method loadMethod = loaderClass.getDeclaredMethod("loadLibrary", new Class[] { String.class });
|
loadMethod.invoke(null, nativeLib.getAbsolutePath());
|
||||||
loadMethod.invoke(null, "snappyjava");
|
}
|
||||||
|
else {
|
||||||
|
// Load preinstalled snappyjava (in the path -Djava.library.path)
|
||||||
|
Method loadMethod = loaderClass.getDeclaredMethod("loadLibrary",
|
||||||
|
new Class[] { String.class });
|
||||||
|
loadMethod.invoke(null, "snappyjava");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.setProperty(KEY_SNAPPY_NATIVE_LOAD_FLAG, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
// And also, preload the other dependent classes
|
// And also, preload the other dependent classes
|
||||||
|
|
Loading…
Reference in New Issue