From 4201cf014cfe00c145edc0b32bf30b1ceaf1495f Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 12 Jan 2017 14:51:44 -0800 Subject: Avoid suspending heap task thread for getting stack traces Instead of suspending the heap task thread, GetThreadStack (called by VMStack_fillStackTraceElements and VMStack_getThreadStackTrace) will return an empty thread stack. This fixes possible deadlocks caused by suspending the GC thread and doing allocations for the stack trace. Bug: 28261069 Test: test-art-host Change-Id: I45a0b8ac94a99d6bbcfcdc2b41afadf941ec0138 --- test/129-ThreadGetId/src/Main.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/129-ThreadGetId/src/Main.java') diff --git a/test/129-ThreadGetId/src/Main.java b/test/129-ThreadGetId/src/Main.java index 9934bba95f..5aefd17f0e 100644 --- a/test/129-ThreadGetId/src/Main.java +++ b/test/129-ThreadGetId/src/Main.java @@ -22,6 +22,7 @@ public class Main implements Runnable { public static void main(String[] args) throws Exception { final Thread[] threads = new Thread[numberOfThreads]; + test_getStackTraces(); for (int t = 0; t < threads.length; t++) { threads[t] = new Thread(new Main()); threads[t].start(); @@ -32,6 +33,19 @@ public class Main implements Runnable { System.out.println("Finishing"); } + static void test_getStackTraces() { + // Check all the current threads for positive IDs. + Map map = Thread.getAllStackTraces(); + for (Map.Entry 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")) { + System.out.println(thread.getName() + " depth " + pair.getValue().length); + } + } + } + public void test_getId() { if (Thread.currentThread().getId() <= 0) { System.out.println("current thread's ID is not positive"); -- cgit v1.2.3-59-g8ed1b