From 9dd0756d7ad7eb31d4d4eda34264b28e8695db04 Mon Sep 17 00:00:00 2001 From: Arya Asemanfar Date: Thu, 6 Dec 2012 10:36:13 -0800 Subject: [PATCH] clear out the hash table after resizing, and check for table modification in reads --- .../internal/ConcurrentIdentityHashMap.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jboss/netty/util/internal/ConcurrentIdentityHashMap.java b/src/main/java/org/jboss/netty/util/internal/ConcurrentIdentityHashMap.java index 944941d44e..c669e43bac 100644 --- a/src/main/java/org/jboss/netty/util/internal/ConcurrentIdentityHashMap.java +++ b/src/main/java/org/jboss/netty/util/internal/ConcurrentIdentityHashMap.java @@ -316,7 +316,11 @@ public final class ConcurrentIdentityHashMap extends AbstractMap V get(Object key, int hash) { if (count != 0) { // read-volatile - HashEntry e = getFirst(hash); + HashEntry[] tab = table; + HashEntry e = tab[hash & tab.length - 1]; + if (tab != table) { + return get(key, hash); + } while (e != null) { if (e.hash == hash && keyEq(key, e.key())) { V opaque = e.value(); @@ -334,7 +338,11 @@ public final class ConcurrentIdentityHashMap extends AbstractMap boolean containsKey(Object key, int hash) { if (count != 0) { // read-volatile - HashEntry e = getFirst(hash); + HashEntry[] tab = table; + HashEntry e = tab[hash & tab.length - 1]; + if (tab != table) { + return containsKey(key, hash); + } while (e != null) { if (e.hash == hash && keyEq(key, e.key())) { return true; @@ -363,6 +371,9 @@ public final class ConcurrentIdentityHashMap extends AbstractMap } } } + if (table != tab) { + return containsValue(value); + } } return false; } @@ -504,6 +515,9 @@ public final class ConcurrentIdentityHashMap extends AbstractMap } } table = newTable; + for (int i = 0; i < oldCapacity; ++i) { + oldTable[i] = null; + } return reduce; }