changeset 51398:5637aca18f1d

8203681: Miscellaneous changes imported from jsr166 CVS 2018-06 Reviewed-by: martin, psandoz
author dl
date Mon, 25 Jun 2018 09:59:16 -0700
parents 3a6d47df8239
children c49a01150a66 8e326bd343bb
files src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java src/java.base/share/classes/java/util/concurrent/TimeUnit.java src/java.base/share/classes/java/util/concurrent/locks/Condition.java test/jdk/java/util/Collection/HotPotatoes.java test/jdk/java/util/Collection/IteratorMicroBenchmark.java test/jdk/java/util/Collection/RemoveMicroBenchmark.java test/jdk/java/util/Map/LockStep.java test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java test/jdk/java/util/concurrent/ConcurrentHashMap/MapCheck.java test/jdk/java/util/concurrent/ConcurrentHashMap/MapLoops.java test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/MapLoops.java test/jdk/java/util/concurrent/tck/AbstractQueuedLongSynchronizerTest.java test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java test/jdk/java/util/concurrent/tck/CompletableFutureTest.java test/jdk/java/util/concurrent/tck/ConcurrentHashMap8Test.java test/jdk/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java test/jdk/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java test/jdk/java/util/concurrent/tck/ConcurrentSkipListSetTest.java test/jdk/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java test/jdk/java/util/concurrent/tck/DelayQueueTest.java test/jdk/java/util/concurrent/tck/LinkedBlockingDequeTest.java test/jdk/java/util/concurrent/tck/LinkedBlockingQueueTest.java test/jdk/java/util/concurrent/tck/LinkedListTest.java test/jdk/java/util/concurrent/tck/LinkedTransferQueueTest.java test/jdk/java/util/concurrent/tck/PriorityBlockingQueueTest.java test/jdk/java/util/concurrent/tck/PriorityQueueTest.java test/jdk/java/util/concurrent/tck/RecursiveActionTest.java test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java test/jdk/java/util/concurrent/tck/TreeSetTest.java test/jdk/java/util/concurrent/tck/TreeSubSetTest.java
diffstat 33 files changed, 164 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Mon Jun 25 09:59:16 2018 -0700
@@ -1129,7 +1129,7 @@
                 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
--- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java	Mon Jun 25 09:59:16 2018 -0700
@@ -1764,9 +1764,7 @@
                 }
                 return true;
             }
-        } catch (ClassCastException unused) {
-            return false;
-        } catch (NullPointerException unused) {
+        } catch (ClassCastException | NullPointerException unused) {
             return false;
         }
     }
--- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java	Mon Jun 25 09:59:16 2018 -0700
@@ -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 @@
             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
--- a/src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java	Mon Jun 25 09:59:16 2018 -0700
@@ -826,7 +826,7 @@
      */
     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")
--- a/src/java.base/share/classes/java/util/concurrent/TimeUnit.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/TimeUnit.java	Mon Jun 25 09:59:16 2018 -0700
@@ -202,6 +202,10 @@
      * {@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 @@
         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
--- a/src/java.base/share/classes/java/util/concurrent/locks/Condition.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/locks/Condition.java	Mon Jun 25 09:59:16 2018 -0700
@@ -312,13 +312,13 @@
      * <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;
--- a/test/jdk/java/util/Collection/HotPotatoes.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/Collection/HotPotatoes.java	Mon Jun 25 09:59:16 2018 -0700
@@ -70,7 +70,8 @@
             System.out.printf("implClazz=%s, argClazz=%s\n",
                               implClazz.getName(), argClazz.getName());
             final int iterations = 100000;
-            final List<Integer> list = (List<Integer>) argClazz.newInstance();
+            final List<Integer> list = (List<Integer>)
+                argClazz.getDeclaredConstructor().newInstance();
             final Integer one = Integer.valueOf(1);
             final List<Integer> oneElementList = Collections.singletonList(one);
             final Constructor<? extends Collection> constr
--- a/test/jdk/java/util/Collection/IteratorMicroBenchmark.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/Collection/IteratorMicroBenchmark.java	Mon Jun 25 09:59:16 2018 -0700
@@ -325,7 +325,7 @@
     }
 
     @SafeVarargs @SuppressWarnings("varargs")
-    private <T> Stream<T> concatStreams(Stream<T> ... streams) {
+    private static <T> Stream<T> concatStreams(Stream<T> ... streams) {
         return Stream.of(streams).flatMap(s -> s);
     }
 
--- a/test/jdk/java/util/Collection/RemoveMicroBenchmark.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/Collection/RemoveMicroBenchmark.java	Mon Jun 25 09:59:16 2018 -0700
@@ -284,7 +284,7 @@
     }
 
     @SafeVarargs @SuppressWarnings("varargs")
