Merge JDK-8145252-TLS13-branch
authorxuelei
Mon, 25 Jun 2018 13:02:39 -0700
branchJDK-8145252-TLS13-branch
changeset 56808 d4844278d72c
parent 56807 b9e374d0534f (current diff)
parent 50767 356eaea05bf0 (diff)
child 56809 745efe8903ab
Merge
--- a/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp	Mon Jun 25 13:02:39 2018 -0700
@@ -265,9 +265,11 @@
   __ push(RegSet::range(r0, r29), sp);         // integer registers except lr & sp
 
   if (save_fpu_registers) {
-    for (int i = 30; i >= 0; i -= 2)
-      __ stpd(as_FloatRegister(i), as_FloatRegister(i+1),
-              Address(__ pre(sp, -2 * wordSize)));
+    for (int i = 31; i>= 0; i -= 4) {
+      __ sub(sp, sp, 4 * wordSize); // no pre-increment for st1. Emulate it without modifying other registers
+      __ st1(as_FloatRegister(i-3), as_FloatRegister(i-2), as_FloatRegister(i-1),
+          as_FloatRegister(i), __ T1D, Address(sp));
+    }
   } else {
     __ add(sp, sp, -32 * wordSize);
   }
@@ -277,9 +279,9 @@
 
 static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {
   if (restore_fpu_registers) {
-    for (int i = 0; i < 32; i += 2)
-      __ ldpd(as_FloatRegister(i), as_FloatRegister(i+1),
-              Address(__ post(sp, 2 * wordSize)));
+    for (int i = 0; i < 32; i += 4)
+      __ ld1(as_FloatRegister(i), as_FloatRegister(i+1), as_FloatRegister(i+2),
+          as_FloatRegister(i+3), __ T1D, Address(__ post(sp, 4 * wordSize)));
   } else {
     __ add(sp, sp, 32 * wordSize);
   }
@@ -290,9 +292,9 @@
 static void restore_live_registers_except_r0(StubAssembler* sasm, bool restore_fpu_registers = true)  {
 
   if (restore_fpu_registers) {
-    for (int i = 0; i < 32; i += 2)
-      __ ldpd(as_FloatRegister(i), as_FloatRegister(i+1),
-              Address(__ post(sp, 2 * wordSize)));
+    for (int i = 0; i < 32; i += 4)
+      __ ld1(as_FloatRegister(i), as_FloatRegister(i+1), as_FloatRegister(i+2),
+          as_FloatRegister(i+3), __ T1D, Address(__ post(sp, 4 * wordSize)));
   } else {
     __ add(sp, sp, 32 * wordSize);
   }
--- a/src/hotspot/share/runtime/arguments.cpp	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/hotspot/share/runtime/arguments.cpp	Mon Jun 25 13:02:39 2018 -0700
@@ -570,6 +570,9 @@
   { "InlineNotify",                  JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
   { "EnableTracing",                 JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
   { "UseLockedTracing",              JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
+  { "NativeMonitorTimeout",          JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
+  { "NativeMonitorSpinLimit",        JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
+  { "NativeMonitorFlags",            JDK_Version::undefined(), JDK_Version::jdk(11), JDK_Version::jdk(12) },
 
 #ifdef TEST_VERIFY_SPECIAL_JVM_FLAGS
   { "dep > obs",                    JDK_Version::jdk(9), JDK_Version::jdk(8), JDK_Version::undefined() },
--- a/src/hotspot/share/runtime/globals.hpp	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/hotspot/share/runtime/globals.hpp	Mon Jun 25 13:02:39 2018 -0700
@@ -854,12 +854,6 @@
           "When true prevents OS-level spurious, or premature, wakeups "    \
           "from Object.wait (Ignored for Windows)")                         \
                                                                             \
-  experimental(intx, NativeMonitorTimeout, -1, "(Unstable)")                \
-                                                                            \
-  experimental(intx, NativeMonitorFlags, 0, "(Unstable)")                   \
-                                                                            \
-  experimental(intx, NativeMonitorSpinLimit, 20, "(Unstable)")              \
-                                                                            \
   develop(bool, UsePthreads, false,                                         \
           "Use pthread-based instead of libthread-based synchronization "   \
           "(SPARC only)")                                                   \
--- a/src/hotspot/share/runtime/mutex.cpp	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/hotspot/share/runtime/mutex.cpp	Mon Jun 25 13:02:39 2018 -0700
@@ -348,9 +348,7 @@
 
   int Probes  = 0;
   int Delay   = 0;
-  int Steps   = 0;
-  int SpinMax = NativeMonitorSpinLimit;
-  int flgs    = NativeMonitorFlags;
+  int SpinMax = 20;
   for (;;) {
     intptr_t v = _LockWord.FullWord;
     if ((v & _LBIT) == 0) {
@@ -360,9 +358,7 @@
       continue;
     }
 
-    if ((flgs & 8) == 0) {
-      SpinPause();
-    }
+    SpinPause();
 
     // Periodically increase Delay -- variable Delay form
     // conceptually: delay *= 1 + 1/Exponent
@@ -374,8 +370,6 @@
       // CONSIDER: Delay += 1 + (Delay/4); Delay &= 0x7FF ;
     }
 
-    if (flgs & 2) continue;
-
     // Consider checking _owner's schedctl state, if OFFPROC abort spin.
     // If the owner is OFFPROC then it's unlike that the lock will be dropped
     // in a timely fashion, which suggests that spinning would not be fruitful
@@ -390,12 +384,11 @@
     // spin loop.  N1 and brethren write-around the L1$ over the xbar into the L2$.
     // Furthermore, they don't have a W$ like traditional SPARC processors.
     // We currently use a Marsaglia Shift-Xor RNG loop.
-    Steps += Delay;
     if (Self != NULL) {
       jint rv = Self->rng[0];
       for (int k = Delay; --k >= 0;) {
         rv = MarsagliaXORV(rv);
-        if ((flgs & 4) == 0 && SafepointMechanism::poll(Self)) return 0;
+        if (SafepointMechanism::poll(Self)) return 0;
       }
       Self->rng[0] = rv;
     } else {
@@ -406,10 +399,6 @@
 
 static int ParkCommon(ParkEvent * ev, jlong timo) {
   // Diagnostic support - periodically unwedge blocked threads
-  intx nmt = NativeMonitorTimeout;
-  if (nmt > 0 && (nmt < timo || timo <= 0)) {
-    timo = nmt;
-  }
   int err = OS_OK;
   if (0 == timo) {
     ev->park();
@@ -466,11 +455,6 @@
   ESelf->reset();
   OrderAccess::fence();
 
-  // Optional optimization ... try barging on the inner lock
-  if ((NativeMonitorFlags & 32) && Atomic::replace_if_null(ESelf, &_OnDeck)) {
-    goto OnDeck_LOOP;
-  }
-
   if (AcquireOrPush(ESelf)) goto Exeunt;
 
   // At any given time there is at most one ondeck thread.
@@ -484,7 +468,6 @@
 
   // Self is now in the OnDeck position and will remain so until it
   // manages to acquire the lock.
- OnDeck_LOOP:
   for (;;) {
     assert(_OnDeck == ESelf, "invariant");
     if (TrySpin(Self)) break;
@@ -706,11 +689,6 @@
     nfy->Notified = 1;
   }
   Thread::muxRelease(_WaitLock);
-  if (nfy != NULL && (NativeMonitorFlags & 16)) {
-    // Experimental code ... light up the wakee in the hope that this thread (the owner)
-    // will drop the lock just about the time the wakee comes ONPROC.
-    nfy->unpark();
-  }
   assert(ILocked(), "invariant");
   return true;
 }
@@ -794,7 +772,7 @@
   for (;;) {
     if (ESelf->Notified) break;
     int err = ParkCommon(ESelf, timo);
-    if (err == OS_TIMEOUT || (NativeMonitorFlags & 1)) break;
+    if (err == OS_TIMEOUT) break;
   }
 
   // Prepare for reentry - if necessary, remove ESelf from WaitSet
--- a/src/java.base/share/classes/java/util/ComparableTimSort.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/ComparableTimSort.java	Mon Jun 25 13:02:39 2018 -0700
@@ -305,7 +305,7 @@
      * @param a the array in which a run is to be counted and possibly reversed
      * @param lo index of the first element in the run
      * @param hi index after the last element that may be contained in the run.
-              It is required that {@code lo < hi}.
+     *        It is required that {@code lo < hi}.
      * @return  the length of the run beginning at the specified position in
      *          the specified array
      */
@@ -394,19 +394,23 @@
      * This method is called each time a new run is pushed onto the stack,
      * so the invariants are guaranteed to hold for i < stackSize upon
      * entry to the method.
+     *
+     * Thanks to Stijn de Gouw, Jurriaan Rot, Frank S. de Boer,
+     * Richard Bubel and Reiner Hahnle, this is fixed with respect to
+     * the analysis in "On the Worst-Case Complexity of TimSort" by
+     * Nicolas Auger, Vincent Jug, Cyril Nicaud, and Carine Pivoteau.
      */
     private void mergeCollapse() {
         while (stackSize > 1) {
             int n = stackSize - 2;
-            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1]) {
+            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1] ||
+                n > 1 && runLen[n-2] <= runLen[n] + runLen[n-1]) {
                 if (runLen[n - 1] < runLen[n + 1])
                     n--;
-                mergeAt(n);
-            } else if (runLen[n] <= runLen[n + 1]) {
-                mergeAt(n);
-            } else {
+            } else if (n < 0 || runLen[n] > runLen[n + 1]) {
                 break; // Invariant is established
             }
+            mergeAt(n);
         }
     }
 
--- a/src/java.base/share/classes/java/util/TimSort.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/TimSort.java	Mon Jun 25 13:02:39 2018 -0700
@@ -339,7 +339,7 @@
      * @param a the array in which a run is to be counted and possibly reversed
      * @param lo index of the first element in the run
      * @param hi index after the last element that may be contained in the run.
-              It is required that {@code lo < hi}.
+     *        It is required that {@code lo < hi}.
      * @param c the comparator to used for the sort
      * @return  the length of the run beginning at the specified position in
      *          the specified array
@@ -429,19 +429,23 @@
      * This method is called each time a new run is pushed onto the stack,
      * so the invariants are guaranteed to hold for i < stackSize upon
      * entry to the method.
+     *
+     * Thanks to Stijn de Gouw, Jurriaan Rot, Frank S. de Boer,
+     * Richard Bubel and Reiner Hahnle, this is fixed with respect to
+     * the analysis in "On the Worst-Case Complexity of TimSort" by
+     * Nicolas Auger, Vincent Jug, Cyril Nicaud, and Carine Pivoteau.
      */
     private void mergeCollapse() {
         while (stackSize > 1) {
             int n = stackSize - 2;
-            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1]) {
+            if (n > 0 && runLen[n-1] <= runLen[n] + runLen[n+1] ||
+                n > 1 && runLen[n-2] <= runLen[n] + runLen[n-1]) {
                 if (runLen[n - 1] < runLen[n + 1])
                     n--;
-                mergeAt(n);
-            } else if (runLen[n] <= runLen[n + 1]) {
-                mergeAt(n);
-            } else {
+            } else if (n < 0 || runLen[n] > runLen[n + 1]) {
                 break; // Invariant is established
             }
+            mergeAt(n);
         }
     }
 
--- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Mon Jun 25 13:02:39 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/ConcurrentHashMap.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java	Mon Jun 25 13:02:39 2018 -0700
@@ -702,12 +702,7 @@
      * See Hackers Delight, sec 3.2
      */
     private static final int tableSizeFor(int c) {
-        int n = c - 1;
-        n |= n >>> 1;
-        n |= n >>> 2;
-        n |= n >>> 4;
-        n |= n >>> 8;
-        n |= n >>> 16;
+        int n = -1 >>> Integer.numberOfLeadingZeros(c - 1);
         return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
     }
 
@@ -844,12 +839,7 @@
      * elements is negative
      */
     public ConcurrentHashMap(int initialCapacity) {
-        if (initialCapacity < 0)
-            throw new IllegalArgumentException();
-        int cap = ((initialCapacity >= (MAXIMUM_CAPACITY >>> 1)) ?
-                   MAXIMUM_CAPACITY :
-                   tableSizeFor(initialCapacity + (initialCapacity >>> 1) + 1));
-        this.sizeCtl = cap;
+        this(initialCapacity, LOAD_FACTOR, 1);
     }
 
     /**
@@ -883,8 +873,8 @@
 
     /**
      * Creates a new, empty map with an initial table size based on
-     * the given number of elements ({@code initialCapacity}), table
-     * density ({@code loadFactor}), and number of concurrently
+     * the given number of elements ({@code initialCapacity}), initial
+     * table density ({@code loadFactor}), and number of concurrently
      * updating threads ({@code concurrencyLevel}).
      *
      * @param initialCapacity the initial capacity. The implementation
@@ -1473,13 +1463,9 @@
         if (size == 0L)
             sizeCtl = 0;
         else {
-            int n;
-            if (size >= (long)(MAXIMUM_CAPACITY >>> 1))
-                n = MAXIMUM_CAPACITY;
-            else {
-                int sz = (int)size;
-                n = tableSizeFor(sz + (sz >>> 1) + 1);
-            }
+            long ts = (long)(1.0 + size / LOAD_FACTOR);
+            int n = (ts >= (long)MAXIMUM_CAPACITY) ?
+                MAXIMUM_CAPACITY : tableSizeFor((int)ts);
             @SuppressWarnings("unchecked")
             Node<K,V>[] tab = (Node<K,V>[])new Node<?,?>[n];
             int mask = n - 1;
--- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/ForkJoinTask.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/TimeUnit.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/src/java.base/share/classes/java/util/concurrent/locks/Condition.java	Mon Jun 25 13:02:39 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/hotspot/jtreg/runtime/Nestmates/membership/TestNestmateMembership.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/test/hotspot/jtreg/runtime/Nestmates/membership/TestNestmateMembership.java	Mon Jun 25 13:02:39 2018 -0700
@@ -670,9 +670,8 @@
 
     static void test_NoHostInvoke() throws Throwable {
         System.out.println("Testing for missing nest-host attribute");
-        String msg = "tried to access method " +
-            "TestNestmateMembership$TargetNoHost.m()V from class " +
-            "TestNestmateMembership$Caller";
+        String msg = "class TestNestmateMembership$Caller tried to access " +
+            "method TestNestmateMembership$TargetNoHost.m()V";
         try {
             Caller.invokeTargetNoHost();
             throw new Error("Missing IllegalAccessError: " + msg);
@@ -698,8 +697,8 @@
             check_expected(expected, msg);
         }
 
-        msg = "tried to access method TestNestmateMembership$Target.m()V" +
-            " from class TestNestmateMembership$CallerNoHost";
+        msg = "class TestNestmateMembership$CallerNoHost tried to access " +
+            "method TestNestmateMembership$Target.m()V";
         try {
             CallerNoHost.invokeTarget();
             throw new Error("Missing IllegalAccessError: " + msg);
@@ -707,8 +706,8 @@
         catch (IllegalAccessError expected) {
             check_expected(expected, msg);
         }
-        msg = "tried to access method TestNestmateMembership$TargetNoHost.m()V" +
-            " from class TestNestmateMembership$CallerNoHost";
+        msg = "class TestNestmateMembership$CallerNoHost tried to access method " +
+            "TestNestmateMembership$TargetNoHost.m()V";
         try {
             CallerNoHost.invokeTargetNoHost();
             throw new Error("Missing IllegalAccessError: " + msg);
@@ -950,8 +949,8 @@
 
     static void test_NoHostConstruct() throws Throwable {
         System.out.println("Testing for missing nest-host attribute");
-        String msg = "tried to access method TestNestmateMembership$TargetNoHost.<init>()V" +
-            " from class TestNestmateMembership$Caller";
+        String msg = "class TestNestmateMembership$Caller tried to access method " +
+            "TestNestmateMembership$TargetNoHost.<init>()V";
         try {
             Caller.newTargetNoHost();
             throw new Error("Missing IncompatibleClassChangeError: " + msg);
@@ -977,8 +976,8 @@
             check_expected(expected, msg);
         }
 
-        msg = "tried to access method TestNestmateMembership$Target.<init>()V" +
-            " from class TestNestmateMembership$CallerNoHost";
+        msg = "class TestNestmateMembership$CallerNoHost tried to access method " +
+            "TestNestmateMembership$Target.<init>()V";
         try {
             CallerNoHost.newTarget();
             throw new Error("Missing IncompatibleClassChangeError: " + msg);
@@ -986,8 +985,8 @@
         catch (IncompatibleClassChangeError expected) {
             check_expected(expected, msg);
         }
-        msg = "tried to access method TestNestmateMembership$TargetNoHost.<init>()V" +
-            " from class TestNestmateMembership$CallerNoHost";
+        msg = "class TestNestmateMembership$CallerNoHost tried to access method " +
+            "TestNestmateMembership$TargetNoHost.<init>()V";
         try {
             CallerNoHost.newTargetNoHost();
             throw new Error("Missing IncompatibleClassChangeError: " + msg);
--- a/test/hotspot/jtreg/runtime/Nestmates/privateConstructors/TestConstructorHierarchy.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/test/hotspot/jtreg/runtime/Nestmates/privateConstructors/TestConstructorHierarchy.java	Mon Jun 25 13:02:39 2018 -0700
@@ -51,7 +51,7 @@
             throw new Error("Unexpected construction of ExternalSuper");
         }
         catch (IllegalAccessError iae) {
-            if (iae.getMessage().contains("tried to access method ExternalSuper.<init>()V from class TestConstructorHierarchy")) {
+            if (iae.getMessage().contains("class TestConstructorHierarchy tried to access method ExternalSuper.<init>()V")) {
                 System.out.println("Got expected exception constructing ExternalSuper: " + iae);
             }
             else throw new Error("Unexpected IllegalAccessError: " + iae);
@@ -61,7 +61,7 @@
             throw new Error("Unexpected construction of NestedA and supers");
         }
         catch (IllegalAccessError iae) {
-            if (iae.getMessage().contains("tried to access method ExternalSuper.<init>()V from class TestConstructorHierarchy$NestedA")) {
+            if (iae.getMessage().contains("class TestConstructorHierarchy$NestedA tried to access method ExternalSuper.<init>()V")) {
                 System.out.println("Got expected exception constructing NestedA: " + iae);
             }
             else throw new Error("Unexpected IllegalAccessError: " + iae);
@@ -71,7 +71,7 @@
             throw new Error("Unexpected construction of ExternalSub");
         }
         catch (IllegalAccessError iae) {
-            if (iae.getMessage().contains("tried to access method TestConstructorHierarchy$NestedA.<init>()V from class ExternalSub")) {
+            if (iae.getMessage().contains("class ExternalSub tried to access method TestConstructorHierarchy$NestedA.<init>()V")) {
                 System.out.println("Got expected exception constructing ExternalSub: " + iae);
             }
             else throw new Error("Unexpected IllegalAccessError: " + iae);
--- a/test/jdk/java/util/Collection/HotPotatoes.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/test/jdk/java/util/Collection/HotPotatoes.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/Collection/IteratorMicroBenchmark.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/Collection/RemoveMicroBenchmark.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/Map/LockStep.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/ConcurrentHashMap/MapCheck.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/ConcurrentHashMap/MapLoops.java	Mon Jun 25 13:02:39 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/ConcurrentHashMap/WhiteBox.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/ConcurrentHashMap/WhiteBox.java	Mon Jun 25 13:02:39 2018 -0700
@@ -45,15 +45,20 @@
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.lang.invoke.VarHandle;
+import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Supplier;
 
 @Test
 public class WhiteBox {
     final ThreadLocalRandom rnd = ThreadLocalRandom.current();
     final VarHandle TABLE, NEXTTABLE, SIZECTL;
+    final MethodHandle TABLE_SIZE_FOR;
 
     WhiteBox() throws ReflectiveOperationException {
         Class<?> mClass = ConcurrentHashMap.class;
@@ -65,11 +70,33 @@
         TABLE = lookup.findVarHandle(mClass, "table", nodeArrayClass);
         NEXTTABLE = lookup.findVarHandle(mClass, "nextTable", nodeArrayClass);
         SIZECTL = lookup.findVarHandle(mClass, "sizeCtl", int.class);
+        TABLE_SIZE_FOR = lookup.findStatic(
+                mClass, "tableSizeFor",
+                MethodType.methodType(int.class, int.class));
     }
 
     Object[] table(ConcurrentHashMap m) { return (Object[]) TABLE.getVolatile(m); }
     Object[] nextTable(ConcurrentHashMap m) { return (Object[]) NEXTTABLE.getVolatile(m); }
     int sizeCtl(ConcurrentHashMap m) { return (int) SIZECTL.getVolatile(m); }
+    int tableSizeFor(int n) {
+        try {
+            return (int) TABLE_SIZE_FOR.invoke(n);
+        } catch (Throwable t) { throw new AssertionError(t); }
+    }
+
+    List<Supplier<ConcurrentHashMap>> newConcurrentHashMapSuppliers(
+        int initialCapacity) {
+        return List.of(
+            () -> new ConcurrentHashMap(initialCapacity),
+            () -> new ConcurrentHashMap(initialCapacity, 0.75f),
+            () -> new ConcurrentHashMap(initialCapacity, 0.75f, 1));
+    }
+
+    ConcurrentHashMap newConcurrentHashMap(int initialCapacity) {
+        List<Supplier<ConcurrentHashMap>> suppliers
+            = newConcurrentHashMapSuppliers(initialCapacity);
+        return suppliers.get(rnd.nextInt(suppliers.size())).get();
+    }
 
     @Test
     public void defaultConstructor() {
@@ -83,7 +110,7 @@
     public void shouldNotResizeWhenInitialCapacityProvided() {
         int initialCapacity = rnd.nextInt(1, 100);
         Object[] initialTable = null;
-        ConcurrentHashMap m = new ConcurrentHashMap(initialCapacity);
+        ConcurrentHashMap m = newConcurrentHashMap(initialCapacity);
 
         // table is lazily initialized
         assertNull(table(m));
@@ -101,6 +128,34 @@
         assertEquals(initialTable.length, expectedInitialTableLength);
     }
 
+    @Test
+    public void constructorsShouldGiveSameInitialCapacity() {
+        int initialCapacity = rnd.nextInt(1, 256);
+        long distinctTableLengths
+            = newConcurrentHashMapSuppliers(initialCapacity).stream()
+            .map(Supplier::get)
+            .mapToInt(map -> { map.put(42, 42); return table(map).length; })
+            .distinct()
+            .count();
+        assertEquals(1L, distinctTableLengths);
+    }
+
+    @Test
+    public void testTableSizeFor() {
+        assertEquals(1, tableSizeFor(0));
+        assertEquals(1, tableSizeFor(1));
+        assertEquals(2, tableSizeFor(2));
+        assertEquals(4, tableSizeFor(3));
+        assertEquals(16, tableSizeFor(15));
+        assertEquals(16, tableSizeFor(16));
+        assertEquals(32, tableSizeFor(17));
+        int maxSize = 1 << 30;
+        assertEquals(maxSize, tableSizeFor(maxSize - 1));
+        assertEquals(maxSize, tableSizeFor(maxSize));
+        assertEquals(maxSize, tableSizeFor(maxSize + 1));
+        assertEquals(maxSize, tableSizeFor(Integer.MAX_VALUE));
+    }
+
     byte[] serialBytes(Object o) {
         try {
             ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -132,7 +187,7 @@
     public void testSerialization() {
         assertInvariants(serialClone(new ConcurrentHashMap()));
 
-        ConcurrentHashMap m = new ConcurrentHashMap(rnd.nextInt(100));
+        ConcurrentHashMap m = newConcurrentHashMap(rnd.nextInt(100));
         m.put(1, 1);
         ConcurrentHashMap clone = serialClone(m);
         assertInvariants(clone);
--- a/test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/MapLoops.java	Mon Jun 25 09:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/MapLoops.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/AbstractQueuedLongSynchronizerTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentHashMap8Test.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentLinkedQueueTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSetTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/DelayQueueTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/LinkedBlockingDequeTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/LinkedBlockingQueueTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/LinkedListTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/LinkedTransferQueueTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/PriorityBlockingQueueTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/PriorityQueueTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/TreeSetTest.java	Mon Jun 25 13:02:39 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:48:06 2018 -0700
+++ b/test/jdk/java/util/concurrent/tck/TreeSubSetTest.java	Mon Jun 25 13:02:39 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());
     }
 
     /**