Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solaris -d64 jvm crash getLong workaround #4

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,33 @@ public static boolean isAvailable()
return theUnsafe != null;
}

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.
*
Expand Down Expand Up @@ -1376,8 +1403,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(littleEndian){
lw = Long.reverseBytes(lw);
Expand Down