Header library to remove dependence on runtime/

Add a new header library to remove libdexfile and others' dependence on
runtime (typically runtime/base) includes in libdexfile.  Also a small step
to tease dexlayout and profman away from relying on these as well.

Bug: 22322814
Test: make -j 50 checkbuild
      make -j 50 test-art-host-gtest

Change-Id: I38e2fe399a75f4bc6318c77a71954c00ea73ec2b
diff --git a/Android.bp b/Android.bp
index bfd86ed..e09b774 100644
--- a/Android.bp
+++ b/Android.bp
@@ -35,6 +35,7 @@
     "dt_fd_forward",
     "dt_fd_forward/export",
     "imgdiag",
+    "libartbase",
     "libdexfile",
     "oatdump",
     "openjdkjvm",
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 6ad4eec..e171289 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -339,6 +339,7 @@
     art_dexoptanalyzer_tests \
     art_hiddenapi_tests \
     art_imgdiag_tests \
+    art_libartbase_tests \
     art_libdexfile_tests \
     art_oatdump_tests \
     art_patchoat_tests \
diff --git a/compiler/debug/dwarf/debug_abbrev_writer.h b/compiler/debug/dwarf/debug_abbrev_writer.h
index 0fc843c..cccca25 100644
--- a/compiler/debug/dwarf/debug_abbrev_writer.h
+++ b/compiler/debug/dwarf/debug_abbrev_writer.h
@@ -22,10 +22,10 @@
 #include <unordered_map>
 
 #include "base/casts.h"
+#include "base/leb128.h"
 #include "base/stl_util.h"
 #include "debug/dwarf/dwarf_constants.h"
 #include "debug/dwarf/writer.h"
