--- old/src/java.base/share/classes/java/util/concurrent/atomic/Striped64.java 2021-01-09 11:35:49.608987427 -0800 +++ new/src/java.base/share/classes/java/util/concurrent/atomic/Striped64.java 2021-01-09 11:35:49.280990010 -0800 @@ -125,7 +125,7 @@ volatile long value; Cell(long x) { value = x; } final boolean cas(long cmp, long val) { - return VALUE.compareAndSet(this, cmp, val); + return VALUE.weakCompareAndSetRelease(this, cmp, val); } final void reset() { VALUE.setVolatile(this, 0L); @@ -178,7 +178,7 @@ * CASes the base field. */ final boolean casBase(long cmp, long val) { - return BASE.compareAndSet(this, cmp, val); + return BASE.weakCompareAndSetRelease(this, cmp, val); } final long getAndSetBase(long val) { @@ -224,20 +224,19 @@ * @param fn the update function, or null for add (this convention * avoids the need for an extra field or function in LongAdder). * @param wasUncontended false if CAS failed before call + * @param index thread index from getProbe */ final void longAccumulate(long x, LongBinaryOperator fn, - boolean wasUncontended) { - int h; - if ((h = getProbe()) == 0) { + boolean wasUncontended, int index) { + if (index == 0) { ThreadLocalRandom.current(); // force initialization - h = getProbe(); + index = getProbe(); wasUncontended = true; } - boolean collide = false; // True if last slot nonempty - done: for (;;) { + for (boolean collide = false;;) { // True if last slot nonempty Cell[] cs; Cell c; int n; long v; if ((cs = cells) != null && (n = cs.length) > 0) { - if ((c = cs[(n - 1) & h]) == null) { + if ((c = cs[(n - 1) & index]) == null) { if (cellsBusy == 0) { // Try to attach new Cell Cell r = new Cell(x); // Optimistically create if (cellsBusy == 0 && casCellsBusy()) { @@ -245,9 +244,9 @@ Cell[] rs; int m, j; if ((rs = cells) != null && (m = rs.length) > 0 && - rs[j = (m - 1) & h] == null) { + rs[j = (m - 1) & index] == null) { rs[j] = r; - break done; + break; } } finally { cellsBusy = 0; @@ -276,15 +275,15 @@ collide = false; continue; // Retry with expanded table } - h = advanceProbe(h); + index = advanceProbe(index); } else if (cellsBusy == 0 && cells == cs && casCellsBusy()) { try { // Initialize table if (cells == cs) { Cell[] rs = new Cell[2]; - rs[h & 1] = new Cell(x); + rs[index & 1] = new Cell(x); cells = rs; - break done; + break; } } finally { cellsBusy = 0; @@ -293,7 +292,7 @@ // Fall back on using base else if (casBase(v = base, (fn == null) ? v + x : fn.applyAsLong(v, x))) - break done; + break; } } @@ -310,18 +309,16 @@ * maintained by copy/paste/adapt. */ final void doubleAccumulate(double x, DoubleBinaryOperator fn, - boolean wasUncontended) { - int h; - if ((h = getProbe()) == 0) { + boolean wasUncontended, int index) { + if (index == 0) { ThreadLocalRandom.current(); // force initialization - h = getProbe(); + index = getProbe(); wasUncontended = true; } - boolean collide = false; // True if last slot nonempty - done: for (;;) { + for (boolean collide = false;;) { // True if last slot nonempty Cell[] cs; Cell c; int n; long v; if ((cs = cells) != null && (n = cs.length) > 0) { - if ((c = cs[(n - 1) & h]) == null) { + if ((c = cs[(n - 1) & index]) == null) { if (cellsBusy == 0) { // Try to attach new Cell Cell r = new Cell(Double.doubleToRawLongBits(x)); if (cellsBusy == 0 && casCellsBusy()) { @@ -329,9 +326,9 @@ Cell[] rs; int m, j; if ((rs = cells) != null && (m = rs.length) > 0 && - rs[j = (m - 1) & h] == null) { + rs[j = (m - 1) & index] == null) { rs[j] = r; - break done; + break; } } finally { cellsBusy = 0; @@ -359,15 +356,15 @@ collide = false; continue; // Retry with expanded table } - h = advanceProbe(h); + index = advanceProbe(index); } else if (cellsBusy == 0 && cells == cs && casCellsBusy()) { try { // Initialize table if (cells == cs) { Cell[] rs = new Cell[2]; - rs[h & 1] = new Cell(Double.doubleToRawLongBits(x)); + rs[index & 1] = new Cell(Double.doubleToRawLongBits(x)); cells = rs; - break done; + break; } } finally { cellsBusy = 0; @@ -375,7 +372,7 @@ } // Fall back on using base else if (casBase(v = base, apply(fn, v, x))) - break done; + break; } }