ART: Move read barrier config out of globals

Reduce the global dependencies by refactoring where the read
barrier constants are defined.

Rename read_barier_c.h to read_barier_config.h and ifdef the
C++ parts to have a common header for both C/asm and C++.

Put heap poisoning configuration into its own minimal header.

Fix up transitive includes.

Test: m
Change-Id: I159669ec61e3d1c4c7ddcd79e63b023a0519717a
diff --git a/cmdline/cmdline_types.h b/cmdline/cmdline_types.h
index 20c4a7e..521156a 100644
--- a/cmdline/cmdline_types.h
+++ b/cmdline/cmdline_types.h
@@ -36,6 +36,7 @@
 #include "jdwp/jdwp.h"
 #include "jit/profile_saver_options.h"
 #include "plugin.h"
+#include "read_barrier_config.h"
 #include "ti/agent.h"
 #include "unit.h"
 
diff --git a/compiler/jni/jni_cfi_test.cc b/compiler/jni/jni_cfi_test.cc
index b552a6e..347f4ea 100644
--- a/compiler/jni/jni_cfi_test.cc
+++ b/compiler/jni/jni_cfi_test.cc
@@ -23,6 +23,7 @@
 #include "cfi_test.h"
 #include "gtest/gtest.h"
 #include "jni/quick/calling_convention.h"
+#include "read_barrier_config.h"
 #include "utils/assembler.h"
 #include "utils/jni_macro_assembler.h"
 
diff --git a/compiler/optimizing/optimizing_cfi_test.cc b/compiler/optimizing/optimizing_cfi_test.cc
index c24f1de..99d5284 100644
--- a/compiler/optimizing/optimizing_cfi_test.cc
+++ b/compiler/optimizing/optimizing_cfi_test.cc
@@ -23,6 +23,7 @@
 #include "gtest/gtest.h"
 #include "optimizing/code_generator.h"
 #include "optimizing/optimizing_unit_test.h"
+#include "read_barrier_config.h"
 #include "utils/arm/assembler_arm_vixl.h"
 #include "utils/assembler.h"
 #include "utils/mips/assembler_mips.h"
diff --git a/runtime/asm_support.h b/runtime/asm_support.h
index f4830e2..a4e3459 100644
--- a/runtime/asm_support.h
+++ b/runtime/asm_support.h
@@ -17,7 +17,8 @@
 #ifndef ART_RUNTIME_ASM_SUPPORT_H_
 #define ART_RUNTIME_ASM_SUPPORT_H_
 
-#include "read_barrier_c.h"
+#include "heap_poisoning.h"
+#include "read_barrier_config.h"
 
 #if defined(__arm__) || defined(__mips__)
 // In quick code for ARM and MIPS we make poor use of registers and perform frequent suspend
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 1534fd6..d673b4a 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -37,6 +37,7 @@
 #include "obj_ptr.h"
 #include "offsets.h"
 #include "process_state.h"
+#include "read_barrier_config.h"
 #include "safe_map.h"
 #include "verify_object.h"
 
diff --git a/runtime/gc_root.h b/runtime/gc_root.h
index 0894e9b..986e28e 100644
--- a/runtime/gc_root.h
+++ b/runtime/gc_root.h
@@ -20,6 +20,7 @@
 #include "base/macros.h"
 #include "base/mutex.h"       // For Locks::mutator_lock_.
 #include "mirror/object_reference.h"
