diff options
Diffstat (limited to 'src/main/java/net/openhft/chronicle/core/UnsafeMemory.java')
-rwxr-xr-x | src/main/java/net/openhft/chronicle/core/UnsafeMemory.java | 12 |
1 files changed, 12 insertions, 0 deletions
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(); } |