summaryrefslogtreecommitdiff
path: root/test/129-ThreadGetId/src/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/129-ThreadGetId/src/Main.java')
-rw-r--r--test/129-ThreadGetId/src/Main.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/test/129-ThreadGetId/src/Main.java b/test/129-ThreadGetId/src/Main.java
index 5aefd17f0e..6ba01ff0b5 100644
--- a/test/129-ThreadGetId/src/Main.java
+++ b/test/129-ThreadGetId/src/Main.java
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import java.lang.reflect.Field;
import java.util.Map;
public class Main implements Runnable {
@@ -33,14 +34,38 @@ public class Main implements Runnable {
System.out.println("Finishing");
}
- static void test_getStackTraces() {
+ static Thread getHeapTaskDaemon() throws Exception {
+ Field f = ThreadGroup.class.getDeclaredField("systemThreadGroup");
+ f.setAccessible(true);
+ ThreadGroup systemThreadGroup = (ThreadGroup) f.get(null);
+
+ while (true) {
+ int activeCount = systemThreadGroup.activeCount();
+ Thread[] array = new Thread[activeCount];
+ systemThreadGroup.enumerate(array);
+ for (Thread thread : array) {
+ if (thread.getName().equals("HeapTaskDaemon") &&
+ thread.getState() != Thread.State.NEW) {
+ return thread;
+ }
+ }
+ // Yield to eventually get the daemon started.
+ Thread.sleep(10);
+ }
+ }
+
+ static void test_getStackTraces() throws Exception {
+ Thread heapDaemon = getHeapTaskDaemon();
+
+ // Force a GC to ensure the daemon truly started.
+ Runtime.getRuntime().gc();
// Check all the current threads for positive IDs.
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
for (Map.Entry<Thread, StackTraceElement[]> pair : map.entrySet()) {
Thread thread = pair.getKey();
// Expect empty stack trace since we do not support suspending the GC thread for
// obtaining stack traces. See b/28261069.
- if (thread.getName().equals("HeapTaskDaemon")) {
+ if (thread == heapDaemon) {
System.out.println(thread.getName() + " depth " + pair.getValue().length);
}
}