Move some remaining dex utilities

There were several utilities related to building/walking/testing dex
files that were not in libdexfile.  This change consolidates these.

Bug: 22322814
Test: make -j 50 test-art-host
Change-Id: Id76e9179d03b8ec7d67f7e0f267121f54f0ec2e0
diff --git a/compiler/Android.bp b/compiler/Android.bp
index c4d538f..e42261c 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -359,9 +359,7 @@
         "utils/atomic_dex_ref_map_test.cc",
         "utils/dedupe_set_test.cc",
         "utils/intrusive_forward_list_test.cc",
-        "utils/string_reference_test.cc",
         "utils/swap_space_test.cc",
-        "utils/test_dex_file_builder_test.cc",
         "verifier_deps_test.cc",
 
         "jni/jni_cfi_test.cc",
diff --git a/compiler/dex/dex_to_dex_compiler.cc b/compiler/dex/dex_to_dex_compiler.cc
index 0caf1b1..be8641f 100644
--- a/compiler/dex/dex_to_dex_compiler.cc
+++ b/compiler/dex/dex_to_dex_compiler.cc
@@ -24,8 +24,8 @@
 #include "base/logging.h"  // For VLOG
 #include "base/macros.h"
 #include "base/mutex.h"
-#include "bytecode_utils.h"
 #include "compiled_method.h"
+#include "dex/bytecode_utils.h"
 #include "dex/dex_file-inl.h"
 #include "dex/dex_instruction-inl.h"
 #include "dex_to_dex_decompiler.h"
diff --git a/compiler/dex/dex_to_dex_compiler.h b/compiler/dex/dex_to_dex_compiler.h
index 7df09f1..7536c31 100644
--- a/compiler/dex/dex_to_dex_compiler.h
+++ b/compiler/dex/dex_to_dex_compiler.h
@@ -24,8 +24,8 @@
 #include "base/bit_vector.h"
 #include "dex/dex_file.h"
 #include "dex/invoke_type.h"
+#include "dex/method_reference.h"
 #include "handle.h"
