From b9f954826c2e81667f5aa466aa3084f789c384fb Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 11 Jun 2015 15:09:16 -0700 Subject: Send SIGQUIT when finalizer times out The motivation is to get a native stack trace of the thread if it is stuck in native code when runing a finalizer. Idea from agampe. Bug: 21060358 Change-Id: I370988e6a0067e1d407c21881c82e49b6adec050 --- libart/src/main/java/java/lang/Daemons.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libart') diff --git a/libart/src/main/java/java/lang/Daemons.java b/libart/src/main/java/java/lang/Daemons.java index 43066e1..a6ac449 100644 --- a/libart/src/main/java/java/lang/Daemons.java +++ b/libart/src/main/java/java/lang/Daemons.java @@ -16,6 +16,8 @@ package java.lang; +import android.system.Os; +import android.system.OsConstants; import dalvik.system.VMRuntime; import java.lang.ref.FinalizerReference; import java.lang.ref.Reference; @@ -295,6 +297,14 @@ public final class Daemons { // We use the stack from where finalize() was running to show where it was stuck. syntheticException.setStackTrace(FinalizerDaemon.INSTANCE.getStackTrace()); Thread.UncaughtExceptionHandler h = Thread.getDefaultUncaughtExceptionHandler(); + // Send SIGQUIT to get native stack traces. + try { + Os.kill(Os.getpid(), OsConstants.SIGQUIT); + // Sleep a few seconds to let the stack traces print. + Thread.sleep(5000); + } catch (Exception e) { + System.logE("failed to send SIGQUIT", e); + } if (h == null) { // If we have no handler, log and exit. System.logE(message, syntheticException); -- cgit v1.1