mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
Reviewed-by: martin
This commit is contained in:
parent
c19d18871c
commit
d771fc3a6b
149 changed files with 872 additions and 571 deletions
|
@ -717,12 +717,12 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
|
|||
*/
|
||||
static Class<?> comparableClassFor(Object x) {
|
||||
if (x instanceof Comparable) {
|
||||
Class<?> c; Type[] ts, as; Type t; ParameterizedType p;
|
||||
Class<?> c; Type[] ts, as; ParameterizedType p;
|
||||
if ((c = x.getClass()) == String.class) // bypass checks
|
||||
return c;
|
||||
if ((ts = c.getGenericInterfaces()) != null) {
|
||||
for (int i = 0; i < ts.length; ++i) {
|
||||
if (((t = ts[i]) instanceof ParameterizedType) &&
|
||||
for (Type t : ts) {
|
||||
if ((t instanceof ParameterizedType) &&
|
||||
((p = (ParameterizedType)t).getRawType() ==
|
||||
Comparable.class) &&
|
||||
(as = p.getActualTypeArguments()) != null &&
|
||||
|
@ -2328,15 +2328,15 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
|
|||
* @param check if <0, don't check resize, if <= 1 only check if uncontended
|
||||
*/
|
||||
private final void addCount(long x, int check) {
|
||||
CounterCell[] as; long b, s;
|
||||
if ((as = counterCells) != null ||
|
||||
CounterCell[] cs; long b, s;
|
||||
if ((cs = counterCells) != null ||
|
||||
!U.compareAndSetLong(this, BASECOUNT, b = baseCount, s = b + x)) {
|
||||
CounterCell a; long v; int m;
|
||||
CounterCell c; long v; int m;
|
||||
boolean uncontended = true;
|
||||
if (as == null || (m = as.length - 1) < 0 ||
|
||||
(a = as[ThreadLocalRandom.getProbe() & m]) == null ||
|
||||
if (cs == null || (m = cs.length - 1) < 0 ||
|
||||
(c = cs[ThreadLocalRandom.getProbe() & m]) == null ||
|
||||
!(uncontended =
|
||||
U.compareAndSetLong(a, CELLVALUE, v = a.value, v + x))) {
|
||||
U.compareAndSetLong(c, CELLVALUE, v = c.value, v + x))) {
|
||||
fullAddCount(x, uncontended);
|
||||
return;
|
||||
}
|
||||
|
@ -2574,13 +2574,12 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
|
|||
}
|
||||
|
||||
final long sumCount() {
|
||||
CounterCell[] as = counterCells; CounterCell a;
|
||||
CounterCell[] cs = counterCells;
|
||||
long sum = baseCount;
|
||||
if (as != null) {
|
||||
for (int i = 0; i < as.length; ++i) {
|
||||
if ((a = as[i]) != null)
|
||||
sum += a.value;
|
||||
}
|
||||
if (cs != null) {
|
||||
for (CounterCell c : cs)
|
||||
if (c != null)
|
||||
sum += c.value;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
@ -2595,9 +2594,9 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
|
|||
}
|
||||
boolean collide = false; // True if last slot nonempty
|
||||
for (;;) {
|
||||
CounterCell[] as; CounterCell a; int n; long v;
|
||||
if ((as = counterCells) != null && (n = as.length) > 0) {
|
||||
if ((a = as[(n - 1) & h]) == null) {
|
||||
CounterCell[] cs; CounterCell c; int n; long v;
|
||||
if ((cs = counterCells) != null && (n = cs.length) > 0) {
|
||||
if ((c = cs[(n - 1) & h]) == null) {
|
||||
if (cellsBusy == 0) { // Try to attach new Cell
|
||||
CounterCell r = new CounterCell(x); // Optimistic create
|
||||
if (cellsBusy == 0 &&
|
||||
|
@ -2623,21 +2622,17 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
|
|||
}
|
||||
else if (!wasUncontended) // CAS already known to fail
|
||||
wasUncontended = true; // Continue after rehash
|
||||
else if (U.compareAndSetLong(a, CELLVALUE, v = a.value, v + x))
|
||||
else if (U.compareAndSetLong(c, CELLVALUE, v = c.value, v + x))
|
||||
break;
|
||||
else if (counterCells != as || n >= NCPU)
|
||||
else if (counterCells != cs || n >= NCPU)
|
||||
collide = false; // At max size or stale
|
||||
else if (!collide)
|
||||
collide = true;
|
||||
else if (cellsBusy == 0 &&
|
||||
U.compareAndSetInt(this, CELLSBUSY, 0, 1)) {
|
||||
try {
|
||||
if (counterCells == as) {// Expand table unless stale
|
||||
CounterCell[] rs = new CounterCell[n << 1];
|
||||
for (int i = 0; i < n; ++i)
|
||||
rs[i] = as[i];
|
||||
counterCells = rs;
|
||||
}
|
||||
if (counterCells == cs) // Expand table unless stale
|
||||
counterCells = Arrays.copyOf(cs, n << 1);
|
||||
} finally {
|
||||
cellsBusy = 0;
|
||||
}
|
||||
|
@ -2646,11 +2641,11 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
|
|||
}
|
||||
h = ThreadLocalRandom.advanceProbe(h);
|
||||
}
|
||||
else if (cellsBusy == 0 && counterCells == as &&
|
||||
else if (cellsBusy == 0 && counterCells == cs &&
|
||||
U.compareAndSetInt(this, CELLSBUSY, 0, 1)) {
|
||||
boolean init = false;
|
||||
try { // Initialize table
|
||||
if (counterCells == as) {
|
||||
if (counterCells == cs) {
|
||||
CounterCell[] rs = new CounterCell[2];
|
||||
rs[h & 1] = new CounterCell(x);
|
||||
counterCells = rs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue