Merge changes I8d333ea5,Ie4efc8bb

* changes:
  ART: Make gAborting an atomic
  ART: Refactor abort code
diff --git a/cmdline/cmdline.h b/cmdline/cmdline.h
index 98010d7..18ca944 100644
--- a/cmdline/cmdline.h
+++ b/cmdline/cmdline.h
@@ -295,7 +295,7 @@
 template <typename Args = CmdlineArgs>
 struct CmdlineMain {
   int Main(int argc, char** argv) {
-    InitLogging(argv, Runtime::Aborter);
+    InitLogging(argv, Runtime::Abort);
     std::unique_ptr<Args> args = std::unique_ptr<Args>(CreateArguments());
     args_ = args.get();
 
diff --git a/cmdline/cmdline_parser_test.cc b/cmdline/cmdline_parser_test.cc
index b224ec7..d957869 100644
--- a/cmdline/cmdline_parser_test.cc
+++ b/cmdline/cmdline_parser_test.cc
@@ -123,7 +123,7 @@
   using RuntimeParser = ParsedOptions::RuntimeParser;
 
   static void SetUpTestCase() {
-    art::InitLogging(nullptr, art::Runtime::Aborter);  // argv = null
+    art::InitLogging(nullptr, art::Runtime::Abort);  // argv = null
   }
 
   virtual void SetUp() {
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index c0ab21d..92d60b2 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1133,7 +1133,7 @@
     original_argc = argc;
     original_argv = argv;
 
-    InitLogging(argv, Runtime::Aborter);
+    InitLogging(argv, Runtime::Abort);
 
     // Skip over argv[0].
     argv++;
diff --git a/dexdump/dexdump_main.cc b/dexdump/dexdump_main.cc
index 74cae3c..606d4f8 100644
--- a/dexdump/dexdump_main.cc
+++ b/dexdump/dexdump_main.cc
@@ -60,7 +60,7 @@
  */
 int dexdumpDriver(int argc, char** argv) {
   // Art specific set up.
-  InitLogging(argv, Runtime::Aborter);
+  InitLogging(argv, Runtime::Abort);
   MemMap::Init();
 
   // Reset options.
diff --git a/dexlayout/dexdiag.cc b/dexlayout/dexdiag.cc
index 78860e3..c14cd5f 100644
--- a/dexlayout/dexdiag.cc
+++ b/dexlayout/dexdiag.cc
@@ -465,7 +465,7 @@
   }
 
   // Art specific set up.
-  InitLogging(argv, Runtime::Aborter);
+  InitLogging(argv, Runtime::Abort);
   MemMap::Init();
 
 #ifdef ART_TARGET_ANDROID
diff --git a/dexlayout/dexlayout_main.cc b/dexlayout/dexlayout_main.cc
index 3c627ea..33d62de 100644
--- a/dexlayout/dexlayout_main.cc
+++ b/dexlayout/dexlayout_main.cc
@@ -67,7 +67,7 @@
  */
 int DexlayoutDriver(int argc, char** argv) {
   // Art specific set up.
-  InitLogging(argv, Runtime::Aborter);
+  InitLogging(argv, Runtime::Abort);
   MemMap::Init();
 
   Options options;
diff --git a/dexlist/dexlist.cc b/dexlist/dexlist.cc
index 29707af..fa232a7 100644
--- a/dexlist/dexlist.cc
+++ b/dexlist/dexlist.cc
@@ -211,7 +211,7 @@
  */
 int dexlistDriver(int argc, char** argv) {
   // Art specific set up.
-  InitLogging(argv, Runtime::Aborter);
+  InitLogging(argv, Runtime::Abort);
   MemMap::Init();
 
   // Reset options.
diff --git a/dexoptanalyzer/dexoptanalyzer.cc b/dexoptanalyzer/dexoptanalyzer.cc
index 9a2eb7f..e2c159a 100644
--- a/dexoptanalyzer/dexoptanalyzer.cc
+++ b/dexoptanalyzer/dexoptanalyzer.cc
@@ -127,7 +127,7 @@
     original_argc = argc;
     original_argv = argv;
 
-    InitLogging(argv, Runtime::Aborter);
+    InitLogging(argv, Runtime::Abort);
     // Skip over the command name.
     argv++;
     argc--;
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc
index 848eb8d..149960e 100644
--- a/patchoat/patchoat.cc
+++ b/patchoat/patchoat.cc
@@ -783,7 +783,7 @@
 }
 
 static int patchoat(int argc, char **argv) {
-  InitLogging(argv, Runtime::Aborter);
+  InitLogging(argv, Runtime::Abort);
   MemMap::Init();
   const bool debug = kIsDebugBuild;
   orig_argc = argc;
diff --git a/profman/profman.cc b/profman/profman.cc
index 14b0262..94e81c7 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -189,7 +189,7 @@
     original_argc = argc;
     original_argv = argv;
 
-    InitLogging(argv, Runtime::Aborter);
+    InitLogging(argv, Runtime::Abort);
 
     // Skip over the command name.
     argv++;
diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc
index 2be9067..4776357 100644
--- a/runtime/base/logging.cc
+++ b/runtime/base/logging.cc
@@ -85,7 +85,7 @@
 
 LogVerbosity gLogVerbosity;
 
-unsigned int gAborting = 0;
+std::atomic<unsigned int> gAborting(0);
 
 static std::unique_ptr<std::string> gCmdLine;
 static std::unique_ptr<std::string> gProgramInvocationName;
diff --git a/runtime/base/logging.h b/runtime/base/logging.h
index d8954e5..15f9353 100644
--- a/runtime/base/logging.h
+++ b/runtime/base/logging.h
@@ -102,7 +102,7 @@
 // 0 if not abort, non-zero if an abort is in progress. Used on fatal exit to prevents recursive
 // aborts. Global declaration allows us to disable some error checking to ensure fatal shutdown
 // makes forward progress.
-extern unsigned int gAborting;
+extern std::atomic<unsigned int> gAborting;
 
 // Configure logging based on ANDROID_LOG_TAGS environment variable.
 // We need to parse a string that looks like
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index 5beac1a..6441a44 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -59,7 +59,7 @@
   // everything else. In case you want to see all messages, comment out the line.
   setenv("ANDROID_LOG_TAGS", "*:e", 1);
 
-  art::InitLogging(argv, art::Runtime::Aborter);
+  art::InitLogging(argv, art::Runtime::Abort);
   LOG(INFO) << "Running main() from common_runtime_test.cc...";
   testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index c11e4bd..46b4392 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -483,7 +483,16 @@
 };
 
 void Runtime::Abort(const char* msg) {
-  gAborting++;  // set before taking any locks
+  auto old_value = gAborting.fetch_add(1);  // set before taking any locks
+
+#ifdef ART_TARGET_ANDROID
+  if (old_value == 0) {
+    // Only set the first abort message.
+    android_set_abort_message(msg);
+  }
+#else
+  UNUSED(old_value);
+#endif
 
   // Ensure that we don't have multiple threads trying to abort at once,
   // which would result in significantly worse diagnostics.
@@ -570,7 +579,7 @@
 bool Runtime::ParseOptions(const RuntimeOptions& raw_options,
                            bool ignore_unrecognized,
                            RuntimeArgumentMap* runtime_options) {
-  InitLogging(/* argv */ nullptr, Aborter);  // Calls Locks::Init() as a side effect.
+  InitLogging(/* argv */ nullptr, Abort);  // Calls Locks::Init() as a side effect.
   bool parsed = ParsedOptions::Parse(raw_options, ignore_unrecognized, runtime_options);
   if (!parsed) {
     LOG(ERROR) << "Failed to parse options";
@@ -2358,14 +2367,6 @@
   }
 }
 
-NO_RETURN
-void Runtime::Aborter(const char* abort_message) {
-#ifdef ART_TARGET_ANDROID
-  android_set_abort_message(abort_message);
-#endif
-  Runtime::Abort(abort_message);
-}
-
 RuntimeCallbacks* Runtime::GetRuntimeCallbacks() {
   return callbacks_.get();
 }
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 2505d87..af9d215 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -649,9 +649,6 @@
     return cha_;
   }
 
-  NO_RETURN
-  static void Aborter(const char* abort_message);
-
   void AttachAgent(const std::string& agent_arg);
 
   const std::list<ti::Agent>& GetAgents() const {