HADOOP-11466. FastByteComparisons: do not use UNSAFE_COMPARER on the SPARC architecture because it is slower there (Suman Somasundar via Colin P. McCabe)

(cherry picked from commit ee7d22e90ce67de3e7ee92f309c048a1d4be0bbe)
(cherry picked from commit 2c69f8cf81aed731762524e821088fd779210601)
This commit is contained in:
Colin Patrick Mccabe 2015-01-21 16:33:02 -08:00
parent 4f5d330623
commit ebb515f5e7
2 changed files with 36 additions and 1 deletions

View File

@ -1,5 +1,21 @@
Hadoop Change Log
Release 2.6.1 - UNRELEASED
INCOMPATIBLE CHANGES
NEW FEATURES
IMPROVEMENTS
OPTIMIZATIONS
BUG FIXES
HADOOP-11466: FastByteComparisons: do not use UNSAFE_COMPARER on the SPARC
architecture because it is slower there (Suman Somasundar via Colin P.
McCabe)
Release 2.6.0 - 2014-11-18
INCOMPATIBLE CHANGES

View File

@ -24,6 +24,9 @@
import sun.misc.Unsafe;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.google.common.primitives.Longs;
import com.google.common.primitives.UnsignedBytes;
@ -33,6 +36,7 @@
* class to be able to compare arrays that start at non-zero offsets.
*/
abstract class FastByteComparisons {
static final Log LOG = LogFactory.getLog(FastByteComparisons.class);
/**
* Lexicographically compare two byte arrays.
@ -71,6 +75,13 @@ private static class LexicographicalComparerHolder {
* implementation if unable to do so.
*/
static Comparer<byte[]> getBestComparer() {
if (System.getProperty("os.arch").equals("sparc")) {
if (LOG.isTraceEnabled()) {
LOG.trace("Lexicographical comparer selected for "
+ "byte aligned system architecture");
}
return lexicographicalComparerJavaImpl();
}
try {
Class<?> theClass = Class.forName(UNSAFE_COMPARER_NAME);
@ -78,8 +89,16 @@ static Comparer<byte[]> getBestComparer() {
@SuppressWarnings("unchecked")
Comparer<byte[]> comparer =
(Comparer<byte[]>) theClass.getEnumConstants()[0];
if (LOG.isTraceEnabled()) {
LOG.trace("Unsafe comparer selected for "
+ "byte unaligned system architecture");
}
return comparer;
} catch (Throwable t) { // ensure we really catch *everything*
if (LOG.isTraceEnabled()) {
LOG.trace(t.getMessage());
LOG.trace("Lexicographical comparer selected");
}
return lexicographicalComparerJavaImpl();
}
}
@ -234,4 +253,4 @@ public int compareTo(byte[] buffer1, int offset1, int length1,
}
}
}
}
}