-    private <T> Stream<T> concatStreams(Stream<T> ... streams) {
+    private static <T> Stream<T> concatStreams(Stream<T> ... streams) {
         return Stream.of(streams).flatMap(s -> s);
     }
 
--- a/test/jdk/java/util/Map/LockStep.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/Map/LockStep.java	Mon Jun 25 09:59:16 2018 -0700
@@ -28,7 +28,6 @@
  * @key randomness
  */
 
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -104,23 +103,21 @@
         final Random r = new Random();
 
         for (int i = 0; i < iterations; i++) {
-            List<Map> maps = Arrays.asList(
-                new Map[] {
-                    new IdentityHashMap(11),
-                    new HashMap(16),
-                    new LinkedHashMap(16),
-                    new WeakHashMap(16),
-                    new Hashtable(16),
-                    new TreeMap(),
-                    new ConcurrentHashMap(16),
-                    new ConcurrentSkipListMap(),
-                    Collections.checkedMap(new HashMap(16), Integer.class, Integer.class),
-                    Collections.checkedSortedMap(new TreeMap(), Integer.class, Integer.class),
-                    Collections.checkedNavigableMap(new TreeMap(), Integer.class, Integer.class),
-                    Collections.synchronizedMap(new HashMap(16)),
-                    Collections.synchronizedSortedMap(new TreeMap()),
-                    Collections.synchronizedNavigableMap(new TreeMap())
-                    });
+            List<Map> maps = List.of(
+                new IdentityHashMap(11),
+                new HashMap(16),
+                new LinkedHashMap(16),
+                new WeakHashMap(16),
+                new Hashtable(16),
+                new TreeMap(),
+                new ConcurrentHashMap(16),
+                new ConcurrentSkipListMap(),
+                Collections.checkedMap(new HashMap(16), Integer.class, Integer.class),
+                Collections.checkedSortedMap(new TreeMap(), Integer.class, Integer.class),
+                Collections.checkedNavigableMap(new TreeMap(), Integer.class, Integer.class),
+                Collections.synchronizedMap(new HashMap(16)),
+                Collections.synchronizedSortedMap(new TreeMap()),
+                Collections.synchronizedNavigableMap(new TreeMap()));
 
             for (int j = 0; j < 10; j++)
                 put(maps, r.nextInt(100), r.nextInt(100));
--- a/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java	Mon Jun 25 09:59:16 2018 -0700
@@ -59,7 +59,6 @@
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.TimeUnit;
 import java.util.function.BooleanSupplier;
 
 @Test
--- a/test/jdk/java/util/concurrent/ConcurrentHashMap/MapCheck.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/ConcurrentHashMap/MapCheck.java	Mon Jun 25 09:59:16 2018 -0700
@@ -109,7 +109,7 @@
 
     static Map newMap(Class cl) {
         try {
-            return (Map)cl.newInstance();
+            return (Map)cl.getDeclaredConstructor().newInstance();
         } catch (Exception e) {
             throw new RuntimeException("Can't instantiate " + cl + ": " + e);
         }
@@ -407,7 +407,7 @@
         timer.start("Put (putAll)           ", size * 2);
         Map s2 = null;
         try {
-            s2 = (Map) (s.getClass().newInstance());
+            s2 = (Map) s.getClass().getDeclaredConstructor().newInstance();
             s2.putAll(s);
         }
         catch (Exception e) { e.printStackTrace(); return; }
--- a/test/jdk/java/util/concurrent/ConcurrentHashMap/MapLoops.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/ConcurrentHashMap/MapLoops.java	Mon Jun 25 09:59:16 2018 -0700
@@ -156,7 +156,8 @@
 
     static void test(int i, int nkeys, Class mapClass) throws Exception {
         System.out.print("Threads: " + i + "\t:");
-        Map<Integer, Integer> map = (Map<Integer,Integer>)mapClass.newInstance();
+        Map<Integer, Integer> map = (Map<Integer, Integer>)
+            mapClass.getDeclaredConstructor().newInstance();
         Integer[] key = makeKeys(nkeys);
         // Uncomment to start with a non-empty table
         //        for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied
--- a/test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/MapLoops.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/MapLoops.java	Mon Jun 25 09:59:16 2018 -0700
@@ -104,7 +104,8 @@
         // warmup
         System.out.println("Warmup...");
         for (int k = 0; k < 2; ++k) {
-            Map<Integer, Integer> map = (Map<Integer,Integer>)mapClass.newInstance();
+            Map<Integer, Integer> map = (Map<Integer, Integer>)
+                mapClass.getDeclaredConstructor().newInstance();
             LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
             CyclicBarrier barrier = new CyclicBarrier(1, timer);
             new Runner(map, key, barrier, rnd.split()).run();
@@ -113,7 +114,8 @@
 
         for (int i = 1; i <= maxThreads; i += (i+1) >>> 1) {
             System.out.print("Threads: " + i + "\t:");
-            Map<Integer, Integer> map = (Map<Integer,Integer>)mapClass.newInstance();
+            Map<Integer, Integer> map = (Map<Integer, Integer>)
+                mapClass.getDeclaredConstructor().newInstance();
             LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
             CyclicBarrier barrier = new CyclicBarrier(i+1, timer);
             for (int k = 0; k < i; ++k)
--- a/test/jdk/java/util/concurrent/tck/AbstractQueuedLongSynchronizerTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/AbstractQueuedLongSynchronizerTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -251,8 +251,8 @@
             assertTrue(c.await(timeoutMillis, MILLISECONDS));
             break;
         case awaitNanos:
-            long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
-            long nanosRemaining = c.awaitNanos(nanosTimeout);
+            long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
+            long nanosRemaining = c.awaitNanos(timeoutNanos);
             assertTrue(nanosRemaining > 0);
             break;
         case awaitUntil:
@@ -279,8 +279,8 @@
                 break;
             case awaitNanos:
                 startTime = System.nanoTime();
-                long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
-                long nanosRemaining = c.awaitNanos(nanosTimeout);
+                long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
+                long nanosRemaining = c.awaitNanos(timeoutNanos);
                 assertTrue(nanosRemaining <= 0);
                 assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
                 assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
--- a/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -255,8 +255,8 @@
             assertTrue(c.await(timeoutMillis, MILLISECONDS));
             break;
         case awaitNanos:
-            long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
-            long nanosRemaining = c.awaitNanos(nanosTimeout);
+            long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
+            long nanosRemaining = c.awaitNanos(timeoutNanos);
             assertTrue(nanosRemaining > 0);
             break;
         case awaitUntil:
@@ -283,8 +283,8 @@
                 break;
             case awaitNanos:
                 startTime = System.nanoTime();
-                long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
-                long nanosRemaining = c.awaitNanos(nanosTimeout);
+                long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
+                long nanosRemaining = c.awaitNanos(timeoutNanos);
                 assertTrue(nanosRemaining <= 0);
                 assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
                 assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
--- a/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -4415,7 +4415,7 @@
             f.complete(null);
 
             f = new CompletableFuture<>();
-            CompletableFuture.anyOf(new CompletableFuture<?>[] { f, incomplete });
+            CompletableFuture.anyOf(f, incomplete);
             f.complete(null);
         }
 
@@ -4433,7 +4433,7 @@
             f.complete(null);
 
             f = new CompletableFuture<>();
-            CompletableFuture.anyOf(new CompletableFuture<?>[] { incomplete, f });
+            CompletableFuture.anyOf(incomplete, f);
             f.complete(null);
         }
     }
--- a/test/jdk/java/util/concurrent/tck/ConcurrentHashMap8Test.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentHashMap8Test.java	Mon Jun 25 09:59:16 2018 -0700
@@ -200,8 +200,8 @@
     static Set populatedSet(Integer[] elements) {
         Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet();
         assertTrue(a.isEmpty());
-        for (int i = 0; i < elements.length; i++)
-            assertTrue(a.add(elements[i]));
+        for (Integer element : elements)
+            assertTrue(a.add(element));
         assertFalse(a.isEmpty());
         assertEquals(elements.length, a.size());
         return a;
--- a/test/jdk/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -689,9 +689,11 @@
      */
     public void testToArray() {
         ConcurrentLinkedDeque q = populatedDeque(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.poll());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -702,8 +704,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.poll());
+        for (Integer o : ints)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -416,9 +416,11 @@
      */
     public void testToArray() {
         ConcurrentLinkedQueue q = populatedQueue(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.poll());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -429,8 +431,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.poll());
+        for (Integer o : ints)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSetTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSetTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -483,9 +483,11 @@
      */
     public void testToArray() {
         ConcurrentSkipListSet q = populatedSet(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.pollFirst());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.pollFirst());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -495,8 +497,9 @@
         ConcurrentSkipListSet<Integer> q = populatedSet(SIZE);
         Integer[] ints = new Integer[SIZE];
         assertSame(ints, q.toArray(ints));
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.pollFirst());
+        for (Integer o : ints)
+            assertSame(o, q.pollFirst());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -434,9 +434,11 @@
      */
     public void testToArray() {
         NavigableSet q = populatedSet(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.pollFirst());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.pollFirst());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -447,8 +449,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.pollFirst());
+        for (Integer o : ints)
+            assertSame(o, q.pollFirst());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/DelayQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/DelayQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -593,10 +593,12 @@
      */
     public void testToArray() throws InterruptedException {
         DelayQueue q = populatedQueue(SIZE);
-        Object[] o = q.toArray();
-        Arrays.sort(o);
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.take());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        Arrays.sort(a);
+        for (Object o : a)
+            assertSame(o, q.take());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -608,8 +610,9 @@
         PDelay[] array = q.toArray(ints);
         assertSame(ints, array);
         Arrays.sort(ints);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.remove());
+        for (PDelay o : ints)
+            assertSame(o, q.remove());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/LinkedBlockingDequeTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/LinkedBlockingDequeTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -1570,9 +1570,11 @@
      */
     public void testToArray() throws InterruptedException {
         LinkedBlockingDeque q = populatedDeque(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.poll());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -1583,8 +1585,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.remove());
+        for (Integer o : ints)
+            assertSame(o, q.remove());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/LinkedBlockingQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/LinkedBlockingQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -656,9 +656,11 @@
      */
     public void testToArray() {
         LinkedBlockingQueue q = populatedQueue(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.poll());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -669,8 +671,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.poll());
+        for (Integer o : ints)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/LinkedListTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/LinkedListTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -385,9 +385,11 @@
      */
     public void testToArray() {
         LinkedList q = populatedQueue(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.poll());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -398,8 +400,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.poll());
+        for (Integer o : ints)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/LinkedTransferQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/LinkedTransferQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -502,10 +502,11 @@
      */
     public void testToArray() {
         LinkedTransferQueue q = populatedQueue(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++) {
-            assertSame(o[i], q.poll());
-        }
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -516,9 +517,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++) {
-            assertSame(ints[i], q.poll());
-        }
+        for (Integer o : ints)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/PriorityBlockingQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/PriorityBlockingQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -600,10 +600,12 @@
      */
     public void testToArray() throws InterruptedException {
         PriorityBlockingQueue q = populatedQueue(SIZE);
-        Object[] o = q.toArray();
-        Arrays.sort(o);
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.take());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        Arrays.sort(a);
+        for (Object o : a)
+            assertSame(o, q.take());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -615,8 +617,9 @@
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
         Arrays.sort(ints);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.take());
