You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2020/02/02 08:16:57 UTC

[GitHub] [hbase] infraio opened a new pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`

infraio opened a new pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`
URL: https://github.com/apache/hbase/pull/1113
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [hbase] infraio commented on a change in pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`

Posted by GitBox <gi...@apache.org>.
infraio commented on a change in pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`
URL: https://github.com/apache/hbase/pull/1113#discussion_r373915832
 
 

 ##########
 File path: hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAvailChecker.java
 ##########
 @@ -21,50 +21,64 @@
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import sun.misc.Unsafe;
 
 import org.apache.yetus.audience.InterfaceAudience;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@SuppressWarnings("restriction")
 @InterfaceAudience.Private
 public class UnsafeAvailChecker {
 
+  private static final Unsafe UNSAFE;
   private static final String CLASS_NAME = "sun.misc.Unsafe";
   private static final Logger LOG = LoggerFactory.getLogger(UnsafeAvailChecker.class);
-  private static boolean avail = false;
   private static boolean unaligned = false;
+  // Split java.version on non-digit chars:
+  private static final int majorVersion =
+      Integer.parseInt(System.getProperty("java.version").split("\\D+")[0]);
 
   static {
-    avail = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+    UNSAFE = AccessController.doPrivileged(new PrivilegedAction<Unsafe>() {
       @Override
-      public Boolean run() {
+      public Unsafe run() {
         try {
           Class<?> clazz = Class.forName(CLASS_NAME);
           Field f = clazz.getDeclaredField("theUnsafe");
           f.setAccessible(true);
-          return f.get(null) != null;
+          return (Unsafe) f.get(null);
         } catch (Throwable e) {
           LOG.warn("sun.misc.Unsafe is not available/accessible", e);
         }
-        return false;
+        return null;
       }
     });
     // When Unsafe itself is not available/accessible consider unaligned as false.
-    if (avail) {
+    if (UNSAFE != null) {
       String arch = System.getProperty("os.arch");
       if ("ppc64".equals(arch) || "ppc64le".equals(arch) || "aarch64".equals(arch)) {
         // java.nio.Bits.unaligned() wrongly returns false on ppc (JDK-8165231),
         unaligned = true;
       } else {
         try {
-          // Using java.nio.Bits#unaligned() to check for unaligned-access capability
-          Class<?> clazz = Class.forName("java.nio.Bits");
-          Method m = clazz.getDeclaredMethod("unaligned");
-          m.setAccessible(true);
-          unaligned = (Boolean) m.invoke(null);
-        } catch (Exception e) {
-          LOG.warn("java.nio.Bits#unaligned() check failed."
-              + "Unsafe based read/write of primitive types won't be used", e);
+          Class<?> bitsClass =
+              Class.forName("java.nio.Bits", false, ClassLoader.getSystemClassLoader());
+          if (majorVersion >= 9) {
+            // Java 9/10 and 11/12 have different field names.
+            Field unalignedField =
+                bitsClass.getDeclaredField(majorVersion >= 11 ? "UNALIGNED" : "unaligned");
+            unaligned = UNSAFE.getBoolean(UNSAFE.staticFieldBase(unalignedField),
 
 Review comment:
   Tried use filed.getBoolean to get the value but still have warning...
   WARNING: Illegal reflective access by org.apache.hadoop.hbase.util.UnsafeAvailChecker (file:/home/xiaohao/code/open_source/hbase/hbase-assembly/target/hbase-3.0.0-SNAPSHOT/lib/hbase-common-3.0.0-SNAPSHOT.jar) to field java.nio.Bits.UNALIGNED

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [hbase] Apache9 commented on a change in pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`

Posted by GitBox <gi...@apache.org>.
Apache9 commented on a change in pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`
URL: https://github.com/apache/hbase/pull/1113#discussion_r373898784
 
 

 ##########
 File path: hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAvailChecker.java
 ##########
 @@ -21,50 +21,64 @@
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import sun.misc.Unsafe;
 
 import org.apache.yetus.audience.InterfaceAudience;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@SuppressWarnings("restriction")
 @InterfaceAudience.Private
 public class UnsafeAvailChecker {
 
+  private static final Unsafe UNSAFE;
 
 Review comment:
   Why this change? I think one of the purpose of this class is to not reference Unsafe directly?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [hbase] ndimiduk commented on a change in pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`

Posted by GitBox <gi...@apache.org>.
ndimiduk commented on a change in pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`
URL: https://github.com/apache/hbase/pull/1113#discussion_r374414331
 
 

 ##########
 File path: hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAvailChecker.java
 ##########
 @@ -21,50 +21,64 @@
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import sun.misc.Unsafe;
 
 import org.apache.yetus.audience.InterfaceAudience;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@SuppressWarnings("restriction")
 @InterfaceAudience.Private
 public class UnsafeAvailChecker {
 
+  private static final Unsafe UNSAFE;
 
 Review comment:
   Indeed that was the old reasoning. The idea was that not all JVM implementations have an `Unsafe` class, so interfacing with it, if it existed, had to be done entirely via reflection.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [hbase] Apache-HBase commented on issue #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`

Posted by GitBox <gi...@apache.org>.
Apache-HBase commented on issue #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`
URL: https://github.com/apache/hbase/pull/1113#issuecomment-581114319
 
 
   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime | Comment |
   |:----:|----------:|--------:|:--------|
   | +0 :ok: |  reexec  |   0m 31s |  Docker mode activated.  |
   ||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  No case conflicting files found.  |
   | +1 :green_heart: |  hbaseanti  |   0m  0s |  Patch does not have any anti-patterns.  |
   | +1 :green_heart: |  @author  |   0m  0s |  The patch does not contain any @author tags.  |
   | -0 :warning: |  test4tests  |   0m  0s |  The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.  |
   ||| _ master Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   5m 32s |  master passed  |
   | +1 :green_heart: |  compile  |   0m 24s |  master passed  |
   | +1 :green_heart: |  checkstyle  |   0m 26s |  master passed  |
   | +1 :green_heart: |  shadedjars  |   4m 43s |  branch has no errors when building our shaded downstream artifacts.  |
   | +1 :green_heart: |  javadoc  |   0m 24s |  master passed  |
   | +0 :ok: |  spotbugs  |   0m 50s |  Used deprecated FindBugs config; considering switching to SpotBugs.  |
   | +1 :green_heart: |  findbugs  |   0m 49s |  master passed  |
   ||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   5m  4s |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 24s |  the patch passed  |
   | -1 :x: |  javac  |   0m 24s |  hbase-common generated 5 new + 30 unchanged - 0 fixed = 35 total (was 30)  |
   | -1 :x: |  checkstyle  |   0m 23s |  hbase-common: The patch generated 1 new + 1 unchanged - 0 fixed = 2 total (was 1)  |
   | +1 :green_heart: |  whitespace  |   0m  0s |  The patch has no whitespace issues.  |
   | +1 :green_heart: |  shadedjars  |   4m 43s |  patch has no errors when building our shaded downstream artifacts.  |
   | +1 :green_heart: |  hadoopcheck  |  15m 50s |  Patch does not cause any errors with Hadoop 2.8.5 2.9.2 or 3.1.2.  |
   | +1 :green_heart: |  javadoc  |   0m 21s |  the patch passed  |
   | +1 :green_heart: |  findbugs  |   0m 55s |  the patch passed  |
   ||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   3m 18s |  hbase-common in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 15s |  The patch does not generate ASF License warnings.  |
   |  |   |  50m 28s |   |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | Client=19.03.5 Server=19.03.5 base: https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/1/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hbase/pull/1113 |
   | Optional Tests | dupname asflicense javac javadoc unit spotbugs findbugs shadedjars hadoopcheck hbaseanti checkstyle compile |
   | uname | Linux 081faf2a9e4a 4.15.0-58-generic #64-Ubuntu SMP Tue Aug 6 11:12:41 UTC 2019 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | /home/jenkins/jenkins-slave/workspace/Base-PreCommit-GitHub-PR_PR-1113/out/precommit/personality/provided.sh |
   | git revision | master / 5a3ad6f08f |
   | Default Java | 1.8.0_181 |
   | javac | https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/1/artifact/out/diff-compile-javac-hbase-common.txt |
   | checkstyle | https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/1/artifact/out/diff-checkstyle-hbase-common.txt |
   |  Test Results | https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/1/testReport/ |
   | Max. process+thread count | 284 (vs. ulimit of 10000) |
   | modules | C: hbase-common U: hbase-common |
   | Console output | https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/1/console |
   | versions | git=2.11.0 maven=2018-06-17T18:33:14Z) findbugs=3.1.11 |
   | Powered by | Apache Yetus 0.11.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [hbase] Apache-HBase commented on issue #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`

Posted by GitBox <gi...@apache.org>.
Apache-HBase commented on issue #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`
URL: https://github.com/apache/hbase/pull/1113#issuecomment-581122357
 
 
   :broken_heart: **-1 overall**
   
   
   
   
   
   
   | Vote | Subsystem | Runtime | Comment |
   |:----:|----------:|--------:|:--------|
   | +0 :ok: |  reexec  |   0m 31s |  Docker mode activated.  |
   ||| _ Prechecks _ |
   | +1 :green_heart: |  dupname  |   0m  0s |  No case conflicting files found.  |
   | +1 :green_heart: |  hbaseanti  |   0m  0s |  Patch does not have any anti-patterns.  |
   | +1 :green_heart: |  @author  |   0m  0s |  The patch does not contain any @author tags.  |
   | -0 :warning: |  test4tests  |   0m  0s |  The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.  |
   ||| _ master Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   5m 35s |  master passed  |
   | +1 :green_heart: |  compile  |   0m 24s |  master passed  |
   | +1 :green_heart: |  checkstyle  |   0m 26s |  master passed  |
   | +1 :green_heart: |  shadedjars  |   4m 39s |  branch has no errors when building our shaded downstream artifacts.  |
   | +1 :green_heart: |  javadoc  |   0m 24s |  master passed  |
   | +0 :ok: |  spotbugs  |   0m 51s |  Used deprecated FindBugs config; considering switching to SpotBugs.  |
   | +1 :green_heart: |  findbugs  |   0m 48s |  master passed  |
   ||| _ Patch Compile Tests _ |
   | +1 :green_heart: |  mvninstall  |   4m 55s |  the patch passed  |
   | +1 :green_heart: |  compile  |   0m 24s |  the patch passed  |
   | -1 :x: |  javac  |   0m 24s |  hbase-common generated 5 new + 30 unchanged - 0 fixed = 35 total (was 30)  |
   | -1 :x: |  checkstyle  |   0m 24s |  hbase-common: The patch generated 2 new + 0 unchanged - 1 fixed = 2 total (was 1)  |
   | +1 :green_heart: |  whitespace  |   0m  0s |  The patch has no whitespace issues.  |
   | +1 :green_heart: |  shadedjars  |   4m 39s |  patch has no errors when building our shaded downstream artifacts.  |
   | +1 :green_heart: |  hadoopcheck  |  15m 45s |  Patch does not cause any errors with Hadoop 2.8.5 2.9.2 or 3.1.2.  |
   | +1 :green_heart: |  javadoc  |   0m 22s |  the patch passed  |
   | +1 :green_heart: |  findbugs  |   0m 54s |  the patch passed  |
   ||| _ Other Tests _ |
   | +1 :green_heart: |  unit  |   3m 20s |  hbase-common in the patch passed.  |
   | +1 :green_heart: |  asflicense  |   0m 15s |  The patch does not generate ASF License warnings.  |
   |  |   |  50m  8s |   |
   
   
   | Subsystem | Report/Notes |
   |----------:|:-------------|
   | Docker | Client=19.03.5 Server=19.03.5 base: https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/2/artifact/out/Dockerfile |
   | GITHUB PR | https://github.com/apache/hbase/pull/1113 |
   | Optional Tests | dupname asflicense javac javadoc unit spotbugs findbugs shadedjars hadoopcheck hbaseanti checkstyle compile |
   | uname | Linux ca6255373eaf 4.15.0-58-generic #64-Ubuntu SMP Tue Aug 6 11:12:41 UTC 2019 x86_64 GNU/Linux |
   | Build tool | maven |
   | Personality | /home/jenkins/jenkins-slave/workspace/Base-PreCommit-GitHub-PR_PR-1113/out/precommit/personality/provided.sh |
   | git revision | master / 5a3ad6f08f |
   | Default Java | 1.8.0_181 |
   | javac | https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/2/artifact/out/diff-compile-javac-hbase-common.txt |
   | checkstyle | https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/2/artifact/out/diff-checkstyle-hbase-common.txt |
   |  Test Results | https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/2/testReport/ |
   | Max. process+thread count | 285 (vs. ulimit of 10000) |
   | modules | C: hbase-common U: hbase-common |
   | Console output | https://builds.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-1113/2/console |
   | versions | git=2.11.0 maven=2018-06-17T18:33:14Z) findbugs=3.1.11 |
   | Powered by | Apache Yetus 0.11.1 https://yetus.apache.org |
   
   
   This message was automatically generated.
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [hbase] infraio commented on a change in pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`

Posted by GitBox <gi...@apache.org>.
infraio commented on a change in pull request #1113: HBASE-21110 Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`
URL: https://github.com/apache/hbase/pull/1113#discussion_r373921789
 
 

 ##########
 File path: hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAvailChecker.java
 ##########
 @@ -21,50 +21,64 @@
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import sun.misc.Unsafe;
 
 import org.apache.yetus.audience.InterfaceAudience;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@SuppressWarnings("restriction")
 @InterfaceAudience.Private
 public class UnsafeAvailChecker {
 
+  private static final Unsafe UNSAFE;
   private static final String CLASS_NAME = "sun.misc.Unsafe";
   private static final Logger LOG = LoggerFactory.getLogger(UnsafeAvailChecker.class);
-  private static boolean avail = false;
   private static boolean unaligned = false;
+  // Split java.version on non-digit chars:
+  private static final int majorVersion =
+      Integer.parseInt(System.getProperty("java.version").split("\\D+")[0]);
 
   static {
-    avail = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+    UNSAFE = AccessController.doPrivileged(new PrivilegedAction<Unsafe>() {
       @Override
-      public Boolean run() {
+      public Unsafe run() {
         try {
           Class<?> clazz = Class.forName(CLASS_NAME);
           Field f = clazz.getDeclaredField("theUnsafe");
           f.setAccessible(true);
-          return f.get(null) != null;
+          return (Unsafe) f.get(null);
         } catch (Throwable e) {
           LOG.warn("sun.misc.Unsafe is not available/accessible", e);
         }
-        return false;
+        return null;
       }
     });
     // When Unsafe itself is not available/accessible consider unaligned as false.
-    if (avail) {
+    if (UNSAFE != null) {
       String arch = System.getProperty("os.arch");
       if ("ppc64".equals(arch) || "ppc64le".equals(arch) || "aarch64".equals(arch)) {
         // java.nio.Bits.unaligned() wrongly returns false on ppc (JDK-8165231),
         unaligned = true;
       } else {
         try {
-          // Using java.nio.Bits#unaligned() to check for unaligned-access capability
-          Class<?> clazz = Class.forName("java.nio.Bits");
-          Method m = clazz.getDeclaredMethod("unaligned");
-          m.setAccessible(true);
-          unaligned = (Boolean) m.invoke(null);
-        } catch (Exception e) {
-          LOG.warn("java.nio.Bits#unaligned() check failed."
-              + "Unsafe based read/write of primitive types won't be used", e);
+          Class<?> bitsClass =
+              Class.forName("java.nio.Bits", false, ClassLoader.getSystemClassLoader());
+          if (majorVersion >= 9) {
+            // Java 9/10 and 11/12 have different field names.
+            Field unalignedField =
+                bitsClass.getDeclaredField(majorVersion >= 11 ? "UNALIGNED" : "unaligned");
+            unaligned = UNSAFE.getBoolean(UNSAFE.staticFieldBase(unalignedField),
 
 Review comment:
   And I found that jdk11's Bits class still has unalign() method but use unalignedMethod.invoke(null) will get a warning too. See https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/share/classes/java/nio/Bits.java#L84

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services