summaryrefslogtreecommitdiff
path: root/src/main/java/net/openhft/chronicle
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/openhft/chronicle')
-rw-r--r--src/main/java/net/openhft/chronicle/core/ClassLoading.java6
-rwxr-xr-xsrc/main/java/net/openhft/chronicle/core/UnsafeMemory.java12
2 files changed, 17 insertions, 1 deletions
diff --git a/src/main/java/net/openhft/chronicle/core/ClassLoading.java b/src/main/java/net/openhft/chronicle/core/ClassLoading.java
index 1167c2e..9a196ec 100644
--- a/src/main/java/net/openhft/chronicle/core/ClassLoading.java
+++ b/src/main/java/net/openhft/chronicle/core/ClassLoading.java
@@ -45,6 +45,10 @@ public enum ClassLoading {
* @return the class loaded.
*/
private static Class defineClass(ClassLoader classLoader, String className, @NotNull byte[] bytes) {
- return UnsafeMemory.UNSAFE.defineClass(className, bytes, 0, bytes.length, classLoader, null);
+ try {
+ return (Class) UnsafeMemory.defineClassMethodHandle.bindTo(classLoader).invokeWithArguments(className, bytes, 0, bytes.length);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
}
}
diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
index ec92c74..2cb1a58 100755
--- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
+++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
@@ -19,6 +19,9 @@ package net.openhft.chronicle.core;
import net.openhft.chronicle.core.annotation.ForceInline;
import org.jetbrains.annotations.NotNull;
import sun.misc.Unsafe;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicLong;
@@ -28,6 +31,7 @@ public class UnsafeMemory implements Memory {
@NotNull
public static final Unsafe UNSAFE;
+ public static final MethodHandle defineClassMethodHandle;
public static final UnsafeMemory INSTANCE;
// see java.nio.Bits.copyMemory
// This number limits the number of bytes to copy per call to Unsafe's
@@ -43,6 +47,14 @@ public class UnsafeMemory implements Memory {
} catch (@NotNull NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
throw new AssertionError(e);
}
+ try {
+ MethodHandles.Lookup baseLookup = MethodHandles.lookup();
+ MethodType defineClassMethodType = MethodType.methodType(Class.class, new Class[]{String.class, byte[].class, int.class, int.class});
+ MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(ClassLoader.class, baseLookup);
+ defineClassMethodHandle = lookup.findVirtual(ClassLoader.class, "defineClass", defineClassMethodType);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
INSTANCE = Jvm.isArm() ? new ARMMemory() : new UnsafeMemory();
}