summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrej Shadura <andrew.shadura@collabora.co.uk>2019-02-27 17:07:09 +0100
committerAndrej Shadura <andrew.shadura@collabora.co.uk>2019-02-27 21:16:44 +0100
commitbf04b6356b99c8874af612ceebe5b7268100de4b (patch)
treebc0a1b1e033a06cdd49e436a3633168f7b2d85df
parent1fb9dc54b5dc0a19510679101a990646a3590d48 (diff)
Java 11 drops defineClass from sun.misc.Unsafe
Closes: #917736
-rw-r--r--debian/patches/java11-compatiblitily.patch90
-rw-r--r--debian/patches/series1
2 files changed, 91 insertions, 0 deletions
diff --git a/debian/patches/java11-compatiblitily.patch b/debian/patches/java11-compatiblitily.patch
new file mode 100644
index 0000000..a8f388a
--- /dev/null
+++ b/debian/patches/java11-compatiblitily.patch
@@ -0,0 +1,90 @@
+From: Andrej Shadura <andrewsh@debian.org>
+Date: Wed, 27 Feb 2019 17:03:02 +0100
+Subject: Fixes the compatibility with Java 11
+
+--- a/src/main/java/net/openhft/chronicle/core/ClassLoading.java
++++ b/src/main/java/net/openhft/chronicle/core/ClassLoading.java
+@@ -41,6 +41,10 @@
+ * @return the class loaded.
+ */
+ private static Class defineClass(ClassLoader classLoader, String className, 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);
++ }
+ }
+ }
+--- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
++++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
+@@ -18,12 +18,16 @@
+
+ import net.openhft.chronicle.core.annotation.ForceInline;
+ 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;
+
+ public class UnsafeMemory implements Memory {
+ static Unsafe UNSAFE;
++ static MethodHandle defineClassMethodHandle;
+ private final AtomicLong nativeMemoryUsed = new AtomicLong();
+
+ public static Memory create() {
+@@ -34,6 +38,14 @@
+ } catch (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);
++ }
+ }
+ return new UnsafeMemory();
+ }
+--- a/pom.xml
++++ b/pom.xml
+@@ -105,8 +105,12 @@
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <compilerArgument>-Xlint:deprecation</compilerArgument>
+- <source>1.8</source>
+- <target>1.8</target>
++ <source>1.9</source>
++ <target>1.9</target>
++ <compilerArgs>
++ <arg>--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED</arg>
++ <arg>--add-exports=java.base/sun.nio.ch=ALL-UNNAMED</arg>
++ </compilerArgs>
+ </configuration>
+ </plugin>
+ <!--
+--- a/src/main/java/net/openhft/chronicle/core/io/IOTools.java
++++ b/src/main/java/net/openhft/chronicle/core/io/IOTools.java
+@@ -16,8 +16,6 @@
+
+ package net.openhft.chronicle.core.io;
+
+-import sun.reflect.Reflection;
+-
+ import java.io.*;
+
+ /**
+@@ -29,7 +27,8 @@ public enum IOTools {
+ public static byte[] readFile(String name) throws IOException {
+ ClassLoader classLoader;
+ try {
+- classLoader = Reflection.getCallerClass().getClassLoader();
++ StackWalker instance = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
++ classLoader = instance.getCallerClass().getClassLoader();
+ } catch (Throwable e) {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ }
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..bdb676a
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+java11-compatiblitily.patch