284 |
|
static volatile TestCase currentTestCase; |
285 |
|
// static volatile int currentRun = 0; |
286 |
|
static { |
287 |
< |
Runnable checkForWedgedTest = new Runnable() { public void run() { |
287 |
> |
Runnable wedgedTestDetector = new Runnable() { public void run() { |
288 |
|
// Avoid spurious reports with enormous runsPerTest. |
289 |
|
// A single test case run should never take more than 1 second. |
290 |
|
// But let's cap it at the high end too ... |
310 |
|
} |
311 |
|
lastTestCase = currentTestCase; |
312 |
|
}}}; |
313 |
< |
Thread thread = new Thread(checkForWedgedTest, "checkForWedgedTest"); |
313 |
> |
Thread thread = new Thread(wedgedTestDetector, "WedgedTestDetector"); |
314 |
|
thread.setDaemon(true); |
315 |
|
thread.start(); |
316 |
|
} |
354 |
|
// Never report first run of any test; treat it as a |
355 |
|
// warmup run, notably to trigger all needed classloading, |
356 |
|
if (i > 0) |
357 |
< |
System.out.printf("%n%s: %d%n", toString(), elapsedMillis); |
357 |
> |
System.out.printf("%s: %d%n", toString(), elapsedMillis); |
358 |
|
} |
359 |
|
} |
360 |
|
|
1083 |
|
} |
1084 |
|
} |
1085 |
|
|
1086 |
+ |
/** Returns true if thread info might be useful in a thread dump. */ |
1087 |
+ |
static boolean threadOfInterest(ThreadInfo info) { |
1088 |
+ |
final String name = info.getThreadName(); |
1089 |
+ |
String lockName; |
1090 |
+ |
if (name == null) |
1091 |
+ |
return true; |
1092 |
+ |
if (name.equals("Signal Dispatcher") |
1093 |
+ |
|| name.equals("WedgedTestDetector")) |
1094 |
+ |
return false; |
1095 |
+ |
if (name.equals("Reference Handler")) { |
1096 |
+ |
// Reference Handler stacktrace changed in JDK-8156500 |
1097 |
+ |
StackTraceElement[] stackTrace; String methodName; |
1098 |
+ |
if ((stackTrace = info.getStackTrace()) != null |
1099 |
+ |
&& stackTrace.length > 0 |
1100 |
+ |
&& (methodName = stackTrace[0].getMethodName()) != null |
1101 |
+ |
&& methodName.equals("waitForReferencePendingList")) |
1102 |
+ |
return false; |
1103 |
+ |
// jdk8 Reference Handler stacktrace |
1104 |
+ |
if ((lockName = info.getLockName()) != null |
1105 |
+ |
&& lockName.startsWith("java.lang.ref")) |
1106 |
+ |
return false; |
1107 |
+ |
} |
1108 |
+ |
if ((name.equals("Finalizer") || name.equals("Common-Cleaner")) |
1109 |
+ |
&& (lockName = info.getLockName()) != null |
1110 |
+ |
&& lockName.startsWith("java.lang.ref")) |
1111 |
+ |
return false; |
1112 |
+ |
if (name.startsWith("ForkJoinPool.commonPool-worker") |
1113 |
+ |
&& (lockName = info.getLockName()) != null |
1114 |
+ |
&& lockName.startsWith("java.util.concurrent.ForkJoinPool")) |
1115 |
+ |
return false; |
1116 |
+ |
return true; |
1117 |
+ |
} |
1118 |
+ |
|
1119 |
|
/** |
1120 |
|
* A debugging tool to print stack traces of most threads, as jstack does. |
1121 |
|
* Uninteresting threads are filtered out. |
1132 |
|
|
1133 |
|
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
1134 |
|
System.err.println("------ stacktrace dump start ------"); |
1135 |
< |
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { |
1136 |
< |
final String name = info.getThreadName(); |
1137 |
< |
String lockName; |
1105 |
< |
if ("Signal Dispatcher".equals(name)) |
1106 |
< |
continue; |
1107 |
< |
if ("Reference Handler".equals(name) |
1108 |
< |
&& (lockName = info.getLockName()) != null |
1109 |
< |
&& lockName.startsWith("java.lang.ref.Reference$Lock")) |
1110 |
< |
continue; |
1111 |
< |
if ("Finalizer".equals(name) |
1112 |
< |
&& (lockName = info.getLockName()) != null |
1113 |
< |
&& lockName.startsWith("java.lang.ref.ReferenceQueue$Lock")) |
1114 |
< |
continue; |
1115 |
< |
if ("checkForWedgedTest".equals(name)) |
1116 |
< |
continue; |
1117 |
< |
System.err.print(info); |
1118 |
< |
} |
1135 |
> |
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) |
1136 |
> |
if (threadOfInterest(info)) |
1137 |
> |
System.err.print(info); |
1138 |
|
System.err.println("------ stacktrace dump end ------"); |
1139 |
|
|
1140 |
|
if (sm != null) System.setSecurityManager(sm); |