-#include "leb128.h"
 
 namespace art {
 namespace dwarf {
diff --git a/compiler/debug/dwarf/debug_info_entry_writer.h b/compiler/debug/dwarf/debug_info_entry_writer.h
index 85f021e..89d16f2 100644
--- a/compiler/debug/dwarf/debug_info_entry_writer.h
+++ b/compiler/debug/dwarf/debug_info_entry_writer.h
@@ -21,11 +21,11 @@
 #include <unordered_map>
 
 #include "base/casts.h"
+#include "base/leb128.h"
 #include "debug/dwarf/debug_abbrev_writer.h"
 #include "debug/dwarf/dwarf_constants.h"
 #include "debug/dwarf/expression.h"
 #include "debug/dwarf/writer.h"
-#include "leb128.h"
 
 namespace art {
 namespace dwarf {
diff --git a/compiler/debug/dwarf/writer.h b/compiler/debug/dwarf/writer.h
index afeb980..c09d97a 100644
--- a/compiler/debug/dwarf/writer.h
+++ b/compiler/debug/dwarf/writer.h
@@ -23,7 +23,7 @@
 #include <android-base/logging.h>
 
 #include "base/bit_utils.h"
-#include "leb128.h"
+#include "base/leb128.h"
 
 namespace art {
 namespace dwarf {
diff --git a/compiler/dex/verification_results.h b/compiler/dex/verification_results.h
index d19e993..9e4192a 100644
--- a/compiler/dex/verification_results.h
+++ b/compiler/dex/verification_results.h
@@ -23,9 +23,9 @@
 #include "base/dchecked_vector.h"
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "class_reference.h"
 #include "method_reference.h"
-#include "safe_map.h"
 #include "utils/atomic_dex_ref_map.h"
 
 namespace art {
diff --git a/compiler/dex/verified_method.h b/compiler/dex/verified_method.h
index 2ed17f1..ecbeed3 100644
--- a/compiler/dex/verified_method.h
+++ b/compiler/dex/verified_method.h
@@ -20,9 +20,9 @@
 #include <vector>
 
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "dex/dex_file.h"
 #include "method_reference.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 2b524a3..a3bb4ec 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -29,6 +29,7 @@
 #include "base/array_ref.h"
 #include "base/bit_utils.h"
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "base/timing_logger.h"
 #include "class_reference.h"
 #include "class_status.h"
@@ -39,7 +40,6 @@
 #include "driver/compiled_method_storage.h"
 #include "method_reference.h"
 #include "os.h"
-#include "safe_map.h"
 #include "thread_pool.h"
 #include "utils/atomic_dex_ref_map.h"
 #include "utils/dex_cache_arrays_layout.h"
diff --git a/compiler/exception_test.cc b/compiler/exception_test.cc
index f00fe63..f582341 100644
--- a/compiler/exception_test.cc
+++ b/compiler/exception_test.cc
@@ -19,6 +19,7 @@
 #include "base/arena_allocator.h"
 #include "base/callee_save_type.h"
 #include "base/enums.h"
+#include "base/leb128.h"
 #include "class_linker.h"
 #include "common_runtime_test.h"
 #include "dex/code_item_accessors-inl.h"
@@ -27,7 +28,6 @@
 #include "dex/dex_file_exception_helpers.h"
 #include "gtest/gtest.h"
 #include "handle_scope-inl.h"
-#include "leb128.h"
 #include "mirror/class-inl.h"
 #include "mirror/object-inl.h"
 #include "mirror/object_array-inl.h"
diff --git a/compiler/jni/quick/calling_convention.h b/compiler/jni/quick/calling_convention.h
index be0bd72..e256ce6 100644
--- a/compiler/jni/quick/calling_convention.h
+++ b/compiler/jni/quick/calling_convention.h
@@ -20,8 +20,8 @@
 #include "base/arena_object.h"
 #include "base/array_ref.h"
 #include "base/enums.h"
+#include "dex/primitive.h"
 #include "handle_scope.h"
-#include "primitive.h"
 #include "thread.h"
 #include "utils/managed_register.h"
 
diff --git a/compiler/linker/arm/relative_patcher_arm_base.h b/compiler/linker/arm/relative_patcher_arm_base.h
index 4c2be1e..b0064d1 100644
--- a/compiler/linker/arm/relative_patcher_arm_base.h
+++ b/compiler/linker/arm/relative_patcher_arm_base.h
@@ -20,9 +20,9 @@
 #include <deque>
 #include <vector>
 
+#include "base/safe_map.h"
 #include "linker/relative_patcher.h"
 #include "method_reference.h"
-#include "safe_map.h"
 
 namespace art {
 namespace linker {
diff --git a/compiler/linker/elf_builder.h b/compiler/linker/elf_builder.h
index 9fb4b18..a5f6099 100644
--- a/compiler/linker/elf_builder.h
+++ b/compiler/linker/elf_builder.h
@@ -24,9 +24,9 @@
 #include "base/array_ref.h"
 #include "base/bit_utils.h"
 #include "base/casts.h"
+#include "base/leb128.h"
 #include "base/unix_file/fd_file.h"
 #include "elf_utils.h"
-#include "leb128.h"
 #include "linker/error_delaying_output_stream.h"
 
 namespace art {
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index 01155dc..ff59173 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -43,6 +43,7 @@
 #include "base/bit_utils.h"
 #include "base/bit_utils_iterator.h"
 #include "base/casts.h"
+#include "base/leb128.h"
 #include "bytecode_utils.h"
 #include "class_linker.h"
 #include "compiled_method.h"
@@ -52,7 +53,6 @@
 #include "graph_visualizer.h"
 #include "intern_table.h"
 #include "intrinsics.h"
-#include "leb128.h"
 #include "mirror/array-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/object_reference.h"
diff --git a/compiler/optimizing/data_type-inl.h b/compiler/optimizing/data_type-inl.h
index e2cf7a8..94807e8 100644
--- a/compiler/optimizing/data_type-inl.h
+++ b/compiler/optimizing/data_type-inl.h
@@ -18,7 +18,7 @@
 #define ART_COMPILER_OPTIMIZING_DATA_TYPE_INL_H_
 
 #include "data_type.h"
-#include "primitive.h"
+#include "dex/primitive.h"
 
 namespace art {
 
diff --git a/compiler/optimizing/data_type_test.cc b/compiler/optimizing/data_type_test.cc
index ca137b7..8fea22b 100644
--- a/compiler/optimizing/data_type_test.cc
+++ b/compiler/optimizing/data_type_test.cc
@@ -20,7 +20,7 @@
 
 #include "base/array_ref.h"
 #include "base/macros.h"
-#include "primitive.h"
+#include "dex/primitive.h"
 
 namespace art {
 
diff --git a/compiler/utils/atomic_dex_ref_map.h b/compiler/utils/atomic_dex_ref_map.h
index 3474e16..cabd79e 100644
--- a/compiler/utils/atomic_dex_ref_map.h
+++ b/compiler/utils/atomic_dex_ref_map.h
@@ -17,9 +17,10 @@
 #ifndef ART_COMPILER_UTILS_ATOMIC_DEX_REF_MAP_H_
 #define ART_COMPILER_UTILS_ATOMIC_DEX_REF_MAP_H_
 
+#include "atomic.h"
 #include "base/dchecked_vector.h"
+#include "base/safe_map.h"
 #include "dex/dex_file_reference.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 1578656..926575e 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -44,6 +44,7 @@
 #include "base/callee_save_type.h"
 #include "base/dumpable.h"
 #include "base/file_utils.h"
+#include "base/leb128.h"
 #include "base/macros.h"
 #include "base/scoped_flock.h"
 #include "base/stl_util.h"
@@ -75,7 +76,6 @@
 #include "interpreter/unstarted_runtime.h"
 #include "java_vm_ext.h"
 #include "jit/profile_compilation_info.h"
-#include "leb128.h"
 #include "linker/buffered_output_stream.h"
 #include "linker/elf_writer.h"
 #include "linker/elf_writer_quick.h"
diff --git a/dex2oat/linker/elf_writer_quick.cc b/dex2oat/linker/elf_writer_quick.cc
index 707e877..d2e863c 100644
--- a/dex2oat/linker/elf_writer_quick.cc
+++ b/dex2oat/linker/elf_writer_quick.cc
@@ -23,6 +23,7 @@
 #include <android-base/logging.h>
 
 #include "base/casts.h"
+#include "base/leb128.h"
 #include "compiled_method.h"
 #include "debug/elf_debug_writer.h"
 #include "debug/method_debug_info.h"
@@ -30,7 +31,6 @@
 #include "elf.h"
 #include "elf_utils.h"
 #include "globals.h"
-#include "leb128.h"
 #include "linker/buffered_output_stream.h"
 #include "linker/elf_builder.h"
 #include "linker/file_output_stream.h"
diff --git a/dex2oat/linker/image_writer.h b/dex2oat/linker/image_writer.h
index a7c1439..856edfb 100644
--- a/dex2oat/linker/image_writer.h
+++ b/dex2oat/linker/image_writer.h
@@ -33,6 +33,7 @@
 #include "base/enums.h"
 #include "base/length_prefixed_array.h"
 #include "base/macros.h"
+#include "base/safe_map.h"
 #include "class_table.h"
 #include "driver/compiler_driver.h"
 #include "image.h"
@@ -43,7 +44,6 @@
 #include "oat_file.h"
 #include "obj_ptr.h"
 #include "os.h"
-#include "safe_map.h"
 #include "utils.h"
 
 namespace art {
diff --git a/dex2oat/linker/multi_oat_relative_patcher.h b/dex2oat/linker/multi_oat_relative_patcher.h
index d97be8d..2413c6e 100644
--- a/dex2oat/linker/multi_oat_relative_patcher.h
+++ b/dex2oat/linker/multi_oat_relative_patcher.h
@@ -18,10 +18,10 @@
 #define ART_DEX2OAT_LINKER_MULTI_OAT_RELATIVE_PATCHER_H_
 
 #include "arch/instruction_set.h"
+#include "base/safe_map.h"
 #include "debug/method_debug_info.h"
 #include "method_reference.h"
 #include "linker/relative_patcher.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index e22936c..c980320 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -27,6 +27,7 @@
 #include "base/enums.h"
 #include "base/file_magic.h"
 #include "base/logging.h"  // For VLOG
+#include "base/safe_map.h"
 #include "base/stl_util.h"
 #include "base/unix_file/fd_file.h"
 #include "class_linker.h"
@@ -61,7 +62,6 @@
 #include "oat_quick_method_header.h"
 #include "os.h"
 #include "quicken_info.h"
-#include "safe_map.h"
 #include "scoped_thread_state_change-inl.h"
 #include "type_lookup_table.h"
 #include "utils/dex_cache_arrays_layout-inl.h"
diff --git a/dex2oat/linker/oat_writer.h b/dex2oat/linker/oat_writer.h
index 2bc56c6..d67e4de 100644
--- a/dex2oat/linker/oat_writer.h
+++ b/dex2oat/linker/oat_writer.h
@@ -24,6 +24,7 @@
 
 #include "base/array_ref.h"
 #include "base/dchecked_vector.h"
+#include "base/safe_map.h"
 #include "compiler.h"
 #include "dex/compact_dex_level.h"
 #include "debug/debug_info.h"
@@ -33,7 +34,6 @@
 #include "mirror/class.h"
 #include "oat.h"
 #include "os.h"
-#include "safe_map.h"
 #include "string_reference.h"
 #include "type_reference.h"
 
diff --git a/dexlayout/dex_ir.h b/dexlayout/dex_ir.h
index d28b824..5ecad2b 100644
--- a/dexlayout/dex_ir.h
+++ b/dexlayout/dex_ir.h
@@ -24,11 +24,11 @@
 #include <map>
 #include <vector>
 
+#include "base/leb128.h"
 #include "base/stl_util.h"
 #include "dex/dex_file-inl.h"
 #include "dex/dex_file_types.h"
 #include "dex/utf.h"
-#include "leb128.h"
 
 namespace art {
 namespace dex_ir {
diff --git a/disassembler/Android.bp b/disassembler/Android.bp
index 8849309..241b191 100644
--- a/disassembler/Android.bp
+++ b/disassembler/Android.bp
@@ -30,6 +30,9 @@
     shared_libs: [
         "libbase",
     ],
+    header_libs: [
+        "art_libartbase_headers",
+    ],
     export_include_dirs: ["."],
 }
 
diff --git a/libartbase/Android.bp b/libartbase/Android.bp
new file mode 100644
index 0000000..290d398
--- /dev/null
+++ b/libartbase/Android.bp
@@ -0,0 +1,39 @@
+//
+// 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.
+//
+
+art_cc_test {
+    name: "art_libartbase_tests",
+    defaults: [
+        "art_gtest_defaults",
+    ],
+    srcs: [
+        "base/bit_utils_test.cc",
+        "base/hash_set_test.cc",
+        "base/leb128_test.cc",
+    ],
+    shared_libs: [
+        "libbase",
+    ],
+}
+
+cc_library_headers {
+    name: "art_libartbase_headers",
+    host_supported: true,
+    export_include_dirs: ["."],
+    shared_libs: ["libbase"],
+    export_shared_lib_headers: ["libbase"],
+}
+
diff --git a/runtime/base/bit_utils.h b/libartbase/base/bit_utils.h
similarity index 98%
rename from runtime/base/bit_utils.h
rename to libartbase/base/bit_utils.h
index d2a99f1..ff6c160 100644
--- a/runtime/base/bit_utils.h
+++ b/libartbase/base/bit_utils.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_BIT_UTILS_H_
-#define ART_RUNTIME_BASE_BIT_UTILS_H_
+#ifndef ART_LIBARTBASE_BASE_BIT_UTILS_H_
+#define ART_LIBARTBASE_BASE_BIT_UTILS_H_
 
 #include <limits>
 #include <type_traits>
@@ -501,4 +501,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_BIT_UTILS_H_
+#endif  // ART_LIBARTBASE_BASE_BIT_UTILS_H_
diff --git a/runtime/base/bit_utils_iterator.h b/libartbase/base/bit_utils_iterator.h
similarity index 95%
rename from runtime/base/bit_utils_iterator.h
rename to libartbase/base/bit_utils_iterator.h
index 2d3d050..3fab15a 100644
--- a/runtime/base/bit_utils_iterator.h
+++ b/libartbase/base/bit_utils_iterator.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_BIT_UTILS_ITERATOR_H_
-#define ART_RUNTIME_BASE_BIT_UTILS_ITERATOR_H_
+#ifndef ART_LIBARTBASE_BASE_BIT_UTILS_ITERATOR_H_
+#define ART_LIBARTBASE_BASE_BIT_UTILS_ITERATOR_H_
 
 #include <iterator>
 #include <limits>
@@ -110,4 +110,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_BIT_UTILS_ITERATOR_H_
+#endif  // ART_LIBARTBASE_BASE_BIT_UTILS_ITERATOR_H_
diff --git a/runtime/base/bit_utils_test.cc b/libartbase/base/bit_utils_test.cc
similarity index 100%
rename from runtime/base/bit_utils_test.cc
rename to libartbase/base/bit_utils_test.cc
diff --git a/runtime/base/casts.h b/libartbase/base/casts.h
similarity index 98%
rename from runtime/base/casts.h
rename to libartbase/base/casts.h
index 3c6b2be..cbd5b67 100644
--- a/runtime/base/casts.h
+++ b/libartbase/base/casts.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_CASTS_H_
-#define ART_RUNTIME_BASE_CASTS_H_
+#ifndef ART_LIBARTBASE_BASE_CASTS_H_
+#define ART_LIBARTBASE_BASE_CASTS_H_
 
 #include <assert.h>
 #include <stdint.h>
@@ -167,4 +167,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_CASTS_H_
+#endif  // ART_LIBARTBASE_BASE_CASTS_H_
diff --git a/runtime/base/enums.h b/libartbase/base/enums.h
similarity index 71%
rename from runtime/base/enums.h
rename to libartbase/base/enums.h
index 52cab2a..ad5578f 100644
--- a/runtime/base/enums.h
+++ b/libartbase/base/enums.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_ENUMS_H_
-#define ART_RUNTIME_BASE_ENUMS_H_
+#ifndef ART_LIBARTBASE_BASE_ENUMS_H_
+#define ART_LIBARTBASE_BASE_ENUMS_H_
 
 #include <cstddef>
 #include <ostream>
@@ -26,7 +26,15 @@
   k32 = 4,
   k64 = 8
 };
-std::ostream& operator<<(std::ostream& os, const PointerSize& rhs);
+
+inline std::ostream& operator<<(std::ostream& os, const PointerSize& rhs) {
+  switch (rhs) {
+    case PointerSize::k32: os << "k32"; break;
+    case PointerSize::k64: os << "k64"; break;
+    default: os << "PointerSize[" << static_cast<int>(rhs) << "]"; break;
+  }
+  return os;
+}
 
 static constexpr PointerSize kRuntimePointerSize = sizeof(void*) == 8U
                                                        ? PointerSize::k64
@@ -34,4 +42,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_ENUMS_H_
+#endif  // ART_LIBARTBASE_BASE_ENUMS_H_
diff --git a/libartbase/base/globals.h b/libartbase/base/globals.h
new file mode 100644
index 0000000..69d1a64
--- /dev/null
+++ b/libartbase/base/globals.h
@@ -0,0 +1,139 @@
+/*
+ * 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_LIBARTBASE_BASE_GLOBALS_H_
+#define ART_LIBARTBASE_BASE_GLOBALS_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace art {
+
+static constexpr size_t KB = 1024;
+static constexpr size_t MB = KB * KB;
+static constexpr size_t GB = KB * KB * KB;
+
+// Runtime sizes.
+static constexpr size_t kBitsPerByte = 8;
+static constexpr size_t kBitsPerByteLog2 = 3;
+static constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte;
+
+// Required stack alignment
+static constexpr size_t kStackAlignment = 16;
+
+// System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple
+// compile-time constant so the compiler can generate better code.
+static constexpr int kPageSize = 4096;
+
+// Returns whether the given memory offset can be used for generating
+// an implicit null check.
+static inline bool CanDoImplicitNullCheckOn(uintptr_t offset) {
+  return offset < kPageSize;
+}
+
+// Required object alignment
+static constexpr size_t kObjectAlignmentShift = 3;
+static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift;
+static constexpr size_t kLargeObjectAlignment = kPageSize;
+
+// Clion, clang analyzer, etc can falsely believe that "if (kIsDebugBuild)" always
+// returns the same value. By wrapping into a call to another constexpr function, we force it
+// to realize that is not actually always evaluating to the same value.
+static constexpr bool GlobalsReturnSelf(bool self) { return self; }
+
+// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
+// TODO: Use only __clang_analyzer__ here. b/64455231
+#if defined(NDEBUG) && !defined(__CLION_IDE__)
+static constexpr bool kIsDebugBuild = GlobalsReturnSelf(false);
+#else
+static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true);
+#endif
+
+#if defined(ART_PGO_INSTRUMENTATION)
+static constexpr bool kIsPGOInstrumentation = true;
+#else
+static constexpr bool kIsPGOInstrumentation = false;
+#endif
+
+// ART_TARGET - Defined for target builds of ART.
+// ART_TARGET_LINUX - Defined for target Linux builds of ART.
+// ART_TARGET_ANDROID - Defined for target Android builds of ART.
+// Note: Either ART_TARGET_LINUX or ART_TARGET_ANDROID need to be set when ART_TARGET is set.
+// Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings
+// (usually only available on Android kernels).
+#if defined(ART_TARGET)
+// Useful in conditionals where ART_TARGET isn't.
+static constexpr bool kIsTargetBuild = true;
+# if defined(ART_TARGET_LINUX)
+static constexpr bool kIsTargetLinux = true;
+# elif defined(ART_TARGET_ANDROID)
+static constexpr bool kIsTargetLinux = false;
+# else
+# error "Either ART_TARGET_LINUX or ART_TARGET_ANDROID needs to be defined for target builds."
+# endif
+#else
+static constexpr bool kIsTargetBuild = false;
+# if defined(ART_TARGET_LINUX)
+# error "ART_TARGET_LINUX defined for host build."
+# elif defined(ART_TARGET_ANDROID)
+# error "ART_TARGET_ANDROID defined for host build."
+# else
+static constexpr bool kIsTargetLinux = false;
+# endif
+#endif
+
+// Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are
+// always available on the host
+#if !defined(ART_TARGET)
+static constexpr bool kHostStaticBuildEnabled = true;
+#else
+static constexpr bool kHostStaticBuildEnabled = false;
+#endif
+
+// Garbage collector constants.
+static constexpr bool kMovingCollector = true;
+static constexpr bool kMarkCompactSupport = false && kMovingCollector;
+// True if we allow moving classes.
+static constexpr bool kMovingClasses = !kMarkCompactSupport;
+
+// If true, enable the tlab allocator by default.
+#ifdef ART_USE_TLAB
+static constexpr bool kUseTlab = true;
+#else
+static constexpr bool kUseTlab = false;
+#endif
+
+// Kinds of tracing clocks.
+enum class TraceClockSource {
+  kThreadCpu,
+  kWall,
+  kDual,  // Both wall and thread CPU clocks.
+};
+
+#if defined(__linux__)
+static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual;
+#else
+static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall;
+#endif
+
+static constexpr bool kDefaultMustRelocate = true;
+
+// Size of a heap reference.
+static constexpr size_t kHeapReferenceSize = sizeof(uint32_t);
+
+}  // namespace art
+
+#endif  // ART_LIBARTBASE_BASE_GLOBALS_H_
diff --git a/runtime/base/hash_map.h b/libartbase/base/hash_map.h
similarity index 94%
rename from runtime/base/hash_map.h
rename to libartbase/base/hash_map.h
index b18d586..0d7198c 100644
--- a/runtime/base/hash_map.h
+++ b/libartbase/base/hash_map.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_HASH_MAP_H_
-#define ART_RUNTIME_BASE_HASH_MAP_H_
+#ifndef ART_LIBARTBASE_BASE_HASH_MAP_H_
+#define ART_LIBARTBASE_BASE_HASH_MAP_H_
 
 #include <utility>
 
@@ -71,4 +71,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_HASH_MAP_H_
+#endif  // ART_LIBARTBASE_BASE_HASH_MAP_H_
diff --git a/runtime/base/hash_set.h b/libartbase/base/hash_set.h
similarity index 99%
rename from runtime/base/hash_set.h
rename to libartbase/base/hash_set.h
index 47e6d93..2f810ea 100644
--- a/runtime/base/hash_set.h
+++ b/libartbase/base/hash_set.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_HASH_SET_H_
-#define ART_RUNTIME_BASE_HASH_SET_H_
+#ifndef ART_LIBARTBASE_BASE_HASH_SET_H_
+#define ART_LIBARTBASE_BASE_HASH_SET_H_
 
 #include <stdint.h>
 
@@ -690,4 +690,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_HASH_SET_H_
+#endif  // ART_LIBARTBASE_BASE_HASH_SET_H_
diff --git a/runtime/base/hash_set_test.cc b/libartbase/base/hash_set_test.cc
similarity index 100%
rename from runtime/base/hash_set_test.cc
rename to libartbase/base/hash_set_test.cc
diff --git a/runtime/base/iteration_range.h b/libartbase/base/iteration_range.h
similarity index 93%
rename from runtime/base/iteration_range.h
rename to libartbase/base/iteration_range.h
index 3f6f5d6..76049a7 100644
--- a/runtime/base/iteration_range.h
+++ b/libartbase/base/iteration_range.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_ITERATION_RANGE_H_
-#define ART_RUNTIME_BASE_ITERATION_RANGE_H_
+#ifndef ART_LIBARTBASE_BASE_ITERATION_RANGE_H_
+#define ART_LIBARTBASE_BASE_ITERATION_RANGE_H_
 
 #include <iterator>
 
@@ -67,4 +67,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_ITERATION_RANGE_H_
+#endif  // ART_LIBARTBASE_BASE_ITERATION_RANGE_H_
diff --git a/runtime/leb128.h b/libartbase/base/leb128.h
similarity index 98%
rename from runtime/leb128.h
rename to libartbase/base/leb128.h
index 07eadc1..ab19daa 100644
--- a/runtime/leb128.h
+++ b/libartbase/base/leb128.h
@@ -14,16 +14,16 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_LEB128_H_
-#define ART_RUNTIME_LEB128_H_
+#ifndef ART_LIBARTBASE_BASE_LEB128_H_
+#define ART_LIBARTBASE_BASE_LEB128_H_
 
 #include <vector>
 
 #include <android-base/logging.h>
 
 #include "base/bit_utils.h"
+#include "base/globals.h"
 #include "base/macros.h"
-#include "globals.h"
 
 namespace art {
 
@@ -374,4 +374,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_LEB128_H_
+#endif  // ART_LIBARTBASE_BASE_LEB128_H_
diff --git a/runtime/leb128_test.cc b/libartbase/base/leb128_test.cc
similarity index 100%
rename from runtime/leb128_test.cc
rename to libartbase/base/leb128_test.cc
diff --git a/runtime/base/macros.h b/libartbase/base/macros.h
similarity index 96%
rename from runtime/base/macros.h
rename to libartbase/base/macros.h
index 512e5ce..6dd981d 100644
--- a/runtime/base/macros.h
+++ b/libartbase/base/macros.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_MACROS_H_
-#define ART_RUNTIME_BASE_MACROS_H_
+#ifndef ART_LIBARTBASE_BASE_MACROS_H_
+#define ART_LIBARTBASE_BASE_MACROS_H_
 
 #include <stddef.h>  // for size_t
 #include <unistd.h>  // for TEMP_FAILURE_RETRY
@@ -98,4 +98,4 @@
 #define LOCKABLE CAPABILITY("mutex")
 #define SHARED_LOCKABLE SHARED_CAPABILITY("mutex")
 
-#endif  // ART_RUNTIME_BASE_MACROS_H_
+#endif  // ART_LIBARTBASE_BASE_MACROS_H_
diff --git a/runtime/base/memory_tool.h b/libartbase/base/memory_tool.h
similarity index 94%
rename from runtime/base/memory_tool.h
rename to libartbase/base/memory_tool.h
index 223c1de..e1df99f 100644
--- a/runtime/base/memory_tool.h
+++ b/libartbase/base/memory_tool.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_MEMORY_TOOL_H_
-#define ART_RUNTIME_BASE_MEMORY_TOOL_H_
+#ifndef ART_LIBARTBASE_BASE_MEMORY_TOOL_H_
+#define ART_LIBARTBASE_BASE_MEMORY_TOOL_H_
 
 #include <stddef.h>
 
@@ -68,4 +68,4 @@
 
 #endif
 
-#endif  // ART_RUNTIME_BASE_MEMORY_TOOL_H_
+#endif  // ART_LIBARTBASE_BASE_MEMORY_TOOL_H_
diff --git a/runtime/safe_map.h b/libartbase/base/safe_map.h
similarity index 93%
rename from runtime/safe_map.h
rename to libartbase/base/safe_map.h
index 33e45bd..e08394e 100644
--- a/runtime/safe_map.h
+++ b/libartbase/base/safe_map.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_SAFE_MAP_H_
-#define ART_RUNTIME_SAFE_MAP_H_
+#ifndef ART_LIBARTBASE_BASE_SAFE_MAP_H_
+#define ART_LIBARTBASE_BASE_SAFE_MAP_H_
 
 #include <map>
 #include <memory>
@@ -23,14 +23,12 @@
 
 #include <android-base/logging.h>
 
-#include "base/allocator.h"
-
 namespace art {
 
 // Equivalent to std::map, but without operator[] and its bug-prone semantics (in particular,
 // the implicit insertion of a default-constructed value on failed lookups).
 template <typename K, typename V, typename Comparator = std::less<K>,
-          typename Allocator = TrackingAllocator<std::pair<const K, V>, kAllocatorTagSafeMap>>
+          typename Allocator = std::allocator<std::pair<const K, V>>>
 class SafeMap {
  private:
   typedef SafeMap<K, V, Comparator, Allocator> Self;
@@ -177,11 +175,6 @@
   return !(lhs == rhs);
 }
 
-template<class Key, class T, AllocatorTag kTag, class Compare = std::less<Key>>
-class AllocationTrackingSafeMap : public SafeMap<
-    Key, T, Compare, TrackingAllocator<std::pair<const Key, T>, kTag>> {
-};
-
 }  // namespace art
 
-#endif  // ART_RUNTIME_SAFE_MAP_H_
+#endif  // ART_LIBARTBASE_BASE_SAFE_MAP_H_
diff --git a/runtime/base/stl_util.h b/libartbase/base/stl_util.h
similarity index 97%
rename from runtime/base/stl_util.h
rename to libartbase/base/stl_util.h
index 02f3765..9d944b1 100644
--- a/runtime/base/stl_util.h
+++ b/libartbase/base/stl_util.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_STL_UTIL_H_
-#define ART_RUNTIME_BASE_STL_UTIL_H_
+#ifndef ART_LIBARTBASE_BASE_STL_UTIL_H_
+#define ART_LIBARTBASE_BASE_STL_UTIL_H_
 
 #include <algorithm>
 #include <set>
@@ -155,4 +155,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_STL_UTIL_H_
+#endif  // ART_LIBARTBASE_BASE_STL_UTIL_H_
diff --git a/runtime/base/stl_util_identity.h b/libartbase/base/stl_util_identity.h
similarity index 89%
rename from runtime/base/stl_util_identity.h
rename to libartbase/base/stl_util_identity.h
index 40a93f7..d7f1b6f 100644
--- a/runtime/base/stl_util_identity.h
+++ b/libartbase/base/stl_util_identity.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_STL_UTIL_IDENTITY_H_
-#define ART_RUNTIME_BASE_STL_UTIL_IDENTITY_H_
+#ifndef ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_
+#define ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_
 
 namespace art {
 
@@ -38,4 +38,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_STL_UTIL_IDENTITY_H_
+#endif  // ART_LIBARTBASE_BASE_STL_UTIL_IDENTITY_H_
diff --git a/runtime/base/stringpiece.h b/libartbase/base/stringpiece.h
similarity index 75%
rename from runtime/base/stringpiece.h
rename to libartbase/base/stringpiece.h
index e7109dc..e8cc2c3 100644
--- a/runtime/base/stringpiece.h
+++ b/libartbase/base/stringpiece.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_STRINGPIECE_H_
-#define ART_RUNTIME_BASE_STRINGPIECE_H_
+#ifndef ART_LIBARTBASE_BASE_STRINGPIECE_H_
+#define ART_LIBARTBASE_BASE_STRINGPIECE_H_
 
 #include <string.h>
 #include <string>
@@ -100,7 +100,14 @@
     length_ -= n;
   }
 
-  int compare(const StringPiece& x) const;
+  int compare(const StringPiece& x) const {
+    int r = memcmp(ptr_, x.ptr_, std::min(length_, x.length_));
+    if (r == 0) {
+      if (length_ < x.length_) r = -1;
+      else if (length_ > x.length_) r = +1;
+    }
+    return r;
+  }
 
   std::string as_string() const {
     return std::string(data(), size());
@@ -114,7 +121,10 @@
     return std::string(data(), size());
   }
 
-  void CopyToString(std::string* target) const;
+  void CopyToString(std::string* target) const {
+    target->assign(ptr_, length_);
+  }
+
   void AppendToString(std::string* target) const;
 
   // Does "this" start with "x"
@@ -138,14 +148,55 @@
     return const_reverse_iterator(ptr_);
   }
 
-  size_type copy(char* buf, size_type n, size_type pos = 0) const;
+  size_type copy(char* buf, size_type n, size_type pos = 0) const {
+    size_type ret = std::min(length_ - pos, n);
+    memcpy(buf, ptr_ + pos, ret);
+    return ret;
+  }
 
-  size_type find(const StringPiece& s, size_type pos = 0) const;
-  size_type find(char c, size_type pos = 0) const;
-  size_type rfind(const StringPiece& s, size_type pos = npos) const;
-  size_type rfind(char c, size_type pos = npos) const;
+  size_type find(const StringPiece& s, size_type pos = 0) const {
+    if (length_ == 0 || pos > static_cast<size_type>(length_)) {
+      return npos;
+    }
+    const char* result = std::search(ptr_ + pos, ptr_ + length_, s.ptr_, s.ptr_ + s.length_);
+    const size_type xpos = result - ptr_;
+    return xpos + s.length_ <= length_ ? xpos : npos;
+  }
 
-  StringPiece substr(size_type pos, size_type n = npos) const;
+  size_type find(char c, size_type pos = 0) const {
+    if (length_ == 0 || pos >= length_) {
+      return npos;
+    }
+    const char* result = std::find(ptr_ + pos, ptr_ + length_, c);
+    return result != ptr_ + length_ ? result - ptr_ : npos;
+  }
+
+  size_type rfind(const StringPiece& s, size_type pos = npos) const {
+    if (length_ < s.length_) return npos;
+    const size_t ulen = length_;
+    if (s.length_ == 0) return std::min(ulen, pos);
+
+    const char* last = ptr_ + std::min(ulen - s.length_, pos) + s.length_;
+    const char* result = std::find_end(ptr_, last, s.ptr_, s.ptr_ + s.length_);
+    return result != last ? result - ptr_ : npos;
+  }
+
+  size_type rfind(char c, size_type pos = npos) const {
+    if (length_ == 0) return npos;
+    for (int i = std::min(pos, static_cast<size_type>(length_ - 1));
+         i >= 0; --i) {
+      if (ptr_[i] == c) {
+        return i;
+      }
+    }
+    return npos;
+  }
+
+  StringPiece substr(size_type pos, size_type n = npos) const {
+    if (pos > static_cast<size_type>(length_)) pos = length_;
+    if (n > length_ - pos) n = length_ - pos;
+    return StringPiece(ptr_ + pos, n);
+  }
 
   int Compare(const StringPiece& rhs) const {
     const int r = memcmp(data(), rhs.data(), std::min(size(), rhs.size()));
@@ -228,8 +279,11 @@
   return !(x < y);
 }
 
-extern std::ostream& operator<<(std::ostream& o, const StringPiece& piece);
+inline std::ostream& operator<<(std::ostream& o, const StringPiece& piece) {
+  o.write(piece.data(), piece.size());
+  return o;
+}
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_STRINGPIECE_H_
+#endif  // ART_LIBARTBASE_BASE_STRINGPIECE_H_
diff --git a/runtime/base/value_object.h b/libartbase/base/value_object.h
similarity index 84%
rename from runtime/base/value_object.h
rename to libartbase/base/value_object.h
index 8c752a9..441bd1a 100644
--- a/runtime/base/value_object.h
+++ b/libartbase/base/value_object.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_VALUE_OBJECT_H_
-#define ART_RUNTIME_BASE_VALUE_OBJECT_H_
+#ifndef ART_LIBARTBASE_BASE_VALUE_OBJECT_H_
+#define ART_LIBARTBASE_BASE_VALUE_OBJECT_H_
 
 #include "base/macros.h"
 
@@ -28,4 +28,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_BASE_VALUE_OBJECT_H_
+#endif  // ART_LIBARTBASE_BASE_VALUE_OBJECT_H_
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
index 65ba7bc..797b459 100644
--- a/libdexfile/Android.bp
+++ b/libdexfile/Android.bp
@@ -29,6 +29,7 @@
         "dex/dex_file_verifier.cc",
         "dex/dex_instruction.cc",
         "dex/modifiers.cc",
+        "dex/primitive.cc",
         "dex/standard_dex_file.cc",
         "dex/utf.cc",
     ],
@@ -59,14 +60,15 @@
         "libz",
     ],
     header_libs: [
-        // This is needed to resolve the base/ header file inclusions here.
-        // TODO: move those headers to art/ rather than under runtime.
-        "libart_runtime_headers",
+        "art_libartbase_headers",
     ],
     export_include_dirs: ["."],
     export_shared_lib_headers: [
         "libbase",
     ],
+    export_header_lib_headers: [
+        "art_libartbase_headers",
+    ],
 }
 
 gensrcs {
@@ -82,7 +84,6 @@
     output_extension: "operator_out.cc",
 }
 
-// TODO: add build support for libdexfiled, as we use DCHECK, etc.
 art_cc_library {
     name: "libdexfile",
     defaults: ["libdexfile_defaults"],
@@ -114,6 +115,7 @@
         "dex/dex_file_loader_test.cc",
         "dex/dex_file_verifier_test.cc",
         "dex/dex_instruction_test.cc",
+        "dex/primitive_test.cc",
         "dex/utf_test.cc",
     ],
     shared_libs: [
diff --git a/libdexfile/dex/compact_dex_file.cc b/libdexfile/dex/compact_dex_file.cc
index f11b678..302b59e 100644
--- a/libdexfile/dex/compact_dex_file.cc
+++ b/libdexfile/dex/compact_dex_file.cc
@@ -16,9 +16,9 @@
 
 #include "compact_dex_file.h"
 
+#include "base/leb128.h"
 #include "code_item_accessors-inl.h"
 #include "dex_file-inl.h"
-#include "leb128.h"
 
 namespace art {
 
diff --git a/libdexfile/dex/compact_offset_table.cc b/libdexfile/dex/compact_offset_table.cc
index 60a7b61..8601b19 100644
--- a/libdexfile/dex/compact_offset_table.cc
+++ b/libdexfile/dex/compact_offset_table.cc
@@ -17,7 +17,7 @@
 #include "compact_offset_table.h"
 
 #include "compact_dex_utils.h"
-#include "leb128.h"
+#include "base/leb128.h"
 
 namespace art {
 
diff --git a/libdexfile/dex/descriptors_names.h b/libdexfile/dex/descriptors_names.h
index 10738ee..62b0118 100644
--- a/libdexfile/dex/descriptors_names.h
+++ b/libdexfile/dex/descriptors_names.h
@@ -19,7 +19,7 @@
 
 #include <string>
 
-#include "primitive.h"
+#include "dex/primitive.h"
 
 namespace art {
 
diff --git a/libdexfile/dex/dex_file-inl.h b/libdexfile/dex/dex_file-inl.h
index c86e879..ae0c2f4 100644
--- a/libdexfile/dex/dex_file-inl.h
+++ b/libdexfile/dex/dex_file-inl.h
@@ -18,11 +18,11 @@
 #define ART_LIBDEXFILE_DEX_DEX_FILE_INL_H_
 
 #include "base/casts.h"
+#include "base/leb128.h"
 #include "base/stringpiece.h"
 #include "compact_dex_file.h"
 #include "dex_file.h"
 #include "invoke_type.h"
-#include "leb128.h"
 #include "standard_dex_file.h"
 
 namespace art {
diff --git a/libdexfile/dex/dex_file.cc b/libdexfile/dex/dex_file.cc
index c055eb2..4613b40 100644
--- a/libdexfile/dex/dex_file.cc
+++ b/libdexfile/dex/dex_file.cc
@@ -29,10 +29,10 @@
 #include "android-base/stringprintf.h"
 
 #include "base/enums.h"
+#include "base/leb128.h"
 #include "base/stl_util.h"
 #include "descriptors_names.h"
 #include "dex_file-inl.h"
-#include "leb128.h"
 #include "standard_dex_file.h"
 #include "utf-inl.h"
 
diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h
index 9b980a4..5560cf1 100644
--- a/libdexfile/dex/dex_file.h
+++ b/libdexfile/dex/dex_file.h
@@ -23,12 +23,12 @@
 
 #include <android-base/logging.h>
 
+#include "base/globals.h"
 #include "base/iteration_range.h"
 #include "base/macros.h"
 #include "base/value_object.h"
 #include "dex_file_types.h"
 #include "dex_instruction_iterator.h"
-#include "globals.h"
 #include "hidden_api_access_flags.h"
 #include "jni.h"
 #include "modifiers.h"
diff --git a/libdexfile/dex/dex_file_verifier.cc b/libdexfile/dex/dex_file_verifier.cc
index 6266705..68bd19e 100644
--- a/libdexfile/dex/dex_file_verifier.cc
+++ b/libdexfile/dex/dex_file_verifier.cc
@@ -23,10 +23,10 @@
 
 #include "android-base/stringprintf.h"
 
+#include "base/leb128.h"
 #include "code_item_accessors-inl.h"
 #include "descriptors_names.h"
 #include "dex_file-inl.h"
-#include "leb128.h"
 #include "modifiers.h"
 #include "utf-inl.h"
 
diff --git a/libdexfile/dex/dex_file_verifier.h b/libdexfile/dex/dex_file_verifier.h
index c4982c2..a80a9d5 100644
--- a/libdexfile/dex/dex_file_verifier.h
+++ b/libdexfile/dex/dex_file_verifier.h
@@ -20,9 +20,9 @@
 #include <unordered_set>
 
 #include "base/hash_map.h"
+#include "base/safe_map.h"
 #include "dex_file.h"
 #include "dex_file_types.h"
-#include "safe_map.h"
 
 namespace art {
 
@@ -227,21 +227,11 @@
     }
   };
   // Map from offset to dex file type, HashMap for performance reasons.
-  template<class Key,
-           class T,
-           class EmptyFn,
-           AllocatorTag kTag,
-           class Hash = std::hash<Key>,
-           class Pred = std::equal_to<Key>>
-  using AllocationTrackingHashMap = HashMap<
-      Key, T, EmptyFn, Hash, Pred, TrackingAllocator<std::pair<Key, T>, kTag>>;
-
-  AllocationTrackingHashMap<uint32_t,
-                            uint16_t,
-                            OffsetTypeMapEmptyFn,
-                            kAllocatorTagDexFileVerifier,
-                            OffsetTypeMapHashCompareFn,
-                            OffsetTypeMapHashCompareFn> offset_to_type_map_;
+  HashMap<uint32_t,
+          uint16_t,
+          OffsetTypeMapEmptyFn,
+          OffsetTypeMapHashCompareFn,
+          OffsetTypeMapHashCompareFn> offset_to_type_map_;
   const uint8_t* ptr_;
   const void* previous_item_;
 
diff --git a/libdexfile/dex/dex_file_verifier_test.cc b/libdexfile/dex/dex_file_verifier_test.cc
index 1cd4b2c..4c3cf77 100644
--- a/libdexfile/dex/dex_file_verifier_test.cc
+++ b/libdexfile/dex/dex_file_verifier_test.cc
@@ -22,6 +22,7 @@
 #include <memory>
 
 #include "base/bit_utils.h"
+#include "base/leb128.h"
 #include "base/macros.h"
 #include "base64_test_util.h"
 #include "descriptors_names.h"
@@ -29,7 +30,6 @@
 #include "dex_file_loader.h"
 #include "dex_file_types.h"
 #include "gtest/gtest.h"
-#include "leb128.h"
 #include "standard_dex_file.h"
 
 namespace art {
diff --git a/libdexfile/dex/dex_instruction.h b/libdexfile/dex/dex_instruction.h
index 3155c14..bf50836 100644
--- a/libdexfile/dex/dex_instruction.h
+++ b/libdexfile/dex/dex_instruction.h
@@ -19,8 +19,8 @@
 
 #include <android-base/logging.h>
 
+#include "base/globals.h"
 #include "base/macros.h"
-#include "globals.h"
 
 typedef uint8_t uint4_t;
 typedef int8_t int4_t;
diff --git a/runtime/hidden_api_access_flags.h b/libdexfile/dex/hidden_api_access_flags.h
similarity index 96%
rename from runtime/hidden_api_access_flags.h
rename to libdexfile/dex/hidden_api_access_flags.h
index 6a88c12..441b3c1 100644
--- a/runtime/hidden_api_access_flags.h
+++ b/libdexfile/dex/hidden_api_access_flags.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_HIDDEN_API_ACCESS_FLAGS_H_
-#define ART_RUNTIME_HIDDEN_API_ACCESS_FLAGS_H_
+#ifndef ART_LIBDEXFILE_DEX_HIDDEN_API_ACCESS_FLAGS_H_
+#define ART_LIBDEXFILE_DEX_HIDDEN_API_ACCESS_FLAGS_H_
 
 #include "base/bit_utils.h"
 #include "dex/modifiers.h"
@@ -167,4 +167,4 @@
 }  // namespace art
 
 
-#endif  // ART_RUNTIME_HIDDEN_API_ACCESS_FLAGS_H_
+#endif  // ART_LIBDEXFILE_DEX_HIDDEN_API_ACCESS_FLAGS_H_
diff --git a/runtime/primitive.cc b/libdexfile/dex/primitive.cc
similarity index 98%
rename from runtime/primitive.cc
rename to libdexfile/dex/primitive.cc
index 6f3571c..215e39a 100644
--- a/runtime/primitive.cc
+++ b/libdexfile/dex/primitive.cc
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "primitive.h"
+#include "dex/primitive.h"
 
 namespace art {
 
diff --git a/runtime/primitive.h b/libdexfile/dex/primitive.h
similarity index 97%
rename from runtime/primitive.h
rename to libdexfile/dex/primitive.h
index 38ad68d..a1883cd 100644
--- a/runtime/primitive.h
+++ b/libdexfile/dex/primitive.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_PRIMITIVE_H_
-#define ART_RUNTIME_PRIMITIVE_H_
+#ifndef ART_LIBDEXFILE_DEX_PRIMITIVE_H_
+#define ART_LIBDEXFILE_DEX_PRIMITIVE_H_
 
 #include <sys/types.h>
 
@@ -223,4 +223,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_PRIMITIVE_H_
+#endif  // ART_LIBDEXFILE_DEX_PRIMITIVE_H_
diff --git a/runtime/primitive_test.cc b/libdexfile/dex/primitive_test.cc
similarity index 98%
rename from runtime/primitive_test.cc
rename to libdexfile/dex/primitive_test.cc
index e433b15..df16c59 100644
--- a/runtime/primitive_test.cc
+++ b/libdexfile/dex/primitive_test.cc
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "primitive.h"
+#include "dex/primitive.h"
 
 #include "gtest/gtest.h"
 
diff --git a/libdexfile/dex/standard_dex_file.cc b/libdexfile/dex/standard_dex_file.cc
index f7317eb..40dcafd 100644
--- a/libdexfile/dex/standard_dex_file.cc
+++ b/libdexfile/dex/standard_dex_file.cc
@@ -17,9 +17,9 @@
 #include "standard_dex_file.h"
 
 #include "base/casts.h"
+#include "base/leb128.h"
 #include "code_item_accessors-inl.h"
 #include "dex_file-inl.h"
-#include "leb128.h"
 
 namespace art {
 
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 41133a8..85c7281 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -34,6 +34,7 @@
 #include "art_field-inl.h"
 #include "art_method-inl.h"
 #include "base/bit_utils_iterator.h"
+#include "base/safe_map.h"
 #include "base/stl_util.h"
 #include "base/unix_file/fd_file.h"
 #include "class_linker-inl.h"
@@ -69,7 +70,6 @@
 #include "oat_file-inl.h"
 #include "oat_file_manager.h"
 #include "os.h"
-#include "safe_map.h"
 #include "scoped_thread_state_change-inl.h"
 #include "stack.h"
 #include "stack_map.h"
diff --git a/openjdkjvmti/fixed_up_dex_file.cc b/openjdkjvmti/fixed_up_dex_file.cc
index 90c6449..16bbee4 100644
--- a/openjdkjvmti/fixed_up_dex_file.cc
+++ b/openjdkjvmti/fixed_up_dex_file.cc
@@ -29,6 +29,7 @@
  * questions.
  */
 
+#include "base/leb128.h"
 #include "fixed_up_dex_file.h"
 #include "dex/art_dex_file_loader.h"
 #include "dex/dex_file-inl.h"
@@ -40,7 +41,6 @@
 #include "dex/compact_dex_level.h"
 #include "dex_to_dex_decompiler.h"
 #include "dexlayout.h"
-#include "leb128.h"
 #include "oat_file.h"
 #include "vdex_file.h"
 
diff --git a/openjdkjvmti/ti_class.cc b/openjdkjvmti/ti_class.cc
index d510ae5..7a94326 100644
--- a/openjdkjvmti/ti_class.cc
+++ b/openjdkjvmti/ti_class.cc
@@ -45,6 +45,7 @@
 #include "dex/art_dex_file_loader.h"
 #include "dex/dex_file_annotations.h"
 #include "dex/dex_file_loader.h"
+#include "dex/primitive.h"
 #include "events-inl.h"
 #include "fixed_up_dex_file.h"
 #include "gc/heap-visit-objects-inl.h"
@@ -62,7 +63,6 @@
 #include "mirror/object_reference.h"
 #include "mirror/reference.h"
 #include "nativehelper/scoped_local_ref.h"
-#include "primitive.h"
 #include "reflection.h"
 #include "runtime.h"
 #include "runtime_callbacks.h"
diff --git a/openjdkjvmti/ti_heap.cc b/openjdkjvmti/ti_heap.cc
index aaa9ab4..d0a7cf0 100644
--- a/openjdkjvmti/ti_heap.cc
+++ b/openjdkjvmti/ti_heap.cc
@@ -21,6 +21,7 @@
 #include "base/macros.h"
 #include "base/mutex.h"
 #include "class_linker.h"
+#include "dex/primitive.h"
 #include "gc/heap-visit-objects-inl.h"
 #include "gc/heap.h"
 #include "gc_root-inl.h"
@@ -33,7 +34,6 @@
 #include "mirror/object_array-inl.h"
 #include "obj_ptr-inl.h"
 #include "object_tagging.h"
-#include "primitive.h"
 #include "runtime.h"
 #include "scoped_thread_state_change-inl.h"
 #include "stack.h"
diff --git a/openjdkjvmti/ti_method.h b/openjdkjvmti/ti_method.h
index e3578a4..c7af695 100644
--- a/openjdkjvmti/ti_method.h
+++ b/openjdkjvmti/ti_method.h
@@ -32,9 +32,9 @@
 #ifndef ART_OPENJDKJVMTI_TI_METHOD_H_
 #define ART_OPENJDKJVMTI_TI_METHOD_H_
 
+#include "dex/primitive.h"
 #include "jni.h"
 #include "jvmti.h"
-#include "primitive.h"
 
 namespace openjdkjvmti {
 
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc
index 9267b18..0115772 100644
--- a/patchoat/patchoat.cc
+++ b/patchoat/patchoat.cc
@@ -33,6 +33,7 @@
 #include "art_method-inl.h"
 #include "base/dumpable.h"
 #include "base/file_utils.h"
+#include "base/leb128.h"
 #include "base/logging.h"  // For InitLogging.
 #include "base/memory_tool.h"
 #include "base/scoped_flock.h"
@@ -45,7 +46,6 @@
 #include "gc/space/image_space.h"
 #include "image-inl.h"
 #include "intern_table.h"
-#include "leb128.h"
 #include "mirror/dex_cache.h"
 #include "mirror/executable.h"
 #include "mirror/method.h"
diff --git a/patchoat/patchoat_test.cc b/patchoat/patchoat_test.cc
index ac3abd0..974ed32 100644
--- a/patchoat/patchoat_test.cc
+++ b/patchoat/patchoat_test.cc
@@ -24,8 +24,8 @@
 #include "android-base/stringprintf.h"
 #include "android-base/strings.h"
 
+#include "base/leb128.h"
 #include "dexopt_test.h"
-#include "leb128.h"
 #include "runtime.h"
 
 #include <gtest/gtest.h>
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 46e0ee4..c017c5f 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -46,7 +46,6 @@
         "base/safe_copy.cc",
         "base/scoped_arena_allocator.cc",
         "base/scoped_flock.cc",
-        "base/stringpiece.cc",
         "base/time_utils.cc",
         "base/timing_logger.cc",
         "base/unix_file/fd_file.cc",
@@ -196,7 +195,6 @@
         "os_linux.cc",
         "parsed_options.cc",
         "plugin.cc",
-        "primitive.cc",
         "quick_exception_handler.cc",
         "read_barrier.cc",
         "reference_table.cc",
@@ -408,6 +406,7 @@
     ],
     header_libs: [
         "art_cmdlineparser_headers",
+        "art_libartbase_headers",
         "libnativehelper_header_only",
         "jni_platform_headers",
     ],
@@ -443,7 +442,6 @@
         "arch/instruction_set.h",
         "base/allocator.h",
         "base/callee_save_type.h",
-        "base/enums.h",
         "base/mutex.h",
         "base/unix_file/fd_file.h",
         "class_status.h",
@@ -545,10 +543,8 @@
         "base/bit_field_test.cc",
         "base/bit_string_test.cc",
         "base/bit_struct_test.cc",
-        "base/bit_utils_test.cc",
         "base/bit_vector_test.cc",
         "base/file_utils_test.cc",
-        "base/hash_set_test.cc",
         "base/hex_dump_test.cc",
         "base/histogram_test.cc",
         "base/logging_test.cc",
@@ -599,7 +595,6 @@
         "jdwp/jdwp_options_test.cc",
         "java_vm_ext_test.cc",
         "jit/profile_compilation_info_test.cc",
-        "leb128_test.cc",
         "mem_map_test.cc",
         "memory_region_test.cc",
         "method_handles_test.cc",
@@ -613,7 +608,6 @@
         "oat_file_assistant_test.cc",
         "parsed_options_test.cc",
         "prebuilt_tools_test.cc",
-        "primitive_test.cc",
         "reference_table_test.cc",
         "runtime_callbacks_test.cc",
         "subtype_check_info_test.cc",
diff --git a/runtime/art_field-inl.h b/runtime/art_field-inl.h
index 99634a0..384581f 100644
--- a/runtime/art_field-inl.h
+++ b/runtime/art_field-inl.h
@@ -23,12 +23,12 @@
 
 #include "class_linker.h"
 #include "dex/dex_file-inl.h"
+#include "dex/primitive.h"
 #include "gc/accounting/card_table-inl.h"
 #include "gc_root-inl.h"
 #include "jvalue.h"
 #include "mirror/dex_cache-inl.h"
 #include "mirror/object-inl.h"
-#include "primitive.h"
 #include "scoped_thread_state_change-inl.h"
 #include "thread-current-inl.h"
 
diff --git a/runtime/art_field.h b/runtime/art_field.h
index 0eeeef2..29d71af 100644
--- a/runtime/art_field.h
+++ b/runtime/art_field.h
@@ -21,10 +21,10 @@
 
 #include "dex/dex_file_types.h"
 #include "dex/modifiers.h"
+#include "dex/primitive.h"
 #include "gc_root.h"
 #include "obj_ptr.h"
 #include "offsets.h"
-#include "primitive.h"
 #include "read_barrier_option.h"
 
 namespace art {
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index 8b48aa2..145eb67 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -28,6 +28,7 @@
 #include "dex/dex_file_annotations.h"
 #include "dex/dex_file_types.h"
 #include "dex/invoke_type.h"
+#include "dex/primitive.h"
 #include "gc_root-inl.h"
 #include "intrinsics_enum.h"
 #include "jit/profiling_info.h"
@@ -38,7 +39,6 @@
 #include "mirror/string.h"
 #include "oat.h"
 #include "obj_ptr-inl.h"
-#include "primitive.h"
 #include "quick/quick_method_frame_info.h"
 #include "read_barrier-inl.h"
 #include "runtime-inl.h"
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 21ee8f1..013856f 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -32,10 +32,10 @@
 #include "dex/dex_file.h"
 #include "dex/dex_instruction_iterator.h"
 #include "dex/modifiers.h"
+#include "dex/primitive.h"
 #include "gc_root.h"
 #include "obj_ptr.h"
 #include "offsets.h"
-#include "primitive.h"
 #include "read_barrier_option.h"
 
 namespace art {
diff --git a/runtime/base/arena_allocator.h b/runtime/base/arena_allocator.h
index beaba67..060b6fa 100644
--- a/runtime/base/arena_allocator.h
+++ b/runtime/base/arena_allocator.h
@@ -20,11 +20,11 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#include "bit_utils.h"
+#include "base/bit_utils.h"
+#include "base/macros.h"
+#include "base/memory_tool.h"
 #include "dchecked_vector.h"
 #include "debug_stack.h"
-#include "macros.h"
-#include "memory_tool.h"
 #include "mutex.h"
 
 namespace art {
diff --git a/runtime/base/arena_containers.h b/runtime/base/arena_containers.h
index dcdb92b..4f57212 100644
--- a/runtime/base/arena_containers.h
+++ b/runtime/base/arena_containers.h
@@ -26,9 +26,9 @@
 
 #include "arena_allocator.h"
 #include "base/dchecked_vector.h"
-#include "hash_map.h"
-#include "hash_set.h"
-#include "safe_map.h"
+#include "base/hash_map.h"
+#include "base/hash_set.h"
+#include "base/safe_map.h"
 
 namespace art {
 
diff --git a/runtime/base/arena_object.h b/runtime/base/arena_object.h
index 06884c2..d01e346 100644
--- a/runtime/base/arena_object.h
+++ b/runtime/base/arena_object.h
@@ -20,7 +20,7 @@
 #include <android-base/logging.h>
 
 #include "arena_allocator.h"
-#include "macros.h"
+#include "base/macros.h"
 #include "scoped_arena_allocator.h"
 
 namespace art {
diff --git a/runtime/base/bit_struct.h b/runtime/base/bit_struct.h
index b207459..7eb63c6 100644
--- a/runtime/base/bit_struct.h
+++ b/runtime/base/bit_struct.h
@@ -17,8 +17,8 @@
 #ifndef ART_RUNTIME_BASE_BIT_STRUCT_H_
 #define ART_RUNTIME_BASE_BIT_STRUCT_H_
 
+#include "base/bit_utils.h"
 #include "bit_struct_detail.h"
-#include "bit_utils.h"
 
 //
 // Zero-cost, type-safe, well-defined "structs" of bit fields.
diff --git a/runtime/base/bit_struct_detail.h b/runtime/base/bit_struct_detail.h
index 912f51c..24f6c4c 100644
--- a/runtime/base/bit_struct_detail.h
+++ b/runtime/base/bit_struct_detail.h
@@ -17,7 +17,7 @@
 #ifndef ART_RUNTIME_BASE_BIT_STRUCT_DETAIL_H_
 #define ART_RUNTIME_BASE_BIT_STRUCT_DETAIL_H_
 
-#include "bit_utils.h"
+#include "base/bit_utils.h"
 #include "globals.h"
 
 #include <type_traits>
diff --git a/runtime/base/hex_dump.h b/runtime/base/hex_dump.h
index 8769ece..2ce0aef 100644
--- a/runtime/base/hex_dump.h
+++ b/runtime/base/hex_dump.h
@@ -17,7 +17,7 @@
 #ifndef ART_RUNTIME_BASE_HEX_DUMP_H_
 #define ART_RUNTIME_BASE_HEX_DUMP_H_
 
-#include "macros.h"
+#include "base/macros.h"
 
 #include <ostream>
 
diff --git a/runtime/base/safe_copy.cc b/runtime/base/safe_copy.cc
index b46b921..7ba5cbd 100644
--- a/runtime/base/safe_copy.cc
+++ b/runtime/base/safe_copy.cc
@@ -24,7 +24,7 @@
 
 #include <android-base/macros.h>
 
-#include "bit_utils.h"
+#include "base/bit_utils.h"
 
 namespace art {
 
diff --git a/runtime/base/scoped_arena_allocator.h b/runtime/base/scoped_arena_allocator.h
index 35e337f..202902e 100644
--- a/runtime/base/scoped_arena_allocator.h
+++ b/runtime/base/scoped_arena_allocator.h
@@ -20,9 +20,9 @@
 #include <android-base/logging.h>
 
 #include "arena_allocator.h"
+#include "base/macros.h"
 #include "debug_stack.h"
 #include "globals.h"
-#include "macros.h"
 
 namespace art {
 
diff --git a/runtime/base/scoped_arena_containers.h b/runtime/base/scoped_arena_containers.h
index 756089f..f8ee3f3 100644
--- a/runtime/base/scoped_arena_containers.h
+++ b/runtime/base/scoped_arena_containers.h
@@ -26,7 +26,7 @@
 
 #include "arena_containers.h"  // For ArenaAllocatorAdapterKind.
 #include "base/dchecked_vector.h"
-#include "safe_map.h"
+#include "base/safe_map.h"
 #include "scoped_arena_allocator.h"
 
 namespace art {
diff --git a/runtime/base/stringpiece.cc b/runtime/base/stringpiece.cc
deleted file mode 100644
index aea4e74..0000000
--- a/runtime/base/stringpiece.cc
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2010 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 "stringpiece.h"
-
-#include <ostream>
-#include <utility>
-
-#include <android-base/logging.h>
-
-namespace art {
-
-void StringPiece::CopyToString(std::string* target) const {
-  target->assign(ptr_, length_);
-}
-
-StringPiece::size_type StringPiece::copy(char* buf, size_type n, size_type pos) const {
-  size_type ret = std::min(length_ - pos, n);
-  memcpy(buf, ptr_ + pos, ret);
-  return ret;
-}
-
-StringPiece::size_type StringPiece::find(const StringPiece& s, size_type pos) const {
-  if (length_ == 0 || pos > static_cast<size_type>(length_)) {
-    return npos;
-  }
-  const char* result = std::search(ptr_ + pos, ptr_ + length_, s.ptr_, s.ptr_ + s.length_);
-  const size_type xpos = result - ptr_;
-  return xpos + s.length_ <= length_ ? xpos : npos;
-}
-
-int StringPiece::compare(const StringPiece& x) const {
-  int r = memcmp(ptr_, x.ptr_, std::min(length_, x.length_));
-  if (r == 0) {
-    if (length_ < x.length_) r = -1;
-    else if (length_ > x.length_) r = +1;
-  }
-  return r;
-}
-
-StringPiece::size_type StringPiece::find(char c, size_type pos) const {
-  if (length_ == 0 || pos >= length_) {
-    return npos;
-  }
-  const char* result = std::find(ptr_ + pos, ptr_ + length_, c);
-  return result != ptr_ + length_ ? result - ptr_ : npos;
-}
-
-StringPiece::size_type StringPiece::rfind(const StringPiece& s, size_type pos) const {
-  if (length_ < s.length_) return npos;
-  const size_t ulen = length_;
-  if (s.length_ == 0) return std::min(ulen, pos);
-
-  const char* last = ptr_ + std::min(ulen - s.length_, pos) + s.length_;
-  const char* result = std::find_end(ptr_, last, s.ptr_, s.ptr_ + s.length_);
-  return result != last ? result - ptr_ : npos;
-}
-
-StringPiece::size_type StringPiece::rfind(char c, size_type pos) const {
-  if (length_ == 0) return npos;
-  for (int i = std::min(pos, static_cast<size_type>(length_ - 1));
-       i >= 0; --i) {
-    if (ptr_[i] == c) {
-      return i;
-    }
-  }
-  return npos;
-}
-
-StringPiece StringPiece::substr(size_type pos, size_type n) const {
-  if (pos > static_cast<size_type>(length_)) pos = length_;
-  if (n > length_ - pos) n = length_ - pos;
-  return StringPiece(ptr_ + pos, n);
-}
-
-std::ostream& operator<<(std::ostream& o, const StringPiece& piece) {
-  o.write(piece.data(), piece.size());
-  return o;
-}
-
-}  // namespace art
diff --git a/runtime/base/tracking_safe_map.h b/runtime/base/tracking_safe_map.h
new file mode 100644
index 0000000..2f3984d
--- /dev/null
+++ b/runtime/base/tracking_safe_map.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2013 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_TRACKING_SAFE_MAP_H_
+#define ART_RUNTIME_BASE_TRACKING_SAFE_MAP_H_
+
+#include "base/allocator.h"
+#include "base/safe_map.h"
+
+namespace art {
+
+template<class Key, class T, AllocatorTag kTag, class Compare = std::less<Key>>
+class AllocationTrackingSafeMap : public SafeMap<
+    Key, T, Compare, TrackingAllocator<std::pair<const Key, T>, kTag>> {
+};
+
+}  // namespace art
+
+#endif  // ART_RUNTIME_BASE_TRACKING_SAFE_MAP_H_
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index f18e0b4..c667fe2 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -36,6 +36,7 @@
 #include "art_method-inl.h"
 #include "base/arena_allocator.h"
 #include "base/casts.h"
+#include "base/leb128.h"
 #include "base/logging.h"
 #include "base/scoped_arena_containers.h"
 #include "base/scoped_flock.h"
@@ -79,7 +80,6 @@
 #include "jit/jit_code_cache.h"
 #include "jit/profile_compilation_info.h"
 #include "jni_internal.h"
-#include "leb128.h"
 #include "linear_alloc.h"
 #include "mirror/call_site.h"
 #include "mirror/class-inl.h"
diff --git a/runtime/common_dex_operations.h b/runtime/common_dex_operations.h
index 1db25c4..37e074d 100644
--- a/runtime/common_dex_operations.h
+++ b/runtime/common_dex_operations.h
@@ -24,6 +24,7 @@
 #include "base/mutex.h"
 #include "class_linker.h"
 #include "dex/code_item_accessors.h"
+#include "dex/primitive.h"
 #include "handle_scope-inl.h"
 #include "instrumentation.h"
 #include "interpreter/shadow_frame.h"
@@ -31,7 +32,6 @@
 #include "mirror/class.h"
 #include "mirror/object.h"
 #include "obj_ptr-inl.h"
-#include "primitive.h"
 #include "runtime.h"
 #include "stack.h"
 #include "thread.h"
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index 8c268d8..e4fbc86 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -38,6 +38,7 @@
 #include "dex/art_dex_file_loader.h"
 #include "dex/dex_file-inl.h"
 #include "dex/dex_file_loader.h"
+#include "dex/primitive.h"
 #include "gc/heap.h"
 #include "gc_root-inl.h"
 #include "gtest/gtest.h"
@@ -51,7 +52,6 @@
 #include "native/dalvik_system_DexFile.h"
 #include "noop_compiler_callbacks.h"
 #include "os.h"
-#include "primitive.h"
 #include "runtime-inl.h"
 #include "scoped_thread_state_change-inl.h"
 #include "thread.h"
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index 5066385..99a4c77 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -29,6 +29,7 @@
 #include "art_field-inl.h"
 #include "art_method-inl.h"
 #include "base/enums.h"
+#include "base/safe_map.h"
 #include "base/strlcpy.h"
 #include "base/time_utils.h"
 #include "class_linker-inl.h"
@@ -64,7 +65,6 @@
 #include "oat_file.h"
 #include "obj_ptr-inl.h"
 #include "reflection.h"
-#include "safe_map.h"
 #include "scoped_thread_state_change-inl.h"
 #include "stack.h"
 #include "thread_list.h"
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index d057ff3..b466181 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -25,11 +25,11 @@
 #include "android-base/strings.h"
 
 #include "arch/instruction_set.h"
+#include "base/leb128.h"
 #include "base/stl_util.h"
 #include "base/unix_file/fd_file.h"
 #include "elf_file_impl.h"
 #include "elf_utils.h"
-#include "leb128.h"
 #include "utils.h"
 
 namespace art {
diff --git a/runtime/gc/accounting/mod_union_table.h b/runtime/gc/accounting/mod_union_table.h
index 4b5d5f3..766e0f5 100644
--- a/runtime/gc/accounting/mod_union_table.h
+++ b/runtime/gc/accounting/mod_union_table.h
@@ -18,11 +18,12 @@
 #define ART_RUNTIME_GC_ACCOUNTING_MOD_UNION_TABLE_H_
 
 #include "base/allocator.h"
+#include "base/safe_map.h"
+#include "base/tracking_safe_map.h"
 #include "bitmap.h"
 #include "card_table.h"
 #include "globals.h"
 #include "mirror/object_reference.h"
-#include "safe_map.h"
 
 #include <set>
 #include <vector>
diff --git a/runtime/gc/accounting/remembered_set.h b/runtime/gc/accounting/remembered_set.h
index 90d4ffb..e9376a9 100644
--- a/runtime/gc/accounting/remembered_set.h
+++ b/runtime/gc/accounting/remembered_set.h
@@ -18,8 +18,8 @@
 #define ART_RUNTIME_GC_ACCOUNTING_REMEMBERED_SET_H_
 
 #include "base/allocator.h"
+#include "base/safe_map.h"
 #include "globals.h"
-#include "safe_map.h"
 
 #include <set>
 #include <vector>
diff --git a/runtime/gc/collector/concurrent_copying.h b/runtime/gc/collector/concurrent_copying.h
index c58dd44..a00dbb5 100644
--- a/runtime/gc/collector/concurrent_copying.h
+++ b/runtime/gc/collector/concurrent_copying.h
@@ -18,12 +18,12 @@
 #define ART_RUNTIME_GC_COLLECTOR_CONCURRENT_COPYING_H_
 
 #include "barrier.h"
+#include "base/safe_map.h"
 #include "garbage_collector.h"
 #include "immune_spaces.h"
 #include "jni.h"
 #include "mirror/object_reference.h"
 #include "offsets.h"
-#include "safe_map.h"
 
 #include <unordered_map>
 #include <vector>
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 9d2d2ed..592172f 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -30,6 +30,7 @@
 #include "base/macros.h"
 #include "base/mutex.h"
 #include "base/runtime_debug.h"
+#include "base/safe_map.h"
 #include "base/time_utils.h"
 #include "gc/collector/gc_type.h"
 #include "gc/collector/iteration.h"
@@ -42,7 +43,6 @@
 #include "offsets.h"
 #include "process_state.h"
 #include "read_barrier_config.h"
-#include "safe_map.h"
 #include "verify_object.h"
 
 namespace art {
diff --git a/runtime/gc/space/large_object_space.h b/runtime/gc/space/large_object_space.h
index 38e28b1..f37d814 100644
--- a/runtime/gc/space/large_object_space.h
+++ b/runtime/gc/space/large_object_space.h
@@ -18,8 +18,9 @@
 #define ART_RUNTIME_GC_SPACE_LARGE_OBJECT_SPACE_H_
 
 #include "base/allocator.h"
+#include "base/safe_map.h"
+#include "base/tracking_safe_map.h"
 #include "dlmalloc_space.h"
-#include "safe_map.h"
 #include "space.h"
 
 #include <set>
diff --git a/runtime/globals.h b/runtime/globals.h
index ca4040d..bdc2177 100644
--- a/runtime/globals.h
+++ b/runtime/globals.h
@@ -17,123 +17,7 @@
 #ifndef ART_RUNTIME_GLOBALS_H_
 #define ART_RUNTIME_GLOBALS_H_
 
-#include <stddef.h>
-#include <stdint.h>
-
-namespace art {
-
-static constexpr size_t KB = 1024;
-static constexpr size_t MB = KB * KB;
-static constexpr size_t GB = KB * KB * KB;
-
-// Runtime sizes.
-static constexpr size_t kBitsPerByte = 8;
-static constexpr size_t kBitsPerByteLog2 = 3;
-static constexpr int kBitsPerIntPtrT = sizeof(intptr_t) * kBitsPerByte;
-
-// Required stack alignment
-static constexpr size_t kStackAlignment = 16;
-
-// System page size. We check this against sysconf(_SC_PAGE_SIZE) at runtime, but use a simple
-// compile-time constant so the compiler can generate better code.
-static constexpr int kPageSize = 4096;
-
-// Returns whether the given memory offset can be used for generating
-// an implicit null check.
-static inline bool CanDoImplicitNullCheckOn(uintptr_t offset) {
-  return offset < kPageSize;
-}
-
-// Required object alignment
-static constexpr size_t kObjectAlignmentShift = 3;
-static constexpr size_t kObjectAlignment = 1u << kObjectAlignmentShift;
-static constexpr size_t kLargeObjectAlignment = kPageSize;
-
-// Clion, clang analyzer, etc can falsely believe that "if (kIsDebugBuild)" always
-// returns the same value. By wrapping into a call to another constexpr function, we force it
-// to realize that is not actually always evaluating to the same value.
-static constexpr bool GlobalsReturnSelf(bool self) { return self; }
-
-// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
-// TODO: Use only __clang_analyzer__ here. b/64455231
-#if defined(NDEBUG) && !defined(__CLION_IDE__)
-static constexpr bool kIsDebugBuild = GlobalsReturnSelf(false);
-#else
-static constexpr bool kIsDebugBuild = GlobalsReturnSelf(true);
-#endif
-
-#if defined(ART_PGO_INSTRUMENTATION)
-static constexpr bool kIsPGOInstrumentation = true;
-#else
-static constexpr bool kIsPGOInstrumentation = false;
-#endif
-
-// ART_TARGET - Defined for target builds of ART.
-// ART_TARGET_LINUX - Defined for target Linux builds of ART.
-// ART_TARGET_ANDROID - Defined for target Android builds of ART.
-// Note: Either ART_TARGET_LINUX or ART_TARGET_ANDROID need to be set when ART_TARGET is set.
-// Note: When ART_TARGET_LINUX is defined mem_map.h will not be using Ashmem for memory mappings
-// (usually only available on Android kernels).
-#if defined(ART_TARGET)
-// Useful in conditionals where ART_TARGET isn't.
-static constexpr bool kIsTargetBuild = true;
-# if defined(ART_TARGET_LINUX)
-static constexpr bool kIsTargetLinux = true;
-# elif defined(ART_TARGET_ANDROID)
-static constexpr bool kIsTargetLinux = false;
-# else
-# error "Either ART_TARGET_LINUX or ART_TARGET_ANDROID needs to be defined for target builds."
-# endif
-#else
-static constexpr bool kIsTargetBuild = false;
-# if defined(ART_TARGET_LINUX)
-# error "ART_TARGET_LINUX defined for host build."
-# elif defined(ART_TARGET_ANDROID)
-# error "ART_TARGET_ANDROID defined for host build."
-# else
-static constexpr bool kIsTargetLinux = false;
-# endif
-#endif
-
-// Additional statically-linked ART binaries (dex2oats, oatdumps, etc.) are
-// always available on the host
-#if !defined(ART_TARGET)
-static constexpr bool kHostStaticBuildEnabled = true;
-#else
-static constexpr bool kHostStaticBuildEnabled = false;
-#endif
-
-// Garbage collector constants.
-static constexpr bool kMovingCollector = true;
-static constexpr bool kMarkCompactSupport = false && kMovingCollector;
-// True if we allow moving classes.
-static constexpr bool kMovingClasses = !kMarkCompactSupport;
-
-// If true, enable the tlab allocator by default.
-#ifdef ART_USE_TLAB
-static constexpr bool kUseTlab = true;
-#else
-static constexpr bool kUseTlab = false;
-#endif
-
-// Kinds of tracing clocks.
-enum class TraceClockSource {
-  kThreadCpu,
-  kWall,
-  kDual,  // Both wall and thread CPU clocks.
-};
-
-#if defined(__linux__)
-static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kDual;
-#else
-static constexpr TraceClockSource kDefaultTraceClockSource = TraceClockSource::kWall;
-#endif
-
-static constexpr bool kDefaultMustRelocate = true;
-
-// Size of a heap reference.
-static constexpr size_t kHeapReferenceSize = sizeof(uint32_t);
-
-}  // namespace art
+// TODO: remove this file in favor of libartbase/base/globals.h
+#include "base/globals.h"
 
 #endif  // ART_RUNTIME_GLOBALS_H_
diff --git a/runtime/hidden_api.h b/runtime/hidden_api.h
index d7e5e18..e0519a0 100644
--- a/runtime/hidden_api.h
+++ b/runtime/hidden_api.h
@@ -17,7 +17,7 @@
 #ifndef ART_RUNTIME_HIDDEN_API_H_
 #define ART_RUNTIME_HIDDEN_API_H_
 
-#include "hidden_api_access_flags.h"
+#include "dex/hidden_api_access_flags.h"
 #include "reflection.h"
 #include "runtime.h"
 
diff --git a/runtime/hprof/hprof.cc b/runtime/hprof/hprof.cc
index af9fbcd..52ee516 100644
--- a/runtime/hprof/hprof.cc
+++ b/runtime/hprof/hprof.cc
@@ -44,6 +44,7 @@
 #include "base/array_ref.h"
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "base/time_utils.h"
 #include "base/unix_file/fd_file.h"
 #include "class_linker.h"
@@ -64,7 +65,6 @@
 #include "mirror/class.h"
 #include "mirror/object-refvisitor-inl.h"
 #include "os.h"
-#include "safe_map.h"
 #include "scoped_thread_state_change-inl.h"
 #include "thread_list.h"
 
diff --git a/runtime/instrumentation.h b/runtime/instrumentation.h
index 46b3f8d..8e7a638 100644
--- a/runtime/instrumentation.h
+++ b/runtime/instrumentation.h
@@ -25,8 +25,8 @@
 #include "base/enums.h"
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "gc_root.h"
-#include "safe_map.h"
 
 namespace art {
 namespace mirror {
diff --git a/runtime/jdwp/object_registry.h b/runtime/jdwp/object_registry.h
index 26869b6..1728a73 100644
--- a/runtime/jdwp/object_registry.h
+++ b/runtime/jdwp/object_registry.h
@@ -23,10 +23,10 @@
 #include <map>
 
 #include "base/casts.h"
+#include "base/safe_map.h"
 #include "handle.h"
 #include "jdwp/jdwp.h"
 #include "obj_ptr.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/runtime/jit/jit_code_cache.h b/runtime/jit/jit_code_cache.h
index fc011dd..0d1311f 100644
--- a/runtime/jit/jit_code_cache.h
+++ b/runtime/jit/jit_code_cache.h
@@ -24,9 +24,9 @@
 #include "base/histogram-inl.h"
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "gc_root.h"
 #include "method_reference.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/runtime/jit/profile_compilation_info.cc b/runtime/jit/profile_compilation_info.cc
index 21caa42..7be29c9 100644
--- a/runtime/jit/profile_compilation_info.cc
+++ b/runtime/jit/profile_compilation_info.cc
@@ -37,6 +37,7 @@
 #include "base/file_utils.h"
 #include "base/logging.h"  // For VLOG.
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "base/scoped_flock.h"
 #include "base/stl_util.h"
 #include "base/systrace.h"
@@ -45,7 +46,6 @@
 #include "dex/dex_file_loader.h"
 #include "jit/profiling_info.h"
 #include "os.h"
-#include "safe_map.h"
 #include "utils.h"
 #include "zip_archive.h"
 
diff --git a/runtime/jit/profile_compilation_info.h b/runtime/jit/profile_compilation_info.h
index 3213c85..7e09b6b 100644
--- a/runtime/jit/profile_compilation_info.h
+++ b/runtime/jit/profile_compilation_info.h
@@ -23,13 +23,13 @@
 #include "atomic.h"
 #include "base/arena_containers.h"
 #include "base/arena_object.h"
+#include "base/safe_map.h"
 #include "bit_memory_region.h"
 #include "dex/dex_cache_resolved_classes.h"
 #include "dex/dex_file.h"
 #include "dex/dex_file_types.h"
 #include "method_reference.h"
 #include "mem_map.h"
-#include "safe_map.h"
 #include "type_reference.h"
 
 namespace art {
diff --git a/runtime/jit/profile_saver.h b/runtime/jit/profile_saver.h
index ce8233b..e5cd11b 100644
--- a/runtime/jit/profile_saver.h
+++ b/runtime/jit/profile_saver.h
@@ -18,11 +18,11 @@
 #define ART_RUNTIME_JIT_PROFILE_SAVER_H_
 
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "jit_code_cache.h"
 #include "method_reference.h"
 #include "profile_compilation_info.h"
 #include "profile_saver_options.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index cd4d954..4c73d87 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -30,6 +30,7 @@
 #include "base/enums.h"
 #include "base/logging.h"  // For VLOG.
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "base/stl_util.h"
 #include "class_linker-inl.h"
 #include "dex/dex_file-inl.h"
@@ -55,7 +56,6 @@
 #include "parsed_options.h"
 #include "reflection.h"
 #include "runtime.h"
-#include "safe_map.h"
 #include "scoped_thread_state_change-inl.h"
 #include "thread.h"
 #include "well_known_classes.h"
diff --git a/runtime/mapping_table.h b/runtime/mapping_table.h
index dcd5f00..6686473 100644
--- a/runtime/mapping_table.h
+++ b/runtime/mapping_table.h
@@ -17,8 +17,8 @@
 #ifndef ART_RUNTIME_MAPPING_TABLE_H_
 #define ART_RUNTIME_MAPPING_TABLE_H_
 
+#include "base/leb128.h"
 #include "base/logging.h"
-#include "leb128.h"
 
 namespace art {
 
diff --git a/runtime/method_info.h b/runtime/method_info.h
index 6485af9..fe06256 100644
--- a/runtime/method_info.h
+++ b/runtime/method_info.h
@@ -19,8 +19,8 @@
 
 #include <android-base/logging.h>
 
+#include "base/leb128.h"
 #include "base/macros.h"
-#include "leb128.h"
 #include "memory_region.h"
 
 namespace art {
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index b9a31e5..a1d0ff7 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -26,12 +26,12 @@
 #include "dex/dex_file.h"
 #include "dex/dex_file_types.h"
 #include "dex/modifiers.h"
+#include "dex/primitive.h"
 #include "gc/allocator_type.h"
 #include "gc_root.h"
 #include "imtable.h"
 #include "object.h"
 #include "object_array.h"
-#include "primitive.h"
 #include "read_barrier_option.h"
 #include "stride_iterator.h"
 #include "thread.h"
diff --git a/runtime/mirror/field.h b/runtime/mirror/field.h
index dd09be3..03fd031 100644
--- a/runtime/mirror/field.h
+++ b/runtime/mirror/field.h
@@ -20,10 +20,10 @@
 #include "accessible_object.h"
 #include "base/enums.h"
 #include "dex/modifiers.h"
+#include "dex/primitive.h"
 #include "gc_root.h"
 #include "obj_ptr.h"
 #include "object.h"
-#include "primitive.h"
 #include "read_barrier_option.h"
 
 namespace art {
diff --git a/runtime/oat.h b/runtime/oat.h
index af14b3e..292c9d6 100644
--- a/runtime/oat.h
+++ b/runtime/oat.h
@@ -21,9 +21,9 @@
 
 #include "arch/instruction_set.h"
 #include "base/macros.h"
+#include "base/safe_map.h"
 #include "compiler_filter.h"
 #include "dex/dex_file.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index 802adc3..255a31b 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -23,7 +23,9 @@
 
 #include "base/array_ref.h"
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "base/stringpiece.h"
+#include "base/tracking_safe_map.h"
 #include "class_status.h"
 #include "compiler_filter.h"
 #include "dex/dex_file.h"
diff --git a/runtime/quicken_info.h b/runtime/quicken_info.h
index f20aa0c..6c18590 100644
--- a/runtime/quicken_info.h
+++ b/runtime/quicken_info.h
@@ -18,9 +18,9 @@
 #define ART_RUNTIME_QUICKEN_INFO_H_
 
 #include "base/array_ref.h"
+#include "base/leb128.h"
 #include "dex/compact_offset_table.h"
 #include "dex/dex_instruction.h"
-#include "leb128.h"
 
 namespace art {
 
diff --git a/runtime/reference_table_test.cc b/runtime/reference_table_test.cc
index 1e7fc3e..06ea384 100644
--- a/runtime/reference_table_test.cc
+++ b/runtime/reference_table_test.cc
@@ -23,12 +23,12 @@
 #include "art_method-inl.h"
 #include "class_linker.h"
 #include "common_runtime_test.h"
+#include "dex/primitive.h"
 #include "handle_scope-inl.h"
 #include "mirror/array-inl.h"
 #include "mirror/class-inl.h"
 #include "mirror/class_loader.h"
 #include "mirror/string.h"
-#include "primitive.h"
 #include "runtime.h"
 #include "scoped_thread_state_change-inl.h"
 #include "thread-current-inl.h"
diff --git a/runtime/reflection-inl.h b/runtime/reflection-inl.h
index 6edb12f..87432ab 100644
--- a/runtime/reflection-inl.h
+++ b/runtime/reflection-inl.h
@@ -23,10 +23,10 @@
 
 #include "common_throws.h"
 #include "dex/descriptors_names.h"
+#include "dex/primitive.h"
 #include "jvalue-inl.h"
 #include "mirror/object-inl.h"
 #include "obj_ptr-inl.h"
-#include "primitive.h"
 #include "utils.h"
 
 namespace art {
diff --git a/runtime/reflection.h b/runtime/reflection.h
index 2da2917..4560a39 100644
--- a/runtime/reflection.h
+++ b/runtime/reflection.h
@@ -18,9 +18,9 @@
 #define ART_RUNTIME_REFLECTION_H_
 
 #include "base/mutex.h"
+#include "dex/primitive.h"
 #include "jni.h"
 #include "obj_ptr.h"
-#include "primitive.h"
 
 namespace art {
 namespace mirror {
diff --git a/runtime/stack_map.h b/runtime/stack_map.h
index 62fb54f..bde3462 100644
--- a/runtime/stack_map.h
+++ b/runtime/stack_map.h
@@ -22,9 +22,9 @@
 #include "arch/code_offset.h"
 #include "base/bit_utils.h"
 #include "base/bit_vector.h"
+#include "base/leb128.h"
 #include "bit_memory_region.h"
 #include "dex/dex_file_types.h"
-#include "leb128.h"
 #include "memory_region.h"
 #include "method_info.h"
 
diff --git a/runtime/trace.h b/runtime/trace.h
index a888dcb..7ce12da 100644
--- a/runtime/trace.h
+++ b/runtime/trace.h
@@ -28,10 +28,10 @@
 
 #include "atomic.h"
 #include "base/macros.h"
+#include "base/safe_map.h"
 #include "globals.h"
 #include "instrumentation.h"
 #include "os.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/runtime/transaction.h b/runtime/transaction.h
index 8539ebc..7adf140 100644
--- a/runtime/transaction.h
+++ b/runtime/transaction.h
@@ -19,12 +19,12 @@
 
 #include "base/macros.h"
 #include "base/mutex.h"
+#include "base/safe_map.h"
 #include "base/value_object.h"
 #include "dex/dex_file_types.h"
+#include "dex/primitive.h"
 #include "gc_root.h"
 #include "offsets.h"
-#include "primitive.h"
-#include "safe_map.h"
 
 #include <list>
 #include <map>
diff --git a/runtime/type_lookup_table.h b/runtime/type_lookup_table.h
index a1f9519..3352d60 100644
--- a/runtime/type_lookup_table.h
+++ b/runtime/type_lookup_table.h
@@ -17,9 +17,9 @@
 #ifndef ART_RUNTIME_TYPE_LOOKUP_TABLE_H_
 #define ART_RUNTIME_TYPE_LOOKUP_TABLE_H_
 
+#include "base/leb128.h"
 #include "dex/dex_file_types.h"
 #include "dex/utf.h"
-#include "leb128.h"
 
 namespace art {
 
diff --git a/runtime/utils.h b/runtime/utils.h
index 7dc8f35..0c3a0a2 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -28,8 +28,8 @@
 #include "arch/instruction_set.h"
 #include "base/casts.h"
 #include "base/stringpiece.h"
+#include "dex/primitive.h"
 #include "globals.h"
-#include "primitive.h"
 
 namespace art {
 
diff --git a/runtime/utils/dex_cache_arrays_layout-inl.h b/runtime/utils/dex_cache_arrays_layout-inl.h
index 855b856..68a5760 100644
--- a/runtime/utils/dex_cache_arrays_layout-inl.h
+++ b/runtime/utils/dex_cache_arrays_layout-inl.h
@@ -22,10 +22,10 @@
 #include <android-base/logging.h>
 
 #include "base/bit_utils.h"
+#include "dex/primitive.h"
 #include "gc_root.h"
 #include "globals.h"
 #include "mirror/dex_cache.h"
-#include "primitive.h"
 
 namespace art {
 
diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc
index 34b9fcc..ba64055 100644
--- a/runtime/vdex_file.cc
+++ b/runtime/vdex_file.cc
@@ -24,14 +24,14 @@
 #include <android-base/logging.h>
 
 #include "base/bit_utils.h"
+#include "base/leb128.h"
 #include "base/stl_util.h"
 #include "base/unix_file/fd_file.h"
 #include "dex/art_dex_file_loader.h"
 #include "dex/dex_file.h"
 #include "dex/dex_file_loader.h"
+#include "dex/hidden_api_access_flags.h"
 #include "dex_to_dex_decompiler.h"
-#include "hidden_api_access_flags.h"
-#include "leb128.h"
 #include "quicken_info.h"
 
 namespace art {
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 9a393ea..52bd736 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -24,6 +24,7 @@
 #include "art_method-inl.h"
 #include "base/aborting.h"
 #include "base/enums.h"
+#include "base/leb128.h"
 #include "base/logging.h"  // For VLOG.
 #include "base/mutex-inl.h"
 #include "base/stl_util.h"
@@ -41,7 +42,6 @@
 #include "handle_scope-inl.h"
 #include "indenter.h"
 #include "intern_table.h"
-#include "leb128.h"
 #include "mirror/class-inl.h"
 #include "mirror/class.h"
 #include "mirror/dex_cache-inl.h"
diff --git a/runtime/verifier/reg_type.h b/runtime/verifier/reg_type.h
index 9055849..3e99407 100644
--- a/runtime/verifier/reg_type.h
+++ b/runtime/verifier/reg_type.h
@@ -27,10 +27,10 @@
 #include "base/macros.h"
 #include "base/mutex.h"
 #include "base/stringpiece.h"
+#include "dex/primitive.h"
 #include "gc_root.h"
 #include "handle_scope.h"
 #include "obj_ptr.h"
-#include "primitive.h"
 
 namespace art {
 namespace mirror {
diff --git a/runtime/verifier/reg_type_cache.h b/runtime/verifier/reg_type_cache.h
index 5277676..b32dc11 100644
--- a/runtime/verifier/reg_type_cache.h
+++ b/runtime/verifier/reg_type_cache.h
@@ -23,8 +23,8 @@
 #include "base/casts.h"
 #include "base/macros.h"
 #include "base/scoped_arena_containers.h"
+#include "dex/primitive.h"
 #include "gc_root.h"
-#include "primitive.h"
 
 namespace art {
 namespace mirror {
diff --git a/runtime/verifier/register_line.h b/runtime/verifier/register_line.h
index 82f63b2..18ad6b5 100644
--- a/runtime/verifier/register_line.h
+++ b/runtime/verifier/register_line.h
@@ -22,8 +22,8 @@
 
 #include <android-base/logging.h>
 
+#include "base/safe_map.h"
 #include "base/scoped_arena_containers.h"
-#include "safe_map.h"
 
 namespace art {
 
diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc
index 7d8c5aa..4772e53 100644
--- a/runtime/verifier/verifier_deps.cc
+++ b/runtime/verifier/verifier_deps.cc
@@ -20,11 +20,11 @@
 
 #include "art_field-inl.h"
 #include "art_method-inl.h"
+#include "base/leb128.h"
 #include "base/stl_util.h"
 #include "compiler_callbacks.h"
 #include "dex/dex_file-inl.h"
 #include "indenter.h"
-#include "leb128.h"
 #include "mirror/class-inl.h"
 #include "mirror/class_loader.h"
 #include "obj_ptr-inl.h"
diff --git a/runtime/zip_archive.h b/runtime/zip_archive.h
index 2ca4aa2..7b45690 100644
--- a/runtime/zip_archive.h
+++ b/runtime/zip_archive.h
@@ -23,11 +23,11 @@
 
 #include <android-base/logging.h>
 
+#include "base/safe_map.h"
 #include "base/unix_file/random_access_file.h"
 #include "globals.h"
 #include "mem_map.h"
 #include "os.h"
-#include "safe_map.h"
 
 // system/core/zip_archive definitions.
 struct ZipEntry;
diff --git a/tools/cpp-define-generator/Android.bp b/tools/cpp-define-generator/Android.bp
index f3342d3..39e57bd 100644
--- a/tools/cpp-define-generator/Android.bp
+++ b/tools/cpp-define-generator/Android.bp
@@ -29,6 +29,7 @@
         "art_defaults",
     ],
     include_dirs: [
+        "art/libartbase",
         "art/libdexfile",
         "art/runtime",
     ],
diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc
index c893da6..d986cf8 100644
--- a/tools/hiddenapi/hiddenapi.cc
+++ b/tools/hiddenapi/hiddenapi.cc
@@ -24,7 +24,7 @@
 #include "base/unix_file/fd_file.h"
 #include "dex/art_dex_file_loader.h"
 #include "dex/dex_file-inl.h"
-#include "hidden_api_access_flags.h"
+#include "dex/hidden_api_access_flags.h"
 #include "mem_map.h"
 #include "os.h"