You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by xv...@apache.org on 2019/04/30 00:43:58 UTC

[incubator-druid] branch jdk9-unsafe created (now 33b7499)

This is an automated email from the ASF dual-hosted git repository.

xvrl pushed a change to branch jdk9-unsafe
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git.


      at 33b7499  replace jdk internal exceptions with closest publicly available one

This branch includes the following new commits:

     new 163f1dd  Remove direct references to unsafe for Java 9+
     new 33b7499  replace jdk internal exceptions with closest publicly available one

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[incubator-druid] 01/02: Remove direct references to unsafe for Java 9+

Posted by xv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xvrl pushed a commit to branch jdk9-unsafe
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git

commit 163f1dd70c842f0176d31574a545d6b6b5db4ed4
Author: Xavier Léauté <xv...@apache.org>
AuthorDate: Fri Apr 12 22:24:01 2019 -0700

    Remove direct references to unsafe for Java 9+
---
 .../druid/hll/HyperLogLogCollectorBenchmark.java   | 41 +++++++++++++++++-----
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/hll/src/test/java/org/apache/druid/hll/HyperLogLogCollectorBenchmark.java b/hll/src/test/java/org/apache/druid/hll/HyperLogLogCollectorBenchmark.java
index 938bd9c..66ea18e 100644
--- a/hll/src/test/java/org/apache/druid/hll/HyperLogLogCollectorBenchmark.java
+++ b/hll/src/test/java/org/apache/druid/hll/HyperLogLogCollectorBenchmark.java
@@ -25,8 +25,11 @@ import com.google.caliper.SimpleBenchmark;
 import com.google.common.base.Preconditions;
 import com.google.common.hash.HashFunction;
 import com.google.common.hash.Hashing;
-import sun.misc.Unsafe;
+import org.apache.druid.java.util.common.UnsafeUtils;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.lang.reflect.Field;
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
@@ -177,24 +180,44 @@ public class HyperLogLogCollectorBenchmark extends SimpleBenchmark
 
 class ByteBuffers
 {
-  private static final Unsafe UNSAFE;
   private static final long ADDRESS_OFFSET;
+  private static final MethodHandle GET_LONG;
 
   static {
     try {
-      Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
-      theUnsafe.setAccessible(true);
-      UNSAFE = (Unsafe) theUnsafe.get(null);
-      ADDRESS_OFFSET = UNSAFE.objectFieldOffset(Buffer.class.getDeclaredField("address"));
+      MethodHandles.Lookup lookup = MethodHandles.lookup();
+      ADDRESS_OFFSET = lookupAddressOffset(lookup);
+      GET_LONG = lookupGetLong(lookup);
     }
-    catch (Exception e) {
-      throw new RuntimeException("Cannot access Unsafe methods", e);
+    catch (Throwable t) {
+      throw new RuntimeException("Unable to lookup Unsafe methods", t);
     }
   }
 
+  private static long lookupAddressOffset(MethodHandles.Lookup lookup) throws Throwable
+  {
+    MethodHandle objectFieldOffset = lookup.findVirtual(UnsafeUtils.theUnsafeClass(), "objectFieldOffset",
+                                                        MethodType.methodType(long.class, Field.class)
+    );
+    return (long) objectFieldOffset.bindTo(UnsafeUtils.theUnsafe()).invoke(Buffer.class.getDeclaredField("address"));
+  }
+
+  private static MethodHandle lookupGetLong(MethodHandles.Lookup lookup) throws Throwable
+  {
+    MethodHandle getLong = lookup.findVirtual(UnsafeUtils.theUnsafeClass(), "getLong",
+                                              MethodType.methodType(long.class, Object.class, long.class)
+    );
+    return getLong.bindTo(UnsafeUtils.theUnsafe());
+  }
+
   public static long getAddress(ByteBuffer buf)
   {
-    return UNSAFE.getLong(buf, ADDRESS_OFFSET);
+    try {
+      return (long) GET_LONG.invoke(buf, ADDRESS_OFFSET);
+    }
+    catch (Throwable t) {
+      throw new UnsupportedOperationException("Unsafe.getLong is unsupported", t);
+    }
   }
 
   public static ByteBuffer allocateAlignedByteBuffer(int capacity, int align)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[incubator-druid] 02/02: replace jdk internal exceptions with closest publicly available one

Posted by xv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xvrl pushed a commit to branch jdk9-unsafe
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git

commit 33b7499c15804005c045e67bd5ca3b09f7e145e2
Author: Xavier Léauté <xv...@apache.org>
AuthorDate: Mon Apr 29 17:26:41 2019 -0700

    replace jdk internal exceptions with closest publicly available one
---
 .../apache/druid/indexing/overlord/supervisor/SupervisorSpec.java    | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/server/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorSpec.java b/server/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorSpec.java
index 5671769..e875dfc 100644
--- a/server/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorSpec.java
+++ b/server/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorSpec.java
@@ -21,7 +21,6 @@ package org.apache.druid.indexing.overlord.supervisor;
 
 import com.fasterxml.jackson.annotation.JsonSubTypes;
 import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
 
 import java.util.List;
 
@@ -45,12 +44,12 @@ public interface SupervisorSpec
 
   default SupervisorSpec createSuspendedSpec()
   {
-    throw new NotImplementedException();
+    throw new UnsupportedOperationException();
   }
 
   default SupervisorSpec createRunningSpec()
   {
-    throw new NotImplementedException();
+    throw new UnsupportedOperationException();
   }
 
   default boolean isSuspended()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org