8214427: probable bug in logic of ConcurrentHashMap.addCount()
Reviewed-by: phh, andrew
Backport-of: 8846159987f902bb6e2b966eb4656da4b6d9469d
diff --git a/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java b/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java
index 880ecb2..bad795e 100644
--- a/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java
+++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java
@@ -2274,17 +2274,15 @@
Node<K,V>[] tab, nt; int n, sc;
while (s >= (long)(sc = sizeCtl) && (tab = table) != null &&
(n = tab.length) < MAXIMUM_CAPACITY) {
- int rs = resizeStamp(n);
+ int rs = resizeStamp(n) << RESIZE_STAMP_SHIFT;
if (sc < 0) {
- if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
- sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
- transferIndex <= 0)
+ if (sc == rs + MAX_RESIZERS || sc == rs + 1 ||
+ (nt = nextTable) == null || transferIndex <= 0)
break;
if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1))
transfer(tab, nt);
}
- else if (U.compareAndSwapInt(this, SIZECTL, sc,
- (rs << RESIZE_STAMP_SHIFT) + 2))
+ else if (U.compareAndSwapInt(this, SIZECTL, sc, rs + 2))
transfer(tab, null);
s = sumCount();
}
@@ -2298,11 +2296,11 @@
Node<K,V>[] nextTab; int sc;
if (tab != null && (f instanceof ForwardingNode) &&
(nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) {
- int rs = resizeStamp(tab.length);
+ int rs = resizeStamp(tab.length) << RESIZE_STAMP_SHIFT;
while (nextTab == nextTable && table == tab &&
(sc = sizeCtl) < 0) {
- if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
- sc == rs + MAX_RESIZERS || transferIndex <= 0)
+ if (sc == rs + MAX_RESIZERS || sc == rs + 1 ||
+ transferIndex <= 0)
break;
if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) {
transfer(tab, nextTab);