dongjoon-hyun commented on a change in pull request #24825: [SPARK-27981][CORE]
Remove `Illegal reflective access` warning for `java.nio.Bits.unaligned()`
URL: https://github.com/apache/spark/pull/24825#discussion_r291796365
##########
File path: common/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
##########
@@ -319,4 +301,36 @@ public static void throwException(Throwable t) {
DOUBLE_ARRAY_OFFSET = 0;
}
}
+
+ // This requires `majorVersion` and `_UNSAFE`.
+ static {
+ boolean _unaligned;
+ String arch = System.getProperty("os.arch", "");
+ if (arch.equals("ppc64le") || arch.equals("ppc64")) {
+ // Since java.nio.Bits.unaligned() doesn't return true on ppc (See
JDK-8165231), but
+ // ppc64 and ppc64le support it
+ _unaligned = true;
+ } else {
+ try {
+ Class<?> bitsClass =
+ Class.forName("java.nio.Bits", false,
ClassLoader.getSystemClassLoader());
+ if (_UNSAFE != null && 9 <= majorVersion && majorVersion <= 12) {
+ // Java 9/10 and 11/12 have different field names.
+ Field unalignedField =
+ bitsClass.getDeclaredField(majorVersion >= 11 ? "UNALIGNED" :
"unaligned");
+ _unaligned = _UNSAFE.getBoolean(
+ _UNSAFE.staticFieldBase(unalignedField),
_UNSAFE.staticFieldOffset(unalignedField));
Review comment:
Only above 5 lines are new content.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]