+#include "read_barrier_option.h"
 
 namespace art {
 class ArtField;
diff --git a/runtime/globals.h b/runtime/globals.h
index 256306d..f0227f3 100644
--- a/runtime/globals.h
+++ b/runtime/globals.h
@@ -19,8 +19,8 @@
 
 #include <stddef.h>
 #include <stdint.h>
-#include "read_barrier_c.h"
-#include "read_barrier_option.h"
+
+#include "heap_poisoning.h"
 
 namespace art {
 
@@ -109,45 +109,6 @@
 // code, if possible.
 static constexpr bool kEmbedClassInCode = true;
 
-#ifdef USE_BAKER_READ_BARRIER
-static constexpr bool kUseBakerReadBarrier = true;
-#else
-static constexpr bool kUseBakerReadBarrier = false;
-#endif
-
-#ifdef USE_BROOKS_READ_BARRIER
-static constexpr bool kUseBrooksReadBarrier = true;
-#else
-static constexpr bool kUseBrooksReadBarrier = false;
-#endif
-
-#ifdef USE_TABLE_LOOKUP_READ_BARRIER
-static constexpr bool kUseTableLookupReadBarrier = true;
-#else
-static constexpr bool kUseTableLookupReadBarrier = false;
-#endif
-
-static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier;
-static constexpr bool kUseReadBarrier =
-    kUseBakerReadBarrier || kUseBrooksReadBarrier || kUseTableLookupReadBarrier;
-
-// Debugging flag that forces the generation of read barriers, but
-// does not trigger the use of the concurrent copying GC.
-//
-// TODO: Remove this flag when the read barriers compiler
-// instrumentation is completed.
-static constexpr bool kForceReadBarrier = false;
-// TODO: Likewise, remove this flag when kForceReadBarrier is removed
-// and replace it with kUseReadBarrier.
-static constexpr bool kEmitCompilerReadBarrier = kForceReadBarrier || kUseReadBarrier;
-
-// If true, references within the heap are poisoned (negated).
-#ifdef USE_HEAP_POISONING
-static constexpr bool kPoisonHeapReferences = true;
-#else
-static constexpr bool kPoisonHeapReferences = false;
-#endif
-
 // If true, enable the tlab allocator by default.
 #ifdef ART_USE_TLAB
 static constexpr bool kUseTlab = true;
diff --git a/runtime/heap_poisoning.h b/runtime/heap_poisoning.h
new file mode 100644
index 0000000..5e6b635
--- /dev/null
+++ b/runtime/heap_poisoning.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 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_HEAP_POISONING_H_
+#define ART_RUNTIME_HEAP_POISONING_H_
+
+// This is a C and C++ header used for both assembly code and mainline code.
+
+#ifdef ART_HEAP_POISONING
+#define USE_HEAP_POISONING
+#endif
+
+#ifdef __cplusplus
+
+namespace art {
+
+// If true, references within the heap are poisoned (negated).
+#ifdef USE_HEAP_POISONING
+static constexpr bool kPoisonHeapReferences = true;
+#else
+static constexpr bool kPoisonHeapReferences = false;
+#endif
+
+}  // namespace art
+
+#endif  // __cplusplus
+
+#endif  // ART_RUNTIME_HEAP_POISONING_H_
diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h
index aedcd66..25b86a5 100644
--- a/runtime/mirror/object.h
+++ b/runtime/mirror/object.h
@@ -24,6 +24,8 @@
 #include "obj_ptr.h"
 #include "object_reference.h"
 #include "offsets.h"
+#include "read_barrier_config.h"
+#include "read_barrier_option.h"
 #include "verify_object.h"
 
 namespace art {
diff --git a/runtime/read_barrier.h b/runtime/read_barrier.h
index 8a106aa..45e78bc 100644
--- a/runtime/read_barrier.h
+++ b/runtime/read_barrier.h
@@ -24,10 +24,7 @@
 #include "jni.h"
 #include "mirror/object_reference.h"
 #include "offsets.h"
-#include "read_barrier_c.h"
-
-// This is a C++ (not C) header file, separate from read_barrier_c.h
-// which needs to be a C header file for asm_support.h.
+#include "read_barrier_config.h"
 
 namespace art {
 namespace mirror {
diff --git a/runtime/read_barrier_c.h b/runtime/read_barrier_c.h
deleted file mode 100644
index 8e5b187..0000000
--- a/runtime/read_barrier_c.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2014 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_READ_BARRIER_C_H_
-#define ART_RUNTIME_READ_BARRIER_C_H_
-
-// This is a C (not C++) header file and is in a separate file (from
-// globals.h) because asm_support.h is a C header file and can't
-// include globals.h.
-
-// Uncomment one of the following two and the two fields in
-// Object.java (libcore) to enable baker, brooks (unimplemented), or
-// table-lookup read barriers.
-
-#ifdef ART_USE_READ_BARRIER
-#if ART_READ_BARRIER_TYPE_IS_BAKER
-#define USE_BAKER_READ_BARRIER
-#elif ART_READ_BARRIER_TYPE_IS_BROOKS
-#define USE_BROOKS_READ_BARRIER
-#elif ART_READ_BARRIER_TYPE_IS_TABLELOOKUP
-#define USE_TABLE_LOOKUP_READ_BARRIER
-#else
-#error "ART read barrier type must be set"
-#endif
-#endif  // ART_USE_READ_BARRIER
-
-#ifdef ART_HEAP_POISONING
-#define USE_HEAP_POISONING
-#endif
-
-#if defined(USE_BAKER_READ_BARRIER) || defined(USE_BROOKS_READ_BARRIER)
-#define USE_BAKER_OR_BROOKS_READ_BARRIER
-#endif
-
-#if defined(USE_BAKER_READ_BARRIER) || defined(USE_BROOKS_READ_BARRIER) || defined(USE_TABLE_LOOKUP_READ_BARRIER)
-#define USE_READ_BARRIER
-#endif
-
-#if defined(USE_BAKER_READ_BARRIER) && defined(USE_BROOKS_READ_BARRIER)
-#error "Only one of Baker or Brooks can be enabled at a time."
-#endif
-
-#endif  // ART_RUNTIME_READ_BARRIER_C_H_
diff --git a/runtime/read_barrier_config.h b/runtime/read_barrier_config.h
new file mode 100644
index 0000000..7067f9b
--- /dev/null
+++ b/runtime/read_barrier_config.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2014 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_READ_BARRIER_CONFIG_H_
+#define ART_RUNTIME_READ_BARRIER_CONFIG_H_
+
+// This is a mixed C-C++ header file that has a global section at the start
+// and a C++ section at the end, because asm_support.h is a C header file and
+// cannot include any C++ syntax.
+
+// Global (C) part.
+
+// Uncomment one of the following two and the two fields in
+// Object.java (libcore) to enable baker, brooks (unimplemented), or
+// table-lookup read barriers.
+
+#ifdef ART_USE_READ_BARRIER
+#if ART_READ_BARRIER_TYPE_IS_BAKER
+#define USE_BAKER_READ_BARRIER
+#elif ART_READ_BARRIER_TYPE_IS_BROOKS
+#define USE_BROOKS_READ_BARRIER
+#elif ART_READ_BARRIER_TYPE_IS_TABLELOOKUP
+#define USE_TABLE_LOOKUP_READ_BARRIER
+#else
+#error "ART read barrier type must be set"
+#endif
+#endif  // ART_USE_READ_BARRIER
+
+#if defined(USE_BAKER_READ_BARRIER) || defined(USE_BROOKS_READ_BARRIER)
+#define USE_BAKER_OR_BROOKS_READ_BARRIER
+#endif
+
+#if defined(USE_BAKER_READ_BARRIER) || defined(USE_BROOKS_READ_BARRIER) || defined(USE_TABLE_LOOKUP_READ_BARRIER)
+#define USE_READ_BARRIER
+#endif
+
+#if defined(USE_BAKER_READ_BARRIER) && defined(USE_BROOKS_READ_BARRIER)
+#error "Only one of Baker or Brooks can be enabled at a time."
+#endif
+
+
+// C++-specific configuration part..
+
+#ifdef __cplusplus
+
+namespace art {
+
+#ifdef USE_BAKER_READ_BARRIER
+static constexpr bool kUseBakerReadBarrier = true;
+#else
+static constexpr bool kUseBakerReadBarrier = false;
+#endif
+
+#ifdef USE_BROOKS_READ_BARRIER
+static constexpr bool kUseBrooksReadBarrier = true;
+#else
+static constexpr bool kUseBrooksReadBarrier = false;
+#endif
+
+#ifdef USE_TABLE_LOOKUP_READ_BARRIER
+static constexpr bool kUseTableLookupReadBarrier = true;
+#else
+static constexpr bool kUseTableLookupReadBarrier = false;
+#endif
+
+static constexpr bool kUseBakerOrBrooksReadBarrier = kUseBakerReadBarrier || kUseBrooksReadBarrier;
+static constexpr bool kUseReadBarrier =
+    kUseBakerReadBarrier || kUseBrooksReadBarrier || kUseTableLookupReadBarrier;
+
+// Debugging flag that forces the generation of read barriers, but
+// does not trigger the use of the concurrent copying GC.
+//
+// TODO: Remove this flag when the read barriers compiler
+// instrumentation is completed.
+static constexpr bool kForceReadBarrier = false;
+// TODO: Likewise, remove this flag when kForceReadBarrier is removed
+// and replace it with kUseReadBarrier.
+static constexpr bool kEmitCompilerReadBarrier = kForceReadBarrier || kUseReadBarrier;
+
+}  // namespace art
+
+#endif  // __cplusplus
+
+#endif  // ART_RUNTIME_READ_BARRIER_CONFIG_H_
diff --git a/runtime/thread.h b/runtime/thread.h
index ad4506e..94c0af2 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -40,6 +40,7 @@
 #include "jvalue.h"
 #include "managed_stack.h"
 #include "offsets.h"
+#include "read_barrier_config.h"
 #include "runtime_stats.h"
 #include "suspend_reason.h"
 #include "thread_state.h"