diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 36d208f09a3..e5bd5ec3fc4 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -658,6 +658,9 @@ Release 2.6.0 - UNRELEASED HADOOP-11250. fix endmacro of set_find_shared_library_without_version in CMakeLists (Yi Liu via Colin P. McCabe) + HADOOP-11221. IdentityHashStore assumes System.identityHashCode() is + non-negative. (Jinghui Wang via szetszwo) + Release 2.5.1 - 2014-09-05 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/IdentityHashStore.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/IdentityHashStore.java index 4209488d39a..3ae4bbac659 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/IdentityHashStore.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/IdentityHashStore.java @@ -92,9 +92,10 @@ public final class IdentityHashStore { } private void putInternal(Object k, Object v) { - int hash = System.identityHashCode(k); - final int numEntries = buffer.length / 2; - int index = hash % numEntries; + final int hash = System.identityHashCode(k); + final int numEntries = buffer.length >> 1; + //computing modulo with the assumption buffer.length is power of 2 + int index = hash & (numEntries-1); while (true) { if (buffer[2 * index] == null) { buffer[2 * index] = k; @@ -127,9 +128,10 @@ public final class IdentityHashStore { if (buffer == null) { return -1; } - final int numEntries = buffer.length / 2; - int hash = System.identityHashCode(k); - int index = hash % numEntries; + final int numEntries = buffer.length >> 1; + final int hash = System.identityHashCode(k); + //computing modulo with the assumption buffer.length is power of 2 + int index = hash & (numEntries -1); int firstIndex = index; do { if (buffer[2 * index] == k) {