You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2014/10/30 18:59:47 UTC

git commit: HADOOP-11221. IdentityHashStore assumes System.identityHashCode() is non-negative. Contributed by Jinghui Wang

Repository: hadoop
Updated Branches:
  refs/heads/trunk b811212f2 -> a3dacc07e


HADOOP-11221. IdentityHashStore assumes System.identityHashCode() is non-negative. Contributed by Jinghui Wang


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/a3dacc07
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/a3dacc07
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/a3dacc07

Branch: refs/heads/trunk
Commit: a3dacc07e2c08bb4ecfce7b5e6d5602273989e9c
Parents: b811212
Author: Tsz-Wo Nicholas Sze <sz...@hortonworks.com>
Authored: Thu Oct 30 10:58:26 2014 -0700
Committer: Tsz-Wo Nicholas Sze <sz...@hortonworks.com>
Committed: Thu Oct 30 10:58:26 2014 -0700

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt       |  3 +++
 .../org/apache/hadoop/util/IdentityHashStore.java     | 14 ++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/a3dacc07/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 016b3b0..6020119 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -1034,6 +1034,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

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a3dacc07/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/IdentityHashStore.java
----------------------------------------------------------------------
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 4209488..3ae4bba 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<K, V> {
   }
 
   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<K, V> {
     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) {