-#include "method_reference.h"
 #include "quicken_info.h"
 
 namespace art {
diff --git a/compiler/dex/inline_method_analyser.h b/compiler/dex/inline_method_analyser.h
index 837cc85..e1d652a 100644
--- a/compiler/dex/inline_method_analyser.h
+++ b/compiler/dex/inline_method_analyser.h
@@ -21,7 +21,7 @@
 #include "base/mutex.h"
 #include "dex/dex_file.h"
 #include "dex/dex_instruction.h"
-#include "method_reference.h"
+#include "dex/method_reference.h"
 
 /*
  * NOTE: This code is part of the quick compiler. It lives in the runtime
diff --git a/compiler/dex/verification_results.h b/compiler/dex/verification_results.h
index 9e4192a..56f0030 100644
--- a/compiler/dex/verification_results.h
+++ b/compiler/dex/verification_results.h
@@ -24,8 +24,8 @@
 #include "base/macros.h"
 #include "base/mutex.h"
 #include "base/safe_map.h"
-#include "class_reference.h"
-#include "method_reference.h"
+#include "dex/class_reference.h"
+#include "dex/method_reference.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 ecbeed3..f04392d 100644
--- a/compiler/dex/verified_method.h
+++ b/compiler/dex/verified_method.h
@@ -22,7 +22,7 @@
 #include "base/mutex.h"
 #include "base/safe_map.h"
 #include "dex/dex_file.h"
-#include "method_reference.h"
+#include "dex/method_reference.h"
 
 namespace art {
 
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 8db892b..fffa3b3 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -33,14 +33,14 @@
 #include "base/quasi_atomic.h"
 #include "base/safe_map.h"
 #include "base/timing_logger.h"
-#include "class_reference.h"
 #include "class_status.h"
 #include "compiler.h"
+#include "dex/class_reference.h"
 #include "dex/dex_file.h"
 #include "dex/dex_file_types.h"
 #include "dex/dex_to_dex_compiler.h"
+#include "dex/method_reference.h"
 #include "driver/compiled_method_storage.h"
-#include "method_reference.h"
 #include "thread_pool.h"
 #include "utils/atomic_dex_ref_map.h"
 #include "utils/dex_cache_arrays_layout.h"
diff --git a/compiler/linker/arm/relative_patcher_arm_base.h b/compiler/linker/arm/relative_patcher_arm_base.h
index b0064d1..ee09bf9 100644
--- a/compiler/linker/arm/relative_patcher_arm_base.h
+++ b/compiler/linker/arm/relative_patcher_arm_base.h
@@ -21,8 +21,8 @@
 #include <vector>
 
 #include "base/safe_map.h"
+#include "dex/method_reference.h"
 #include "linker/relative_patcher.h"
-#include "method_reference.h"
 
 namespace art {
 namespace linker {
diff --git a/compiler/linker/linker_patch.h b/compiler/linker/linker_patch.h
index 36051d2..710d8a6 100644
--- a/compiler/linker/linker_patch.h
+++ b/compiler/linker/linker_patch.h
@@ -23,7 +23,7 @@
 #include <android-base/logging.h>
 
 #include "base/bit_utils.h"
-#include "method_reference.h"
+#include "dex/method_reference.h"
 
 namespace art {
 
diff --git a/compiler/linker/relative_patcher.h b/compiler/linker/relative_patcher.h
index 548e128..b58e3df 100644
--- a/compiler/linker/relative_patcher.h
+++ b/compiler/linker/relative_patcher.h
@@ -23,7 +23,7 @@
 #include "arch/instruction_set_features.h"
 #include "base/array_ref.h"
 #include "base/macros.h"
-#include "method_reference.h"
+#include "dex/method_reference.h"
 
 namespace art {
 
diff --git a/compiler/linker/relative_patcher_test.h b/compiler/linker/relative_patcher_test.h
index 9e9d14a..d21f279 100644
--- a/compiler/linker/relative_patcher_test.h
+++ b/compiler/linker/relative_patcher_test.h
@@ -23,15 +23,15 @@
 #include "base/macros.h"
 #include "compiled_method-inl.h"
 #include "dex/verification_results.h"
+#include "dex/method_reference.h"
+#include "dex/string_reference.h"
 #include "driver/compiler_driver.h"
 #include "driver/compiler_options.h"
 #include "globals.h"
 #include "gtest/gtest.h"
 #include "linker/relative_patcher.h"
-#include "method_reference.h"
 #include "oat.h"
 #include "oat_quick_method_header.h"
-#include "string_reference.h"
 #include "vector_output_stream.h"
 
 namespace art {
diff --git a/compiler/optimizing/block_builder.cc b/compiler/optimizing/block_builder.cc
index 2b568bc..95f2e98 100644
--- a/compiler/optimizing/block_builder.cc
+++ b/compiler/optimizing/block_builder.cc
@@ -17,7 +17,7 @@
 #include "block_builder.h"
 
 #include "base/logging.h"  // FOR VLOG.
-#include "bytecode_utils.h"
+#include "dex/bytecode_utils.h"
 #include "dex/code_item_accessors-inl.h"
 #include "dex/dex_file_exception_helpers.h"
 #include "quicken_info.h"
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index 0fcc9c6..c2ae764 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -44,9 +44,9 @@
 #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"
+#include "dex/bytecode_utils.h"
 #include "dex/code_item_accessors-inl.h"
 #include "dex/verified_method.h"
 #include "driver/compiler_driver.h"
diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h
index 7031483..a487320 100644
--- a/compiler/optimizing/code_generator.h
+++ b/compiler/optimizing/code_generator.h
@@ -24,6 +24,8 @@
 #include "base/bit_field.h"
 #include "base/bit_utils.h"
 #include "base/enums.h"
+#include "dex/string_reference.h"
+#include "dex/type_reference.h"
 #include "globals.h"
 #include "graph_visualizer.h"
 #include "locations.h"
@@ -33,8 +35,6 @@
 #include "read_barrier_option.h"
 #include "stack.h"
 #include "stack_map.h"
-#include "string_reference.h"
-#include "type_reference.h"
 #include "utils/label.h"
 
 namespace art {
diff --git a/compiler/optimizing/code_generator_arm64.h b/compiler/optimizing/code_generator_arm64.h
index b59ccd9..a8a9802 100644
--- a/compiler/optimizing/code_generator_arm64.h
+++ b/compiler/optimizing/code_generator_arm64.h
@@ -21,11 +21,11 @@
 #include "code_generator.h"
 #include "common_arm64.h"
 #include "dex/dex_file_types.h"
+#include "dex/string_reference.h"
+#include "dex/type_reference.h"
 #include "driver/compiler_options.h"
 #include "nodes.h"
 #include "parallel_move_resolver.h"
-#include "string_reference.h"
-#include "type_reference.h"
 #include "utils/arm64/assembler_arm64.h"
 
 // TODO(VIXL): Make VIXL compile with -Wshadow.
diff --git a/compiler/optimizing/code_generator_arm_vixl.h b/compiler/optimizing/code_generator_arm_vixl.h
index 2d8f6a6..6a07e36 100644
--- a/compiler/optimizing/code_generator_arm_vixl.h
+++ b/compiler/optimizing/code_generator_arm_vixl.h
@@ -20,11 +20,11 @@
 #include "base/enums.h"
 #include "code_generator.h"
 #include "common_arm.h"
+#include "dex/string_reference.h"
+#include "dex/type_reference.h"
 #include "driver/compiler_options.h"
 #include "nodes.h"
 #include "parallel_move_resolver.h"
-#include "string_reference.h"
-#include "type_reference.h"
 #include "utils/arm/assembler_arm_vixl.h"
 
 // TODO(VIXL): make vixl clean wrt -Wshadow.
diff --git a/compiler/optimizing/code_generator_mips.h b/compiler/optimizing/code_generator_mips.h
index d906896..1f1743f 100644
--- a/compiler/optimizing/code_generator_mips.h
+++ b/compiler/optimizing/code_generator_mips.h
@@ -19,11 +19,11 @@
 
 #include "code_generator.h"
 #include "dex/dex_file_types.h"
+#include "dex/string_reference.h"
+#include "dex/type_reference.h"
 #include "driver/compiler_options.h"
 #include "nodes.h"
 #include "parallel_move_resolver.h"
-#include "string_reference.h"
-#include "type_reference.h"
 #include "utils/mips/assembler_mips.h"
 
 namespace art {
diff --git a/compiler/optimizing/code_generator_mips64.h b/compiler/optimizing/code_generator_mips64.h
index d1da1ce..74c947e 100644
--- a/compiler/optimizing/code_generator_mips64.h
+++ b/compiler/optimizing/code_generator_mips64.h
@@ -18,10 +18,10 @@
 #define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS64_H_
 
 #include "code_generator.h"
+#include "dex/type_reference.h"
 #include "driver/compiler_options.h"
 #include "nodes.h"
 #include "parallel_move_resolver.h"
-#include "type_reference.h"
 #include "utils/mips64/assembler_mips64.h"
 
 namespace art {
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index a38e271..c7aef37 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -20,9 +20,9 @@
 #include "base/arena_bit_vector.h"
 #include "base/bit_vector-inl.h"
 #include "block_builder.h"
-#include "bytecode_utils.h"
 #include "class_linker.h"
 #include "data_type-inl.h"
+#include "dex/bytecode_utils.h"
 #include "dex/dex_instruction-inl.h"
 #include "driver/compiler_driver-inl.h"
 #include "driver/dex_compilation_unit.h"
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index cbf748d..a8fcea2 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -34,12 +34,12 @@
 #include "dex/dex_file.h"
 #include "dex/dex_file_types.h"
 #include "dex/invoke_type.h"
+#include "dex/method_reference.h"
 #include "entrypoints/quick/quick_entrypoints_enum.h"
 #include "handle.h"
 #include "handle_scope.h"
 #include "intrinsics_enum.h"
 #include "locations.h"
-#include "method_reference.h"
 #include "mirror/class.h"
 #include "offsets.h"
 #include "utils/intrusive_forward_list.h"
diff --git a/compiler/optimizing/ssa_builder.cc b/compiler/optimizing/ssa_builder.cc
index cb38476..dd54468 100644
--- a/compiler/optimizing/ssa_builder.cc
+++ b/compiler/optimizing/ssa_builder.cc
@@ -16,8 +16,8 @@
 
 #include "ssa_builder.h"
 
-#include "bytecode_utils.h"
 #include "data_type-inl.h"
+#include "dex/bytecode_utils.h"
 #include "mirror/class-inl.h"
 #include "nodes.h"
 #include "reference_type_propagation.h"
diff --git a/compiler/utils/atomic_dex_ref_map-inl.h b/compiler/utils/atomic_dex_ref_map-inl.h
index 7023b9a..7977e82 100644
--- a/compiler/utils/atomic_dex_ref_map-inl.h
+++ b/compiler/utils/atomic_dex_ref_map-inl.h
@@ -21,10 +21,10 @@
 
 #include <type_traits>
 
-#include "class_reference.h"
+#include "dex/class_reference.h"
 #include "dex/dex_file-inl.h"
-#include "method_reference.h"
-#include "type_reference.h"
+#include "dex/method_reference.h"
+#include "dex/type_reference.h"
 
 namespace art {
 
diff --git a/compiler/utils/atomic_dex_ref_map_test.cc b/compiler/utils/atomic_dex_ref_map_test.cc
index d58d60b..4e1ef12 100644
--- a/compiler/utils/atomic_dex_ref_map_test.cc
+++ b/compiler/utils/atomic_dex_ref_map_test.cc
@@ -20,7 +20,7 @@
 
 #include "common_runtime_test.h"
 #include "dex/dex_file-inl.h"
-#include "method_reference.h"
+#include "dex/method_reference.h"
 #include "scoped_thread_state_change-inl.h"
 
 namespace art {
diff --git a/compiler/utils/string_reference_test.cc b/compiler/utils/string_reference_test.cc
deleted file mode 100644
index 4b07e65..0000000
--- a/compiler/utils/string_reference_test.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2016 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 "string_reference.h"
-
-#include <memory>
-
-#include "dex/dex_file_types.h"
-#include "gtest/gtest.h"
-#include "utils/test_dex_file_builder.h"
-
-namespace art {
-
-TEST(StringReference, ValueComparator) {
-  // This is a regression test for the StringReferenceValueComparator using the wrong
-  // dex file to get the string data from a StringId. We construct two dex files with
-  // just a single string with the same length but different value. This creates dex
-  // files that have the same layout, so the byte offset read from the StringId in one
-  // dex file, when used in the other dex file still points to valid string data, except
-  // that it's the wrong string. Without the fix the strings would then compare equal.
-  TestDexFileBuilder builder1;
-  builder1.AddString("String1");
-  std::unique_ptr<const DexFile> dex_file1 = builder1.Build("dummy location 1");
-  ASSERT_EQ(1u, dex_file1->NumStringIds());
-  ASSERT_STREQ("String1", dex_file1->GetStringData(dex_file1->GetStringId(dex::StringIndex(0))));
-  StringReference sr1(dex_file1.get(), dex::StringIndex(0));
-
-  TestDexFileBuilder builder2;
-  builder2.AddString("String2");
-  std::unique_ptr<const DexFile> dex_file2 = builder2.Build("dummy location 2");
-  ASSERT_EQ(1u, dex_file2->NumStringIds());
-  ASSERT_STREQ("String2", dex_file2->GetStringData(dex_file2->GetStringId(dex::StringIndex(0))));
-  StringReference sr2(dex_file2.get(), dex::StringIndex(0));
-
-  StringReferenceValueComparator cmp;
-  EXPECT_TRUE(cmp(sr1, sr2));  // "String1" < "String2" is true.
-  EXPECT_FALSE(cmp(sr2, sr1));  // "String2" < "String1" is false.
-}
-
-TEST(StringReference, ValueComparator2) {
-  const char* const kDexFile1Strings[] = {
-      "",
-      "abc",
-      "abcxyz",
-  };
-  const char* const kDexFile2Strings[] = {
-      "a",
-      "abc",
-      "abcdef",
-      "def",
-  };
-  const bool expectedCmp12[arraysize(kDexFile1Strings)][arraysize(kDexFile2Strings)] = {
-      { true, true, true, true },
-      { false, false, true, true },
-      { false, false, false, true },
-  };
-  const bool expectedCmp21[arraysize(kDexFile2Strings)][arraysize(kDexFile1Strings)] = {
-      { false, true, true },
-      { false, false, true },
-      { false, false, true },
-      { false, false, false },
-  };
-
-  TestDexFileBuilder builder1;
-  for (const char* s : kDexFile1Strings) {
-    builder1.AddString(s);
-  }
-  std::unique_ptr<const DexFile> dex_file1 = builder1.Build("dummy location 1");
-  ASSERT_EQ(arraysize(kDexFile1Strings), dex_file1->NumStringIds());
-  for (size_t index = 0; index != arraysize(kDexFile1Strings); ++index) {
-    ASSERT_STREQ(kDexFile1Strings[index],
-                 dex_file1->GetStringData(dex_file1->GetStringId(dex::StringIndex(index))));
-  }
-
-  TestDexFileBuilder builder2;
-  for (const char* s : kDexFile2Strings) {
-    builder2.AddString(s);
-  }
-  std::unique_ptr<const DexFile> dex_file2 = builder2.Build("dummy location 1");
-  ASSERT_EQ(arraysize(kDexFile2Strings), dex_file2->NumStringIds());
-  for (size_t index = 0; index != arraysize(kDexFile2Strings); ++index) {
-    ASSERT_STREQ(kDexFile2Strings[index],
-                 dex_file2->GetStringData(dex_file2->GetStringId(dex::StringIndex(index))));
-  }
-
-  StringReferenceValueComparator cmp;
-  for (size_t index1 = 0; index1 != arraysize(kDexFile1Strings); ++index1) {
-    for (size_t index2 = 0; index2 != arraysize(kDexFile2Strings); ++index2) {
-      StringReference sr1(dex_file1.get(), dex::StringIndex(index1));
-      StringReference sr2(dex_file2.get(), dex::StringIndex(index2));
-      EXPECT_EQ(expectedCmp12[index1][index2], cmp(sr1, sr2)) << index1 << " " << index2;
-      EXPECT_EQ(expectedCmp21[index2][index1], cmp(sr2, sr1)) << index1 << " " << index2;
-    }
-  }
-}
-
-}  // namespace art
diff --git a/compiler/utils/test_dex_file_builder.h b/compiler/utils/test_dex_file_builder.h
deleted file mode 100644
index 58f1ec7..0000000
--- a/compiler/utils/test_dex_file_builder.h
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * Copyright (C) 2015 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_COMPILER_UTILS_TEST_DEX_FILE_BUILDER_H_
-#define ART_COMPILER_UTILS_TEST_DEX_FILE_BUILDER_H_
-
-#include <zlib.h>
-
-#include <cstring>
-#include <map>
-#include <set>
-#include <vector>
-
-#include <android-base/logging.h>
-
-#include "base/bit_utils.h"
-#include "dex/art_dex_file_loader.h"
-#include "dex/dex_file_loader.h"
-#include "dex/standard_dex_file.h"
-
-namespace art {
-
-class TestDexFileBuilder {
- public:
-  TestDexFileBuilder()
-      : strings_(), types_(), fields_(), protos_(), dex_file_data_() {
-  }
-
-  void AddString(const std::string& str) {
-    CHECK(dex_file_data_.empty());
-    auto it = strings_.emplace(str, IdxAndDataOffset()).first;
-    CHECK_LT(it->first.length(), 128u);  // Don't allow multi-byte length in uleb128.
-  }
-
-  void AddType(const std::string& descriptor) {
-    CHECK(dex_file_data_.empty());
-    AddString(descriptor);
-    types_.emplace(descriptor, 0u);
-  }
-
-  void AddField(const std::string& class_descriptor, const std::string& type,
-                const std::string& name) {
-    CHECK(dex_file_data_.empty());
-    AddType(class_descriptor);
-    AddType(type);
-    AddString(name);
-    FieldKey key = { class_descriptor, type, name };
-    fields_.emplace(key, 0u);
-  }
-
-  void AddMethod(const std::string& class_descriptor, const std::string& signature,
-                 const std::string& name) {
-    CHECK(dex_file_data_.empty());
-    AddType(class_descriptor);
-    AddString(name);
-
-    ProtoKey proto_key = CreateProtoKey(signature);
-    AddString(proto_key.shorty);
-    AddType(proto_key.return_type);
-    for (const auto& arg_type : proto_key.args) {
-      AddType(arg_type);
-    }
-    auto it = protos_.emplace(proto_key, IdxAndDataOffset()).first;
-    const ProtoKey* proto = &it->first;  // Valid as long as the element remains in protos_.
-
-    MethodKey method_key = {
-        class_descriptor, name, proto
-    };
-    methods_.emplace(method_key, 0u);
-  }
-
-  // NOTE: The builder holds the actual data, so it must live as long as the dex file.
-  std::unique_ptr<const DexFile> Build(const std::string& dex_location) {
-    CHECK(dex_file_data_.empty());
-    union {
-      uint8_t data[sizeof(DexFile::Header)];
-      uint64_t force_alignment;
-    } header_data;
-    std::memset(header_data.data, 0, sizeof(header_data.data));
-    DexFile::Header* header = reinterpret_cast<DexFile::Header*>(&header_data.data);
-    std::copy_n(StandardDexFile::kDexMagic, 4u, header->magic_);
-    std::copy_n(StandardDexFile::kDexMagicVersions[0], 4u, header->magic_ + 4u);
-    header->header_size_ = sizeof(DexFile::Header);
-    header->endian_tag_ = DexFile::kDexEndianConstant;
-    header->link_size_ = 0u;  // Unused.
-    header->link_off_ = 0u;  // Unused.
-    header->map_off_ = 0u;  // Unused. TODO: This is wrong. Dex files created by this builder
-                            //               cannot be verified. b/26808512
-
-    uint32_t data_section_size = 0u;
-
-    uint32_t string_ids_offset = sizeof(DexFile::Header);
-    uint32_t string_idx = 0u;
-    for (auto& entry : strings_) {
-      entry.second.idx = string_idx;
-      string_idx += 1u;
-      entry.second.data_offset = data_section_size;
-      data_section_size += entry.first.length() + 1u /* length */ + 1u /* null-terminator */;
-    }
-    header->string_ids_size_ = strings_.size();
-    header->string_ids_off_ = strings_.empty() ? 0u : string_ids_offset;
-
-    uint32_t type_ids_offset = string_ids_offset + strings_.size() * sizeof(DexFile::StringId);
-    uint32_t type_idx = 0u;
-    for (auto& entry : types_) {
-      entry.second = type_idx;
-      type_idx += 1u;
-    }
-    header->type_ids_size_ = types_.size();
-    header->type_ids_off_ = types_.empty() ? 0u : type_ids_offset;
-
-    uint32_t proto_ids_offset = type_ids_offset + types_.size() * sizeof(DexFile::TypeId);
-    uint32_t proto_idx = 0u;
-    for (auto& entry : protos_) {
-      entry.second.idx = proto_idx;
-      proto_idx += 1u;
-      size_t num_args = entry.first.args.size();
-      if (num_args != 0u) {
-        entry.second.data_offset = RoundUp(data_section_size, 4u);
-        data_section_size = entry.second.data_offset + 4u + num_args * sizeof(DexFile::TypeItem);
-      } else {
-        entry.second.data_offset = 0u;
-      }
-    }
-    header->proto_ids_size_ = protos_.size();
-    header->proto_ids_off_ = protos_.empty() ? 0u : proto_ids_offset;
-
-    uint32_t field_ids_offset = proto_ids_offset + protos_.size() * sizeof(DexFile::ProtoId);
-    uint32_t field_idx = 0u;
-    for (auto& entry : fields_) {
-      entry.second = field_idx;
-      field_idx += 1u;
-    }
-    header->field_ids_size_ = fields_.size();
-    header->field_ids_off_ = fields_.empty() ? 0u : field_ids_offset;
-
-    uint32_t method_ids_offset = field_ids_offset + fields_.size() * sizeof(DexFile::FieldId);
-    uint32_t method_idx = 0u;
-    for (auto& entry : methods_) {
-      entry.second = method_idx;
-      method_idx += 1u;
-    }
-    header->method_ids_size_ = methods_.size();
-    header->method_ids_off_ = methods_.empty() ? 0u : method_ids_offset;
-
-    // No class defs.
-    header->class_defs_size_ = 0u;
-    header->class_defs_off_ = 0u;
-
-    uint32_t data_section_offset = method_ids_offset + methods_.size() * sizeof(DexFile::MethodId);
-    header->data_size_ = data_section_size;
-    header->data_off_ = (data_section_size != 0u) ? data_section_offset : 0u;
-
-    uint32_t total_size = data_section_offset + data_section_size;
-
-    dex_file_data_.resize(total_size);
-
-    for (const auto& entry : strings_) {
-      CHECK_LT(entry.first.size(), 128u);
-      uint32_t raw_offset = data_section_offset + entry.second.data_offset;
-      dex_file_data_[raw_offset] = static_cast<uint8_t>(entry.first.size());
-      std::memcpy(&dex_file_data_[raw_offset + 1], entry.first.c_str(), entry.first.size() + 1);
-      Write32(string_ids_offset + entry.second.idx * sizeof(DexFile::StringId), raw_offset);
-    }
-
-    for (const auto& entry : types_) {
-      Write32(type_ids_offset + entry.second * sizeof(DexFile::TypeId), GetStringIdx(entry.first));
-      ++type_idx;
-    }
-
-    for (const auto& entry : protos_) {
-      size_t num_args = entry.first.args.size();
-      uint32_t type_list_offset =
-          (num_args != 0u) ? data_section_offset + entry.second.data_offset : 0u;
-      uint32_t raw_offset = proto_ids_offset + entry.second.idx * sizeof(DexFile::ProtoId);
-      Write32(raw_offset + 0u, GetStringIdx(entry.first.shorty));
-      Write16(raw_offset + 4u, GetTypeIdx(entry.first.return_type));
-      Write32(raw_offset + 8u, type_list_offset);
-      if (num_args != 0u) {
-        CHECK_NE(entry.second.data_offset, 0u);
-        Write32(type_list_offset, num_args);
-        for (size_t i = 0; i != num_args; ++i) {
-          Write16(type_list_offset + 4u + i * sizeof(DexFile::TypeItem),
-                  GetTypeIdx(entry.first.args[i]));
-        }
-      }
-    }
-
-    for (const auto& entry : fields_) {
-      uint32_t raw_offset = field_ids_offset + entry.second * sizeof(DexFile::FieldId);
-      Write16(raw_offset + 0u, GetTypeIdx(entry.first.class_descriptor));
-      Write16(raw_offset + 2u, GetTypeIdx(entry.first.type));
-      Write32(raw_offset + 4u, GetStringIdx(entry.first.name));
-    }
-
-    for (const auto& entry : methods_) {
-      uint32_t raw_offset = method_ids_offset + entry.second * sizeof(DexFile::MethodId);
-      Write16(raw_offset + 0u, GetTypeIdx(entry.first.class_descriptor));
-      auto it = protos_.find(*entry.first.proto);
-      CHECK(it != protos_.end());
-      Write16(raw_offset + 2u, it->second.idx);
-      Write32(raw_offset + 4u, GetStringIdx(entry.first.name));
-    }
-
-    // Leave signature as zeros.
-
-    header->file_size_ = dex_file_data_.size();
-
-    // Write the complete header early, as part of it needs to be checksummed.
-    std::memcpy(&dex_file_data_[0], header_data.data, sizeof(DexFile::Header));
-
-    // Checksum starts after the checksum field.
-    size_t skip = sizeof(header->magic_) + sizeof(header->checksum_);
-    header->checksum_ = adler32(adler32(0L, Z_NULL, 0),
-                                dex_file_data_.data() + skip,
-                                dex_file_data_.size() - skip);
-
-    // Write the complete header again, just simpler that way.
-    std::memcpy(&dex_file_data_[0], header_data.data, sizeof(DexFile::Header));
-
-    static constexpr bool kVerify = false;
-    static constexpr bool kVerifyChecksum = false;
-    std::string error_msg;
-    const ArtDexFileLoader dex_file_loader;
-    std::unique_ptr<const DexFile> dex_file(dex_file_loader.Open(
-        &dex_file_data_[0],
-        dex_file_data_.size(),
-        dex_location,
-        0u,
-        nullptr,
-        kVerify,
-        kVerifyChecksum,
-        &error_msg));
-    CHECK(dex_file != nullptr) << error_msg;
-    return dex_file;
-  }
-
-  uint32_t GetStringIdx(const std::string& type) {
-    auto it = strings_.find(type);
-    CHECK(it != strings_.end());
-    return it->second.idx;
-  }
-
-  uint32_t GetTypeIdx(const std::string& type) {
-    auto it = types_.find(type);
-    CHECK(it != types_.end());
-    return it->second;
-  }
-
-  uint32_t GetFieldIdx(const std::string& class_descriptor, const std::string& type,
-                       const std::string& name) {
-    FieldKey key = { class_descriptor, type, name };
-    auto it = fields_.find(key);
-    CHECK(it != fields_.end());
-    return it->second;
-  }
-
-  uint32_t GetMethodIdx(const std::string& class_descriptor, const std::string& signature,
-                        const std::string& name) {
-    ProtoKey proto_key = CreateProtoKey(signature);
-    MethodKey method_key = { class_descriptor, name, &proto_key };
-    auto it = methods_.find(method_key);
-    CHECK(it != methods_.end());
-    return it->second;
-  }
-
- private:
-  struct IdxAndDataOffset {
-    uint32_t idx;
-    uint32_t data_offset;
-  };
-
-  struct FieldKey {
-    const std::string class_descriptor;
-    const std::string type;
-    const std::string name;
-  };
-  struct FieldKeyComparator {
-    bool operator()(const FieldKey& lhs, const FieldKey& rhs) const {
-      if (lhs.class_descriptor != rhs.class_descriptor) {
-        return lhs.class_descriptor < rhs.class_descriptor;
-      }
-      if (lhs.name != rhs.name) {
-        return lhs.name < rhs.name;
-      }
-      return lhs.type < rhs.type;
-    }
-  };
-
-  struct ProtoKey {
-    std::string shorty;
-    std::string return_type;
-    std::vector<std::string> args;
-  };
-  struct ProtoKeyComparator {
-    bool operator()(const ProtoKey& lhs, const ProtoKey& rhs) const {
-      if (lhs.return_type != rhs.return_type) {
-        return lhs.return_type < rhs.return_type;
-      }
-      size_t min_args = std::min(lhs.args.size(), rhs.args.size());
-      for (size_t i = 0; i != min_args; ++i) {
-        if (lhs.args[i] != rhs.args[i]) {
-          return lhs.args[i] < rhs.args[i];
-        }
-      }
-      return lhs.args.size() < rhs.args.size();
-    }
-  };
-
-  struct MethodKey {
-    std::string class_descriptor;
-    std::string name;
-    const ProtoKey* proto;
-  };
-  struct MethodKeyComparator {
-    bool operator()(const MethodKey& lhs, const MethodKey& rhs) const {
-      if (lhs.class_descriptor != rhs.class_descriptor) {
-        return lhs.class_descriptor < rhs.class_descriptor;
-      }
-      if (lhs.name != rhs.name) {
-        return lhs.name < rhs.name;
-      }
-      return ProtoKeyComparator()(*lhs.proto, *rhs.proto);
-    }
-  };
-
-  ProtoKey CreateProtoKey(const std::string& signature) {
-    CHECK_EQ(signature[0], '(');
-    const char* args = signature.c_str() + 1;
-    const char* args_end = std::strchr(args, ')');
-    CHECK(args_end != nullptr);
-    const char* return_type = args_end + 1;
-
-    ProtoKey key = {
-        std::string() + ((*return_type == '[') ? 'L' : *return_type),
-        return_type,
-        std::vector<std::string>()
-    };
-    while (args != args_end) {
-      key.shorty += (*args == '[') ? 'L' : *args;
-      const char* arg_start = args;
-      while (*args == '[') {
-        ++args;
-      }
-      if (*args == 'L') {
-        do {
-          ++args;
-          CHECK_NE(args, args_end);
-        } while (*args != ';');
-      }
-      ++args;
-      key.args.emplace_back(arg_start, args);
-    }
-    return key;
-  }
-
-  void Write32(size_t offset, uint32_t value) {
-    CHECK_LE(offset + 4u, dex_file_data_.size());
-    CHECK_EQ(dex_file_data_[offset + 0], 0u);
-    CHECK_EQ(dex_file_data_[offset + 1], 0u);
-    CHECK_EQ(dex_file_data_[offset + 2], 0u);
-    CHECK_EQ(dex_file_data_[offset + 3], 0u);
-    dex_file_data_[offset + 0] = static_cast<uint8_t>(value >> 0);
-    dex_file_data_[offset + 1] = static_cast<uint8_t>(value >> 8);
-    dex_file_data_[offset + 2] = static_cast<uint8_t>(value >> 16);
-    dex_file_data_[offset + 3] = static_cast<uint8_t>(value >> 24);
-  }
-
-  void Write16(size_t offset, uint32_t value) {
-    CHECK_LE(value, 0xffffu);
-    CHECK_LE(offset + 2u, dex_file_data_.size());
-    CHECK_EQ(dex_file_data_[offset + 0], 0u);
-    CHECK_EQ(dex_file_data_[offset + 1], 0u);
-    dex_file_data_[offset + 0] = static_cast<uint8_t>(value >> 0);
-    dex_file_data_[offset + 1] = static_cast<uint8_t>(value >> 8);
-  }
-
-  std::map<std::string, IdxAndDataOffset> strings_;
-  std::map<std::string, uint32_t> types_;
-  std::map<FieldKey, uint32_t, FieldKeyComparator> fields_;
-  std::map<ProtoKey, IdxAndDataOffset, ProtoKeyComparator> protos_;
-  std::map<MethodKey, uint32_t, MethodKeyComparator> methods_;
-
-  std::vector<uint8_t> dex_file_data_;
-};
-
-}  // namespace art
-
-#endif  // ART_COMPILER_UTILS_TEST_DEX_FILE_BUILDER_H_
diff --git a/compiler/utils/test_dex_file_builder_test.cc b/compiler/utils/test_dex_file_builder_test.cc
deleted file mode 100644
index 788afd8..0000000
--- a/compiler/utils/test_dex_file_builder_test.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2015 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 "test_dex_file_builder.h"
-
-#include "base/utils.h"
-#include "dex/dex_file-inl.h"
-#include "gtest/gtest.h"
-
-namespace art {
-
-TEST(TestDexFileBuilderTest, SimpleTest) {
-  TestDexFileBuilder builder;
-  builder.AddString("Arbitrary string");
-  builder.AddType("Ljava/lang/Class;");
-  builder.AddField("LTestClass;", "[I", "intField");
-  builder.AddMethod("LTestClass;", "()I", "foo");
-  builder.AddMethod("LTestClass;", "(Ljava/lang/Object;[Ljava/lang/Object;)LTestClass;", "bar");
-  const char* dex_location = "TestDexFileBuilder/SimpleTest";
-  std::unique_ptr<const DexFile> dex_file(builder.Build(dex_location));
-  ASSERT_TRUE(dex_file != nullptr);
-  EXPECT_STREQ(dex_location, dex_file->GetLocation().c_str());
-
-  static const char* const expected_strings[] = {
-      "Arbitrary string",
-      "I",
-      "LLL",  // shorty
-      "LTestClass;",
-      "Ljava/lang/Class;",
-      "Ljava/lang/Object;",
-      "[I",
-      "[Ljava/lang/Object;",
-      "bar",
-      "foo",
-      "intField",
-  };
-  ASSERT_EQ(arraysize(expected_strings), dex_file->NumStringIds());
-  for (size_t i = 0; i != arraysize(expected_strings); ++i) {
-    EXPECT_STREQ(expected_strings[i],
-                 dex_file->GetStringData(dex_file->GetStringId(dex::StringIndex(i)))) << i;
-  }
-
-  static const char* const expected_types[] = {
-      "I",
-      "LTestClass;",
-      "Ljava/lang/Class;",
-      "Ljava/lang/Object;",
-      "[I",
-      "[Ljava/lang/Object;",
-  };
-  ASSERT_EQ(arraysize(expected_types), dex_file->NumTypeIds());
-  for (size_t i = 0; i != arraysize(expected_types); ++i) {
-    EXPECT_STREQ(expected_types[i],
-                 dex_file->GetTypeDescriptor(dex_file->GetTypeId(dex::TypeIndex(i)))) << i;
-  }
-
-  ASSERT_EQ(1u, dex_file->NumFieldIds());
-  EXPECT_STREQ("[I TestClass.intField", dex_file->PrettyField(0u).c_str());
-
-  ASSERT_EQ(2u, dex_file->NumProtoIds());
-  ASSERT_EQ(2u, dex_file->NumMethodIds());
-  EXPECT_STREQ("TestClass TestClass.bar(java.lang.Object, java.lang.Object[])",
-               dex_file->PrettyMethod(0u).c_str());
-  EXPECT_STREQ("int TestClass.foo()",
-               dex_file->PrettyMethod(1u).c_str());
-
-  EXPECT_EQ(0u, builder.GetStringIdx("Arbitrary string"));
-  EXPECT_EQ(2u, builder.GetTypeIdx("Ljava/lang/Class;"));
-  EXPECT_EQ(0u, builder.GetFieldIdx("LTestClass;", "[I", "intField"));
-  EXPECT_EQ(1u, builder.GetMethodIdx("LTestClass;", "()I", "foo"));
-  EXPECT_EQ(0u, builder.GetMethodIdx("LTestClass;", "(Ljava/lang/Object;[Ljava/lang/Object;)LTestClass;", "bar"));
-}
-
-}  // namespace art