40 |
|
import java.util.concurrent.ExecutionException; |
41 |
|
import java.util.concurrent.Executors; |
42 |
|
import java.util.concurrent.ExecutorService; |
43 |
+ |
import java.util.concurrent.ForkJoinPool; |
44 |
|
import java.util.concurrent.Future; |
45 |
|
import java.util.concurrent.RecursiveAction; |
46 |
|
import java.util.concurrent.RecursiveTask; |
199 |
|
} |
200 |
|
|
201 |
|
protected void runTestProfiled() throws Throwable { |
202 |
< |
// Warmup run, notably to trigger all needed classloading. |
203 |
< |
super.runTest(); |
203 |
< |
long t0 = System.nanoTime(); |
204 |
< |
try { |
202 |
> |
for (int i = 0; i < 2; i++) { |
203 |
> |
long startTime = System.nanoTime(); |
204 |
|
super.runTest(); |
205 |
< |
} finally { |
206 |
< |
long elapsedMillis = millisElapsedSince(t0); |
207 |
< |
if (elapsedMillis >= profileThreshold) |
205 |
> |
long elapsedMillis = millisElapsedSince(startTime); |
206 |
> |
if (elapsedMillis < profileThreshold) |
207 |
> |
break; |
208 |
> |
// Never report first run of any test; treat it as a |
209 |
> |
// warmup run, notably to trigger all needed classloading, |
210 |
> |
if (i > 0) |
211 |
|
System.out.printf("%n%s: %d%n", toString(), elapsedMillis); |
212 |
|
} |
213 |
|
} |
522 |
|
setDelays(); |
523 |
|
} |
524 |
|
|
525 |
+ |
void tearDownFail(String format, Object... args) { |
526 |
+ |
String msg = toString() + ": " + String.format(format, args); |
527 |
+ |
System.err.println(msg); |
528 |
+ |
printAllStackTraces(); |
529 |
+ |
throw new AssertionFailedError(msg); |
530 |
+ |
} |
531 |
+ |
|
532 |
|
/** |
533 |
|
* Extra checks that get done for all test cases. |
534 |
|
* |
556 |
|
} |
557 |
|
|
558 |
|
if (Thread.interrupted()) |
559 |
< |
throw new AssertionFailedError("interrupt status set in main thread"); |
559 |
> |
tearDownFail("interrupt status set in main thread"); |
560 |
|
|
561 |
|
checkForkJoinPoolThreadLeaks(); |
562 |
|
} |
565 |
|
* Finds missing try { ... } finally { joinPool(e); } |
566 |
|
*/ |
567 |
|
void checkForkJoinPoolThreadLeaks() throws InterruptedException { |
568 |
< |
Thread[] survivors = new Thread[5]; |
568 |
> |
Thread[] survivors = new Thread[7]; |
569 |
|
int count = Thread.enumerate(survivors); |
570 |
|
for (int i = 0; i < count; i++) { |
571 |
|
Thread thread = survivors[i]; |
573 |
|
if (name.startsWith("ForkJoinPool-")) { |
574 |
|
// give thread some time to terminate |
575 |
|
thread.join(LONG_DELAY_MS); |
576 |
< |
if (!thread.isAlive()) continue; |
577 |
< |
throw new AssertionFailedError |
578 |
< |
(String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n", |
570 |
< |
toString(), name)); |
576 |
> |
if (thread.isAlive()) |
577 |
> |
tearDownFail("Found leaked ForkJoinPool thread thread=%s", |
578 |
> |
thread); |
579 |
|
} |
580 |
|
} |
581 |
+ |
|
582 |
+ |
if (!ForkJoinPool.commonPool() |
583 |
+ |
.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) |
584 |
+ |
tearDownFail("ForkJoin common pool thread stuck"); |
585 |
|
} |
586 |
|
|
587 |
|
/** |