Added fix for java 32bit on windows
This commit is contained in:
parent
e08b35caa8
commit
b01ba51ade
@ -15,13 +15,19 @@
|
|||||||
*/
|
*/
|
||||||
package dorkbox.util;
|
package dorkbox.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.sun.jna.Library;
|
||||||
import com.sun.jna.Native;
|
import com.sun.jna.Native;
|
||||||
|
import com.sun.jna.NativeLibrary;
|
||||||
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;
|
||||||
|
import com.sun.jna.win32.StdCallFunctionMapper;
|
||||||
|
|
||||||
// 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
|
||||||
@ -69,6 +75,7 @@ public class BootStrapClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: this does not work in java8 x86 *on windows XP windows7, etc. It only works on x64
|
||||||
public
|
public
|
||||||
interface JVM extends com.sun.jna.Library {
|
interface JVM extends com.sun.jna.Library {
|
||||||
void JVM_DefineClass(Pointer env, String name, Object loader, byte[] buffer, int length, Object protectionDomain);
|
void JVM_DefineClass(Pointer env, String name, Object loader, byte[] buffer, int length, Object protectionDomain);
|
||||||
@ -110,18 +117,7 @@ public class BootStrapClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static {
|
||||||
* Inject class bytes directly into the bootstrap classloader.
|
|
||||||
* <p>
|
|
||||||
* This is a VERY DANGEROUS method to use!
|
|
||||||
*
|
|
||||||
* @param classBytes
|
|
||||||
* the bytes to inject
|
|
||||||
*/
|
|
||||||
public static
|
|
||||||
void defineClass(byte[] classBytes) throws Exception {
|
|
||||||
|
|
||||||
if (libjvm == null) {
|
|
||||||
String libName;
|
String libName;
|
||||||
if (OS.isMacOsX()) {
|
if (OS.isMacOsX()) {
|
||||||
if (OS.javaVersion < 7) {
|
if (OS.javaVersion < 7) {
|
||||||
@ -137,8 +133,40 @@ public class BootStrapClassLoader {
|
|||||||
else {
|
else {
|
||||||
libName = "jvm";
|
libName = "jvm";
|
||||||
}
|
}
|
||||||
libjvm = (JVM) Native.loadLibrary(libName, JVM.class);
|
|
||||||
|
// function name is SLIGHTLY different on windows x32 java builds.
|
||||||
|
// For actual name use: http://www.nirsoft.net/utils/dll_export_viewer.html
|
||||||
|
if (OS.isWindows() && OS.is32bit()) {
|
||||||
|
Map options = new HashMap();
|
||||||
|
options.put(Library.OPTION_FUNCTION_MAPPER, new StdCallFunctionMapper() {
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
String getFunctionName(NativeLibrary library, Method method) {
|
||||||
|
String methodName = method.getName();
|
||||||
|
if (methodName.equals("JVM_DefineClass")) {
|
||||||
|
// specifically Oracle Java 32bit builds. Tested on XP and Win7
|
||||||
|
return "_JVM_DefineClass@24";
|
||||||
}
|
}
|
||||||
|
return methodName;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
libjvm = Native.loadLibrary(libName, JVM.class, options);
|
||||||
|
} else {
|
||||||
|
libjvm = Native.loadLibrary(libName, JVM.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject class bytes directly into the bootstrap classloader.
|
||||||
|
* <p>
|
||||||
|
* This is a VERY DANGEROUS method to use!
|
||||||
|
*
|
||||||
|
* @param classBytes
|
||||||
|
* the bytes to inject
|
||||||
|
*/
|
||||||
|
public static
|
||||||
|
void defineClass(byte[] classBytes) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
// get the number of JVM's running
|
// get the number of JVM's running
|
||||||
int[] jvmCount = {100};
|
int[] jvmCount = {100};
|
||||||
|
Loading…
Reference in New Issue
Block a user