--- jsr166/src/test/tck/JSR166TestCase.java 2015/09/25 23:32:15 1.146 +++ jsr166/src/test/tck/JSR166TestCase.java 2015/10/03 19:08:13 1.150 @@ -15,6 +15,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -186,15 +187,18 @@ public class JSR166TestCase extends Test return (regex == null) ? null : Pattern.compile(regex); } - protected void runTest() throws Throwable { + public void runBare() throws Throwable { if (methodFilter == null - || methodFilter.matcher(toString()).find()) { - for (int i = 0; i < runsPerTest; i++) { - if (profileTests) - runTestProfiled(); - else - super.runTest(); - } + || methodFilter.matcher(toString()).find()) + super.runBare(); + } + + protected void runTest() throws Throwable { + for (int i = 0; i < runsPerTest; i++) { + if (profileTests) + runTestProfiled(); + else + super.runTest(); } } @@ -740,9 +744,19 @@ public class JSR166TestCase extends Test } /** + * Allows use of try-with-resources with per-test thread pools. + */ + static class PoolCloser + implements AutoCloseable { + public final T pool; + public PoolCloser(T pool) { this.pool = pool; } + public void close() { joinPool(pool); } + } + + /** * Waits out termination of a thread pool or fails doing so. */ - void joinPool(ExecutorService pool) { + static void joinPool(ExecutorService pool) { try { pool.shutdown(); if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) @@ -785,12 +799,24 @@ public class JSR166TestCase extends Test /** * A debugging tool to print all stack traces, as jstack does. + * Uninteresting threads are filtered out. */ static void printAllStackTraces() { - for (ThreadInfo info : - ManagementFactory.getThreadMXBean() - .dumpAllThreads(true, true)) + ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + System.err.println("------ stacktrace dump start ------"); + for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { + String name = info.getThreadName(); + if ("Signal Dispatcher".equals(name)) + continue; + if ("Reference Handler".equals(name) + && info.getLockName().startsWith("java.lang.ref.Reference$Lock")) + continue; + if ("Finalizer".equals(name) + && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock")) + continue; System.err.print(info); + } + System.err.println("------ stacktrace dump end ------"); } /** @@ -1251,6 +1277,13 @@ public class JSR166TestCase extends Test }}; } + public Runnable countDowner(final CountDownLatch latch) { + return new CheckedRunnable() { + public void realRun() throws InterruptedException { + latch.countDown(); + }}; + } + public Runnable awaiter(final CountDownLatch latch) { return new CheckedRunnable() { public void realRun() throws InterruptedException {