[jdk8u-dev] RFR: 8214427: probable bug in logic of ConcurrentHashMap.addCount() [v3]

Andrew John Hughes andrew at openjdk.org
Mon Aug 15 08:25:34 UTC 2022


On Thu, 21 Jul 2022 06:46:08 GMT, Poison <duke at openjdk.org> wrote:

>> 8214427: probable bug in logic of ConcurrentHashMap.addCount()
>> 
>> This backport fixes the problem that the MAX_RESIZERS control does not take effect when multi-threaded expansion in ConcurrentHashMap.
>
> Poison has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
> 
>  - Backport 8846159987f902bb6e2b966eb4656da4b6d9469d
>    
>    format code
>  - Merge branch 'openjdk:master' into backport-8214427
>  - Merge branch 'openjdk:master' into backport-8214427
>  - Backport 8846159987f902bb6e2b966eb4656da4b6d9469d

Diff looks right now, thanks.
~~~
@@ -24,16 +15,16 @@
 +                    if (sc == rs + MAX_RESIZERS || sc == rs + 1 ||
 +                        (nt = nextTable) == null || transferIndex <= 0)
                          break;
-                     if (U.compareAndSetInt(this, SIZECTL, sc, sc + 1))
+                     if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1))
                          transfer(tab, nt);
                  }
--                else if (U.compareAndSetInt(this, SIZECTL, sc,
+-                else if (U.compareAndSwapInt(this, SIZECTL, sc,
 -                                             (rs << RESIZE_STAMP_SHIFT) + 2))
-+                else if (U.compareAndSetInt(this, SIZECTL, sc, rs + 2))
++                else if (U.compareAndSwapInt(this, SIZECTL, sc, rs + 2))
                      transfer(tab, null);
                  s = sumCount();
              }
-@@ -2358,11 +2356,11 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
+@@ -2298,11 +2296,11 @@ final Node<K,V>[] helpTransfer(Node<K,V>[] tab, Node<K,V> f) {
          Node<K,V>[] nextTab; int sc;
          if (tab != null && (f instanceof ForwardingNode) &&
              (nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) {
@@ -46,5 +37,5 @@
 +                if (sc == rs + MAX_RESIZERS || sc == rs + 1 ||
 +                    transferIndex <= 0)
                      break;
-                 if (U.compareAndSetInt(this, SIZECTL, sc, sc + 1)) {
+                 if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) {
                      transfer(tab, nextTab);
~~~

-------------

Marked as reviewed by andrew (Reviewer).

PR: https://git.openjdk.org/jdk8u-dev/pull/18


More information about the jdk8u-dev mailing list