8203681: Miscellaneous changes imported from jsr166 CVS 2018-06

Reviewed-by: martin, psandoz
This commit is contained in:
Doug Lea 2018-06-25 09:59:16 -07:00
parent 3afeb2cb48
commit 0a0a8a5791
33 changed files with 164 additions and 123 deletions

View file

@ -1129,7 +1129,7 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
final int len = items.length;
// how far takeIndex has advanced since the previous
// operation of this iterator
long dequeues = (cycles - prevCycles) * len
long dequeues = (long) (cycles - prevCycles) * len
+ (takeIndex - prevTakeIndex);
// Check indices for invalidation

View file

@ -1764,9 +1764,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
}
return true;
}
} catch (ClassCastException unused) {
return false;
} catch (NullPointerException unused) {
} catch (ClassCastException | NullPointerException unused) {
return false;
}
}

View file

@ -34,6 +34,7 @@
package java.util.concurrent;
import java.lang.invoke.VarHandle;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
@ -299,6 +300,9 @@ public class CopyOnWriteArrayList<E>
CopyOnWriteArrayList<E> clone =
(CopyOnWriteArrayList<E>) super.clone();
clone.resetLock();
// Unlike in readObject, here we cannot visibility-piggyback on the
// volatile write in setArray().
VarHandle.releaseFence();
return clone;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable

View file

@ -826,7 +826,7 @@ public abstract class ForkJoinTask<V> implements Future<V>, Serializable {
*/
public static <T extends ForkJoinTask<?>> Collection<T> invokeAll(Collection<T> tasks) {
if (!(tasks instanceof RandomAccess) || !(tasks instanceof List<?>)) {
invokeAll(tasks.toArray(new ForkJoinTask<?>[tasks.size()]));
invokeAll(tasks.toArray(new ForkJoinTask<?>[0]));
return tasks;
}
@SuppressWarnings("unchecked")

View file

@ -202,6 +202,10 @@ public enum TimeUnit {
* {@code unit.convert(Duration.of(n, unit.toChronoUnit()))}
* is equivalent to {@code n} (in the absence of overflow).
*
* @apiNote
* This method differs from {@link Duration#toNanos()} in that it
* does not throw {@link ArithmeticException} on numeric overflow.
*
* @param duration the time duration
* @return the converted duration in this unit,
* or {@code Long.MIN_VALUE} if conversion would negatively overflow,
@ -216,7 +220,7 @@ public enum TimeUnit {
if (secs < 0 && nano > 0) {
// use representation compatible with integer division
secs++;
nano -= SECOND_SCALE;
nano -= (int) SECOND_SCALE;
}
final long s, nanoVal;
// Optimize for the common case - NANOSECONDS without overflow

View file

@ -312,13 +312,13 @@ public interface Condition {
* <pre> {@code
* boolean aMethod(long timeout, TimeUnit unit)
* throws InterruptedException {
* long nanos = unit.toNanos(timeout);
* long nanosRemaining = unit.toNanos(timeout);
* lock.lock();
* try {
* while (!conditionBeingWaitedFor()) {
* if (nanos <= 0L)
* if (nanosRemaining <= 0L)
* return false;
* nanos = theCondition.awaitNanos(nanos);
* nanosRemaining = theCondition.awaitNanos(nanosRemaining);
* }
* // ...
* return true;