+        for (Integer o : ints)
+            assertSame(o, q.take());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/PriorityQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/PriorityQueueTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -463,10 +463,12 @@
      */
     public void testToArray() {
         PriorityQueue q = populatedQueue(SIZE);
-        Object[] o = q.toArray();
-        Arrays.sort(o);
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.poll());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        Arrays.sort(a);
+        for (Object o : a)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -478,8 +480,9 @@
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
         Arrays.sort(ints);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.poll());
+        for (Integer o : ints)
+            assertSame(o, q.poll());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -364,8 +364,8 @@
                 fibActions[4].cancel(true);
                 fibActions[5].completeExceptionally(new FJException());
 
-                for (int i = 0; i < fibActions.length; i++)
-                    fibActions[i].fork();
+                for (FibAction fibAction : fibActions)
+                    fibAction.fork();
 
                 sq.put(fibActions);
 
--- a/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -361,9 +361,7 @@
         TestSubscriber s = new TestSubscriber();
         SubmissionPublisher<Integer> p = basicPublisher();
         s.throwOnCall = true;
-        try {
-            p.subscribe(s);
-        } catch (Exception ok) {}
+        p.subscribe(s);
         s.awaitError();
         assertEquals(0, s.nexts);
         assertEquals(1, s.errors);
--- a/test/jdk/java/util/concurrent/tck/TreeSetTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/TreeSetTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -481,9 +481,11 @@
      */
     public void testToArray() {
         TreeSet q = populatedSet(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.pollFirst());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.pollFirst());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -494,8 +496,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.pollFirst());
+        for (Integer o : ints)
+            assertSame(o, q.pollFirst());
+        assertTrue(q.isEmpty());
     }
 
     /**
--- a/test/jdk/java/util/concurrent/tck/TreeSubSetTest.java	Mon Jun 25 09:59:16 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/TreeSubSetTest.java	Mon Jun 25 09:59:16 2018 -0700
@@ -432,9 +432,11 @@
      */
     public void testToArray() {
         NavigableSet q = populatedSet(SIZE);
-        Object[] o = q.toArray();
-        for (int i = 0; i < o.length; i++)
-            assertSame(o[i], q.pollFirst());
+        Object[] a = q.toArray();
+        assertSame(Object[].class, a.getClass());
+        for (Object o : a)
+            assertSame(o, q.pollFirst());
+        assertTrue(q.isEmpty());
     }
 
     /**
@@ -445,8 +447,9 @@
         Integer[] ints = new Integer[SIZE];
         Integer[] array = q.toArray(ints);
         assertSame(ints, array);
-        for (int i = 0; i < ints.length; i++)
-            assertSame(ints[i], q.pollFirst());
+        for (Integer o : ints)
+            assertSame(o, q.pollFirst());
+        assertTrue(q.isEmpty());
     }
 
     /**