Skip to content

Commit

Permalink
SPARK-19999 - fix jdk bug
Browse files Browse the repository at this point in the history
  • Loading branch information
samelamin committed Mar 29, 2017
1 parent ce112ce commit bcef03d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions common/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ public final class Platform {
private static final boolean unaligned;
static {
boolean _unaligned;
// use reflection to access unaligned field
try {
Class<?> bitsClass =
Class.forName("java.nio.Bits", false, ClassLoader.getSystemClassLoader());
Method unalignedMethod = bitsClass.getDeclaredMethod("unaligned");
unalignedMethod.setAccessible(true);
_unaligned = Boolean.TRUE.equals(unalignedMethod.invoke(null));
} catch (Throwable t) {
// We at least know x86 and x64 support unaligned access.
String arch = System.getProperty("os.arch", "");
//noinspection DynamicRegexReplaceableByCompiledPattern
_unaligned = arch.matches("^(i[3-6]86|x86(_64)?|x64|amd64|aarch64)$");
if (arch.matches("^(ppc64le | ppc64)$")) {
_unaligned = true;
} else {
//Since java.nio.Bits.unaligned() doesn't return true on ppc (See JDK-8165231)
try {
Class<?> bitsClass =
Class.forName("java.nio.Bits", false, ClassLoader.getSystemClassLoader());
Method unalignedMethod = bitsClass.getDeclaredMethod("unaligned");
unalignedMethod.setAccessible(true);
_unaligned = Boolean.TRUE.equals(unalignedMethod.invoke(null));
} catch (Throwable t) {
// We at least know x86 and x64 support unaligned access.
String arch = System.getProperty("os.arch", "");
//noinspection DynamicRegexReplaceableByCompiledPattern
_unaligned = arch.matches("^(i[3-6]86|x86(_64)?|x64|amd64|aarch64)$");
}
}
unaligned = _unaligned;
}
Expand Down

0 comments on commit bcef03d

Please sign in to comment.