8150523: improve jtreg test timeout handling, especially -timeout:
authordl
Thu, 03 Mar 2016 10:43:07 -0800
changeset 36233 f85ed703cf7e
parent 36232 7a020ad42ac0
child 36234 df992fe1472b
8150523: improve jtreg test timeout handling, especially -timeout: Reviewed-by: martin, psandoz, smarks
jdk/test/java/util/concurrent/BlockingQueue/CancelledProducerConsumerLoops.java
jdk/test/java/util/concurrent/BlockingQueue/Interrupt.java
jdk/test/java/util/concurrent/BlockingQueue/MultipleProducersSingleConsumerLoops.java
jdk/test/java/util/concurrent/BlockingQueue/ProducerConsumerLoops.java
jdk/test/java/util/concurrent/BlockingQueue/SingleProducerMultipleConsumerLoops.java
jdk/test/java/util/concurrent/CompletableFuture/Basic.java
jdk/test/java/util/concurrent/ConcurrentHashMap/MapLoops.java
jdk/test/java/util/concurrent/ConcurrentQueues/ConcurrentQueueLoops.java
jdk/test/java/util/concurrent/ConcurrentQueues/GCRetention.java
jdk/test/java/util/concurrent/CyclicBarrier/Basic.java
jdk/test/java/util/concurrent/DelayQueue/Stress.java
jdk/test/java/util/concurrent/Exchanger/ExchangeLoops.java
jdk/test/java/util/concurrent/ExecutorCompletionService/ExecutorCompletionServiceLoops.java
jdk/test/java/util/concurrent/Executors/AutoShutdown.java
jdk/test/java/util/concurrent/FutureTask/CancelledFutureLoops.java
jdk/test/java/util/concurrent/FutureTask/DoneMeansDone.java
jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/DelayOverflow.java
jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/GCRetention.java
jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/ZeroCorePoolSize.java
jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/ZeroCoreThreads.java
jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java
jdk/test/java/util/concurrent/ThreadPoolExecutor/Custom.java
jdk/test/java/util/concurrent/ThreadPoolExecutor/FlakyThreadFactory.java
jdk/test/java/util/concurrent/ThreadPoolExecutor/SelfInterrupt.java
jdk/test/java/util/concurrent/ThreadPoolExecutor/ThreadRestarts.java
jdk/test/java/util/concurrent/ThreadPoolExecutor/TimeOutShrink.java
jdk/test/java/util/concurrent/locks/Lock/CheckedLockLoops.java
jdk/test/java/util/concurrent/locks/Lock/FlakyMutex.java
jdk/test/java/util/concurrent/locks/Lock/TimedAcquireLeak.java
jdk/test/java/util/concurrent/locks/LockSupport/ParkLoops.java
jdk/test/java/util/concurrent/locks/ReentrantLock/LockOncePerThreadLoops.java
jdk/test/java/util/concurrent/locks/ReentrantLock/SimpleReentrantLockLoops.java
jdk/test/java/util/concurrent/locks/ReentrantLock/TimeoutLockLoops.java
jdk/test/java/util/concurrent/locks/ReentrantReadWriteLock/Count.java
jdk/test/java/util/concurrent/locks/ReentrantReadWriteLock/MapLoops.java
jdk/test/java/util/concurrent/locks/StampedLock/Basic.java
--- a/jdk/test/java/util/concurrent/BlockingQueue/CancelledProducerConsumerLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/BlockingQueue/CancelledProducerConsumerLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,8 +35,11 @@
  * @test
  * @bug 4486658
  * @summary Checks for responsiveness of blocking queues to cancellation.
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.SplittableRandom;
@@ -53,8 +56,10 @@
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.TimeUnit;
+import jdk.testlibrary.Utils;
 
 public class CancelledProducerConsumerLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static ExecutorService pool;
 
     public static void main(String[] args) throws Exception {
@@ -73,7 +78,7 @@
                 new CancelledProducerConsumerLoops(i, queue).run();
         }
         pool.shutdown();
-        if (! pool.awaitTermination(10L, TimeUnit.SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new AssertionError("timed out");
         pool = null;
     }
@@ -117,18 +122,18 @@
             assertCancelled(cons[i]);
         }
 
-        if (!producersInterrupted.await(10L, TimeUnit.SECONDS))
+        if (!producersInterrupted.await(LONG_DELAY_MS, MILLISECONDS))
             throw new AssertionError("timed out");
-        if (!consumersInterrupted.await(10L, TimeUnit.SECONDS))
+        if (!consumersInterrupted.await(LONG_DELAY_MS, MILLISECONDS))
             throw new AssertionError("timed out");
         if (prods[0].isDone() || prods[0].isCancelled())
             throw new AssertionError("completed too early");
 
         done = true;
 
-        if (! (prods[0].get(10L, TimeUnit.SECONDS) instanceof Integer))
+        if (! (prods[0].get(LONG_DELAY_MS, MILLISECONDS) instanceof Integer))
             throw new AssertionError("expected Integer");
-        if (! (cons[0].get(10L, TimeUnit.SECONDS) instanceof Integer))
+        if (! (cons[0].get(LONG_DELAY_MS, MILLISECONDS) instanceof Integer))
             throw new AssertionError("expected Integer");
     }
 
@@ -138,7 +143,7 @@
         if (!future.isCancelled())
             throw new AssertionError("not cancelled");
         try {
-            future.get(10L, TimeUnit.SECONDS);
+            future.get(LONG_DELAY_MS, MILLISECONDS);
             throw new AssertionError("should throw CancellationException");
         } catch (CancellationException success) {}
     }
--- a/jdk/test/java/util/concurrent/BlockingQueue/Interrupt.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/BlockingQueue/Interrupt.java	Thu Mar 03 10:43:07 2016 -0800
@@ -26,10 +26,10 @@
  * @bug 6384064
  * @summary Check proper handling of interrupts
  * @author Martin Buchholz
