From 618f1beb87ed5cfaa7923d6b3bf1afb5f5480613 Mon Sep 17 00:00:00 2001 From: vharseko Date: Mon, 22 Sep 2014 13:55:22 +0400 Subject: [PATCH] solaris -d64 jvm crash getLong workaround --- .../org/apache/hadoop/hbase/util/Bytes.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java index 88f8b0ca5ee2..0f68fc014ac6 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java @@ -1195,6 +1195,33 @@ static boolean lessThanUnsigned(long x1, long x2) { return (x1 + Long.MIN_VALUE) < (x2 + Long.MIN_VALUE); } + private static final boolean unaligned=!"sparcv9".equals(System.getProperty("os.arch")); + + private long getLong(Object address, long offset) { + if (unaligned) { + return theUnsafe.getLong(address, offset); + } else { + if (littleEndian) { + return (((long) theUnsafe.getByte(address, offset + 7) ) << 56) | + (((long) theUnsafe.getByte(address, offset + 6) & 0xff) << 48) | + (((long) theUnsafe.getByte(address, offset + 5) & 0xff) << 40) | + (((long) theUnsafe.getByte(address, offset + 4) & 0xff) << 32) | + (((long) theUnsafe.getByte(address, offset + 3) & 0xff) << 24) | + (((long) theUnsafe.getByte(address, offset + 2) & 0xff) << 16) | + (((long) theUnsafe.getByte(address, offset + 1) & 0xff) << 8) | + (((long) theUnsafe.getByte(address, offset ) & 0xff) ); + } else { + return (((long) theUnsafe.getByte(address, offset ) ) << 56) | + (((long) theUnsafe.getByte(address, offset + 1) & 0xff) << 48) | + (((long) theUnsafe.getByte(address, offset + 2) & 0xff) << 40) | + (((long) theUnsafe.getByte(address, offset + 3) & 0xff) << 32) | + (((long) theUnsafe.getByte(address, offset + 4) & 0xff) << 24) | + (((long) theUnsafe.getByte(address, offset + 5) & 0xff) << 16) | + (((long) theUnsafe.getByte(address, offset + 6) & 0xff) << 8) | + (((long) theUnsafe.getByte(address, offset + 7) & 0xff) ); + } + } + } /** * Lexicographically compare two arrays. * @@ -1226,8 +1253,8 @@ public int compareTo(byte[] buffer1, int offset1, int length1, * On the other hand, it is substantially faster on 64-bit. */ for (int i = 0; i < minWords * SIZEOF_LONG; i += SIZEOF_LONG) { - long lw = theUnsafe.getLong(buffer1, offset1Adj + (long) i); - long rw = theUnsafe.getLong(buffer2, offset2Adj + (long) i); + long lw = getLong(buffer1, offset1Adj + (long) i); + long rw = getLong(buffer2, offset2Adj + (long) i); long diff = lw ^ rw; if (diff != 0) {