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.

(cherry picked from commit b9f954826c2e81667f5aa466aa3084f789c384fb)

Bug: 21060358
Change-Id: I370988e6a0067e1d407c21881c82e49b6adec050
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 @@
             // 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);