OSDN Git Service

ART: Extend DumpRecursiveAbort
authorAndreas Gampe <agampe@google.com>
Sat, 19 Nov 2016 01:21:12 +0000 (17:21 -0800)
committerAndreas Gampe <agampe@google.com>
Sat, 19 Nov 2016 01:42:58 +0000 (17:42 -0800)
Accept recursive dump request for deeper recursions. Otherwise,
two or more threads aborting concurrently would ensure that there
are no dumps.

Test: m test-art-host
Change-Id: Ib82d64cceba0de89e352d9b15bcd5708db82498c

runtime/runtime.cc

index 771ac27..1490f05 100644 (file)
@@ -372,9 +372,7 @@ struct AbortState {
   void Dump(std::ostream& os) const {
     if (gAborting > 1) {
       os << "Runtime aborting --- recursively, so no thread-specific detail!\n";
-      if (gAborting == 2) {
-        DumpRecursiveAbort(os);
-      }
+      DumpRecursiveAbort(os);
       return;
     }
     gAborting++;
@@ -434,8 +432,17 @@ struct AbortState {
 
   // For recursive aborts.
   void DumpRecursiveAbort(std::ostream& os) const NO_THREAD_SAFETY_ANALYSIS {
-    // The only thing we'll attempt is dumping the native stack of the current thread.
-    DumpNativeStack(os, GetTid());
+    // The only thing we'll attempt is dumping the native stack of the current thread. We will only
+    // try this if we haven't exceeded an arbitrary amount of recursions, to recover and actually
+    // die.
+    // Note: as we're using a global counter for the recursive abort detection, there is a potential
+    //       race here and it is not OK to just print when the counter is "2" (one from
+    //       Runtime::Abort(), one from previous Dump() call). Use a number that seems large enough.
+    static constexpr size_t kOnlyPrintWhenRecursionLessThan = 100u;
+    if (gAborting < kOnlyPrintWhenRecursionLessThan) {
+      gAborting++;
+      DumpNativeStack(os, GetTid());
+    }
   }
 };