ART: Move runtime-debug flags to own files

To reduce the need for base/logging.h and separate out concerns.

Test: m
Change-Id: Ib373357325c6e622f608ada341594c3bea2fce2e
diff --git a/runtime/Android.bp b/runtime/Android.bp
index a136ccb..6477347 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -39,6 +39,7 @@
         "base/hex_dump.cc",
         "base/logging.cc",
         "base/mutex.cc",
+        "base/runtime_debug.cc",
         "base/safe_copy.cc",
         "base/scoped_arena_allocator.cc",
         "base/scoped_flock.cc",
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 4718150..2c23c99 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -25,8 +25,8 @@
 #include "base/casts.h"
 #include "base/enums.h"
 #include "base/iteration_range.h"
-#include "base/logging.h"  // For RUNTIME_DEBUG_FLAG.
 #include "base/macros.h"
+#include "base/runtime_debug.h"
 #include "dex_file.h"
 #include "dex_instruction_iterator.h"
 #include "gc_root.h"
diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc
index 4776357..26106ee 100644
--- a/runtime/base/logging.cc
+++ b/runtime/base/logging.cc
@@ -34,55 +34,6 @@
 
 namespace art {
 
-// We test here that the runtime-debug-checks are actually a no-op constexpr false in release
-// builds, as we can't check that in gtests (which are always debug).
-
-#ifdef NDEBUG
-namespace {
-DECLARE_RUNTIME_DEBUG_FLAG(kTestForConstexpr);
-static_assert(!kTestForConstexpr, "Issue with DECLARE_RUNTIME_DEBUG_FLAG in NDEBUG.");
-}
-#endif
-
-// Implementation of runtime debug flags. This should be compile-time optimized away in release
-// builds.
-namespace {
-bool gSlowEnabled = false;  // Default for slow flags is "off."
-
-// Use a function with a static to ensure our vector storage doesn't have initialization order
-// issues.
-std::vector<bool*>& GetFlagPtrs() {
-  static std::vector<bool*> g_flag_ptrs;
-  return g_flag_ptrs;
-}
-
-bool RegisterRuntimeDebugFlagImpl(bool* flag_ptr) {
-  GetFlagPtrs().push_back(flag_ptr);
-  return gSlowEnabled;
-}
-
-void SetRuntimeDebugFlagsEnabledImpl(bool enabled) {
-  gSlowEnabled = enabled;
-  for (bool* flag_ptr : GetFlagPtrs()) {
-    *flag_ptr = enabled;
-  }
-}
-
-}  // namespace
-
-bool RegisterRuntimeDebugFlag(bool* flag_ptr) {
-  if (kIsDebugBuild) {
-    return RegisterRuntimeDebugFlagImpl(flag_ptr);
-  }
-  return false;
-}
-
-void SetRuntimeDebugFlagsEnabled(bool enabled) {
-  if (kIsDebugBuild) {
-    SetRuntimeDebugFlagsEnabledImpl(enabled);
-  }
-}
-
 LogVerbosity gLogVerbosity;
 
 std::atomic<unsigned int> gAborting(0);
diff --git a/runtime/base/logging.h b/runtime/base/logging.h
index 5703b3c..981fbbf 100644
--- a/runtime/base/logging.h
+++ b/runtime/base/logging.h
@@ -63,43 +63,6 @@
 // Global log verbosity setting, initialized by InitLogging.
 extern LogVerbosity gLogVerbosity;
 
-// Runtime debug flags are flags that have a runtime component, that is, their value can be changed.
-// This is meant to implement fast vs slow debug builds, in that certain debug flags can be turned
-// on and off. To that effect, expose two macros to help implement and globally drive these flags:
-//
-// In the header, declare a (class) flag like this:
-//
-//   class C {
-//     DECLARE_RUNTIME_DEBUG_FLAG(kFlag);
-//   };
-//
-// This will declare a flag kFlag that is a constexpr false in release builds, and a static field
-// in debug builds. Usage is than uniform as C::kFlag.
-//
-// In the cc file, define the flag like this:
-//
-//   DEFINE_RUNTIME_DEBUG_FLAG(C, kFlag);
-//
-// This will define the static storage, as necessary, and register the flag with the runtime
-// infrastructure to toggle the value.
-
-#ifdef NDEBUG
-#define DECLARE_RUNTIME_DEBUG_FLAG(x) \
-  static constexpr bool x = false;
-// Note: the static_assert in the following only works for public flags. Fix this when we cross
-//       the line at some point.
-#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \
-  static_assert(!C::x, "Unexpected enabled flag in release build");
-#else
-#define DECLARE_RUNTIME_DEBUG_FLAG(x) \
-  static bool x;
-#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \
-  bool C::x = RegisterRuntimeDebugFlag(&C::x);
-#endif  // NDEBUG
-
-bool RegisterRuntimeDebugFlag(bool* runtime_debug_flag);
-void SetRuntimeDebugFlagsEnabled(bool enabled);
-
 // 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.
diff --git a/runtime/base/logging_test.cc b/runtime/base/logging_test.cc
index d380b9e..404e080 100644
--- a/runtime/base/logging_test.cc
+++ b/runtime/base/logging_test.cc
@@ -22,6 +22,7 @@
 #include "base/bit_utils.h"
 #include "base/macros.h"
 #include "common_runtime_test.h"
+#include "runtime_debug.h"
 
 namespace art {
 
diff --git a/runtime/base/runtime_debug.cc b/runtime/base/runtime_debug.cc
new file mode 100644
index 0000000..4f8a8ec
--- /dev/null
+++ b/runtime/base/runtime_debug.cc
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "runtime_debug.h"
+
+#include <vector>
+
+#include "globals.h"
+
+namespace art {
+
+// We test here that the runtime-debug-checks are actually a no-op constexpr false in release
+// builds, as we can't check that in gtests (which are always debug).
+
+#ifdef NDEBUG
+namespace {
+DECLARE_RUNTIME_DEBUG_FLAG(kTestForConstexpr);
+static_assert(!kTestForConstexpr, "Issue with DECLARE_RUNTIME_DEBUG_FLAG in NDEBUG.");
+}
+#endif
+
+// Implementation of runtime debug flags. This should be compile-time optimized away in release
+// builds.
+namespace {
+bool gSlowEnabled = false;  // Default for slow flags is "off."
+
+// Use a function with a static to ensure our vector storage doesn't have initialization order
+// issues.
+std::vector<bool*>& GetFlagPtrs() {
+  static std::vector<bool*> g_flag_ptrs;
+  return g_flag_ptrs;
+}
+
+bool RegisterRuntimeDebugFlagImpl(bool* flag_ptr) {
+  GetFlagPtrs().push_back(flag_ptr);
+  return gSlowEnabled;
+}
+
+void SetRuntimeDebugFlagsEnabledImpl(bool enabled) {
+  gSlowEnabled = enabled;
+  for (bool* flag_ptr : GetFlagPtrs()) {
+    *flag_ptr = enabled;
+  }
+}
+
+}  // namespace
+
+bool RegisterRuntimeDebugFlag(bool* flag_ptr) {
+  if (kIsDebugBuild) {
+    return RegisterRuntimeDebugFlagImpl(flag_ptr);
+  }
+  return false;
+}
+
+void SetRuntimeDebugFlagsEnabled(bool enabled) {
+  if (kIsDebugBuild) {
+    SetRuntimeDebugFlagsEnabledImpl(enabled);
+  }
+}
+
+}  // namespace art
diff --git a/runtime/base/runtime_debug.h b/runtime/base/runtime_debug.h
new file mode 100644
index 0000000..89a0361
--- /dev/null
+++ b/runtime/base/runtime_debug.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_BASE_RUNTIME_DEBUG_H_
+#define ART_RUNTIME_BASE_RUNTIME_DEBUG_H_
+
+namespace art {
+
+// Runtime debug flags are flags that have a runtime component, that is, their value can be changed.
+// This is meant to implement fast vs slow debug builds, in that certain debug flags can be turned
+// on and off. To that effect, expose two macros to help implement and globally drive these flags:
+//
+// In the header, declare a (class) flag like this:
+//
+//   class C {
+//     DECLARE_RUNTIME_DEBUG_FLAG(kFlag);
+//   };
+//
+// This will declare a flag kFlag that is a constexpr false in release builds, and a static field
+// in debug builds. Usage is than uniform as C::kFlag.
+//
+// In the cc file, define the flag like this:
+//
+//   DEFINE_RUNTIME_DEBUG_FLAG(C, kFlag);
+//
+// This will define the static storage, as necessary, and register the flag with the runtime
+// infrastructure to toggle the value.
+
+#ifdef NDEBUG
+#define DECLARE_RUNTIME_DEBUG_FLAG(x) \
+  static constexpr bool x = false;
+// Note: the static_assert in the following only works for public flags. Fix this when we cross
+//       the line at some point.
+#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \
+  static_assert(!C::x, "Unexpected enabled flag in release build");
+#else
+#define DECLARE_RUNTIME_DEBUG_FLAG(x) \
+  static bool x;
+#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \
+  bool C::x = RegisterRuntimeDebugFlag(&C::x);
+#endif  // NDEBUG
+
+bool RegisterRuntimeDebugFlag(bool* runtime_debug_flag);
+void SetRuntimeDebugFlagsEnabled(bool enabled);
+
+}  // namespace art
+
+#endif  // ART_RUNTIME_BASE_RUNTIME_DEBUG_H_
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index ef1647c..6db4d92 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -30,6 +30,7 @@
 #include "base/file_utils.h"
 #include "base/logging.h"
 #include "base/macros.h"
+#include "base/runtime_debug.h"
 #include "base/stl_util.h"
 #include "base/unix_file/fd_file.h"
 #include "class_linker.h"
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 10bae71..bb21b7c 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -27,9 +27,9 @@
 #include "allocator_type.h"
 #include "arch/instruction_set.h"
 #include "atomic.h"
-#include "base/logging.h"  // For DECLARE_RUNTIME_DEBUG_FLAG.
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/runtime_debug.h"
 #include "base/time_utils.h"
 #include "gc/collector/gc_type.h"
 #include "gc/collector/iteration.h"
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index a6aa916..783d05d 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -22,6 +22,7 @@
 #include "base/enums.h"
 #include "base/logging.h"  // For VLOG.
 #include "base/memory_tool.h"
+#include "base/runtime_debug.h"
 #include "debugger.h"
 #include "entrypoints/runtime_asm_entrypoints.h"
 #include "interpreter/interpreter.h"
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index bdbb80b..fd80aae 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -25,6 +25,7 @@
 #include "art_method-inl.h"
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/runtime_debug.h"
 #include "debugger.h"
 #include "java_vm_ext.h"
 #include "jit/jit.h"
diff --git a/runtime/native_stack_dump.cc b/runtime/native_stack_dump.cc
index f166714..841506b 100644
--- a/runtime/native_stack_dump.cc
+++ b/runtime/native_stack_dump.cc
@@ -41,6 +41,7 @@
 
 #include "arch/instruction_set.h"
 #include "base/file_utils.h"
+#include "base/logging.h"  // For gAborting.
 #include "base/memory_tool.h"
 #include "base/mutex.h"
 #include "base/unix_file/fd_file.h"
diff --git a/runtime/read_barrier.h b/runtime/read_barrier.h
index ce2cb0e..e8df2ad 100644
--- a/runtime/read_barrier.h
+++ b/runtime/read_barrier.h
@@ -19,9 +19,9 @@
 
 #include <android-base/logging.h>
 
-#include "base/logging.h"  // For DECLARE_RUNTIME_DEBUG_FLAG.
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/runtime_debug.h"
 #include "gc_root.h"
 #include "jni.h"
 #include "mirror/object_reference.h"
diff --git a/runtime/thread-inl.h b/runtime/thread-inl.h
index b5a9626..9d08531 100644
--- a/runtime/thread-inl.h
+++ b/runtime/thread-inl.h
@@ -20,6 +20,7 @@
 #include "thread.h"
 
 #include "base/casts.h"
+#include "base/logging.h"  // For gAborting.
 #include "base/mutex-inl.h"
 #include "base/time_utils.h"
 #include "jni_env_ext.h"