summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2019-02-27 17:03:02 +0100
committerAndrej Shadura <andrewsh@debian.org>2019-02-27 17:10:30 +0100
commit1edac7c9b8b68c6a325482cd1b64bcbe172bfac4 (patch)
tree3c821c9f7f3b9d7751be3f80d48a813572c16be9
parent2597ae734b74b481fedaa4f9a91585aa23f0d724 (diff)
Fixes the compatibility with Java 11archive/debian/2.17.5-1
Gbp-Pq: Name java11-compatiblitily.patch
-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();
}