--- jsr166/src/jsr166e/ConcurrentHashMapV8.java 2013/12/01 13:39:02 1.117
+++ jsr166/src/jsr166e/ConcurrentHashMapV8.java 2016/03/07 23:55:31 1.126
@@ -15,7 +15,6 @@ import java.lang.reflect.Type;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Enumeration;
import java.util.HashMap;
@@ -115,32 +114,31 @@ import java.util.concurrent.locks.Reentr
* objects do not support method {@code setValue}.
*
*
- * - forEach: Perform a given action on each element.
+ *
- forEach: Perform a given action on each element.
* A variant form applies a given transformation on each element
- * before performing the action.
+ * before performing the action.
*
- * - search: Return the first available non-null result of
+ *
- search: Return the first available non-null result of
* applying a given function on each element; skipping further
- * search when a result is found.
+ * search when a result is found.
*
- * - reduce: Accumulate each element. The supplied reduction
+ *
- reduce: Accumulate each element. The supplied reduction
* function cannot rely on ordering (more formally, it should be
* both associative and commutative). There are five variants:
*
*
*
- * - Plain reductions. (There is not a form of this method for
+ *
- Plain reductions. (There is not a form of this method for
* (key, value) function arguments since there is no corresponding
- * return type.)
+ * return type.)
*
- * - Mapped reductions that accumulate the results of a given
- * function applied to each element.
+ * - Mapped reductions that accumulate the results of a given
+ * function applied to each element.
*
- *
- Reductions to scalar doubles, longs, and ints, using a
- * given basis value.
+ * - Reductions to scalar doubles, longs, and ints, using a
+ * given basis value.
*
*
- *
*
*
* These bulk operations accept a {@code parallelismThreshold}
@@ -489,7 +487,7 @@ public class ConcurrentHashMapV8 ex
*
* Maintaining API and serialization compatibility with previous
* versions of this class introduces several oddities. Mainly: We
- * leave untouched but unused constructor arguments refering to
+ * leave untouched but unused constructor arguments referring to
* concurrencyLevel. We accept a loadFactor constructor argument,
* but apply it only to initial table capacity (which is the only
* time that we can guarantee to honor it.) We also declare an
@@ -638,10 +636,10 @@ public class ConcurrentHashMapV8 ex
this.next = next;
}
- public final K getKey() { return key; }
- public final V getValue() { return val; }
- public final int hashCode() { return key.hashCode() ^ val.hashCode(); }
- public final String toString(){ return key + "=" + val; }
+ public final K getKey() { return key; }
+ public final V getValue() { return val; }
+ public final int hashCode() { return key.hashCode() ^ val.hashCode(); }
+ public final String toString() { return key + "=" + val; }
public final V setValue(V value) {
throw new UnsupportedOperationException();
}
@@ -2218,7 +2216,7 @@ public class ConcurrentHashMapV8 ex
* Must be negative when shifted left by RESIZE_STAMP_SHIFT.
*/
static final int resizeStamp(int n) {
- return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1));
+ return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1));
}
/**
@@ -2282,14 +2280,14 @@ public class ConcurrentHashMapV8 ex
int rs = resizeStamp(n);
if (sc < 0) {
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
- sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
- transferIndex <= 0)
+ sc == rs + MAX_RESIZERS || (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))
+ (rs << RESIZE_STAMP_SHIFT) + 2))
transfer(tab, null);
s = sumCount();
}
@@ -2303,13 +2301,13 @@ public class ConcurrentHashMapV8 ex
Node[] nextTab; int sc;
if (tab != null && (f instanceof ForwardingNode) &&
(nextTab = ((ForwardingNode)f).nextTable) != null) {
- int rs = resizeStamp(tab.length);
+ int rs = resizeStamp(tab.length);
while (nextTab == nextTable && table == tab &&
- (sc = sizeCtl) < 0) {
- if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
+ (sc = sizeCtl) < 0) {
+ if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
sc == rs + MAX_RESIZERS || transferIndex <= 0)
- break;
- if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) {
+ break;
+ if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) {
transfer(tab, nextTab);
break;
}
@@ -2350,7 +2348,7 @@ public class ConcurrentHashMapV8 ex
else if (tab == table) {
int rs = resizeStamp(n);
if (sc < 0) {
- Node[] nt;
+ Node[] nt;
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
transferIndex <= 0)
@@ -2359,7 +2357,7 @@ public class ConcurrentHashMapV8 ex
transfer(tab, nt);
}
else if (U.compareAndSwapInt(this, SIZECTL, sc,
- (rs << RESIZE_STAMP_SHIFT) + 2))
+ (rs << RESIZE_STAMP_SHIFT) + 2))
transfer(tab, null);
}
}
@@ -2417,7 +2415,7 @@ public class ConcurrentHashMapV8 ex
return;
}
if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, sc - 1)) {
- if ((sc - 2) != resizeStamp(n))
+ if ((sc - 2) != resizeStamp(n) << RESIZE_STAMP_SHIFT)
return;
finishing = advance = true;
i = n; // recheck before commit
@@ -2533,8 +2531,9 @@ public class ConcurrentHashMapV8 ex
}
}
}
+
/**
- * Returns a list on non-TreeNodes replacing those in given list.
+ * Returns a list of non-TreeNodes replacing those in given list.
*/
static Node untreeify(Node b) {
Node hd = null, tl = null;
@@ -2578,7 +2577,7 @@ public class ConcurrentHashMapV8 ex
final TreeNode findTreeNode(int h, Object k, Class> kc) {
if (k != null) {
TreeNode p = this;
- do {
+ do {
int ph, dir; K pk; TreeNode q;
TreeNode pl = p.left, pr = p.right;
if ((ph = p.hash) > h)
@@ -2732,14 +2731,15 @@ public class ConcurrentHashMapV8 ex
* using tree comparisons from root, but continues linear
* search when lock not available.
*/
-final Node find(int h, Object k) {
+ final Node find(int h, Object k) {
if (k != null) {
- for (Node e = first; e != null; e = e.next) {
+ for (Node e = first; e != null; ) {
int s; K ek;
if (((s = lockState) & (WAITER|WRITER)) != 0) {
if (e.hash == h &&
((ek = e.key) == k || (ek != null && k.equals(ek))))
return e;
+ e = e.next;
}
else if (U.compareAndSwapInt(this, LOCKSTATE, s,
s + READER)) {
@@ -3026,7 +3026,7 @@ final Node find(int h, Object k) {
static TreeNode balanceDeletion(TreeNode root,
TreeNode x) {
- for (TreeNode xp, xpl, xpr;;) {
+ for (TreeNode xp, xpl, xpr;;) {
if (x == null || x == root)
return root;
else if ((xp = x.parent) == null) {