clear out the hash table after resizing, and check for table modification in reads
This commit is contained in:
parent
7aa2cfad65
commit
9dd0756d7a
@ -316,7 +316,11 @@ public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
|
||||
|
||||
V get(Object key, int hash) {
|
||||
if (count != 0) { // read-volatile
|
||||
HashEntry<K, V> e = getFirst(hash);
|
||||
HashEntry<K, V>[] tab = table;
|
||||
HashEntry<K, V> 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<K, V> extends AbstractMap<K, V>
|
||||
|
||||
boolean containsKey(Object key, int hash) {
|
||||
if (count != 0) { // read-volatile
|
||||
HashEntry<K, V> e = getFirst(hash);
|
||||
HashEntry<K, V>[] tab = table;
|
||||
HashEntry<K, V> 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<K, V> extends AbstractMap<K, V>
|
||||
}
|
||||
}
|
||||
}
|
||||
if (table != tab) {
|
||||
return containsValue(value);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -504,6 +515,9 @@ public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
|
||||
}
|
||||
}
|
||||
table = newTable;
|
||||
for (int i = 0; i < oldCapacity; ++i) {
|
||||
oldTable[i] = null;
|
||||
}
|
||||
return reduce;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user