mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +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
|
@ -1550,7 +1550,6 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
setBit(deathRow, i - beg);
|
||||
if (modCount != expectedModCount)
|
||||
throw new ConcurrentModificationException();
|
||||
expectedModCount++;
|
||||
modCount++;
|
||||
int w = beg;
|
||||
for (i = beg; i < end; i++)
|
||||
|
|
|
@ -1023,7 +1023,6 @@ public class Vector<E>
|
|||
setBit(deathRow, i - beg);
|
||||
if (modCount != expectedModCount)
|
||||
throw new ConcurrentModificationException();
|
||||
expectedModCount++;
|
||||
modCount++;
|
||||
int w = beg;
|
||||
for (i = beg; i < end; i++)
|
||||
|
|
|
@ -245,8 +245,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
|
|||
Future<T> f = futures.get(i);
|
||||
if (!f.isDone()) {
|
||||
try { f.get(); }
|
||||
catch (CancellationException ignore) {}
|
||||
catch (ExecutionException ignore) {}
|
||||
catch (CancellationException | ExecutionException ignore) {}
|
||||
}
|
||||
}
|
||||
return futures;
|
||||
|
@ -283,8 +282,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
|
|||
Future<T> f = futures.get(j);
|
||||
if (!f.isDone()) {
|
||||
try { f.get(deadline - System.nanoTime(), NANOSECONDS); }
|
||||
catch (CancellationException ignore) {}
|
||||
catch (ExecutionException ignore) {}
|
||||
catch (CancellationException | ExecutionException ignore) {}
|
||||
catch (TimeoutException timedOut) {
|
||||
break timedOut;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2204,9 +2204,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
|
|||
Collection<?> c = (Collection<?>) o;
|
||||
try {
|
||||
return containsAll(c) && c.containsAll(this);
|
||||
} catch (ClassCastException unused) {
|
||||
return false;
|
||||
} catch (NullPointerException unused) {
|
||||
} catch (ClassCastException | NullPointerException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2331,9 +2329,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
|
|||
Collection<?> c = (Collection<?>) o;
|
||||
try {
|
||||
return containsAll(c) && c.containsAll(this);
|
||||
} catch (ClassCastException unused) {
|
||||
return false;
|
||||
} catch (NullPointerException unused) {
|
||||
} catch (ClassCastException | NullPointerException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2453,9 +2449,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
|
|||
if (k == null) // pass by markers and headers
|
||||
return true;
|
||||
int c = cpr(cmp, k, hi);
|
||||
if (c > 0 || (c == 0 && !hiInclusive))
|
||||
return false;
|
||||
return true;
|
||||
return c < 0 || (c == 0 && hiInclusive);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -309,9 +309,7 @@ public class ConcurrentSkipListSet<E>
|
|||
Collection<?> c = (Collection<?>) o;
|
||||
try {
|
||||
return containsAll(c) && c.containsAll(this);
|
||||
} catch (ClassCastException unused) {
|
||||
return false;
|
||||
} catch (NullPointerException unused) {
|
||||
} catch (ClassCastException | NullPointerException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -508,7 +508,7 @@ public class CopyOnWriteArrayList<E>
|
|||
public boolean remove(Object o) {
|
||||
Object[] snapshot = getArray();
|
||||
int index = indexOf(o, snapshot, 0, snapshot.length);
|
||||
return (index < 0) ? false : remove(o, snapshot, index);
|
||||
return index >= 0 && remove(o, snapshot, index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -587,8 +587,8 @@ public class CopyOnWriteArrayList<E>
|
|||
*/
|
||||
public boolean addIfAbsent(E e) {
|
||||
Object[] snapshot = getArray();
|
||||
return indexOf(e, snapshot, 0, snapshot.length) >= 0 ? false :
|
||||
addIfAbsent(e, snapshot);
|
||||
return indexOf(e, snapshot, 0, snapshot.length) < 0
|
||||
&& addIfAbsent(e, snapshot);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -980,13 +980,10 @@ public class CopyOnWriteArrayList<E>
|
|||
|
||||
List<?> list = (List<?>)o;
|
||||
Iterator<?> it = list.iterator();
|
||||
Object[] elements = getArray();
|
||||
for (int i = 0, len = elements.length; i < len; i++)
|
||||
if (!it.hasNext() || !Objects.equals(elements[i], it.next()))
|
||||
for (Object element : getArray())
|
||||
if (!it.hasNext() || !Objects.equals(element, it.next()))
|
||||
return false;
|
||||
if (it.hasNext())
|
||||
return false;
|
||||
return true;
|
||||
return !it.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1353,17 +1353,16 @@ public class LinkedBlockingDeque<E>
|
|||
@SuppressWarnings("unchecked")
|
||||
private boolean bulkRemove(Predicate<? super E> filter) {
|
||||
boolean removed = false;
|
||||
Node<E> p = null;
|
||||
final ReentrantLock lock = this.lock;
|
||||
Node<E> p = null;
|
||||
Node<E>[] nodes = null;
|
||||
int n, len = 0;
|
||||
do {
|
||||
// 1. Extract batch of up to 64 elements while holding the lock.
|
||||
long deathRow = 0; // "bitset" of size 64
|
||||
lock.lock();
|
||||
try {
|
||||
if (nodes == null) {
|
||||
if (p == null) p = first;
|
||||
if (nodes == null) { // first batch; initialize
|
||||
p = first;
|
||||
for (Node<E> q = p; q != null; q = succ(q))
|
||||
if (q.item != null && ++len == 64)
|
||||
break;
|
||||
|
@ -1376,6 +1375,7 @@ public class LinkedBlockingDeque<E>
|
|||
}
|
||||
|
||||
// 2. Run the filter on the elements while lock is free.
|
||||
long deathRow = 0L; // "bitset" of size 64
|
||||
for (int i = 0; i < n; i++) {
|
||||
final E e;
|
||||
if ((e = nodes[i].item) != null && filter.test(e))
|
||||
|
@ -1393,6 +1393,7 @@ public class LinkedBlockingDeque<E>
|
|||
unlink(q);
|
||||
removed = true;
|
||||
}
|
||||
nodes[i] = null; // help GC
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
|
|
|
@ -1060,11 +1060,10 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
|
|||
int n, len = 0;
|
||||
do {
|
||||
// 1. Extract batch of up to 64 elements while holding the lock.
|
||||
long deathRow = 0; // "bitset" of size 64
|
||||
fullyLock();
|
||||
try {
|
||||
if (nodes == null) {
|
||||
if (p == null) p = head.next;
|
||||
if (nodes == null) { // first batch; initialize
|
||||
p = head.next;
|
||||
for (Node<E> q = p; q != null; q = succ(q))
|
||||
if (q.item != null && ++len == 64)
|
||||
break;
|
||||
|
@ -1077,6 +1076,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
|
|||
}
|
||||
|
||||
// 2. Run the filter on the elements while lock is free.
|
||||
long deathRow = 0L; // "bitset" of size 64
|
||||
for (int i = 0; i < n; i++) {
|
||||
final E e;
|
||||
if ((e = nodes[i].item) != null && filter.test(e))
|
||||
|
@ -1095,6 +1095,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
|
|||
unlink(q, ancestor);
|
||||
removed = true;
|
||||
}
|
||||
nodes[i] = null; // help GC
|
||||
}
|
||||
} finally {
|
||||
fullyUnlock();
|
||||
|
|
|
@ -772,9 +772,8 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
|||
Node first = null;
|
||||
restartFromHead: for (;;) {
|
||||
Node h = head, p = h;
|
||||
for (; p != null;) {
|
||||
final Object item;
|
||||
if ((item = p.item) != null) {
|
||||
while (p != null) {
|
||||
if (p.item != null) {
|
||||
if (p.isData) {
|
||||
first = p;
|
||||
break;
|
||||
|
@ -1602,8 +1601,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
|||
// Read in elements until trailing null sentinel found
|
||||
Node h = null, t = null;
|
||||
for (Object item; (item = s.readObject()) != null; ) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Node newNode = new Node((E) item);
|
||||
Node newNode = new Node(item);
|
||||
if (h == null)
|
||||
h = t = newNode;
|
||||
else
|
||||
|
|
|
@ -269,8 +269,8 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
|
|||
if (a.getClass() != Object[].class)
|
||||
a = Arrays.copyOf(a, n, Object[].class);
|
||||
if (screen && (n == 1 || this.comparator != null)) {
|
||||
for (int i = 0; i < n; ++i)
|
||||
if (a[i] == null)
|
||||
for (Object elt : a)
|
||||
if (elt == null)
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.queue = a;
|
||||
|
|
|
@ -753,8 +753,10 @@ public class SubmissionPublisher<T> implements Publisher<T>,
|
|||
else
|
||||
pred.next = next;
|
||||
}
|
||||
else
|
||||
else {
|
||||
subs.add(b.subscriber);
|
||||
pred = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
return subs;
|
||||
|
|
|
@ -67,7 +67,7 @@ import jdk.internal.misc.VM;
|
|||
* {@code ThreadLocalRandom.current().nextX(...)} (where
|
||||
* {@code X} is {@code Int}, {@code Long}, etc).
|
||||
* When all usages are of this form, it is never possible to
|
||||
* accidently share a {@code ThreadLocalRandom} across multiple threads.
|
||||
* accidentally share a {@code ThreadLocalRandom} across multiple threads.
|
||||
*
|
||||
* <p>This class also provides additional commonly used bounded random
|
||||
* generation methods.
|
||||
|
|
|
@ -264,13 +264,12 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
* assist in storage reclamation when large numbers of queued tasks
|
||||
* become cancelled.</dd>
|
||||
*
|
||||
* <dt>Finalization</dt>
|
||||
* <dt>Reclamation</dt>
|
||||
*
|
||||
* <dd>A pool that is no longer referenced in a program <em>AND</em>
|
||||
* has no remaining threads will be {@code shutdown} automatically. If
|
||||
* you would like to ensure that unreferenced pools are reclaimed even
|
||||
* if users forget to call {@link #shutdown}, then you must arrange
|
||||
* that unused threads eventually die, by setting appropriate
|
||||
* has no remaining threads may be reclaimed (garbage collected)
|
||||
* without being explicity shutdown. You can configure a pool to allow
|
||||
* all unused threads to eventually die by setting appropriate
|
||||
* keep-alive times, using a lower bound of zero core threads and/or
|
||||
* setting {@link #allowCoreThreadTimeOut(boolean)}. </dd>
|
||||
*
|
||||
|
@ -361,7 +360,7 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
|
|||
* time, but need not hit each state. The transitions are:
|
||||
*
|
||||
* RUNNING -> SHUTDOWN
|
||||
* On invocation of shutdown(), perhaps implicitly in finalize()
|
||||
* On invocation of shutdown()
|
||||
* (RUNNING or SHUTDOWN) -> STOP
|
||||
* On invocation of shutdownNow()
|
||||
* SHUTDOWN -> TIDYING
|
||||
|
@ -581,9 +580,6 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
|
|||
private static final RuntimePermission shutdownPerm =
|
||||
new RuntimePermission("modifyThread");
|
||||
|
||||
/** The context to be used when executing the finalizer, or null. */
|
||||
private final AccessControlContext acc;
|
||||
|
||||
/**
|
||||
* Class Worker mainly maintains interrupt control state for
|
||||
* threads running tasks, along with other minor bookkeeping.
|
||||
|
@ -1300,9 +1296,6 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
|
|||
throw new IllegalArgumentException();
|
||||
if (workQueue == null || threadFactory == null || handler == null)
|
||||
throw new NullPointerException();
|
||||
this.acc = (System.getSecurityManager() == null)
|
||||
? null
|
||||
: AccessController.getContext();
|
||||
this.corePoolSize = corePoolSize;
|
||||
this.maximumPoolSize = maximumPoolSize;
|
||||
this.workQueue = workQueue;
|
||||
|
@ -1469,33 +1462,6 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes {@code shutdown} when this executor is no longer
|
||||
* referenced and it has no threads.
|
||||
*
|
||||
* <p>This method is invoked with privileges that are restricted by
|
||||
* the security context of the caller that invokes the constructor.
|
||||
*
|
||||
* @deprecated The {@code finalize} method has been deprecated.
|
||||
* Subclasses that override {@code finalize} in order to perform cleanup
|
||||
* should be modified to use alternative cleanup mechanisms and
|
||||
* to remove the overriding {@code finalize} method.
|
||||
* When overriding the {@code finalize} method, its implementation must explicitly
|
||||
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
|
||||
* See the specification for {@link Object#finalize()} for further
|
||||
* information about migration options.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
protected void finalize() {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm == null || acc == null) {
|
||||
shutdown();
|
||||
} else {
|
||||
PrivilegedAction<Void> pa = () -> { shutdown(); return null; };
|
||||
AccessController.doPrivileged(pa, acc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the thread factory used to create new threads.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue