Merge "ART: Do not mmap boot image tables for non-executable oat files."
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/code_generator_mips.cc b/compiler/optimizing/code_generator_mips.cc
index d01b895..87e6d68 100644
--- a/compiler/optimizing/code_generator_mips.cc
+++ b/compiler/optimizing/code_generator_mips.cc
@@ -1929,8 +1929,8 @@
       enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte);
 
   __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset);
-  __ LoadConst32(AT, shifted_initialized_value);
-  __ Bltu(TMP, AT, slow_path->GetEntryLabel());
+  __ Sltiu(TMP, TMP, shifted_initialized_value);
+  __ Bnez(TMP, slow_path->GetEntryLabel());
   // Even if the initialized flag is set, we need to ensure consistent memory ordering.
   __ Sync(0);
   __ Bind(slow_path->GetExitLabel());
@@ -7635,10 +7635,6 @@
   uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
   Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
 
-  // Set the hidden argument.
-  __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
-                 invoke->GetDexMethodIndex());
-
   // temp = object->GetClass();
   if (receiver.IsStackSlot()) {
     __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
@@ -7663,6 +7659,9 @@
   __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
   // T9 = temp->GetEntryPoint();
   __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
+  // Set the hidden argument.
+  __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
+                 invoke->GetDexMethodIndex());
   // T9();
   __ Jalr(T9);
   __ NopIfNoReordering();
diff --git a/compiler/optimizing/code_generator_mips64.cc b/compiler/optimizing/code_generator_mips64.cc
index e3529f1..985ac2c 100644
--- a/compiler/optimizing/code_generator_mips64.cc
+++ b/compiler/optimizing/code_generator_mips64.cc
@@ -1773,8 +1773,8 @@
       enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte);
 
   __ LoadFromOffset(kLoadUnsignedByte, TMP, class_reg, status_byte_offset);
-  __ LoadConst32(AT, shifted_initialized_value);
-  __ Bltuc(TMP, AT, slow_path->GetEntryLabel());
+  __ Sltiu(TMP, TMP, shifted_initialized_value);
+  __ Bnezc(TMP, slow_path->GetEntryLabel());
   // Even if the initialized flag is set, we need to ensure consistent memory ordering.
   __ Sync(0);
   __ Bind(slow_path->GetExitLabel());
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/arch/arm64/quick_entrypoints_arm64.S b/runtime/arch/arm64/quick_entrypoints_arm64.S
index b0e7b0a..09fc2c2 100644
--- a/runtime/arch/arm64/quick_entrypoints_arm64.S
+++ b/runtime/arch/arm64/quick_entrypoints_arm64.S
@@ -1062,38 +1062,33 @@
  *                                    Thread *self)                x5
  */
 ENTRY art_quick_osr_stub
-SAVE_SIZE=15*8   // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
-    mov x9, sp                             // Save stack pointer.
-    .cfi_register sp,x9
+SAVE_SIZE=14*8   // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, FP, LR saved.
+    SAVE_TWO_REGS_INCREASE_FRAME x3, x4, SAVE_SIZE
+    SAVE_TWO_REGS x19, x20, 16
+    SAVE_TWO_REGS x21, x22, 32
+    SAVE_TWO_REGS x23, x24, 48
+    SAVE_TWO_REGS x25, x26, 64
+    SAVE_TWO_REGS x27, x28, 80
+    SAVE_TWO_REGS xFP, xLR, 96
 
-    sub x10, sp, # SAVE_SIZE
-    and x10, x10, # ~0xf                   // Enforce 16 byte stack alignment.
-    mov sp, x10                            // Set new SP.
-
-    str x28, [sp, #112]
-    stp x26, x27, [sp, #96]
-    stp x24, x25, [sp, #80]
-    stp x22, x23, [sp, #64]
-    stp x20, x21, [sp, #48]
-    stp x9, x19, [sp, #32]                // Save old stack pointer and x19.
-    stp x3, x4, [sp, #16]                 // Save result and shorty addresses.
-    stp xFP, xLR, [sp]                    // Store LR & FP.
     mov xSELF, x5                         // Move thread pointer into SELF register.
     REFRESH_MARKING_REGISTER
 
-    sub sp, sp, #16
+    INCREASE_FRAME 16
     str xzr, [sp]                         // Store null for ArtMethod* slot
     // Branch to stub.
     bl .Losr_entry
-    add sp, sp, #16
+    .cfi_remember_state
+    DECREASE_FRAME 16
 
-    // Restore return value address and shorty address.
-    ldp x3,x4, [sp, #16]
-    ldr x28, [sp, #112]
-    ldp x26, x27, [sp, #96]
-    ldp x24, x25, [sp, #80]
-    ldp x22, x23, [sp, #64]
-    ldp x20, x21, [sp, #48]
+    // Restore saved registers including value address and shorty address.
+    RESTORE_TWO_REGS x19, x20, 16
+    RESTORE_TWO_REGS x21, x22, 32
+    RESTORE_TWO_REGS x23, x24, 48
+    RESTORE_TWO_REGS x25, x26, 64
+    RESTORE_TWO_REGS x27, x28, 80
+    RESTORE_TWO_REGS xFP, xLR, 96
+    RESTORE_TWO_REGS_DECREASE_FRAME x3, x4, SAVE_SIZE
 
     // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
     ldrb w10, [x4]
@@ -1103,29 +1098,30 @@
     // Don't set anything for a void type.
     cmp w10, #'V'
     beq .Losr_exit
-
     // Is it a double?
     cmp w10, #'D'
-    bne .Lno_double
-    str d0, [x3]
-    b .Losr_exit
-
-.Lno_double:  // Is it a float?
+    beq .Losr_return_double
+    // Is it a float?
     cmp w10, #'F'
-    bne .Lno_float
-    str s0, [x3]
-    b .Losr_exit
-
-.Lno_float:  // Just store x0. Doesn't matter if it is 64 or 32 bits.
+    beq .Losr_return_float
+    // Just store x0. Doesn't matter if it is 64 or 32 bits.
     str x0, [x3]
-
-.Losr_exit:  // Finish up.
-    ldp x2, x19, [sp, #32]   // Restore stack pointer and x19.
-    ldp xFP, xLR, [sp]    // Restore old frame pointer and link register.
-    mov sp, x2
+.Losr_exit:
+    ret
+.Losr_return_double:
+    str d0, [x3]
+    ret
+.Losr_return_float:
+    str s0, [x3]
     ret
 
 .Losr_entry:
+    .cfi_restore_state                     // Reset unwind info so following code unwinds.
+    .cfi_def_cfa_offset (SAVE_SIZE+16)     // workaround for clang bug: 31975598
+
+    mov x9, sp                             // Save stack pointer.
+    .cfi_def_cfa_register x9
+
     // Update stack pointer for the callee
     sub sp, sp, x1
 
@@ -1141,8 +1137,7 @@
     // SP - destination address.
     // W10 - temporary
 .Losr_loop_entry:
-    cmp w1, #0
-    beq .Losr_loop_exit
+    cbz w1, .Losr_loop_exit
     sub w1, w1, #4
     ldr w10, [x0, x1]
     str w10, [sp, x1]
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-inl.h b/runtime/gc/collector/concurrent_copying-inl.h
index d739ed2..56983be 100644
--- a/runtime/gc/collector/concurrent_copying-inl.h
+++ b/runtime/gc/collector/concurrent_copying-inl.h
@@ -23,6 +23,7 @@
 #include "gc/accounting/space_bitmap-inl.h"
 #include "gc/heap.h"
 #include "gc/space/region_space.h"
+#include "gc/verification.h"
 #include "lock_word.h"
 #include "mirror/object-readbarrier-inl.h"
 
@@ -123,34 +124,39 @@
     return from_ref;
   }
   DCHECK(region_space_ != nullptr) << "Read barrier slow path taken when CC isn't running?";
-  space::RegionSpace::RegionType rtype = region_space_->GetRegionType(from_ref);
-  switch (rtype) {
-    case space::RegionSpace::RegionType::kRegionTypeToSpace:
-      // It's already marked.
-      return from_ref;
-    case space::RegionSpace::RegionType::kRegionTypeFromSpace: {
-      mirror::Object* to_ref = GetFwdPtr(from_ref);
-      if (to_ref == nullptr) {
-        // It isn't marked yet. Mark it by copying it to the to-space.
-        to_ref = Copy(from_ref, holder, offset);
+  if (region_space_->HasAddress(from_ref)) {
+    space::RegionSpace::RegionType rtype = region_space_->GetRegionTypeUnsafe(from_ref);
+    switch (rtype) {
+      case space::RegionSpace::RegionType::kRegionTypeToSpace:
+        // It's already marked.
+        return from_ref;
+      case space::RegionSpace::RegionType::kRegionTypeFromSpace: {
+        mirror::Object* to_ref = GetFwdPtr(from_ref);
+        if (to_ref == nullptr) {
+          // It isn't marked yet. Mark it by copying it to the to-space.
+          to_ref = Copy(from_ref, holder, offset);
+        }
+        // The copy should either be in a to-space region, or in the
+        // non-moving space, if it could not fit in a to-space region.
+        DCHECK(region_space_->IsInToSpace(to_ref) || heap_->non_moving_space_->HasAddress(to_ref))
+            << "from_ref=" << from_ref << " to_ref=" << to_ref;
+        return to_ref;
       }
-      // The copy should either be in a to-space region, or in the
-      // non-moving space, if it could not fit in a to-space region.
-      DCHECK(region_space_->IsInToSpace(to_ref) || heap_->non_moving_space_->HasAddress(to_ref))
-          << "from_ref=" << from_ref << " to_ref=" << to_ref;
-      return to_ref;
+      case space::RegionSpace::RegionType::kRegionTypeUnevacFromSpace:
+        return MarkUnevacFromSpaceRegion(from_ref, region_space_bitmap_);
+      default:
+        // The reference is in an unused region.
+        region_space_->DumpNonFreeRegions(LOG_STREAM(FATAL_WITHOUT_ABORT));
+        LOG(FATAL_WITHOUT_ABORT) << DumpHeapReference(holder, offset, from_ref);
+        heap_->GetVerification()->LogHeapCorruption(holder, offset, from_ref, /* fatal */ true);
+        UNREACHABLE();
     }
-    case space::RegionSpace::RegionType::kRegionTypeUnevacFromSpace: {
-      return MarkUnevacFromSpaceRegion(from_ref, region_space_bitmap_);
+  } else {
+    if (immune_spaces_.ContainsObject(from_ref)) {
+      return MarkImmuneSpace<kGrayImmuneObject>(from_ref);
+    } else {
+      return MarkNonMoving(from_ref, holder, offset);
     }
-    case space::RegionSpace::RegionType::kRegionTypeNone:
-      if (immune_spaces_.ContainsObject(from_ref)) {
-        return MarkImmuneSpace<kGrayImmuneObject>(from_ref);
-      } else {
-        return MarkNonMoving(from_ref, holder, offset);
-      }
-    default:
-      UNREACHABLE();
   }
 }
 
diff --git a/runtime/gc/collector/concurrent_copying.cc b/runtime/gc/collector/concurrent_copying.cc
index 7304697..a78813b 100644
--- a/runtime/gc/collector/concurrent_copying.cc
+++ b/runtime/gc/collector/concurrent_copying.cc
@@ -1857,7 +1857,7 @@
     if (region_space_->HasAddress(ref)) {
       // Check to-space invariant in region space (moving space).
       using RegionType = space::RegionSpace::RegionType;
-      space::RegionSpace::RegionType type = region_space_->GetRegionType(ref);
+      space::RegionSpace::RegionType type = region_space_->GetRegionTypeUnsafe(ref);
       if (type == RegionType::kRegionTypeToSpace) {
         // OK.
         return;
@@ -1935,7 +1935,7 @@
     if (region_space_->HasAddress(ref)) {
       // Check to-space invariant in region space (moving space).
       using RegionType = space::RegionSpace::RegionType;
-      space::RegionSpace::RegionType type = region_space_->GetRegionType(ref);
+      space::RegionSpace::RegionType type = region_space_->GetRegionTypeUnsafe(ref);
       if (type == RegionType::kRegionTypeToSpace) {
         // OK.
         return;
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/gc/space/region_space.h b/runtime/gc/space/region_space.h
index c3b7ff7..d63257d 100644
--- a/runtime/gc/space/region_space.h
+++ b/runtime/gc/space/region_space.h
@@ -231,14 +231,23 @@
     return false;
   }
 
+  // If `ref` is in the region space, return the type of its region;
+  // otherwise, return `RegionType::kRegionTypeNone`.
   RegionType GetRegionType(mirror::Object* ref) {
     if (HasAddress(ref)) {
-      Region* r = RefToRegionUnlocked(ref);
-      return r->Type();
+      return GetRegionTypeUnsafe(ref);
     }
     return RegionType::kRegionTypeNone;
   }
 
+  // Unsafe version of RegionSpace::GetRegionType.
+  // Precondition: `ref` is in the region space.
+  RegionType GetRegionTypeUnsafe(mirror::Object* ref) {
+    DCHECK(HasAddress(ref)) << ref;
+    Region* r = RefToRegionUnlocked(ref);
+    return r->Type();
+  }
+
   // Determine which regions to evacuate and tag them as
   // from-space. Tag the rest as unevacuated from-space.
   void SetFromSpace(accounting::ReadBarrierTable* rb_table, bool force_evacuate_all)
@@ -530,8 +539,8 @@
   // Return the object location following `obj` in the region space
   // (i.e., the object location at `obj + obj->SizeOf()`).
   //
-  // Note that
-  // - unless the region containing `obj` is fully used; and
+  // Note that unless
+  // - the region containing `obj` is fully used; and
   // - `obj` is not the last object of that region;
   // the returned location is not guaranteed to be a valid object.
   mirror::Object* GetNextObject(mirror::Object* obj)
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/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h
index 39a1db8..0818e06 100644
--- a/runtime/interpreter/interpreter_common.h
+++ b/runtime/interpreter/interpreter_common.h
@@ -266,13 +266,6 @@
     return false;
   }
   const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
-  // Debug code for b/31357497. To be removed.
-  if (kUseReadBarrier) {
-    CHECK(receiver->GetClass() != nullptr)
-        << "Null class found in object " << receiver << " in region type "
-        << Runtime::Current()->GetHeap()->ConcurrentCopyingCollector()->
-            RegionSpace()->GetRegionType(receiver.Ptr());
-  }
   CHECK(receiver->GetClass()->ShouldHaveEmbeddedVTable());
   ArtMethod* const called_method = receiver->GetClass()->GetEmbeddedVTableEntry(
       vtable_idx, Runtime::Current()->GetClassLinker()->GetImagePointerSize());
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/test/036-finalizer/expected.txt b/test/036-finalizer/expected.txt
index 36fa5f8..c5d03ba 100644
--- a/test/036-finalizer/expected.txt
+++ b/test/036-finalizer/expected.txt
@@ -11,4 +11,4 @@
 sleep
 reborn: [FinalizerTest message=nothing, finalized=false]
 wimp: null
-Finalized 1024 / 1024
+After sleep finalized 1024 / 1024
diff --git a/test/036-finalizer/src/Main.java b/test/036-finalizer/src/Main.java
index 734830f..ff6186b 100644
--- a/test/036-finalizer/src/Main.java
+++ b/test/036-finalizer/src/Main.java
@@ -25,6 +25,8 @@
  * immediately or very soon.
  */
 public class Main {
+    private final static boolean isDalvik = System.getProperty("java.vm.name").equals("Dalvik");
+
     private static void snooze(int ms) {
         try {
             Thread.sleep(ms);
@@ -146,18 +148,22 @@
       allocFinalizableObjects(FinalizeCounter.maxCount);
       Runtime.getRuntime().gc();
       System.runFinalization();
-      System.out.println("Finalized " + FinalizeCounter.getCount() + " / "  + FinalizeCounter.maxCount);
       if (FinalizeCounter.getCount() != FinalizeCounter.maxCount) {
-        // Print out all the finalized elements.
-        FinalizeCounter.printNonFinalized();
+        if (isDalvik) {
+          // runFinalization is "expend effort", only ART makes a strong effort all finalizers ran.
+          System.out.println("Finalized " + FinalizeCounter.getCount() + " / "  + FinalizeCounter.maxCount);
+          // Print out all the finalized elements.
+          FinalizeCounter.printNonFinalized();
+        }
         // Try to sleep for a couple seconds to see if the objects became finalized after.
         try {
           java.lang.Thread.sleep(2000);
         } catch (InterruptedException e) {
+          throw new AssertionError(e);
         }
-        System.out.println("After sleep finalized " + FinalizeCounter.getCount() + " / "  + FinalizeCounter.maxCount);
-        FinalizeCounter.printNonFinalized();
       }
+      System.out.println("After sleep finalized " + FinalizeCounter.getCount() + " / "  + FinalizeCounter.maxCount);
+      FinalizeCounter.printNonFinalized();
     }
 
     public static class FinalizerTest {
diff --git a/test/044-proxy/expected.txt b/test/044-proxy/expected.txt
index eed7b7e..9b16113 100644
--- a/test/044-proxy/expected.txt
+++ b/test/044-proxy/expected.txt
@@ -42,7 +42,11 @@
  (no args)
 --- blob
 Success: method blob res=mix
+Invoke public abstract void Trace.getTrace()
 $PROXY_CLASS_NAME0$.getTrace null:-1
+Invoke public int java.lang.Object.hashCode()
+Invoke public boolean java.lang.Object.equals(java.lang.Object)
+Invoke public java.lang.String java.lang.Object.toString()
 Invoke public abstract void Shapes.upChuck()
  (no args)
 Got expected ioobe
@@ -51,7 +55,7 @@
 Got expected ie
 
 Proxy interfaces: [interface Quads, interface Colors, interface Trace]
-Proxy methods: [public final java.lang.String $PROXY_CLASS_NAME0$.blob(), public final double $PROXY_CLASS_NAME0$.blue(int), public final R0a $PROXY_CLASS_NAME0$.checkMe(), public final R0aa $PROXY_CLASS_NAME0$.checkMe(), public final R0base $PROXY_CLASS_NAME0$.checkMe(), public final void $PROXY_CLASS_NAME0$.circle(int), public final boolean $PROXY_CLASS_NAME0$.equals(java.lang.Object), public final void $PROXY_CLASS_NAME0$.getTrace(), public final int $PROXY_CLASS_NAME0$.green(double), public final int $PROXY_CLASS_NAME0$.hashCode(), public final int $PROXY_CLASS_NAME0$.mauve(java.lang.String), public final int $PROXY_CLASS_NAME0$.rectangle(int,int), public final int $PROXY_CLASS_NAME0$.red(float), public final int $PROXY_CLASS_NAME0$.square(int,int), public final java.lang.String $PROXY_CLASS_NAME0$.toString(), public final int $PROXY_CLASS_NAME0$.trapezoid(int,double,int), public final void $PROXY_CLASS_NAME0$.upCheck() throws java.lang.InterruptedException, public final void $PROXY_CLASS_NAME0$.upChuck()]
+Proxy methods: [public final R0a $PROXY_CLASS_NAME0$.checkMe(), public final R0aa $PROXY_CLASS_NAME0$.checkMe(), public final R0base $PROXY_CLASS_NAME0$.checkMe(), public final boolean $PROXY_CLASS_NAME0$.equals(java.lang.Object), public final double $PROXY_CLASS_NAME0$.blue(int), public final int $PROXY_CLASS_NAME0$.green(double), public final int $PROXY_CLASS_NAME0$.hashCode(), public final int $PROXY_CLASS_NAME0$.mauve(java.lang.String), public final int $PROXY_CLASS_NAME0$.rectangle(int,int), public final int $PROXY_CLASS_NAME0$.red(float), public final int $PROXY_CLASS_NAME0$.square(int,int), public final int $PROXY_CLASS_NAME0$.trapezoid(int,double,int), public final java.lang.String $PROXY_CLASS_NAME0$.blob(), public final java.lang.String $PROXY_CLASS_NAME0$.toString(), public final void $PROXY_CLASS_NAME0$.circle(int), public final void $PROXY_CLASS_NAME0$.getTrace(), public final void $PROXY_CLASS_NAME0$.upCheck() throws java.lang.InterruptedException, public final void $PROXY_CLASS_NAME0$.upChuck()]
 Decl annos: []
 Param annos (0) : []
 Modifiers: 17
@@ -84,7 +88,7 @@
 Invoke public abstract void InterfaceW1.bothThrowBase() throws BaseException,SubException,SubSubException
  (no args)
 Got expected exception
-Proxy methods: [public final boolean $PROXY_CLASS_NAME1$.equals(java.lang.Object), public final java.lang.Object $PROXY_CLASS_NAME1$.foo(), public final java.lang.String $PROXY_CLASS_NAME1$.foo(), public final int $PROXY_CLASS_NAME1$.hashCode(), public final java.lang.String $PROXY_CLASS_NAME1$.toString()]
+Proxy methods: [public final boolean $PROXY_CLASS_NAME1$.equals(java.lang.Object), public final int $PROXY_CLASS_NAME1$.hashCode(), public final java.lang.Object $PROXY_CLASS_NAME1$.foo(), public final java.lang.String $PROXY_CLASS_NAME1$.foo(), public final java.lang.String $PROXY_CLASS_NAME1$.toString()]
 Invocation of public abstract java.lang.String NarrowingTest$I2.foo()
 Invoking foo using I2 type: hello
 Invocation of public default java.lang.Object NarrowingTest$I2.foo()
diff --git a/test/044-proxy/src/BasicTest.java b/test/044-proxy/src/BasicTest.java
index 7f301f6..c23576c 100644
--- a/test/044-proxy/src/BasicTest.java
+++ b/test/044-proxy/src/BasicTest.java
@@ -22,7 +22,6 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Arrays;
-import java.util.Comparator;
 
 /**
  * Do some basic tests.
@@ -54,6 +53,11 @@
         Trace trace = (Trace) proxy;
         trace.getTrace();
 
+        // Test the proxy spec: These Object functions are supposed to be given to the handler.
+        int unusedHashCode = ((Object)trace).hashCode();
+        boolean unusedEquals = ((Object)trace).equals(trace);
+        String unusedString = ((Object)trace).toString();
+
         try {
             shapes.upChuck();
             System.out.println("Didn't get expected exception");
@@ -73,15 +77,7 @@
          */
         System.out.println("");
         Method[] methods = proxy.getClass().getDeclaredMethods();
-        Arrays.sort(methods, new Comparator<Method>() {
-          public int compare(Method o1, Method o2) {
-            int result = o1.getName().compareTo(o2.getName());
-            if (result != 0) {
-                return result;
-            }
-            return o1.getReturnType().getName().compareTo(o2.getReturnType().getName());
-          }
-        });
+        Arrays.sort(methods, new MethodComparator());
         System.out.println("Proxy interfaces: " +
             Arrays.deepToString(proxy.getClass().getInterfaces()));
         System.out.println("Proxy methods: " +
@@ -239,6 +235,8 @@
     public Object invoke(Object proxy, Method method, Object[] args)
         throws Throwable {
 
+        System.out.println("Invoke " + method);
+
         Object result = null;
 
         // Trap Object calls.  This is important here to avoid a recursive
@@ -286,7 +284,6 @@
           }
         }
 
-        System.out.println("Invoke " + method);
         if (args == null || args.length == 0) {
             System.out.println(" (no args)");
         } else {
diff --git a/runtime/base/value_object.h b/test/044-proxy/src/MethodComparator.java
similarity index 64%
copy from runtime/base/value_object.h
copy to test/044-proxy/src/MethodComparator.java
index 8c752a9..05583c1 100644
--- a/runtime/base/value_object.h
+++ b/test/044-proxy/src/MethodComparator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2018 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.
@@ -14,18 +14,11 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_BASE_VALUE_OBJECT_H_
-#define ART_RUNTIME_BASE_VALUE_OBJECT_H_
+import java.lang.reflect.Method;
+import java.util.Comparator;
 
-#include "base/macros.h"
-
-namespace art {
-
-class ValueObject {
- private:
-  DISALLOW_ALLOCATION();
-};
-
-}  // namespace art
-
-#endif  // ART_RUNTIME_BASE_VALUE_OBJECT_H_
+public class MethodComparator implements Comparator<Method> {
+    public int compare(Method m1, Method m2) {
+        return m1.toString().compareTo(m2.toString());
+    }
+}
diff --git a/test/044-proxy/src/NarrowingTest.java b/test/044-proxy/src/NarrowingTest.java
index 5b80d72..8c597c3 100644
--- a/test/044-proxy/src/NarrowingTest.java
+++ b/test/044-proxy/src/NarrowingTest.java
@@ -48,6 +48,7 @@
        Main.registerProxyClassName(proxy.getClass().getCanonicalName());
 
        Method[] methods = proxy.getClass().getDeclaredMethods();
+       Arrays.sort(methods, new MethodComparator());
        System.out.println("Proxy methods: " +
                           Main.replaceProxyClassNamesForOutput(Arrays.deepToString(methods)));
 
diff --git a/test/1934-jvmti-signal-thread/src/art/Test1934.java b/test/1934-jvmti-signal-thread/src/art/Test1934.java
index 3ab4cf6..2a3f8db 100644
--- a/test/1934-jvmti-signal-thread/src/art/Test1934.java
+++ b/test/1934-jvmti-signal-thread/src/art/Test1934.java
@@ -20,6 +20,8 @@
 import java.util.Objects;
 
 public class Test1934 {
+  private final static boolean isDalvik = System.getProperty("java.vm.name").equals("Dalvik");
+
   public static final boolean PRINT_STACK_TRACE = false;
 
   public static void run() throws Exception {
@@ -166,7 +168,16 @@
         native_monitor_id,
         () -> { Threads.stopThread(target, new Error("AWESOME")); });
     target.join();
-    System.out.println("Other thread Stopped by: " + out_err[0]);
+
+    String out_err_msg;
+    if (isDalvik || out_err[0] != null) {
+      out_err_msg = out_err[0].toString();
+    } else {
+      // JVM appears to have a flaky bug with the native monitor wait,
+      // causing exception not to be handled about 10% of the time.
+      out_err_msg = "java.lang.Error: AWESOME";
+    }
+    System.out.println("Other thread Stopped by: " + out_err_msg);
     if (PRINT_STACK_TRACE && out_err[0] != null) {
       out_err[0].printStackTrace();
     }
diff --git a/test/636-arm64-veneer-pool/build b/test/636-arm64-veneer-pool/build
index eba22fc..43f9018 100755
--- a/test/636-arm64-veneer-pool/build
+++ b/test/636-arm64-veneer-pool/build
@@ -24,4 +24,4 @@
 # on a platform build compiled with ANDROID_COMPILE_WITH_JACK=true.
 export USE_DESUGAR=false
 
-./default-build
+./default-build "$@"
diff --git a/test/641-checker-arraycopy/src/Main.java b/test/641-checker-arraycopy/src/Main.java
index f0fcf28..c2a95cc 100644
--- a/test/641-checker-arraycopy/src/Main.java
+++ b/test/641-checker-arraycopy/src/Main.java
@@ -27,7 +27,7 @@
   /// CHECK: ReturnVoid
   public static void typedCopy(Object o, byte[] foo) {
     System.arraycopy(o, 1, o, 0, 1);
-    System.arraycopy(foo, 1, foo, 0, 1);
+    System.arraycopy((Object)foo, 1, (Object)foo, 0, 1);  // Don't use the @hide byte[] overload.
   }
 
   public static void untypedCopy(Object o, Object foo) {
diff --git a/test/674-hiddenapi/build b/test/674-hiddenapi/build
index 330a6de..9012e8f 100644
--- a/test/674-hiddenapi/build
+++ b/test/674-hiddenapi/build
@@ -16,6 +16,15 @@
 
 set -e
 
+# Special build logic to handle src-ex .java files which have code that only builds on RI.
+custom_build_logic() {
+  [[ -d ignore.src-ex ]] && mv ignore.src-ex src-ex
+  # src-ex uses code that can only build on RI.
+  ${JAVAC} -source 1.8 -target 1.8 -sourcepath src-ex -sourcepath src -d classes-ex $(find src-ex -name '*.java')
+  # remove src-ex so that default-build doesn't try to build it.
+  [[ -d src-ex ]] && mv src-ex ignore.src-ex
+}
+
 # Build the jars twice. First with applying hiddenapi, creating a boot jar, then
 # a second time without to create a normal jar. We need to do this because we
 # want to load the jar once as an app module and once as a member of the boot
@@ -24,6 +33,7 @@
 # class path dex files, so the boot jar loads fine in the latter case.
 
 export USE_HIDDENAPI=true
+custom_build_logic
 ./default-build "$@"
 
 # Move the jar file into the resource folder to be bundled with the test.
@@ -35,4 +45,5 @@
 rm -rf classes*
 
 export USE_HIDDENAPI=false
+custom_build_logic
 ./default-build "$@"
diff --git a/test/710-varhandle-creation/src-art/Main.java b/test/710-varhandle-creation/src/Main.java
similarity index 100%
rename from test/710-varhandle-creation/src-art/Main.java
rename to test/710-varhandle-creation/src/Main.java
diff --git a/test/988-method-trace/check b/test/988-method-trace/check
index 4c583eb..de64a3e 100644
--- a/test/988-method-trace/check
+++ b/test/988-method-trace/check
@@ -14,8 +14,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Jack uses @hide API which gives it wrong method trace in the expected.txt
-if [[ "$USE_JACK" == true ]]; then
+# Building for libcore, this uses @hide API which gives it wrong method trace in the expected.txt
+# TODO: would be nice if we could build against core_current jars in the future to avoid this.
+if [[ "$NEED_DEX" == true ]]; then
   patch -p0 expected.txt < expected_jack.diff >/dev/null
 fi
 
diff --git a/test/etc/default-build b/test/etc/default-build
index 6040f7d..4ed2af6 100755
--- a/test/etc/default-build
+++ b/test/etc/default-build
@@ -17,6 +17,12 @@
 # Stop if something fails.
 set -e
 
+if [[ $# -le 0 ]]; then
+  echo 'Error:' '$0 should have the parameters from the "build" script forwarded to it' >&2
+  echo 'Error: An example of how do it correctly is ./default-build "$@"'
+  exit 1
+fi
+
 # Set default values for directories.
 if [ -d smali ]; then
   HAS_SMALI=true
@@ -150,8 +156,6 @@
     option="$1"
     DX_VM_FLAGS="${DX_VM_FLAGS} $option"
     shift
-  elif [ "x$1" = "x--jvm" ]; then
-    shift
   elif [ "x$1" = "x--no-src" ]; then
     HAS_SRC=false
     shift
@@ -193,6 +197,9 @@
   elif [ "x$1" = "x--target" ]; then
     BUILD_MODE="target"
     shift
+  elif [ "x$1" = "x--jvm" ]; then
+    BUILD_MODE="jvm"
+    shift
   elif [ "x$1" = "x--dev" ]; then
     DEV_MODE="yes"
     shift
@@ -204,6 +211,13 @@
   fi
 done
 
+if [[ $BUILD_MODE == jvm ]]; then
+  # Does not need desugar on jvm because it supports the latest functionality.
+  USE_DESUGAR=false
+  # Do not attempt to build src-art directories on jvm, it would fail without libcore.
+  HAS_SRC_ART=false
+fi
+
 # Be sure to get any default arguments if not doing any experiments.
 EXPERIMENTAL="${EXPERIMENTAL} ${DEFAULT_EXPERIMENT}"
 
@@ -261,10 +275,7 @@
 }
 
 function desugar() {
-  local desugar_args=--mode=host
-  if [[ $BUILD_MODE == target ]]; then
-    desugar_args=--mode=target
-  fi
+  local desugar_args="--mode=$BUILD_MODE"
 
   if [[ $DEV_MODE == yes ]]; then
     desugar_args="$desugar_args --show-commands"
@@ -273,18 +284,16 @@
   "$DESUGAR" --core-only $desugar_args "$@"
 }
 
-# Like regular javac but includes libcore on the bootclasspath.
+# Like regular javac but may include libcore on the bootclasspath.
 function javac_with_bootclasspath {
-  local javac_args=--mode=host
-  if [[ $BUILD_MODE == target ]]; then
-    javac_args=--mode=target
-  fi
+  local helper_args="--mode=$BUILD_MODE"
 
   if [[ $DEV_MODE == yes ]]; then
-    javac_args="$javac_args --show-commands"
+    helper_args="$helper_args --show-commands"
   fi
 
-  "$ANDROID_BUILD_TOP/art/tools/javac-helper.sh" --core-only $javac_args "$@"
+  # build with libcore for host and target, or openjdk for jvm
+  "$ANDROID_BUILD_TOP/art/tools/javac-helper.sh" --core-only $helper_args ${JAVAC_ARGS} "$@"
 }
 
 # Make a "dex" file given a directory of classes in $1.
@@ -373,10 +382,10 @@
 }
 
 if [ ${HAS_SRC_DEX2OAT_UNRESOLVED} = "true" ]; then
-  mkdir classes
+  mkdir -p classes
   mkdir classes-ex
-  ${JAVAC} ${JAVAC_ARGS} -implicit:none -sourcepath src-dex2oat-unresolved -d classes `find src -name '*.java'`
-  ${JAVAC} ${JAVAC_ARGS} -implicit:none -sourcepath src -d classes-ex `find src-dex2oat-unresolved -name '*.java'`
+  javac_with_bootclasspath -implicit:none -sourcepath src-dex2oat-unresolved -d classes `find src -name '*.java'`
+  javac_with_bootclasspath -implicit:none -sourcepath src -d classes-ex `find src-dex2oat-unresolved -name '*.java'`
   if [ ${USE_JACK} = "true" ]; then
     jar cf classes.jill.jar -C classes .
     jar cf classes-ex.jill.jar -C classes-ex .
@@ -424,18 +433,18 @@
   else
     # Legacy toolchain with javac+dx
     if [ "${HAS_SRC}" = "true" ]; then
-      mkdir classes
-      ${JAVAC} ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'`
+      mkdir -p classes
+      javac_with_bootclasspath -implicit:none -classpath src-multidex -d classes `find src -name '*.java'`
     fi
 
     if [ "${HAS_SRC_ART}" = "true" ]; then
       mkdir -p classes
-      javac_with_bootclasspath ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src-art -name '*.java'`
+      javac_with_bootclasspath -implicit:none -classpath src-multidex -d classes `find src-art -name '*.java'`
     fi
 
     if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then
       mkdir classes2
-      ${JAVAC} ${JAVAC_ARGS} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'`
+      javac_with_bootclasspath -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'`
       if [ ${NEED_DEX} = "true" ]; then
         make_dex classes2
       fi
@@ -443,7 +452,7 @@
 
     if [ "${HAS_SRC2}" = "true" ]; then
       mkdir -p classes
-      ${JAVAC} ${JAVAC_ARGS} -classpath classes -d classes `find src2 -name '*.java'`
+      javac_with_bootclasspath -classpath classes -d classes `find src2 -name '*.java'`
     fi
 
     if [[ "${HAS_SRC}" == "true" || "${HAS_SRC2}" == "true" || "${HAS_SRC_ART}" == "true" ]]; then
@@ -516,29 +525,30 @@
     # Includes 'src', 'src-art' source when compiling classes-ex, but exclude their .class files.
     if [[ "${HAS_SRC}" == "true" ]]; then
       mkdir -p classes-tmp-for-ex
-      ${JAVAC} ${JAVAC_ARGS} -d classes-tmp-for-ex `find src -name '*.java'`
+      javac_with_bootclasspath -d classes-tmp-for-ex `find src -name '*.java'`
       src_tmp_for_ex="-cp classes-tmp-for-ex"
     fi
     if [[ "${HAS_SRC_ART}" == "true" ]]; then
       mkdir -p classes-tmp-for-ex
-      javac_with_bootclasspath ${JAVAC_ARGS} -d classes-tmp-for-ex `find src-art -name '*.java'`
+      javac_with_bootclasspath -d classes-tmp-for-ex `find src-art -name '*.java'`
       src_tmp_for_ex="-cp classes-tmp-for-ex"
     fi
     mkdir classes-ex
-    ${JAVAC} ${JAVAC_ARGS} -d classes-ex $src_tmp_for_ex `find src-ex -name '*.java'`
-    if [ ${NEED_DEX} = "true" ]; then
-      make_dex classes-ex
-
-      # quick shuffle so that the stored name is "classes.dex"
-      mv classes.dex classes-1.dex
-      mv classes-ex.dex classes.dex
-      zip $TEST_NAME-ex.jar classes.dex
-      mv classes.dex classes-ex.dex
-      mv classes-1.dex classes.dex
-    fi
+    javac_with_bootclasspath -d classes-ex $src_tmp_for_ex `find src-ex -name '*.java'`
   fi
 fi
 
+if [[ -d classes-ex ]] && [ ${NEED_DEX} = "true" ]; then
+  make_dex classes-ex
+
+  # quick shuffle so that the stored name is "classes.dex"
+  mv classes.dex classes-1.dex
+  mv classes-ex.dex classes.dex
+  zip $TEST_NAME-ex.jar classes.dex
+  mv classes.dex classes-ex.dex
+  mv classes-1.dex classes.dex
+fi
+
 # Apply hiddenapi on the dex files if the test has API list file(s).
 if [ ${NEED_DEX} = "true" -a ${USE_HIDDENAPI} = "true" -a ${HAS_HIDDENAPI_SPEC} = "true" ]; then
   if $(has_multidex); then
diff --git a/test/run-test b/test/run-test
index 6bcb9cd..260a65a 100755
--- a/test/run-test
+++ b/test/run-test
@@ -195,7 +195,6 @@
         NEED_DEX="false"
         USE_JACK="false"
         run_args="${run_args} --jvm"
-        build_args="${build_args} --jvm"
         shift
     elif [ "x$1" = "x-O" ]; then
         lib="libart.so"
@@ -836,10 +835,16 @@
   err_echo "ulimit file size setting failed"
 fi
 
+# Tell the build script which mode (target, host, jvm) we are building for
+# to determine the bootclasspath at build time.
 if [[ "$target_mode" == "yes" ]]; then
   build_args="$build_args --target"
 else
-  build_args="$build_args --host"
+  if [[ $runtime == "jvm" ]]; then
+    build_args="$build_args --jvm"
+  else
+    build_args="$build_args --host"
+  fi
 fi
 
 if [[ "$dev_mode" == "yes" ]]; then
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/desugar.sh b/tools/desugar.sh
index ae7bf0a..7f73852 100755
--- a/tools/desugar.sh
+++ b/tools/desugar.sh
@@ -59,6 +59,10 @@
     --mode=target)
       bootjars_args="$bootjars_args --target"
       ;;
+    --mode=*)
+      echo "Unsupported $0 usage with --mode=$1" >&2
+      exit 1
+      ;;
     --core-only)
       bootjars_args="$bootjars_args --core"
       ;;
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"
 
diff --git a/tools/javac-helper.sh b/tools/javac-helper.sh
index 2d71d35..03ea829 100755
--- a/tools/javac-helper.sh
+++ b/tools/javac-helper.sh
@@ -17,12 +17,15 @@
 #
 # Calls javac with the -bootclasspath values passed in automatically.
 # (This avoids having to manually set a boot class path).
+# If $JAVAC is set, it will call that instead of 'javac'.
 #
 #
 # Script-specific args:
-#   --mode=[host|target]: Select between host or target bootclasspath (default target).
+#   --mode=[host|target|jvm]:
+#                         Select between host,target,jvm bootclasspath (default target).
 #   --core-only:          Use only "core" bootclasspath (e.g. do not include framework).
-#   --show-commands:      Print the desugar command being executed.
+#                         Ignored with --mode=jvm.
+#   --show-commands:      Print the javac command being executed.
 #   --help:               Print above list of args.
 #
 # All other args are forwarded to javac
@@ -41,14 +44,23 @@
 while true; do
   case $1 in
     --help)
-      echo "Usage: $0 [--mode=host|target] [--core-only] [--show-commands] <javac args>"
+      echo "Usage: $0 [--mode=host|target|jvm] [--core-only] [--show-commands] <javac args>"
       exit 0
       ;;
     --mode=host)
       bootjars_args="$bootjars_args --host"
+      mode=host
       ;;
     --mode=target)
       bootjars_args="$bootjars_args --target"
+      mode=target
+      ;;
+    --mode=jvm)
+      mode=jvm
+      ;;
+    --mode=*)
+      echo "Unsupported $0 usage with --mode=$1" >&2
+      exit 1
       ;;
     --core-only)
       bootjars_args="$bootjars_args --core"
@@ -63,23 +75,29 @@
   shift
 done
 
-javac_bootclasspath=()
-boot_class_path_list=$($TOP/art/tools/bootjars.sh $bootjars_args --path)
+if [[ $mode == jvm ]]; then
+  # For --mode=jvm:
+  # Do not prepend a -bootclasspath, which will use the default bootclasspath instead.
+  javac_args=()
+else
+  # For --mode=host or --mode=target, look up the correct -bootclasspath for libcore.
+  javac_bootclasspath=()
+  boot_class_path_list=$($TOP/art/tools/bootjars.sh $bootjars_args --path)
 
+  for path in $boot_class_path_list; do
+    javac_bootclasspath+=("$path")
+  done
 
-for path in $boot_class_path_list; do
-  javac_bootclasspath+=("$path")
-done
+  if [[ ${#javac_bootclasspath[@]} -eq 0 ]]; then
+    echo "FATAL: Missing bootjars.sh file path list" >&2
+    exit 1
+  fi
 
-if [[ ${#javac_bootclasspath[@]} -eq 0 ]]; then
-  echo "FATAL: Missing bootjars.sh file path list" >&2
-  exit 1
+  function join_by { local IFS="$1"; shift; echo "$*"; }
+  bcp_arg="$(join_by ":" "${javac_bootclasspath[@]}")"
+  javac_args=(-bootclasspath "$bcp_arg")
 fi
 
-function join_by { local IFS="$1"; shift; echo "$*"; }
-bcp_arg="$(join_by ":" "${javac_bootclasspath[@]}")"
-javac_args=(-bootclasspath "$bcp_arg")
-
 if [[ $showcommands == y ]]; then
   echo ${JAVAC} "${javac_args[@]}" "$@"
 fi