In the addCount method(also in the helpTransfer method),the first condition for stopping the capacity expansion is (sc >>> RESIZE_STAMP_SHIFT) != rs,I know there's a bug here in JDK8:probable bug in logic of ConcurrentHashMap.addCount().But in JDK12, what I'm wondering is: Why has this condition (sc >>> RESIZE_STAMP_SHIFT) != rs been removed? I think this condition should become (sc >>> RESIZE_STAMP_SHIFT) != (rs >>> RESIZE_STAMP_SHIFT) in JDK12.
In JDK8:
private final void addCount(long x, int check) {
//...
if (check >= 0) {
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);
if (sc < 0) {
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
transferIndex <= 0)
break;
//...
}
//...
}
}
}
In JDK12:
private final void addCount(long x, int check) {
//...
if (check >= 0) {
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) << RESIZE_STAMP_SHIFT;
if (sc < 0) {
if (sc == rs + MAX_RESIZERS || sc == rs + 1 ||
(nt = nextTable) == null || transferIndex <= 0)
break;
//...
}
//...
}
}
}
I've also noticed the issue of Bug in the logic of ConcurrentHashMap.addCount() when used in Threads, but it's still in open status