changeset 48843:21efc1774302

8195590: Miscellaneous changes imported from jsr166 CVS 2018-02 Reviewed-by: martin, psandoz, dholmes
author dl
date Sat, 10 Feb 2018 09:23:41 -0800
parents a5a2e4770524
children 09e128cfff3e
files src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java src/java.base/share/classes/java/util/concurrent/Executors.java src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java test/jdk/java/util/AbstractMap/AbstractMapClone.java test/jdk/java/util/Collections/EmptyNavigableSet.java test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.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/ForkJoinPoolTest.java test/jdk/java/util/concurrent/tck/JSR166TestCase.java test/jdk/java/util/concurrent/tck/LongAdderTest.java test/jdk/java/util/concurrent/tck/ReentrantLockTest.java test/jdk/java/util/concurrent/tck/ReentrantReadWriteLockTest.java test/jdk/java/util/concurrent/tck/SemaphoreTest.java test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java
diffstat 16 files changed, 187 insertions(+), 186 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Sat Feb 10 09:23:41 2018 -0800
@@ -1584,34 +1584,40 @@
     void checkInvariants() {
         // meta-assertions
         // assert lock.isHeldByCurrentThread();
-        try {
-            // Unlike ArrayDeque, we have a count field but no spare slot.
-            // We prefer ArrayDeque's strategy (and the names of its fields!),
-            // but our field layout is baked into the serial form, and so is
-            // too annoying to change.
-            //
-            // putIndex == takeIndex must be disambiguated by checking count.
-            int capacity = items.length;
-            // assert capacity > 0;
-            // assert takeIndex >= 0 && takeIndex < capacity;
-            // assert putIndex >= 0 && putIndex < capacity;
-            // assert count <= capacity;
-            // assert takeIndex == putIndex || items[takeIndex] != null;
-            // assert count == capacity || items[putIndex] == null;
-            // assert takeIndex == putIndex || items[dec(putIndex, capacity)] != null;
-        } catch (Throwable t) {
-            System.err.printf("takeIndex=%d putIndex=%d count=%d capacity=%d%n",
-                              takeIndex, putIndex, count, items.length);
-            System.err.printf("items=%s%n",
-                              Arrays.toString(items));
-            throw t;
+        if (!invariantsSatisfied()) {
+            String detail = String.format(
+                "takeIndex=%d putIndex=%d count=%d capacity=%d items=%s",
+                takeIndex, putIndex, count, items.length,
+                Arrays.toString(items));
+            System.err.println(detail);
+            throw new AssertionError(detail);
         }
     }
 
+    private boolean invariantsSatisfied() {
+        // Unlike ArrayDeque, we have a count field but no spare slot.
+        // We prefer ArrayDeque's strategy (and the names of its fields!),
+        // but our field layout is baked into the serial form, and so is
+        // too annoying to change.
+        //
+        // putIndex == takeIndex must be disambiguated by checking count.
+        int capacity = items.length;
+        return capacity > 0
+            && items.getClass() == Object[].class
+            && (takeIndex | putIndex | count) >= 0
+            && takeIndex <  capacity
+            && putIndex  <  capacity
+            && count     <= capacity
+            && (putIndex - takeIndex - count) % capacity == 0
+            && (count == 0 || items[takeIndex] != null)
+            && (count == capacity || items[putIndex] == null)
+            && (count == 0 || items[dec(putIndex, capacity)] != null);
+    }
+
     /**
-     * Deserializes this queue and then checks some invariants.
+     * Reconstitutes this queue from a stream (that is, deserializes it).
      *
-     * @param s the input stream
+     * @param s the stream
      * @throws ClassNotFoundException if the class of a serialized object
      *         could not be found
      * @throws java.io.InvalidObjectException if invariants are violated
@@ -1623,15 +1629,7 @@
         // Read in items array and various fields
         s.defaultReadObject();
 
-        // Check invariants over count and index fields. Note that
-        // if putIndex==takeIndex, count can be either 0 or items.length.
-        if (items.length == 0 ||
-            takeIndex < 0 || takeIndex >= items.length ||
-            putIndex  < 0 || putIndex  >= items.length ||
-            count < 0     || count     >  items.length ||
-            Math.floorMod(putIndex - takeIndex, items.length) !=
-            Math.floorMod(count, items.length)) {
+        if (!invariantsSatisfied())
             throw new java.io.InvalidObjectException("invariants violated");
-        }
     }
 }
--- a/src/java.base/share/classes/java/util/concurrent/Executors.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/src/java.base/share/classes/java/util/concurrent/Executors.java	Sat Feb 10 09:23:41 2018 -0800
@@ -35,6 +35,7 @@
 
 package java.util.concurrent;
 
+import static java.lang.ref.Reference.reachabilityFence;
 import java.security.AccessControlContext;
 import java.security.AccessControlException;
 import java.security.AccessController;
@@ -185,9 +186,7 @@
      * returned executor is guaranteed not to be reconfigurable to use
      * additional threads.
      *
-     * @param threadFactory the factory to use when creating new
-     * threads
-     *
+     * @param threadFactory the factory to use when creating new threads
      * @return the newly created single-threaded Executor
      * @throws NullPointerException if threadFactory is null
      */
@@ -226,6 +225,7 @@
      * will reuse previously constructed threads when they are
      * available, and uses the provided
      * ThreadFactory to create new threads when needed.
+     *
      * @param threadFactory the factory to use when creating new threads
      * @return the newly created thread pool
      * @throws NullPointerException if threadFactory is null
@@ -248,6 +248,7 @@
      * given time. Unlike the otherwise equivalent
      * {@code newScheduledThreadPool(1)} the returned executor is
      * guaranteed not to be reconfigurable to use additional threads.
+     *
      * @return the newly created scheduled executor
      */
     public static ScheduledExecutorService newSingleThreadScheduledExecutor() {
@@ -266,9 +267,9 @@
      * equivalent {@code newScheduledThreadPool(1, threadFactory)}
      * the returned executor is guaranteed not to be reconfigurable to
      * use additional threads.
-     * @param threadFactory the factory to use when creating new
-     * threads
-     * @return a newly created scheduled executor
+     *
+     * @param threadFactory the factory to use when creating new threads
+     * @return the newly created scheduled executor
      * @throws NullPointerException if threadFactory is null
      */
     public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory) {
@@ -281,7 +282,7 @@
      * given delay, or to execute periodically.
      * @param corePoolSize the number of threads to keep in the pool,
      * even if they are idle
-     * @return a newly created scheduled thread pool
+     * @return the newly created scheduled thread pool
      * @throws IllegalArgumentException if {@code corePoolSize < 0}
      */
     public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) {
@@ -295,7 +296,7 @@
      * even if they are idle
      * @param threadFactory the factory to use when the executor
      * creates a new thread
-     * @return a newly created scheduled thread pool
+     * @return the newly created scheduled thread pool
      * @throws IllegalArgumentException if {@code corePoolSize < 0}
      * @throws NullPointerException if threadFactory is null
      */
@@ -678,44 +679,76 @@
      * of an ExecutorService implementation.
      */
     private static class DelegatedExecutorService
-            extends AbstractExecutorService {
+            implements ExecutorService {
         private final ExecutorService e;
         DelegatedExecutorService(ExecutorService executor) { e = executor; }
-        public void execute(Runnable command) { e.execute(command); }
+        public void execute(Runnable command) {
+            try {
+                e.execute(command);
+            } finally { reachabilityFence(this); }
+        }
         public void shutdown() { e.shutdown(); }
-        public List<Runnable> shutdownNow() { return e.shutdownNow(); }
-        public boolean isShutdown() { return e.isShutdown(); }
-        public boolean isTerminated() { return e.isTerminated(); }
+        public List<Runnable> shutdownNow() {
+            try {
+                return e.shutdownNow();
+            } finally { reachabilityFence(this); }
+        }
+        public boolean isShutdown() {
+            try {
+                return e.isShutdown();
+            } finally { reachabilityFence(this); }
+        }
+        public boolean isTerminated() {
+            try {
+                return e.isTerminated();
+            } finally { reachabilityFence(this); }
+        }
         public boolean awaitTermination(long timeout, TimeUnit unit)
             throws InterruptedException {
-            return e.awaitTermination(timeout, unit);
+            try {
+                return e.awaitTermination(timeout, unit);
+            } finally { reachabilityFence(this); }
         }
         public Future<?> submit(Runnable task) {
-            return e.submit(task);
+            try {
+                return e.submit(task);
+            } finally { reachabilityFence(this); }
         }
         public <T> Future<T> submit(Callable<T> task) {
-            return e.submit(task);
+            try {
+                return e.submit(task);
+            } finally { reachabilityFence(this); }
         }
         public <T> Future<T> submit(Runnable task, T result) {
-            return e.submit(task, result);
+            try {
+                return e.submit(task, result);
+            } finally { reachabilityFence(this); }
         }
         public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
             throws InterruptedException {
-            return e.invokeAll(tasks);
+            try {
+                return e.invokeAll(tasks);
+            } finally { reachabilityFence(this); }
         }
         public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
                                              long timeout, TimeUnit unit)
             throws InterruptedException {
-            return e.invokeAll(tasks, timeout, unit);
+            try {
+                return e.invokeAll(tasks, timeout, unit);
+            } finally { reachabilityFence(this); }
         }
         public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
             throws InterruptedException, ExecutionException {
-            return e.invokeAny(tasks);
+            try {
+                return e.invokeAny(tasks);
+            } finally { reachabilityFence(this); }
         }
         public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
                                long timeout, TimeUnit unit)
             throws InterruptedException, ExecutionException, TimeoutException {
-            return e.invokeAny(tasks, timeout, unit);
+            try {
+                return e.invokeAny(tasks, timeout, unit);
+            } finally { reachabilityFence(this); }
         }
     }
 
--- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java	Sat Feb 10 09:23:41 2018 -0800
@@ -323,10 +323,8 @@
      */
     public void put(E e) throws InterruptedException {
         if (e == null) throw new NullPointerException();
-        // Note: convention in all put/take/etc is to preset local var
-        // holding count negative to indicate failure unless set.
-        int c = -1;
-        Node<E> node = new Node<E>(e);
+        final int c;
+        final Node<E> node = new Node<E>(e);
         final ReentrantLock putLock = this.putLock;
         final AtomicInteger count = this.count;
         putLock.lockInterruptibly();
@@ -367,7 +365,7 @@
 
         if (e == null) throw new NullPointerException();
         long nanos = unit.toNanos(timeout);
-        int c = -1;
+        final int c;
         final ReentrantLock putLock = this.putLock;
         final AtomicInteger count = this.count;
         putLock.lockInterruptibly();
@@ -405,28 +403,28 @@
         final AtomicInteger count = this.count;
         if (count.get() == capacity)
             return false;
-        int c = -1;
-        Node<E> node = new Node<E>(e);
+        final int c;
+        final Node<E> node = new Node<E>(e);
         final ReentrantLock putLock = this.putLock;
         putLock.lock();
         try {
-            if (count.get() < capacity) {
-                enqueue(node);
-                c = count.getAndIncrement();
-                if (c + 1 < capacity)
-                    notFull.signal();
-            }
+            if (count.get() == capacity)
+                return false;
+            enqueue(node);
+            c = count.getAndIncrement();
+            if (c + 1 < capacity)
+                notFull.signal();
         } finally {
             putLock.unlock();
         }
         if (c == 0)
             signalNotEmpty();
-        return c >= 0;
+        return true;
     }
 
     public E take() throws InterruptedException {
-        E x;
-        int c = -1;
+        final E x;
+        final int c;
         final AtomicInteger count = this.count;
         final ReentrantLock takeLock = this.takeLock;
         takeLock.lockInterruptibly();
@@ -447,8 +445,8 @@
     }
 
     public E poll(long timeout, TimeUnit unit) throws InterruptedException {
-        E x = null;
-        int c = -1;
+        final E x;
+        final int c;
         long nanos = unit.toNanos(timeout);
         final AtomicInteger count = this.count;
         final ReentrantLock takeLock = this.takeLock;
@@ -475,17 +473,17 @@
         final AtomicInteger count = this.count;
         if (count.get() == 0)
             return null;
-        E x = null;
-        int c = -1;
+        final E x;
+        final int c;
         final ReentrantLock takeLock = this.takeLock;
         takeLock.lock();
         try {
-            if (count.get() > 0) {
-                x = dequeue();
-                c = count.getAndDecrement();
-                if (c > 1)
-                    notEmpty.signal();
-            }
+            if (count.get() == 0)
+                return null;
+            x = dequeue();
+            c = count.getAndDecrement();
+            if (c > 1)
+                notEmpty.signal();
         } finally {
             takeLock.unlock();
         }
@@ -495,6 +493,7 @@
     }
 
     public E peek() {
+        final AtomicInteger count = this.count;
         if (count.get() == 0)
             return null;
         final ReentrantLock takeLock = this.takeLock;
--- a/test/jdk/java/util/AbstractMap/AbstractMapClone.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/AbstractMap/AbstractMapClone.java	Sat Feb 10 09:23:41 2018 -0800
@@ -48,10 +48,11 @@
     }
 
     public Object clone() {
-        AbstractMapClone clone = null;
+        final AbstractMapClone clone;
         try {
-        clone = (AbstractMapClone)super.clone();
+            clone = (AbstractMapClone)super.clone();
         } catch (CloneNotSupportedException e) {
+            throw new AssertionError(e);
         }
         clone.map = (Map)((HashMap)map).clone();
         return clone;
--- a/test/jdk/java/util/Collections/EmptyNavigableSet.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/Collections/EmptyNavigableSet.java	Sat Feb 10 09:23:41 2018 -0800
@@ -163,10 +163,7 @@
      */
     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
     public void testEmptyIterator(String description, NavigableSet<?> navigableSet) {
-        Iterator emptyIterator = navigableSet.iterator();
-
-        assertFalse((emptyIterator != null) && (emptyIterator.hasNext()),
-            "The iterator is not empty.");
+        assertFalse(navigableSet.iterator().hasNext(), "The iterator is not empty.");
     }
 
     /**
--- a/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java	Sat Feb 10 09:23:41 2018 -0800
@@ -181,7 +181,7 @@
             Object x = it.next();
             assertSame(x, a[i]);
             assertSame(x, b[i]);
-            if (xx != null) assertSame(x, yy[i]);
+            assertSame(x, yy[i]);
         }
         if (rnd.nextBoolean()) assertTrue(!it.hasNext());
     }
--- a/test/jdk/java/util/concurrent/tck/AbstractQueuedLongSynchronizerTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/AbstractQueuedLongSynchronizerTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -43,7 +43,6 @@
 import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
 import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject;
 
-import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -168,7 +167,7 @@
         long startTime = System.nanoTime();
         while (!sync.isQueued(t)) {
             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
-                throw new AssertionFailedError("timed out");
+                throw new AssertionError("timed out");
             Thread.yield();
         }
         assertTrue(t.isAlive());
--- a/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -44,7 +44,6 @@
 import java.util.concurrent.locks.AbstractQueuedSynchronizer;
 import java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject;
 
-import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -172,7 +171,7 @@
         long startTime = System.nanoTime();
         while (!sync.isQueued(t)) {
             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
-                throw new AssertionFailedError("timed out");
+                throw new AssertionError("timed out");
             Thread.yield();
         }
         assertTrue(t.isAlive());
--- a/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -68,7 +68,6 @@
 import java.util.function.Predicate;
 import java.util.function.Supplier;
 
-import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -319,7 +318,7 @@
         }
 
         f = new CompletableFuture<>();
-        f.completeExceptionally(ex = new CFException());
+        f.completeExceptionally(new CFException());
         f.obtrudeValue(v1);
         checkCompletedNormally(f, v1);
         f.obtrudeException(ex = new CFException());
@@ -4217,7 +4216,7 @@
         static void assertZero(CompletableFuture<?> f) {
             try {
                 f.getNow(null);
-                throw new AssertionFailedError("should throw");
+                throw new AssertionError("should throw");
             } catch (CompletionException success) {
                 assertTrue(success.getCause() instanceof ZeroException);
             }
--- a/test/jdk/java/util/concurrent/tck/ForkJoinPoolTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/ForkJoinPoolTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -55,7 +55,6 @@
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.ReentrantLock;
 
-import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -331,7 +330,7 @@
                        p.getFactory());
             while (! p.isQuiescent()) {
                 if (millisElapsedSince(startTime) > LONG_DELAY_MS)
-                    throw new AssertionFailedError("timed out");
+                    throw new AssertionError("timed out");
                 assertFalse(p.getAsyncMode());
                 assertFalse(p.isShutdown());
                 assertFalse(p.isTerminating());
--- a/test/jdk/java/util/concurrent/tck/JSR166TestCase.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/JSR166TestCase.java	Sat Feb 10 09:23:41 2018 -0800
@@ -126,7 +126,6 @@
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.regex.Pattern;
 
-import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestResult;
@@ -446,11 +445,10 @@
         for (String testClassName : testClassNames) {
             try {
                 Class<?> testClass = Class.forName(testClassName);
-                Method m = testClass.getDeclaredMethod("suite",
-                                                       new Class<?>[0]);
+                Method m = testClass.getDeclaredMethod("suite");
                 suite.addTest(newTestSuite((Test)m.invoke(null)));
-            } catch (Exception e) {
-                throw new Error("Missing test class", e);
+            } catch (ReflectiveOperationException e) {
+                throw new AssertionError("Missing test class", e);
             }
         }
     }
@@ -627,8 +625,8 @@
             for (String methodName : testMethodNames(testClass))
                 suite.addTest((Test) c.newInstance(data, methodName));
             return suite;
-        } catch (Exception e) {
-            throw new Error(e);
+        } catch (ReflectiveOperationException e) {
+            throw new AssertionError(e);
         }
     }
 
@@ -644,14 +642,14 @@
         if (atLeastJava8()) {
             String name = testClass.getName();
             String name8 = name.replaceAll("Test$", "8Test");
-            if (name.equals(name8)) throw new Error(name);
+            if (name.equals(name8)) throw new AssertionError(name);
             try {
                 return (Test)
                     Class.forName(name8)
-                    .getMethod("testSuite", new Class[] { dataClass })
+                    .getMethod("testSuite", dataClass)
                     .invoke(null, data);
-            } catch (Exception e) {
-                throw new Error(e);
+            } catch (ReflectiveOperationException e) {
+                throw new AssertionError(e);
             }
         } else {
             return new TestSuite();
@@ -760,7 +758,7 @@
         String msg = toString() + ": " + String.format(format, args);
         System.err.println(msg);
         dumpTestThreads();
-        throw new AssertionFailedError(msg);
+        throw new AssertionError(msg);
     }
 
     /**
@@ -781,12 +779,8 @@
                 throw (RuntimeException) t;
             else if (t instanceof Exception)
                 throw (Exception) t;
-            else {
-                AssertionFailedError afe =
-                    new AssertionFailedError(t.toString());
-                afe.initCause(t);
-                throw afe;
-            }
+            else
+                throw new AssertionError(t.toString(), t);
         }
 
         if (Thread.interrupted())
@@ -820,83 +814,83 @@
 
     /**
      * Just like fail(reason), but additionally recording (using
-     * threadRecordFailure) any AssertionFailedError thrown, so that
-     * the current testcase will fail.
+     * threadRecordFailure) any AssertionError thrown, so that the
+     * current testcase will fail.
      */
     public void threadFail(String reason) {
         try {
             fail(reason);
-        } catch (AssertionFailedError t) {
-            threadRecordFailure(t);
-            throw t;
+        } catch (AssertionError fail) {
+            threadRecordFailure(fail);
+            throw fail;
         }
     }
 
     /**
      * Just like assertTrue(b), but additionally recording (using
-     * threadRecordFailure) any AssertionFailedError thrown, so that
-     * the current testcase will fail.
+     * threadRecordFailure) any AssertionError thrown, so that the
+     * current testcase will fail.
      */
     public void threadAssertTrue(boolean b) {
         try {
             assertTrue(b);
-        } catch (AssertionFailedError t) {
-            threadRecordFailure(t);
-            throw t;
+        } catch (AssertionError fail) {
+            threadRecordFailure(fail);
+            throw fail;
         }
     }
 
     /**
      * Just like assertFalse(b), but additionally recording (using
-     * threadRecordFailure) any AssertionFailedError thrown, so that
-     * the current testcase will fail.
+     * threadRecordFailure) any AssertionError thrown, so that the
+     * current testcase will fail.
      */
     public void threadAssertFalse(boolean b) {
         try {
             assertFalse(b);
-        } catch (AssertionFailedError t) {
-            threadRecordFailure(t);
-            throw t;
+        } catch (AssertionError fail) {
+            threadRecordFailure(fail);
+            throw fail;
         }
     }
 
     /**
      * Just like assertNull(x), but additionally recording (using
-     * threadRecordFailure) any AssertionFailedError thrown, so that
-     * the current testcase will fail.
+     * threadRecordFailure) any AssertionError thrown, so that the
+     * current testcase will fail.
      */
     public void threadAssertNull(Object x) {
         try {
             assertNull(x);
-        } catch (AssertionFailedError t) {
-            threadRecordFailure(t);
-            throw t;
+        } catch (AssertionError fail) {
+            threadRecordFailure(fail);
+            throw fail;
         }
     }
 
     /**
      * Just like assertEquals(x, y), but additionally recording (using
-     * threadRecordFailure) any AssertionFailedError thrown, so that
-     * the current testcase will fail.
+     * threadRecordFailure) any AssertionError thrown, so that the
+     * current testcase will fail.
      */
     public void threadAssertEquals(long x, long y) {
         try {
             assertEquals(x, y);
-        } catch (AssertionFailedError t) {
-            threadRecordFailure(t);
-            throw t;
+        } catch (AssertionError fail) {
+            threadRecordFailure(fail);
+            throw fail;
         }
     }
 
     /**
      * Just like assertEquals(x, y), but additionally recording (using
-     * threadRecordFailure) any AssertionFailedError thrown, so that
-     * the current testcase will fail.
+     * threadRecordFailure) any AssertionError thrown, so that the
+     * current testcase will fail.
      */
     public void threadAssertEquals(Object x, Object y) {
         try {
             assertEquals(x, y);
-        } catch (AssertionFailedError fail) {
+        } catch (AssertionError fail) {
             threadRecordFailure(fail);
             throw fail;
         } catch (Throwable fail) {
@@ -906,13 +900,13 @@
 
     /**
      * Just like assertSame(x, y), but additionally recording (using
-     * threadRecordFailure) any AssertionFailedError thrown, so that
-     * the current testcase will fail.
+     * threadRecordFailure) any AssertionError thrown, so that the
+     * current testcase will fail.
      */
     public void threadAssertSame(Object x, Object y) {
         try {
             assertSame(x, y);
-        } catch (AssertionFailedError fail) {
+        } catch (AssertionError fail) {
             threadRecordFailure(fail);
             throw fail;
         }
@@ -934,8 +928,8 @@
 
     /**
      * Records the given exception using {@link #threadRecordFailure},
-     * then rethrows the exception, wrapping it in an
-     * AssertionFailedError if necessary.
+     * then rethrows the exception, wrapping it in an AssertionError
+     * if necessary.
      */
     public void threadUnexpectedException(Throwable t) {
         threadRecordFailure(t);
@@ -944,12 +938,8 @@
             throw (RuntimeException) t;
         else if (t instanceof Error)
             throw (Error) t;
-        else {
-            AssertionFailedError afe =
-                new AssertionFailedError("unexpected exception: " + t);
-            afe.initCause(t);
-            throw afe;
-        }
+        else
+            throw new AssertionError("unexpected exception: " + t, t);
     }
 
     /**
@@ -1125,7 +1115,7 @@
         for (long retries = LONG_DELAY_MS * 3 / 4; retries-->0; ) {
             try { delay(1); }
             catch (InterruptedException fail) {
-                fail("Unexpected InterruptedException");
+                throw new AssertionError("Unexpected InterruptedException", fail);
             }
             Thread.State s = thread.getState();
             if (s == expected)
@@ -1311,16 +1301,13 @@
 
     /**
      * Sleeps until the given time has elapsed.
-     * Throws AssertionFailedError if interrupted.
+     * Throws AssertionError if interrupted.
      */
     static void sleep(long millis) {
         try {
             delay(millis);
         } catch (InterruptedException fail) {
-            AssertionFailedError afe =
-                new AssertionFailedError("Unexpected InterruptedException");
-            afe.initCause(fail);
-            throw afe;
+            throw new AssertionError("Unexpected InterruptedException", fail);
         }
     }
 
@@ -1411,7 +1398,7 @@
 //             r.run();
 //         } catch (Throwable fail) { threadUnexpectedException(fail); }
 //         if (millisElapsedSince(startTime) > timeoutMillis/2)
-//             throw new AssertionFailedError("did not return promptly");
+//             throw new AssertionError("did not return promptly");
 //     }
 
 //     void assertTerminatesPromptly(Runnable r) {
@@ -1428,7 +1415,7 @@
             assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS));
         } catch (Throwable fail) { threadUnexpectedException(fail); }
         if (millisElapsedSince(startTime) > timeoutMillis/2)
-            throw new AssertionFailedError("timed get did not return promptly");
+            throw new AssertionError("timed get did not return promptly");
     }
 
     <T> void checkTimedGet(Future<T> f, T expectedValue) {
@@ -1670,7 +1657,7 @@
 //         long startTime = System.nanoTime();
 //         while (!flag.get()) {
 //             if (millisElapsedSince(startTime) > timeoutMillis)
-//                 throw new AssertionFailedError("timed out");
+//                 throw new AssertionError("timed out");
 //             Thread.yield();
 //         }
 //     }
@@ -1757,7 +1744,7 @@
 
     /**
      * A CyclicBarrier that uses timed await and fails with
-     * AssertionFailedErrors instead of throwing checked exceptions.
+     * AssertionErrors instead of throwing checked exceptions.
      */
     public static class CheckedBarrier extends CyclicBarrier {
         public CheckedBarrier(int parties) { super(parties); }
@@ -1766,12 +1753,9 @@
             try {
                 return super.await(2 * LONG_DELAY_MS, MILLISECONDS);
             } catch (TimeoutException timedOut) {
-                throw new AssertionFailedError("timed out");
+                throw new AssertionError("timed out");
             } catch (Exception fail) {
-                AssertionFailedError afe =
-                    new AssertionFailedError("Unexpected exception: " + fail);
-                afe.initCause(fail);
-                throw afe;
+                throw new AssertionError("Unexpected exception: " + fail, fail);
             }
         }
     }
@@ -1894,14 +1878,11 @@
             try { throwingAction.run(); }
             catch (Throwable t) {
                 threw = true;
-                if (!expectedExceptionClass.isInstance(t)) {
-                    AssertionFailedError afe =
-                        new AssertionFailedError
-                        ("Expected " + expectedExceptionClass.getName() +
-                         ", got " + t.getClass().getName());
-                    afe.initCause(t);
-                    threadUnexpectedException(afe);
-                }
+                if (!expectedExceptionClass.isInstance(t))
+                    throw new AssertionError(
+                            "Expected " + expectedExceptionClass.getName() +
+                            ", got " + t.getClass().getName(),
+                            t);
             }
             if (!threw)
                 shouldThrow(expectedExceptionClass.getName());
--- a/test/jdk/java/util/concurrent/tck/LongAdderTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/LongAdderTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -69,7 +69,7 @@
     /**
      * decrement decrements and sum returns current value
      */
-    public void testDecrementAndsum() {
+    public void testDecrementAndSum() {
         LongAdder ai = new LongAdder();
         ai.decrement();
         assertEquals(-1, ai.sum());
@@ -80,7 +80,7 @@
     /**
      * incrementAndGet increments and returns current value
      */
-    public void testIncrementAndsum() {
+    public void testIncrementAndSum() {
         LongAdder ai = new LongAdder();
         ai.increment();
         assertEquals(1, ai.sum());
--- a/test/jdk/java/util/concurrent/tck/ReentrantLockTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/ReentrantLockTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -45,7 +45,6 @@
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 
-import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -115,7 +114,7 @@
         long startTime = System.nanoTime();
         while (!lock.hasQueuedThread(t)) {
             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
-                throw new AssertionFailedError("timed out");
+                throw new AssertionError("timed out");
             Thread.yield();
         }
         assertTrue(t.isAlive());
--- a/test/jdk/java/util/concurrent/tck/ReentrantReadWriteLockTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/ReentrantReadWriteLockTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -44,7 +44,6 @@
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -115,7 +114,7 @@
         long startTime = System.nanoTime();
         while (!lock.hasQueuedThread(t)) {
             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
-                throw new AssertionFailedError("timed out");
+                throw new AssertionError("timed out");
             Thread.yield();
         }
         assertTrue(t.isAlive());
--- a/test/jdk/java/util/concurrent/tck/SemaphoreTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/SemaphoreTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -40,7 +40,6 @@
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.ThreadLocalRandom;
 
-import junit.framework.AssertionFailedError;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -101,7 +100,7 @@
         long startTime = System.nanoTime();
         while (!s.hasQueuedThread(t)) {
             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
-                throw new AssertionFailedError("timed out");
+                throw new AssertionError("timed out");
             Thread.yield();
         }
         assertTrue(s.hasQueuedThreads());
@@ -115,7 +114,7 @@
         long startTime = System.nanoTime();
         while (!s.hasQueuedThreads()) {
             if (millisElapsedSince(startTime) > LONG_DELAY_MS)
-                throw new AssertionFailedError("timed out");
+                throw new AssertionError("timed out");
             Thread.yield();
         }
     }
--- a/test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java	Sat Feb 10 09:17:53 2018 -0800
+++ b/test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java	Sat Feb 10 09:23:41 2018 -0800
@@ -90,8 +90,7 @@
         ThreadLocalRandom rnd = ThreadLocalRandom.current();
         final java.lang.reflect.Method m;
         try {
-            m = ThreadLocalRandom.class.getDeclaredMethod(
-                    "next", new Class[] { int.class });
+            m = ThreadLocalRandom.class.getDeclaredMethod("next", int.class);
             m.setAccessible(true);
         } catch (SecurityException acceptable) {
             // Security manager may deny access