Skip to content
Snippets Groups Projects
Commit 258bff2c authored by samelamin's avatar samelamin Committed by Sean Owen
Browse files

[SPARK-19999] Workaround JDK-8165231 to identify PPC64 architectures as supporting unaligned access

 java.nio.Bits.unaligned() does not return true for the ppc64le arch.
see https://bugs.openjdk.java.net/browse/JDK-8165231
## What changes were proposed in this pull request?
check architecture

## How was this patch tested?

unit test

Author: samelamin <hussam.elamin@gmail.com>
Author: samelamin <sam_elamin@discovery.com>

Closes #17472 from samelamin/SPARK-19999.
parent 0197262a
No related branches found
No related tags found
No related merge requests found
...@@ -46,18 +46,22 @@ public final class Platform { ...@@ -46,18 +46,22 @@ public final class Platform {
private static final boolean unaligned; private static final boolean unaligned;
static { static {
boolean _unaligned; boolean _unaligned;
// use reflection to access unaligned field String arch = System.getProperty("os.arch", "");
try { if (arch.equals("ppc64le") || arch.equals("ppc64")) {
Class<?> bitsClass = // Since java.nio.Bits.unaligned() doesn't return true on ppc (See JDK-8165231), but ppc64 and ppc64le support it
Class.forName("java.nio.Bits", false, ClassLoader.getSystemClassLoader()); _unaligned = true;
Method unalignedMethod = bitsClass.getDeclaredMethod("unaligned"); } else {
unalignedMethod.setAccessible(true); try {
_unaligned = Boolean.TRUE.equals(unalignedMethod.invoke(null)); Class<?> bitsClass =
} catch (Throwable t) { Class.forName("java.nio.Bits", false, ClassLoader.getSystemClassLoader());
// We at least know x86 and x64 support unaligned access. Method unalignedMethod = bitsClass.getDeclaredMethod("unaligned");
String arch = System.getProperty("os.arch", ""); unalignedMethod.setAccessible(true);
//noinspection DynamicRegexReplaceableByCompiledPattern _unaligned = Boolean.TRUE.equals(unalignedMethod.invoke(null));
_unaligned = arch.matches("^(i[3-6]86|x86(_64)?|x64|amd64|aarch64)$"); } catch (Throwable t) {
// We at least know x86 and x64 support unaligned access.
//noinspection DynamicRegexReplaceableByCompiledPattern
_unaligned = arch.matches("^(i[3-6]86|x86(_64)?|x64|amd64|aarch64)$");
}
} }
unaligned = _unaligned; unaligned = _unaligned;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment