Fixed bootstrap injection for MacOSX
This commit is contained in:
parent
2f16e5275f
commit
982b8eed6c
|
@ -19,7 +19,6 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.sun.jna.Native;
|
import com.sun.jna.Native;
|
||||||
import com.sun.jna.Platform;
|
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
import com.sun.jna.Structure;
|
import com.sun.jna.Structure;
|
||||||
import com.sun.jna.ptr.PointerByReference;
|
import com.sun.jna.ptr.PointerByReference;
|
||||||
|
@ -27,6 +26,9 @@ import com.sun.jna.ptr.PointerByReference;
|
||||||
// http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/be698ac28848/src/share/native/java/lang/ClassLoader.c
|
// http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/be698ac28848/src/share/native/java/lang/ClassLoader.c
|
||||||
// http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/tip/src/share/vm/prims/jvm.cpp
|
// http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/tip/src/share/vm/prims/jvm.cpp
|
||||||
|
|
||||||
|
// objdump -T <file> | grep foo
|
||||||
|
// otool -T <file> | grep foo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives us the ability to inject bytes directly into java's bootstrap classloader.
|
* Gives us the ability to inject bytes directly into java's bootstrap classloader.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -73,7 +75,6 @@ public class BootStrapClassLoader {
|
||||||
int JNI_GetCreatedJavaVMs(JavaVM.ByReference[] vmArray, int bufsize, int[] vmCount);
|
int JNI_GetCreatedJavaVMs(JavaVM.ByReference[] vmArray, int bufsize, int[] vmCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static
|
public static
|
||||||
class JNIInvokeInterface extends Structure {
|
class JNIInvokeInterface extends Structure {
|
||||||
public static
|
public static
|
||||||
|
@ -119,8 +120,23 @@ public class BootStrapClassLoader {
|
||||||
*/
|
*/
|
||||||
public static
|
public static
|
||||||
void defineClass(byte[] classBytes) throws Exception {
|
void defineClass(byte[] classBytes) throws Exception {
|
||||||
|
|
||||||
if (libjvm == null) {
|
if (libjvm == null) {
|
||||||
String libName = Platform.isMac() ? "JavaVM" : "jvm";
|
String libName;
|
||||||
|
if (OS.isMacOsX()) {
|
||||||
|
if (OS.javaVersion < 7) {
|
||||||
|
libName = "JavaVM";
|
||||||
|
} else {
|
||||||
|
String javaLocation = System.getProperty("java.home");
|
||||||
|
|
||||||
|
// have to explicitly specify the JVM library via full path
|
||||||
|
// this is OK, because for java on MacOSX, this is the only location it can exist
|
||||||
|
libName = javaLocation + "/lib/server/libjvm.dylib";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
libName = "jvm";
|
||||||
|
}
|
||||||
libjvm = (JVM) Native.loadLibrary(libName, JVM.class);
|
libjvm = (JVM) Native.loadLibrary(libName, JVM.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user