+ * @library /lib/testlibrary/
  */
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -41,8 +41,10 @@
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
+import jdk.testlibrary.Utils;
 
 public class Interrupt {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
 
     static void checkInterrupted0(Iterable<Fun> fs, Executor ex) {
         for (Fun f : fs) {
@@ -71,7 +73,7 @@
         checkInterrupted0(fs, immediateExecutor);
         checkInterrupted0(fs, delayedExecutor);
         stpe.shutdown();
-        check(stpe.awaitTermination(10L, SECONDS));
+        check(stpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
     }
 
     static void testQueue(final BlockingQueue<Object> q) {
@@ -82,12 +84,12 @@
             q.clear();
             List<Fun> fs = new ArrayList<Fun>();
             fs.add(() -> q.take());
-            fs.add(() -> q.poll(60, SECONDS));
+            fs.add(() -> q.poll(LONG_DELAY_MS, MILLISECONDS));
             if (deq != null) {
                 fs.add(() -> deq.takeFirst());
                 fs.add(() -> deq.takeLast());
-                fs.add(() -> deq.pollFirst(7, SECONDS));
-                fs.add(() -> deq.pollLast(7, SECONDS));
+                fs.add(() -> deq.pollFirst(LONG_DELAY_MS, MILLISECONDS));
+                fs.add(() -> deq.pollLast(LONG_DELAY_MS, MILLISECONDS));
             }
 
             checkInterrupted(fs);
@@ -99,12 +101,12 @@
 
             fs.clear();
             fs.add(() -> q.put(1));
-            fs.add(() -> q.offer(1, 7, SECONDS));
+            fs.add(() -> q.offer(1, LONG_DELAY_MS, MILLISECONDS));
             if (deq != null) {
                 fs.add(() -> deq.putFirst(1));
                 fs.add(() -> deq.putLast(1));
-                fs.add(() -> deq.offerFirst(1, 7, SECONDS));
-                fs.add(() -> deq.offerLast(1, 7, SECONDS));
+                fs.add(() -> deq.offerFirst(1, LONG_DELAY_MS, MILLISECONDS));
+                fs.add(() -> deq.offerLast(1, LONG_DELAY_MS, MILLISECONDS));
             }
             checkInterrupted(fs);
         } catch (Throwable t) {
--- a/jdk/test/java/util/concurrent/BlockingQueue/MultipleProducersSingleConsumerLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/BlockingQueue/MultipleProducersSingleConsumerLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,10 +35,11 @@
  * @test
  * @bug 4486658
  * @summary  multiple producers and single consumer using blocking queues
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
@@ -51,8 +52,10 @@
 import java.util.concurrent.PriorityBlockingQueue;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.atomic.AtomicInteger;
+import jdk.testlibrary.Utils;
 
 public class MultipleProducersSingleConsumerLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static ExecutorService pool;
 
     public static void main(String[] args) throws Exception {
@@ -77,7 +80,7 @@
         }
 
         pool.shutdown();
-        if (! pool.awaitTermination(10L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
         pool = null;
     }
--- a/jdk/test/java/util/concurrent/BlockingQueue/ProducerConsumerLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/BlockingQueue/ProducerConsumerLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,10 +35,11 @@
  * @test
  * @bug 4486658
  * @summary  multiple producers and consumers using blocking queues
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
@@ -51,8 +52,10 @@
 import java.util.concurrent.PriorityBlockingQueue;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.atomic.AtomicInteger;
+import jdk.testlibrary.Utils;
 
 public class ProducerConsumerLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static ExecutorService pool;
 
     public static void main(String[] args) throws Exception {
@@ -77,7 +80,7 @@
             run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
         pool = null;
    }
--- a/jdk/test/java/util/concurrent/BlockingQueue/SingleProducerMultipleConsumerLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/BlockingQueue/SingleProducerMultipleConsumerLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,10 +35,11 @@
  * @test
  * @bug 4486658
  * @summary  check ordering for blocking queues with 1 producer and multiple consumers
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
@@ -50,8 +51,10 @@
 import java.util.concurrent.LinkedTransferQueue;
 import java.util.concurrent.PriorityBlockingQueue;
 import java.util.concurrent.SynchronousQueue;
+import jdk.testlibrary.Utils;
 
 public class SingleProducerMultipleConsumerLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static ExecutorService pool;
 
     public static void main(String[] args) throws Exception {
@@ -75,7 +78,7 @@
             run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
         pool = null;
    }
--- a/jdk/test/java/util/concurrent/CompletableFuture/Basic.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/CompletableFuture/Basic.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,15 +34,17 @@
 /*
  * @test
  * @bug 8005696
+ * @summary Basic tests for CompletableFuture
+ * @library /lib/testlibrary/
  * @run main Basic
  * @run main/othervm -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 Basic
- * @summary Basic tests for CompletableFuture
  * @author Chris Hegarty
  */
 
 import static java.util.concurrent.CompletableFuture.runAsync;
 import static java.util.concurrent.CompletableFuture.supplyAsync;
 import static java.util.concurrent.ForkJoinPool.commonPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.lang.reflect.Array;
@@ -54,8 +56,10 @@
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicInteger;
+import jdk.testlibrary.Utils;
 
 public class Basic {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
 
     static void checkCompletedNormally(CompletableFuture<?> cf, Object value) {
         checkCompletedNormally(cf, value == null ? null : new Object[] { value });
@@ -109,12 +113,13 @@
     }
 
     private static void realMain(String[] args) throws Throwable {
-        ExecutorService executor = Executors.newFixedThreadPool(2);
+        ExecutorService pool = Executors.newFixedThreadPool(2);
         try {
-            test(executor);
+            test(pool);
         } finally {
-            executor.shutdown();
-            executor.awaitTermination(30L, SECONDS);
+            pool.shutdown();
+            if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
+                throw new Error();
         }
     }
 
--- a/jdk/test/java/util/concurrent/ConcurrentHashMap/MapLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ConcurrentHashMap/MapLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,7 +34,6 @@
 /*
  * @test
  * @bug 4486658
- * @run main/timeout=1600 MapLoops
  * @summary Exercise multithreaded maps, by default ConcurrentHashMap.
  * Multithreaded hash table test.  Each thread does a random walk
  * though elements of "key" array. On each iteration, it checks if
@@ -42,9 +41,11 @@
  * inserts it, and if present, with probability premove it removes
  * it.  (pinsert and premove are expressed as percentages to simplify
  * parsing from command line.)
+ * @library /lib/testlibrary/
+ * @run main/timeout=1600 MapLoops
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.List;
 import java.util.Map;
@@ -53,8 +54,10 @@
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import jdk.testlibrary.Utils;
 
 public class MapLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static int nkeys       = 1000; // 10_000
     static int pinsert     = 60;
     static int premove     = 2;
@@ -126,7 +129,7 @@
                 i = k;
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
 
         if (! throwables.isEmpty())
--- a/jdk/test/java/util/concurrent/ConcurrentQueues/ConcurrentQueueLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ConcurrentQueues/ConcurrentQueueLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,11 +34,12 @@
 /*
  * @test
  * @bug 4486658 6785442
+ * @summary Checks that a set of threads can repeatedly get and modify items
+ * @library /lib/testlibrary/
  * @run main ConcurrentQueueLoops 8 123456
- * @summary Checks that a set of threads can repeatedly get and modify items
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -57,8 +58,10 @@
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.LinkedTransferQueue;
 import java.util.concurrent.atomic.AtomicInteger;
+import jdk.testlibrary.Utils;
 
 public class ConcurrentQueueLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     ExecutorService pool;
     AtomicInteger totalItems;
     boolean print;
@@ -106,16 +109,14 @@
         print = false;
         System.out.println("Warmup...");
         oneRun(1, items, q);
-        //Thread.sleep(100);
         oneRun(3, items, q);
-        Thread.sleep(100);
         print = true;
 
         for (int i = 1; i <= maxStages; i += (i+1) >>> 1) {
             oneRun(i, items, q);
         }
         pool.shutdown();
-        check(pool.awaitTermination(60L, SECONDS));
+        check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
    }
 
     class Stage implements Callable<Integer> {
--- a/jdk/test/java/util/concurrent/ConcurrentQueues/GCRetention.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ConcurrentQueues/GCRetention.java	Thu Mar 03 10:43:07 2016 -0800
@@ -38,10 +38,14 @@
  * @run main GCRetention 12345
  */
 
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+import java.lang.ref.WeakReference;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.LinkedTransferQueue;
@@ -59,6 +63,25 @@
     // Suitable for benchmarking.  Overridden by args[0] for testing.
     int count = 1024 * 1024;
 
+    /** No guarantees, but effective in practice. */
+    static void forceFullGc() {
+        CountDownLatch finalizeDone = new CountDownLatch(1);
+        WeakReference<?> ref = new WeakReference<Object>(new Object() {
+            protected void finalize() { finalizeDone.countDown(); }});
+        try {
+            for (int i = 0; i < 10; i++) {
+                System.gc();
+                if (finalizeDone.await(1L, SECONDS) && ref.get() == null) {
+                    System.runFinalization(); // try to pick up stragglers
+                    return;
+                }
+            }
+        } catch (InterruptedException unexpected) {
+            throw new AssertionError("unexpected InterruptedException");
+        }
+        throw new AssertionError("failed to do a \"full\" gc");
+    }
+
     final Map<String,String> results = new ConcurrentHashMap<String,String>();
 
     Collection<Queue<Boolean>> queues() {
@@ -117,8 +140,8 @@
         long t0 = System.nanoTime();
         for (int i = 0; i < count; i++)
             check(q.add(Boolean.TRUE));
-        System.gc();
-        System.gc();
+        forceFullGc();
+        // forceFullGc();
         Boolean x;
         while ((x = q.poll()) != null)
             equal(x, Boolean.TRUE);
--- a/jdk/test/java/util/concurrent/CyclicBarrier/Basic.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/CyclicBarrier/Basic.java	Thu Mar 03 10:43:07 2016 -0800
@@ -25,11 +25,11 @@
  * @test
  * @bug 6253848 6366811
  * @summary Basic tests for CyclicBarrier
+ * @library /lib/testlibrary/
  * @author Martin Buchholz, David Holmes
  */
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -39,8 +39,10 @@
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicInteger;
+import jdk.testlibrary.Utils;
 
 public class Basic {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
 
     private static void checkBroken(final CyclicBarrier barrier) {
         check(barrier.isBroken());
@@ -77,7 +79,7 @@
     private static final CyclicBarrier atTheStartingGate = new CyclicBarrier(3);
 
     private static void toTheStartingGate() {
-        try { atTheStartingGate.await(10, SECONDS); pass(); }
+        try { atTheStartingGate.await(LONG_DELAY_MS, MILLISECONDS); pass(); }
         catch (Throwable t) {
             unexpected(t);
             reset(atTheStartingGate);
@@ -314,13 +316,13 @@
             Throwable throwable() { return this.throwable; }
             boolean interruptBit() { return this.interrupted; }
             void realRun() throws Throwable {
-                startingGate.await(10, SECONDS);
+                startingGate.await(LONG_DELAY_MS, MILLISECONDS);
                 try {
-                    if (timed) barrier.await(10, SECONDS);
+                    if (timed) barrier.await(LONG_DELAY_MS, MILLISECONDS);
                     else barrier.await(); }
                 catch (Throwable throwable) { this.throwable = throwable; }
 
-                try { doneSignal.await(10, SECONDS); }
+                try { doneSignal.await(LONG_DELAY_MS, MILLISECONDS); }
                 catch (InterruptedException e) { interrupted = true; }
             }
         }
@@ -354,7 +356,7 @@
                 waiter.start();
                 waiters.add(waiter);
             }
-            startingGate.await(10, SECONDS);
+            startingGate.await(LONG_DELAY_MS, MILLISECONDS);
             while (barrier.getNumberWaiting() < N) Thread.yield();
             barrier.await();
             doneSignal.countDown();
@@ -383,7 +385,7 @@
                 waiter.start();
                 waiters.add(waiter);
             }
-            startingGate.await(10, SECONDS);
+            startingGate.await(LONG_DELAY_MS, MILLISECONDS);
             while (barrier.getNumberWaiting() < N) Thread.yield();
             for (int i = 0; i < N/2; i++)
                 waiters.get(i).interrupt();
--- a/jdk/test/java/util/concurrent/DelayQueue/Stress.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/DelayQueue/Stress.java	Thu Mar 03 10:43:07 2016 -0800
@@ -26,6 +26,7 @@
 
 import java.util.concurrent.DelayQueue;
 import java.util.concurrent.Delayed;
+import java.util.concurrent.TimeUnit;
 
 /**
  * This is not a regression test, but a stress benchmark test for
--- a/jdk/test/java/util/concurrent/Exchanger/ExchangeLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/Exchanger/ExchangeLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,18 +34,20 @@
 /*
  * @test
  * @bug 4486658
- * @run main/timeout=720 ExchangeLoops
  * @summary checks to make sure a pipeline of exchangers passes data.
+ * @library /lib/testlibrary/
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.Exchanger;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import jdk.testlibrary.Utils;
 
 public class ExchangeLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static final ExecutorService pool = Executors.newCachedThreadPool();
     static boolean print = false;
 
@@ -56,14 +58,14 @@
 
     public static void main(String[] args) throws Exception {
         int maxStages = 5;
-        int iters = 10000;
+        int iters = 2000;
 
         if (args.length > 0)
             maxStages = Integer.parseInt(args[0]);
 
         print = false;
         System.out.println("Warmup...");
-        oneRun(2, 100000);
+        oneRun(2, iters);
         print = true;
 
         for (int i = 2; i <= maxStages; i += (i+1) >>> 1) {
@@ -71,7 +73,7 @@
             oneRun(i, iters);
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
    }
 
--- a/jdk/test/java/util/concurrent/ExecutorCompletionService/ExecutorCompletionServiceLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ExecutorCompletionService/ExecutorCompletionServiceLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,19 +34,21 @@
 /*
  * @test
  * @bug 4965960
- * @run main/timeout=3600 ExecutorCompletionServiceLoops
- * @summary  Exercise ExecutorCompletionServiceLoops
+ * @summary  Exercise ExecutorCompletionService
+ * @library /lib/testlibrary/
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorCompletionService;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import jdk.testlibrary.Utils;
 
 public class ExecutorCompletionServiceLoops {
-    static final int POOLSIZE = 100;
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+    static final int POOLSIZE = 10;
     static final ExecutorService pool =
         Executors.newFixedThreadPool(POOLSIZE);
     static final ExecutorCompletionService<Integer> ecs =
@@ -55,23 +57,21 @@
 
     public static void main(String[] args) throws Exception {
         int max = 8;
-        int base = 10000;
+        int base = 2000;
 
         if (args.length > 0)
             max = Integer.parseInt(args[0]);
 
         System.out.println("Warmup...");
         oneTest(base);
-        Thread.sleep(100);
         print = true;
 
         for (int i = 1; i <= max; i += (i+1) >>> 1) {
             System.out.print("n: " + i * base);
             oneTest(i * base);
-            Thread.sleep(100);
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
    }
 
--- a/jdk/test/java/util/concurrent/Executors/AutoShutdown.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/Executors/AutoShutdown.java	Thu Mar 03 10:43:07 2016 -0800
@@ -24,26 +24,32 @@
 /*
  * @test
  * @bug 6399443
+ * @summary Check for auto-shutdown and gc of singleThreadExecutors
+ * @library /lib/testlibrary/
  * @run main/othervm/timeout=1000 AutoShutdown
- * @summary Check for auto-shutdown and gc of singleThreadExecutors
  * @author Martin Buchholz
  */
 
+import static java.util.concurrent.Executors.defaultThreadFactory;
+import static java.util.concurrent.Executors.newFixedThreadPool;
+import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
+import static java.util.concurrent.Executors.newSingleThreadExecutor;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.lang.ref.WeakReference;
 import java.util.Arrays;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executor;
 import java.util.concurrent.TimeUnit;
-import static java.util.concurrent.Executors.defaultThreadFactory;
-import static java.util.concurrent.Executors.newFixedThreadPool;
-import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
-import static java.util.concurrent.Executors.newSingleThreadExecutor;
+import jdk.testlibrary.Utils;
 
 public class AutoShutdown {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
 
     static void await(CountDownLatch latch) throws InterruptedException {
-        if (!latch.await(100L, TimeUnit.SECONDS))
+        if (!latch.await(LONG_DELAY_MS, MILLISECONDS))
             throw new AssertionError("timed out waiting for latch");
     }
 
--- a/jdk/test/java/util/concurrent/FutureTask/CancelledFutureLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/FutureTask/CancelledFutureLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,13 +34,14 @@
 /*
  * @test
  * @bug 4486658
- * @run main/timeout=2000 CancelledFutureLoops
  * @summary Checks for responsiveness of futures to cancellation.
  * Runs under the assumption that ITERS computations require more than
  * TIMEOUT msecs to complete.
+ * @library /lib/testlibrary/
+ * @run main/timeout=2000 CancelledFutureLoops
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.SplittableRandom;
 import java.util.concurrent.BrokenBarrierException;
@@ -51,8 +52,10 @@
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.locks.ReentrantLock;
+import jdk.testlibrary.Utils;
 
 public final class CancelledFutureLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static final ExecutorService pool = Executors.newCachedThreadPool();
     static final SplittableRandom rnd = new SplittableRandom();
     static boolean print = false;
@@ -80,7 +83,7 @@
             Thread.sleep(TIMEOUT);
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, SECONDS))
+        if (! pool.awaitTermination(6 * LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
     }
 
--- a/jdk/test/java/util/concurrent/FutureTask/DoneMeansDone.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/FutureTask/DoneMeansDone.java	Thu Mar 03 10:43:07 2016 -0800
@@ -36,8 +36,11 @@
  * @bug 8073704
  * @summary Checks that once isDone() returns true,
  * get() never throws InterruptedException or TimeoutException
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.ArrayList;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
@@ -49,8 +52,11 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
+import jdk.testlibrary.Utils;
 
 public class DoneMeansDone {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+
     public static void main(String[] args) throws Throwable {
         final int iters = 1000;
         final int nThreads = 2;
@@ -92,7 +98,7 @@
         }
         done.set(true);
         pool.shutdown();
-        if (!pool.awaitTermination(10L, TimeUnit.SECONDS))
+        if (!pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new AssertionError();
         for (Future<?> future : futures)
             future.get();
--- a/jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/DelayOverflow.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/DelayOverflow.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,14 +35,21 @@
  * @test
  * @bug 6725789
  * @summary Check for long overflow in task time comparison.
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.DAYS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
+import jdk.testlibrary.Utils;
 
 public class DelayOverflow {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+
     static void waitForNanoTimeTick() {
         for (long t0 = System.nanoTime(); t0 == System.nanoTime(); )
             ;
@@ -52,16 +59,16 @@
                      Runnable r, int how) {
         switch (how) {
         case 0:
-            pool.schedule(r, 0, TimeUnit.MILLISECONDS);
+            pool.schedule(r, 0, MILLISECONDS);
             break;
         case 1:
-            pool.schedule(Executors.callable(r), 0, TimeUnit.DAYS);
+            pool.schedule(Executors.callable(r), 0, DAYS);
             break;
         case 2:
-            pool.scheduleWithFixedDelay(r, 0, 1000, TimeUnit.NANOSECONDS);
+            pool.scheduleWithFixedDelay(r, 0, 1000, NANOSECONDS);
             break;
         case 3:
-            pool.scheduleAtFixedRate(r, 0, 1000, TimeUnit.MILLISECONDS);
+            pool.scheduleAtFixedRate(r, 0, 1000, MILLISECONDS);
             break;
         default:
             fail(String.valueOf(how));
@@ -72,16 +79,16 @@
                                 Runnable r, int how) {
         switch (how) {
         case 0:
-            pool.schedule(r, Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+            pool.schedule(r, Long.MAX_VALUE, MILLISECONDS);
             break;
         case 1:
-            pool.schedule(Executors.callable(r), Long.MAX_VALUE, TimeUnit.DAYS);
+            pool.schedule(Executors.callable(r), Long.MAX_VALUE, DAYS);
             break;
         case 2:
-            pool.scheduleWithFixedDelay(r, Long.MAX_VALUE, 1000, TimeUnit.NANOSECONDS);
+            pool.scheduleWithFixedDelay(r, Long.MAX_VALUE, 1000, NANOSECONDS);
             break;
         case 3:
-            pool.scheduleAtFixedRate(r, Long.MAX_VALUE, 1000, TimeUnit.MILLISECONDS);
+            pool.scheduleAtFixedRate(r, Long.MAX_VALUE, 1000, MILLISECONDS);
             break;
         default:
             fail(String.valueOf(how));
@@ -114,14 +121,14 @@
                                 proceedLatch.await();
                             } catch (Throwable t) { unexpected(t); }
                         }};
-                pool.schedule(keepPoolBusy, 0, TimeUnit.SECONDS);
+                pool.schedule(keepPoolBusy, 0, DAYS);
                 busyLatch.await();
                 scheduleNow(pool, notifier, nowHow);
                 waitForNanoTimeTick();
                 scheduleAtTheEndOfTime(pool, neverRuns, thenHow);
                 proceedLatch.countDown();
 
-                check(runLatch.await(10L, TimeUnit.SECONDS));
+                check(runLatch.await(LONG_DELAY_MS, MILLISECONDS));
                 equal(runLatch.getCount(), 0L);
 
                 pool.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
@@ -142,10 +149,9 @@
                         } catch (Throwable t) { unexpected(t); }
                     }};
             pool.scheduleWithFixedDelay(scheduleNowScheduler,
-                                        0, Long.MAX_VALUE,
-                                        TimeUnit.NANOSECONDS);
+                                        0, Long.MAX_VALUE, NANOSECONDS);
 
-            check(runLatch.await(10L, TimeUnit.SECONDS));
+            check(runLatch.await(LONG_DELAY_MS, MILLISECONDS));
             equal(runLatch.getCount(), 0L);
 
             pool.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
--- a/jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/GCRetention.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/GCRetention.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,8 +34,11 @@
 /*
  * @test
  * @summary Ensure that waiting pool threads don't retain refs to tasks.
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.lang.ref.WeakReference;
 import java.util.concurrent.Delayed;
 import java.util.concurrent.ExecutionException;
@@ -44,8 +47,11 @@
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import jdk.testlibrary.Utils;
 
 public class GCRetention {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+
     /**
      * A custom thread pool with a custom RunnableScheduledFuture, for the
      * sole purpose of ensuring that the task retains a strong reference to
@@ -116,7 +122,7 @@
             Thread.sleep(10);
         }
         pool.shutdown();
-        pool.awaitTermination(10L, TimeUnit.SECONDS);
+        pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS);
         if (cleared < size)
             throw new Error(String.format
                             ("references to %d/%d tasks retained (\"leaked\")",
--- a/jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/ZeroCorePoolSize.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/ZeroCorePoolSize.java	Thu Mar 03 10:43:07 2016 -0800
@@ -26,16 +26,21 @@
  * @bug 7091003
  * @summary ScheduledExecutorService never executes Runnable
  *          with corePoolSize of zero
+ * @library /lib/testlibrary/
  * @author Chris Hegarty
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import jdk.testlibrary.Utils;
 
 /**
  * Verify that tasks can be run even with a core pool size of 0.
  */
 public class ZeroCorePoolSize {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
 
     volatile boolean taskRun;
 
@@ -49,10 +54,10 @@
         };
         check(pool.getCorePoolSize() == 0);
 
-        pool.schedule(task, 1, TimeUnit.SECONDS);
+        pool.schedule(task, 12L, MILLISECONDS);
 
         pool.shutdown();
-        check(pool.awaitTermination(20L, TimeUnit.SECONDS));
+        check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
         check(pool.getCorePoolSize() == 0);
         check(taskRun);
     }
--- a/jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/ZeroCoreThreads.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ScheduledThreadPoolExecutor/ZeroCoreThreads.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,9 +35,11 @@
  * @test
  * @bug 8022642 8065320 8129861
  * @summary Ensure relative sanity when zero core threads
+ * @library /lib/testlibrary/
  */
 
 import static java.util.concurrent.TimeUnit.HOURS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.SECONDS;
 
 import java.lang.reflect.Field;
@@ -45,8 +47,28 @@
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.BooleanSupplier;
+import jdk.testlibrary.Utils;
 
 public class ZeroCoreThreads {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+
+    static long millisElapsedSince(long startTime) {
+        return (System.nanoTime() - startTime) / (1000L * 1000L);
+    }
+
+    static void spinWaitUntil(BooleanSupplier predicate, long timeoutMillis) {
+        long startTime = -1L;
+        while (!predicate.getAsBoolean()) {
+            if (startTime == -1L)
+                startTime = System.nanoTime();
+            else if (millisElapsedSince(startTime) > timeoutMillis)
+                throw new AssertionError(
+                    String.format("timed out after %s ms", timeoutMillis));
+            Thread.yield();
+        }
+    }
+
     static boolean hasWaiters(ReentrantLock lock, Condition condition) {
         lock.lock();
         try {
@@ -56,6 +78,11 @@
         }
     }
 
+    static void awaitHasWaiters(ReentrantLock lock, Condition condition,
+                                long timeoutMillis) {
+        spinWaitUntil(() -> hasWaiters(lock, condition), timeoutMillis);
+    }
+
     static <T> T getField(Object x, String fieldName) {
         try {
             Field field = x.getClass().getDeclaredField(fieldName);
@@ -72,7 +99,7 @@
             test(p);
         } finally {
             p.shutdownNow();
-            check(p.awaitTermination(10L, SECONDS));
+            check(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
         }
     }
 
@@ -89,13 +116,7 @@
         equal(0L, p.getCompletedTaskCount());
         p.schedule(dummy, 1L, HOURS);
         // Ensure one pool thread actually waits in timed queue poll
-        long t0 = System.nanoTime();
-        while (!hasWaiters(lock, available)) {
-            if (System.nanoTime() - t0 > SECONDS.toNanos(10L))
-                throw new AssertionError
-                    ("timed out waiting for a waiter to show up");
-            Thread.yield();
-        }
+        awaitHasWaiters(lock, available, LONG_DELAY_MS);
         equal(1, p.getPoolSize());
         equal(1, p.getLargestPoolSize());
         equal(1L, p.getTaskCount());
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	Thu Mar 03 10:43:07 2016 -0800
@@ -25,17 +25,22 @@
  * @test
  * @bug 6233235 6268386
  * @summary Test allowsCoreThreadTimeOut
+ * @library /lib/testlibrary/
  * @author Martin Buchholz
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import jdk.testlibrary.Utils;
 
 public class CoreThreadTimeOut {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
 
     static class IdentifiableThreadFactory implements ThreadFactory {
         static ThreadFactory defaultThreadFactory
@@ -60,8 +65,8 @@
         return count;
     }
 
-    static long millisElapsedSince(long t0) {
-        return (System.nanoTime() - t0) / (1000L * 1000L);
+    static long millisElapsedSince(long startTime) {
+        return (System.nanoTime() - startTime) / (1000L * 1000L);
     }
 
     void test(String[] args) throws Throwable {
@@ -89,7 +94,7 @@
         equal(countExecutorThreads(), 0);
         tpe.shutdown();
         check(tpe.allowsCoreThreadTimeOut());
-        check(tpe.awaitTermination(10L, TimeUnit.SECONDS));
+        check(tpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
 
         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
         if (failed > 0) throw new Exception("Some tests failed");
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/Custom.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/Custom.java	Thu Mar 03 10:43:07 2016 -0800
@@ -25,9 +25,12 @@
  * @test
  * @bug 6277663
  * @summary Test TPE extensibility framework
+ * @library /lib/testlibrary/
  * @author Martin Buchholz
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.Callable;
 import java.util.concurrent.FutureTask;
@@ -37,8 +40,11 @@
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.BooleanSupplier;
+import jdk.testlibrary.Utils;
 
 public class Custom {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static volatile int passed = 0, failed = 0;
     static void pass() { passed++; }
     static void fail() { failed++; Thread.dumpStack(); }
@@ -97,6 +103,22 @@
 
     private static final int threadCount = 10;
 
+    static long millisElapsedSince(long startTime) {
+        return (System.nanoTime() - startTime) / (1000L * 1000L);
+    }
+
+    static void spinWaitUntil(BooleanSupplier predicate, long timeoutMillis) {
+        long startTime = -1L;
+        while (!predicate.getAsBoolean()) {
+            if (startTime == -1L)
+                startTime = System.nanoTime();
+            else if (millisElapsedSince(startTime) > timeoutMillis)
+                throw new AssertionError(
+                    String.format("timed out after %s ms", timeoutMillis));
+            Thread.yield();
+        }
+    }
+
     public static void main(String[] args) throws Throwable {
         CustomTPE tpe = new CustomTPE();
         equal(tpe.getCorePoolSize(), threadCount);
@@ -106,9 +128,8 @@
         equal(countExecutorThreads(), threadCount);
         equal(CustomTask.births.get(), threadCount);
         tpe.shutdown();
-        tpe.awaitTermination(120L, TimeUnit.SECONDS);
-        Thread.sleep(1000);
-        equal(countExecutorThreads(), 0);
+        tpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS);
+        spinWaitUntil(() -> countExecutorThreads() == 0, LONG_DELAY_MS);
 
         CustomSTPE stpe = new CustomSTPE();
         for (int i = 0; i < threadCount; i++)
@@ -116,9 +137,8 @@
         equal(CustomSTPE.decorations.get(), threadCount);
         equal(countExecutorThreads(), threadCount);
         stpe.shutdown();
-        stpe.awaitTermination(120L, TimeUnit.SECONDS);
-        Thread.sleep(1000);
-        equal(countExecutorThreads(), 0);
+        stpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS);
+        spinWaitUntil(() -> countExecutorThreads() == 0, LONG_DELAY_MS);
 
         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
         if (failed > 0) throw new Exception("Some tests failed");
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/FlakyThreadFactory.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/FlakyThreadFactory.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,14 +35,20 @@
 /*
  * @test
  * @summary Should be able to shutdown a pool when worker creation failed.
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import jdk.testlibrary.Utils;
 
 public class FlakyThreadFactory {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+
     void test(String[] args) throws Throwable {
         test(NullPointerException.class,
              new ThreadFactory() {
@@ -89,7 +95,7 @@
             check(exceptionClass.isInstance(t));
         }
         pool.shutdown();
-        check(pool.awaitTermination(10L, TimeUnit.SECONDS));
+        check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
     }
 
     //--------------------- Infrastructure ---------------------------
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/SelfInterrupt.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/SelfInterrupt.java	Thu Mar 03 10:43:07 2016 -0800
@@ -25,14 +25,20 @@
  * @test
  * @bug 6576792
  * @summary non-idle worker threads should not be interrupted
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import jdk.testlibrary.Utils;
 
 public class SelfInterrupt {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+
     void test(String[] args) throws Throwable {
         final int n = 100;
         final ThreadPoolExecutor pool =
@@ -58,7 +64,7 @@
                 } catch (Throwable t) { unexpected(t); }}});
         finishLine.await();
         pool.shutdown();
-        check(pool.awaitTermination(1000L, TimeUnit.SECONDS));
+        check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
     }
 
     //--------------------- Infrastructure ---------------------------
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/ThreadRestarts.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/ThreadRestarts.java	Thu Mar 03 10:43:07 2016 -0800
@@ -36,6 +36,7 @@
  * @test
  * @summary Only one thread should be created when a thread needs to
  * be kept alive to service a delayed task waiting in the queue.
+ * @library /lib/testlibrary/
  */
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -44,8 +45,12 @@
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicLong;
+import jdk.testlibrary.Utils;
 
 public class ThreadRestarts {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+    static final long FAR_FUTURE_MS = 10 * LONG_DELAY_MS;
+
     public static void main(String[] args) throws Exception {
         test(false);
         test(true);
@@ -56,14 +61,15 @@
         ScheduledThreadPoolExecutor stpe
             = new ScheduledThreadPoolExecutor(10, ctf);
         try {
+            // schedule a dummy task in the "far future"
             Runnable nop = new Runnable() { public void run() {}};
-            stpe.schedule(nop, 10*1000L, MILLISECONDS);
+            stpe.schedule(nop, FAR_FUTURE_MS, MILLISECONDS);
             stpe.setKeepAliveTime(1L, MILLISECONDS);
             stpe.allowCoreThreadTimeOut(allowTimeout);
-            MILLISECONDS.sleep(100L);
+            MILLISECONDS.sleep(12L);
         } finally {
             stpe.shutdownNow();
-            if (!stpe.awaitTermination(60L, SECONDS))
+            if (!stpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
                 throw new AssertionError("timed out");
         }
         if (ctf.count.get() > 1)
@@ -76,8 +82,9 @@
         final AtomicLong count = new AtomicLong(0L);
 
         public Thread newThread(Runnable r) {
+            count.getAndIncrement();
             Thread t = new Thread(r);
-            count.getAndIncrement();
+            t.setDaemon(true);
             return t;
         }
     }
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/TimeOutShrink.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/TimeOutShrink.java	Thu Mar 03 10:43:07 2016 -0800
@@ -25,15 +25,22 @@
  * @test
  * @bug 6458662
  * @summary poolSize might shrink below corePoolSize after timeout
+ * @library /lib/testlibrary/
  * @author Martin Buchholz
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import jdk.testlibrary.Utils;
 
 public class TimeOutShrink {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+    static final long KEEPALIVE_MS = 12L;
+
     static void checkPoolSizes(ThreadPoolExecutor pool,
                                int size, int core, int max) {
         equal(pool.getPoolSize(), size);
@@ -45,7 +52,8 @@
         final int n = 4;
         final CyclicBarrier barrier = new CyclicBarrier(2*n+1);
         final ThreadPoolExecutor pool
-            = new ThreadPoolExecutor(n, 2*n, 1L, TimeUnit.SECONDS,
+            = new ThreadPoolExecutor(n, 2*n,
+                                     KEEPALIVE_MS, MILLISECONDS,
                                      new SynchronousQueue<Runnable>());
         final Runnable r = new Runnable() { public void run() {
             try {
@@ -58,12 +66,16 @@
         barrier.await();
         checkPoolSizes(pool, 2*n, n, 2*n);
         barrier.await();
-        while (pool.getPoolSize() > n)
-            Thread.sleep(100);
-        Thread.sleep(100);
+        long nap = KEEPALIVE_MS + (KEEPALIVE_MS >> 2);
+        for (long sleepyTime = 0L; pool.getPoolSize() > n; ) {
+            check((sleepyTime += nap) <= LONG_DELAY_MS);
+            Thread.sleep(nap);
+        }
+        checkPoolSizes(pool, n, n, 2*n);
+        Thread.sleep(nap);
         checkPoolSizes(pool, n, n, 2*n);
         pool.shutdown();
-        check(pool.awaitTermination(60L, TimeUnit.SECONDS));
+        check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
     }
 
     //--------------------- Infrastructure ---------------------------
--- a/jdk/test/java/util/concurrent/locks/Lock/CheckedLockLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/Lock/CheckedLockLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,9 +35,10 @@
  * @test
  * @bug 4486658
  * @summary basic safety and liveness of ReentrantLocks, and other locks based on them
+ * @library /lib/testlibrary/
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.SplittableRandom;
 import java.util.concurrent.CyclicBarrier;
@@ -47,8 +48,10 @@
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
+import jdk.testlibrary.Utils;
 
 public final class CheckedLockLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static ExecutorService pool;
     static final SplittableRandom rnd = new SplittableRandom();
 
@@ -63,7 +66,7 @@
             oneTest(i, iters / i);
         }
         pool.shutdown();
-        if (! pool.awaitTermination(10L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
         pool = null;
     }
--- a/jdk/test/java/util/concurrent/locks/Lock/FlakyMutex.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/Lock/FlakyMutex.java	Thu Mar 03 10:43:07 2016 -0800
@@ -25,9 +25,12 @@
  * @test
  * @bug 6503247 6574123
  * @summary Test resilience to tryAcquire methods that throw
+ * @library /lib/testlibrary/
  * @author Martin Buchholz
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.Random;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
@@ -36,6 +39,7 @@
 import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
+import jdk.testlibrary.Utils;
 
 /**
  * This uses a variant of the standard Mutex demo, except with a
@@ -44,6 +48,7 @@
  */
 @SuppressWarnings("serial")
 public class FlakyMutex implements Lock {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static class MyError extends Error {}
     static class MyException extends Exception {}
     static class MyRuntimeException extends RuntimeException {}
@@ -91,7 +96,7 @@
                 } catch (Throwable t) { unexpected(t); }}});}
         barrier.await();
         es.shutdown();
-        check(es.awaitTermination(30L, TimeUnit.SECONDS));
+        check(es.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
     }
 
     private static class FlakySync extends AbstractQueuedLongSynchronizer {
--- a/jdk/test/java/util/concurrent/locks/Lock/TimedAcquireLeak.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/Lock/TimedAcquireLeak.java	Thu Mar 03 10:43:07 2016 -0800
@@ -25,9 +25,11 @@
  * @test
  * @bug 6460501 6236036 6500694 6490770
  * @summary Repeated failed timed waits shouldn't leak memory
+ * @library /lib/testlibrary/
  * @author Martin Buchholz
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
 import static java.util.concurrent.TimeUnit.SECONDS;
 
@@ -54,8 +56,11 @@
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import jdk.testlibrary.Utils;
 
 public class TimedAcquireLeak {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
+
     static String javahome() {
         String jh = System.getProperty("java.home");
         return (jh.endsWith("jre")) ? jh.substring(0, jh.length() - 4) : jh;
@@ -191,7 +196,7 @@
 
         final String[] jobCmd = {
             java, "-Xmx8m", "-XX:+UsePerfData",
-            "-classpath", System.getProperty("test.classes", "."),
+            "-classpath", System.getProperty("test.class.path"),
             childClassName, uniqueID
         };
         final Process p = new ProcessBuilder(jobCmd).start();
@@ -219,7 +224,7 @@
         check(Math.abs(n1 - n0) < 10);
         check(n1 < 25);
         drainers.shutdown();
-        if (!drainers.awaitTermination(10L, SECONDS)) {
+        if (!drainers.awaitTermination(LONG_DELAY_MS, MILLISECONDS)) {
             drainers.shutdownNow(); // last resort
             throw new AssertionError("thread pool did not terminate");
         }
--- a/jdk/test/java/util/concurrent/locks/LockSupport/ParkLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/LockSupport/ParkLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,11 +35,12 @@
  * @test
  * @bug 8074773
  * @summary Stress test looks for lost unparks
+ * @library /lib/testlibrary/
  * @modules java.management
- * @run main/timeout=1200 ParkLoops
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.lang.management.ManagementFactory;
 import java.lang.management.ThreadInfo;
 import java.util.SplittableRandom;
@@ -49,13 +50,12 @@
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReferenceArray;
 import java.util.concurrent.locks.LockSupport;
+import jdk.testlibrary.Utils;
 
 public final class ParkLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static final int THREADS = 4;
-    // static final int ITERS = 2_000_000;
-    // static final int TIMEOUT = 3500;  // in seconds
-    static final int ITERS = 100_000;
-    static final int TIMEOUT = 1000;  // in seconds
+    static final int ITERS = 30_000;
 
     static class Parker implements Runnable {
         static {
@@ -130,13 +130,13 @@
             pool.submit(unparker);
         }
         try {
-          if (!done.await(TIMEOUT, SECONDS)) {
+          if (!done.await(LONG_DELAY_MS, MILLISECONDS)) {
             dumpAllStacks();
             throw new AssertionError("lost unpark");
           }
         } finally {
           pool.shutdown();
-          pool.awaitTermination(10L, SECONDS);
+          pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS);
         }
     }
 
--- a/jdk/test/java/util/concurrent/locks/ReentrantLock/LockOncePerThreadLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/ReentrantLock/LockOncePerThreadLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,25 +34,27 @@
 /*
  * @test
  * @bug 4486658
- * @run main/timeout=15000 LockOncePerThreadLoops
  * @summary Checks for missed signals by locking and unlocking each of an array of locks once per thread
+ * @library /lib/testlibrary/
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.SplittableRandom;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.locks.ReentrantLock;
+import jdk.testlibrary.Utils;
 
 public final class LockOncePerThreadLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static final ExecutorService pool = Executors.newCachedThreadPool();
     static final SplittableRandom rnd = new SplittableRandom();
     static boolean print = false;
-    static int nlocks = 50000;
-    static int nthreads = 100;
-    static int replications = 5;
+    static int nlocks = 20_000;
+    static int nthreads = 20;
+    static int replications = 3;
 
     public static void main(String[] args) throws Exception {
         if (args.length > 0)
@@ -66,10 +68,9 @@
         for (int i = 0; i < replications; ++i) {
             System.out.print("Iteration: " + i);
             new ReentrantLockLoop().test();
-            Thread.sleep(100);
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
     }
 
--- a/jdk/test/java/util/concurrent/locks/ReentrantLock/SimpleReentrantLockLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/ReentrantLock/SimpleReentrantLockLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,23 +34,25 @@
 /*
  * @test
  * @bug 4486658
- * @run main/timeout=4500 SimpleReentrantLockLoops
  * @summary multiple threads using a single lock
+ * @library /lib/testlibrary/
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.SplittableRandom;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.locks.ReentrantLock;
+import jdk.testlibrary.Utils;
 
 public final class SimpleReentrantLockLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static final ExecutorService pool = Executors.newCachedThreadPool();
     static final SplittableRandom rnd = new SplittableRandom();
     static boolean print = false;
-    static int iters = 1000000;
+    static int iters = 100_000;
 
     public static void main(String[] args) throws Exception {
         int maxThreads = 5;
@@ -66,11 +68,10 @@
             while (n-- > 0) {
                 System.out.print("Threads: " + i);
                 new ReentrantLockLoop(i).test();
-                Thread.sleep(100);
             }
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
     }
 
--- a/jdk/test/java/util/concurrent/locks/ReentrantLock/TimeoutLockLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/ReentrantLock/TimeoutLockLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -34,18 +34,22 @@
 /*
  * @test
  * @bug 4486658 5031862 8140471
- * @run main TimeoutLockLoops
  * @summary Checks for responsiveness of locks to timeouts.
+ * @library /lib/testlibrary/
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.util.SplittableRandom;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.ReentrantLock;
+import jdk.testlibrary.Utils;
 
 public final class TimeoutLockLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static final ExecutorService pool = Executors.newCachedThreadPool();
     static final SplittableRandom rnd = new SplittableRandom();
     static boolean print = false;
@@ -63,7 +67,7 @@
             new ReentrantLockLoop(i).test();
         }
         pool.shutdown();
-        if (! pool.awaitTermination(60L, TimeUnit.SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
     }
 
--- a/jdk/test/java/util/concurrent/locks/ReentrantReadWriteLock/Count.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/ReentrantReadWriteLock/Count.java	Thu Mar 03 10:43:07 2016 -0800
@@ -25,9 +25,12 @@
  * @test
  * @bug 6207928 6328220 6378321 6625723
  * @summary Recursive lock invariant sanity checks
+ * @library /lib/testlibrary/
  * @author Martin Buchholz
  */
 
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -42,9 +45,11 @@
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
+import jdk.testlibrary.Utils;
 
 // I am the Cownt, and I lahve to cownt.
 public class Count {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     final Random rnd = new Random();
 
     void lock(Lock lock) {
@@ -102,7 +107,7 @@
                     barrier.await();
                 } catch (Throwable t) { unexpected(t); }}});}
         es.shutdown();
-        check(es.awaitTermination(10L, TimeUnit.SECONDS));
+        check(es.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
     }
 
     void testReentrantLocks(final boolean fair,
--- a/jdk/test/java/util/concurrent/locks/ReentrantReadWriteLock/MapLoops.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/ReentrantReadWriteLock/MapLoops.java	Thu Mar 03 10:43:07 2016 -0800
@@ -41,17 +41,20 @@
  * inserts it, and if present, with probability premove it removes
  * it.  (pinsert and premove are expressed as percentages to simplify
  * parsing from command line.)
+ * @library /lib/testlibrary/
  */
 
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.util.Map;
 import java.util.SplittableRandom;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import jdk.testlibrary.Utils;
 
 public class MapLoops {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
     static final int NKEYS = 100000;
     static int pinsert     = 60;
     static int premove     = 2;
@@ -125,7 +128,7 @@
             map.clear();
         }
         pool.shutdown();
-        if (! pool.awaitTermination(10L, SECONDS))
+        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
             throw new Error();
     }
 
--- a/jdk/test/java/util/concurrent/locks/StampedLock/Basic.java	Thu Mar 03 10:39:34 2016 -0800
+++ b/jdk/test/java/util/concurrent/locks/StampedLock/Basic.java	Thu Mar 03 10:43:07 2016 -0800
@@ -35,6 +35,7 @@
  * @test
  * @bug 8005697
  * @summary Basic tests for StampedLock
+ * @library /lib/testlibrary/
  * @author Chris Hegarty
  */
 
@@ -49,8 +50,10 @@
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.StampedLock;
+import jdk.testlibrary.Utils;
 
 public class Basic {
+    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
 
     static void checkResult(Locker l, Class<? extends Throwable> c) {
         Throwable t = l.thrown();
@@ -268,7 +271,7 @@
                     case 2: case 5:
                         return interruptibleReader(sl, -1, SECONDS, gate, view ^= true);
                     default:
-                        return interruptibleReader(sl, 30, SECONDS, gate, view ^= true); }}
+                        return interruptibleReader(sl, LONG_DELAY_MS, MILLISECONDS, gate, view ^= true); }}
             public void remove() {throw new UnsupportedOperationException();}};
     }
 
@@ -286,7 +289,7 @@
                     case 2: case 5:
                         return interruptibleWriter(sl, -1, SECONDS, gate, view ^= true);
                     default:
-                        return interruptibleWriter(sl, 30, SECONDS, gate, view ^= true); }}
+                        return interruptibleWriter(sl, LONG_DELAY_MS, MILLISECONDS, gate, view ^= true); }}
             public void remove() {throw new UnsupportedOperationException();}};
     }
 
@@ -454,13 +457,13 @@
             // We test interrupting both before and after trying to acquire
             boolean view = false;
             StampedLock sl = new StampedLock();
-            for (long timeout : new long[] { -1L, 30L, -1L, 30L }) {
+            for (long timeout : new long[] { -1L, LONG_DELAY_MS, -1L, LONG_DELAY_MS }) {
                 long stamp;
                 Thread.State state;
 
                 stamp = sl.writeLock();
                 try {
-                    Reader r = interruptibleReader(sl, timeout, SECONDS, null, view);
+                    Reader r = interruptibleReader(sl, timeout, MILLISECONDS, null, view);
                     r.start();
                     r.interrupt();
                     r.join();
@@ -471,7 +474,7 @@
 
                 stamp = sl.writeLock();
                 try {
-                    Reader r = interruptibleReader(sl, timeout, SECONDS, null, view);
+                    Reader r = interruptibleReader(sl, timeout, MILLISECONDS, null, view);
                     r.start();
                     waitForThreadToBlock(r);
                     r.interrupt();
@@ -483,7 +486,7 @@
 
                 stamp = sl.readLock();
                 try {
-                    Writer w = interruptibleWriter(sl, timeout, SECONDS, null, view);
+                    Writer w = interruptibleWriter(sl, timeout, MILLISECONDS, null, view);
                     w.start();
                     w.interrupt();
                     w.join();
@@ -494,7 +497,7 @@
 
                 stamp = sl.readLock();
                 try {
-                    Writer w = interruptibleWriter(sl, timeout, SECONDS, null, view);
+                    Writer w = interruptibleWriter(sl, timeout, MILLISECONDS, null, view);
                     w.start();
                     waitForThreadToBlock(w);
                     w.interrupt();
@@ -509,7 +512,7 @@
                 check(!sl.tryUnlockRead());
                 check(!sl.tryUnlockWrite());
                 check(sl.tryOptimisticRead() != 0L);
-                if (timeout == 30L)
+                if (timeout == LONG_DELAY_MS)
                     view = true;
             }
         } catch (Throwable t) { unexpected(t); }