Fix abort regression.

Change https://googleplex-android-review.googlesource.com/#/c/249463/ set a
boolean prior to testing it meaning that all aborts were seen as recursive and
no meaningful log information was given.

Also a fix related to https://googleplex-android-review.googlesource.com/293665
where we were attempting to dump other threads stacks during aborting even
though those threads weren't suspended.

Change-Id: I1f848512c5e380529579db3d16bb8f5ddda36ad3
diff --git a/src/base/logging.cc b/src/base/logging.cc
index 6d0452b..c9f28c8 100644
--- a/src/base/logging.cc
+++ b/src/base/logging.cc
@@ -25,7 +25,7 @@
 
 LogVerbosity gLogVerbosity;
 
-bool gAborting = false;
+unsigned int gAborting = 0;
 
 static LogSeverity gMinimumLogSeverity = INFO;
 static std::string* gCmdLine;
diff --git a/src/base/logging.h b/src/base/logging.h
index a08acab..310357d 100644
--- a/src/base/logging.h
+++ b/src/base/logging.h
@@ -319,7 +319,7 @@
 
 // Used on fatal exit. Prevents recursive aborts. Allows us to disable
 // some error checking to ensure fatal shutdown makes forward progress.
-extern bool gAborting;
+extern unsigned int gAborting;
 
 extern void InitLogging(char* argv[]);
 
diff --git a/src/compiler/driver/compiler_driver.cc b/src/compiler/driver/compiler_driver.cc
index 9db9ee8..7ce01ed 100644
--- a/src/compiler/driver/compiler_driver.cc
+++ b/src/compiler/driver/compiler_driver.cc
@@ -1397,7 +1397,7 @@
   "Ljavax/net/ssl/HttpsURLConnection;", // Calls SSLSocketFactory.getDefault -> java.security.Security.getProperty.
   "Llibcore/icu/LocaleData;", // Requires java.util.Locale.
   "Llibcore/icu/TimeZoneNames;", // Requires java.util.TimeZone.
-  "Llibcore/io/IoUtils;",  // Calls OsConstants.initConstants.
+  "Llibcore/io/IoUtils;",  // Calls Random.<init> -> System.currentTimeMillis -> FileDescriptor -> OsConstants.initConstants.
   "Llibcore/io/OsConstants;", // Platform specific.
   "Llibcore/net/MimeUtils;", // Calls libcore.net.MimeUtils.getContentTypesPropertiesStream -> System.getProperty.
   "Llibcore/util/ZoneInfo;", // Sub-class of TimeZone.
diff --git a/src/runtime.cc b/src/runtime.cc
index 23a7309..9661f50 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -147,11 +147,11 @@
 
 struct AbortState {
   void Dump(std::ostream& os) {
-    if (gAborting) {
+    if (gAborting > 1) {
       os << "Runtime aborting --- recursively, so no thread-specific detail!\n";
       return;
     }
-    gAborting = true;
+    gAborting++;
     os << "Runtime aborting...\n";
     if (Runtime::Current() == NULL) {
       os << "(Runtime does not yet exist!)\n";
@@ -193,7 +193,7 @@
 };
 
 void Runtime::Abort() {
-  gAborting = true;  // set before taking any locks
+  gAborting++;  // set before taking any locks
 
   // Ensure that we don't have multiple threads trying to abort at once,
   // which would result in significantly worse diagnostics.
diff --git a/src/runtime_linux.cc b/src/runtime_linux.cc
index 0be6339..a4fc3af 100644
--- a/src/runtime_linux.cc
+++ b/src/runtime_linux.cc
@@ -236,7 +236,7 @@
   }
   handlingUnexpectedSignal = true;
 
-  gAborting = true;  // set before taking any locks
+  gAborting++;  // set before taking any locks
   MutexLock mu(Thread::Current(), *Locks::unexpected_signal_lock_);
 
   bool has_address = (signal_number == SIGILL || signal_number == SIGBUS ||
diff --git a/src/thread.cc b/src/thread.cc
index 2c955b1..74d58e3 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -859,14 +859,18 @@
 }
 
 void Thread::DumpStack(std::ostream& os) const {
-  // If we're currently in native code, dump that stack before dumping the managed stack.
-  if (ShouldShowNativeStack(this)) {
-    DumpKernelStack(os, GetTid(), "  kernel: ", false);
-    DumpNativeStack(os, GetTid(), "  native: ", false);
+  if (this == Thread::Current() || IsSuspended()) {
+    // If we're currently in native code, dump that stack before dumping the managed stack.
+    if (ShouldShowNativeStack(this)) {
+      DumpKernelStack(os, GetTid(), "  kernel: ", false);
+      DumpNativeStack(os, GetTid(), "  native: ", false);
+    }
+    UniquePtr<Context> context(Context::Create());
+    StackDumpVisitor dumper(os, const_cast<Thread*>(this), context.get(), !throwing_OutOfMemoryError_);
+    dumper.WalkStack();
+  } else {
+    os << "Not able to dump stack of thread that isn't suspended";
   }
-  UniquePtr<Context> context(Context::Create());
-  StackDumpVisitor dumper(os, const_cast<Thread*>(this), context.get(), !throwing_OutOfMemoryError_);
-  dumper.WalkStack();
 }
 
 void Thread::ThreadExitCallback(void* arg) {