Skip to content

Commit a2e6494

Browse files
committedJun 2, 2022
8214427: probable bug in logic of ConcurrentHashMap.addCount()
Reviewed-by: martin Backport-of: 8846159
1 parent e7036ec commit a2e6494

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed
 

‎src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -2334,17 +2334,15 @@ private final void addCount(long x, int check) {
23342334
Node<K,V>[] tab, nt; int n, sc;
23352335
while (s >= (long)(sc = sizeCtl) && (tab = table) != null &&
23362336
(n = tab.length) < MAXIMUM_CAPACITY) {
2337-
int rs = resizeStamp(n);
2337+
int rs = resizeStamp(n) << RESIZE_STAMP_SHIFT;
23382338
if (sc < 0) {
2339-
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2340-
sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
2341-
transferIndex <= 0)
2339+
if (sc == rs + MAX_RESIZERS || sc == rs + 1 ||
2340+
(nt = nextTable) == null || transferIndex <= 0)
23422341
break;
23432342
if (U.compareAndSetInt(this, SIZECTL, sc, sc + 1))
23442343
transfer(tab, nt);
23452344
}
2346-
else if (U.compareAndSetInt(this, SIZECTL, sc,
2347-
(rs << RESIZE_STAMP_SHIFT) + 2))
2345+
else if (U.compareAndSetInt(this, SIZECTL, sc, rs + 2))
23482346
transfer(tab, null);
23492347
s = sumCount();
23502348
}
@@ -2358,11 +2356,11 @@ final Node<K,V>[] helpTransfer(Node<K,V>[] tab, Node<K,V> f) {
23582356
Node<K,V>[] nextTab; int sc;
23592357
if (tab != null && (f instanceof ForwardingNode) &&
23602358
(nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) {
2361-
int rs = resizeStamp(tab.length);
2359+
int rs = resizeStamp(tab.length) << RESIZE_STAMP_SHIFT;
23622360
while (nextTab == nextTable && table == tab &&
23632361
(sc = sizeCtl) < 0) {
2364-
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2365-
sc == rs + MAX_RESIZERS || transferIndex <= 0)
2362+
if (sc == rs + MAX_RESIZERS || sc == rs + 1 ||
2363+
transferIndex <= 0)
23662364
break;
23672365
if (U.compareAndSetInt(this, SIZECTL, sc, sc + 1)) {
23682366
transfer(tab, nextTab);

0 commit comments

Comments
 (0)