Move libdexfile out of runtime

Move the files out of runtime, leaving unfortunate dependences still
there on runtime/base (for the moment).  Also separates the build logic
into two Android.bp files.

Bug: 22322814
Test: make -j 50 test-art-host
Change-Id: Ib0a1cda833b29ecfa4c8c50f23fab89ba666f491
diff --git a/Android.bp b/Android.bp
index 4bcceff..ad42d3f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -36,6 +36,7 @@
     "dt_fd_forward",
     "dt_fd_forward/export",
     "imgdiag",
+    "libdexfile",
     "oatdump",
     "openjdkjvm",
     "openjdkjvmti",
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index d6c87b6..59a1046 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -333,6 +333,7 @@
     art_dexoptanalyzer_tests \
     art_hiddenapi_tests \
     art_imgdiag_tests \
+    art_libdexfile_tests \
     art_oatdump_tests \
     art_patchoat_tests \
     art_profman_tests \
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
new file mode 100644
index 0000000..bcf2bdb
--- /dev/null
+++ b/libdexfile/Android.bp
@@ -0,0 +1,117 @@
+//
+// 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.
+//
+
+cc_defaults {
+    name: "libdexfile_defaults",
+    defaults: ["art_defaults"],
+    host_supported: true,
+    srcs: [
+        "dex/compact_dex_debug_info.cc",
+        "dex/compact_dex_file.cc",
+        "dex/descriptors_names.cc",
+        "dex/dex_file.cc",
+        "dex/dex_file_exception_helpers.cc",
+        "dex/dex_file_loader.cc",
+        "dex/dex_file_tracking_registrar.cc",
+        "dex/dex_file_verifier.cc",
+        "dex/dex_instruction.cc",
+        "dex/modifiers.cc",
+        "dex/standard_dex_file.cc",
+        "dex/utf.cc",
+    ],
+
+    target: {
+        android: {
+            static_libs: [
+                "libziparchive",
+                "libz",
+                "libbase",
+            ],
+            shared_libs: [
+                "libutils",
+            ],
+        },
+        host: {
+            shared_libs: [
+                "libziparchive",
+                "libz",
+            ],
+        },
+    },
+    generated_sources: ["dexfile_operator_srcs"],
+    shared_libs: [
+        "liblog",
+        // For common macros.
+        "libbase",
+        "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",
+    ],
+    export_include_dirs: ["."],
+    export_shared_lib_headers: [
+        "libbase",
+    ],
+}
+
+gensrcs {
+    name: "dexfile_operator_srcs",
+    cmd: "$(location generate-operator-out.py) art/libdexfile $(in) > $(out)",
+    tool_files: ["generate-operator-out.py"],
+    srcs: [
+        "dex/dex_file.h",
+        "dex/dex_instruction.h",
+        "dex/dex_instruction_utils.h",
+        "dex/invoke_type.h",
+    ],
+    output_extension: "operator_out.cc",
+}
+
+// TODO: add build support for libdexfiled, as we use DCHECK, etc.
+art_cc_library {
+    name: "libdexfile",
+    defaults: ["libdexfile_defaults"],
+    // Leave the symbols in the shared library so that stack unwinders can
+    // produce meaningful name resolution.
+    strip: {
+        keep_symbols: true,
+    },
+}
+
+art_cc_test {
+    name: "art_libdexfile_tests",
+    defaults: [
+        "art_gtest_defaults",
+    ],
+    srcs: [
+        "dex/code_item_accessors_test.cc",
+        "dex/compact_dex_debug_info_test.cc",
+        "dex/compact_dex_file_test.cc",
+        "dex/dex_file_loader_test.cc",
+        "dex/dex_file_verifier_test.cc",
+        "dex/dex_instruction_test.cc",
+        "dex/utf_test.cc",
+    ],
+    shared_libs: [
+        "libbacktrace",
+        "libziparchive",
+    ],
+    include_dirs: [
+        "external/zlib",
+    ],
+}
diff --git a/runtime/dex/base64_test_util.h b/libdexfile/dex/base64_test_util.h
similarity index 95%
rename from runtime/dex/base64_test_util.h
rename to libdexfile/dex/base64_test_util.h
index 0657f9f..683e429 100644
--- a/runtime/dex/base64_test_util.h
+++ b/libdexfile/dex/base64_test_util.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_BASE64_TEST_UTIL_H_
-#define ART_RUNTIME_DEX_BASE64_TEST_UTIL_H_
+#ifndef ART_LIBDEXFILE_DEX_BASE64_TEST_UTIL_H_
+#define ART_LIBDEXFILE_DEX_BASE64_TEST_UTIL_H_
 
 #include <base/logging.h>
 #include <stdint.h>
@@ -96,4 +96,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_BASE64_TEST_UTIL_H_
+#endif  // ART_LIBDEXFILE_DEX_BASE64_TEST_UTIL_H_
diff --git a/runtime/dex/code_item_accessors-inl.h b/libdexfile/dex/code_item_accessors-inl.h
similarity index 97%
rename from runtime/dex/code_item_accessors-inl.h
rename to libdexfile/dex/code_item_accessors-inl.h
index 9c39935..c166f5f 100644
--- a/runtime/dex/code_item_accessors-inl.h
+++ b/libdexfile/dex/code_item_accessors-inl.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_INL_H_
-#define ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_INL_H_
+#ifndef ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_INL_H_
+#define ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_INL_H_
 
 #include "code_item_accessors.h"
 
@@ -201,4 +201,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_INL_H_
+#endif  // ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_INL_H_
diff --git a/runtime/dex/code_item_accessors.h b/libdexfile/dex/code_item_accessors.h
similarity index 96%
rename from runtime/dex/code_item_accessors.h
rename to libdexfile/dex/code_item_accessors.h
index beb78f6..ba7c126 100644
--- a/runtime/dex/code_item_accessors.h
+++ b/libdexfile/dex/code_item_accessors.h
@@ -16,10 +16,9 @@
 
 // TODO: Dex helpers have ART specific APIs, we may want to refactor these for use in dexdump.
 
-#ifndef ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_H_
-#define ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_H_
+#ifndef ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_H_
+#define ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_H_
 
-#include "base/mutex.h"
 #include "compact_dex_file.h"
 #include "dex_file.h"
 #include "dex_instruction_iterator.h"
@@ -164,4 +163,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_CODE_ITEM_ACCESSORS_H_
+#endif  // ART_LIBDEXFILE_DEX_CODE_ITEM_ACCESSORS_H_
diff --git a/runtime/dex/code_item_accessors_test.cc b/libdexfile/dex/code_item_accessors_test.cc
similarity index 100%
rename from runtime/dex/code_item_accessors_test.cc
rename to libdexfile/dex/code_item_accessors_test.cc
diff --git a/runtime/dex/compact_dex_debug_info.cc b/libdexfile/dex/compact_dex_debug_info.cc
similarity index 100%
rename from runtime/dex/compact_dex_debug_info.cc
rename to libdexfile/dex/compact_dex_debug_info.cc
diff --git a/runtime/dex/compact_dex_debug_info.h b/libdexfile/dex/compact_dex_debug_info.h
similarity index 92%
rename from runtime/dex/compact_dex_debug_info.h
rename to libdexfile/dex/compact_dex_debug_info.h
index 1aff758..bfd0bbe 100644
--- a/runtime/dex/compact_dex_debug_info.h
+++ b/libdexfile/dex/compact_dex_debug_info.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_COMPACT_DEX_DEBUG_INFO_H_
-#define ART_RUNTIME_DEX_COMPACT_DEX_DEBUG_INFO_H_
+#ifndef ART_LIBDEXFILE_DEX_COMPACT_DEX_DEBUG_INFO_H_
+#define ART_LIBDEXFILE_DEX_COMPACT_DEX_DEBUG_INFO_H_
 
 #include <cstdint>
 #include <vector>
@@ -62,4 +62,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_COMPACT_DEX_DEBUG_INFO_H_
+#endif  // ART_LIBDEXFILE_DEX_COMPACT_DEX_DEBUG_INFO_H_
diff --git a/runtime/dex/compact_dex_debug_info_test.cc b/libdexfile/dex/compact_dex_debug_info_test.cc
similarity index 100%
rename from runtime/dex/compact_dex_debug_info_test.cc
rename to libdexfile/dex/compact_dex_debug_info_test.cc
diff --git a/runtime/dex/compact_dex_file.cc b/libdexfile/dex/compact_dex_file.cc
similarity index 100%
rename from runtime/dex/compact_dex_file.cc
rename to libdexfile/dex/compact_dex_file.cc
diff --git a/runtime/dex/compact_dex_file.h b/libdexfile/dex/compact_dex_file.h
similarity index 98%
rename from runtime/dex/compact_dex_file.h
rename to libdexfile/dex/compact_dex_file.h
index 31aeb27..47b170c 100644
--- a/runtime/dex/compact_dex_file.h
+++ b/libdexfile/dex/compact_dex_file.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_COMPACT_DEX_FILE_H_
-#define ART_RUNTIME_DEX_COMPACT_DEX_FILE_H_
+#ifndef ART_LIBDEXFILE_DEX_COMPACT_DEX_FILE_H_
+#define ART_LIBDEXFILE_DEX_COMPACT_DEX_FILE_H_
 
 #include "base/casts.h"
 #include "dex_file.h"
@@ -288,4 +288,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_COMPACT_DEX_FILE_H_
+#endif  // ART_LIBDEXFILE_DEX_COMPACT_DEX_FILE_H_
diff --git a/runtime/dex/compact_dex_file_test.cc b/libdexfile/dex/compact_dex_file_test.cc
similarity index 100%
rename from runtime/dex/compact_dex_file_test.cc
rename to libdexfile/dex/compact_dex_file_test.cc
diff --git a/runtime/dex/compact_dex_level.h b/libdexfile/dex/compact_dex_level.h
similarity index 90%
rename from runtime/dex/compact_dex_level.h
rename to libdexfile/dex/compact_dex_level.h
index de9ca3c..2325ac2 100644
--- a/runtime/dex/compact_dex_level.h
+++ b/libdexfile/dex/compact_dex_level.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_COMPACT_DEX_LEVEL_H_
-#define ART_RUNTIME_DEX_COMPACT_DEX_LEVEL_H_
+#ifndef ART_LIBDEXFILE_DEX_COMPACT_DEX_LEVEL_H_
+#define ART_LIBDEXFILE_DEX_COMPACT_DEX_LEVEL_H_
 
 #include <string>
 
@@ -47,4 +47,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_COMPACT_DEX_LEVEL_H_
+#endif  // ART_LIBDEXFILE_DEX_COMPACT_DEX_LEVEL_H_
diff --git a/runtime/dex/compact_dex_utils.h b/libdexfile/dex/compact_dex_utils.h
similarity index 87%
rename from runtime/dex/compact_dex_utils.h
rename to libdexfile/dex/compact_dex_utils.h
index 1c7e951..c88b799 100644
--- a/runtime/dex/compact_dex_utils.h
+++ b/libdexfile/dex/compact_dex_utils.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_COMPACT_DEX_UTILS_H_
-#define ART_RUNTIME_DEX_COMPACT_DEX_UTILS_H_
+#ifndef ART_LIBDEXFILE_DEX_COMPACT_DEX_UTILS_H_
+#define ART_LIBDEXFILE_DEX_COMPACT_DEX_UTILS_H_
 
 #include <vector>
 
@@ -34,4 +34,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_COMPACT_DEX_UTILS_H_
+#endif  // ART_LIBDEXFILE_DEX_COMPACT_DEX_UTILS_H_
diff --git a/runtime/dex/descriptors_names.cc b/libdexfile/dex/descriptors_names.cc
similarity index 100%
rename from runtime/dex/descriptors_names.cc
rename to libdexfile/dex/descriptors_names.cc
diff --git a/runtime/dex/descriptors_names.h b/libdexfile/dex/descriptors_names.h
similarity index 93%
rename from runtime/dex/descriptors_names.h
rename to libdexfile/dex/descriptors_names.h
index 22e9573..10738ee 100644
--- a/runtime/dex/descriptors_names.h
+++ b/libdexfile/dex/descriptors_names.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DESCRIPTORS_NAMES_H_
-#define ART_RUNTIME_DEX_DESCRIPTORS_NAMES_H_
+#ifndef ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_
+#define ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_
 
 #include <string>
 
@@ -60,4 +60,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DESCRIPTORS_NAMES_H_
+#endif  // ART_LIBDEXFILE_DEX_DESCRIPTORS_NAMES_H_
diff --git a/runtime/dex/dex_file-inl.h b/libdexfile/dex/dex_file-inl.h
similarity index 98%
rename from runtime/dex/dex_file-inl.h
rename to libdexfile/dex/dex_file-inl.h
index aa53daa..b424b50 100644
--- a/runtime/dex/dex_file-inl.h
+++ b/libdexfile/dex/dex_file-inl.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_FILE_INL_H_
-#define ART_RUNTIME_DEX_DEX_FILE_INL_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_INL_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_INL_H_
 
 #include "base/bit_utils.h"
 #include "base/casts.h"
@@ -518,4 +518,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_FILE_INL_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_FILE_INL_H_
diff --git a/runtime/dex/dex_file.cc b/libdexfile/dex/dex_file.cc
similarity index 100%
rename from runtime/dex/dex_file.cc
rename to libdexfile/dex/dex_file.cc
diff --git a/runtime/dex/dex_file.h b/libdexfile/dex/dex_file.h
similarity index 99%
rename from runtime/dex/dex_file.h
rename to libdexfile/dex/dex_file.h
index cf8c840..a38e76c 100644
--- a/runtime/dex/dex_file.h
+++ b/libdexfile/dex/dex_file.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_FILE_H_
-#define ART_RUNTIME_DEX_DEX_FILE_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_H_
 
 #include <memory>
 #include <string>
@@ -1440,4 +1440,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_FILE_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_FILE_H_
diff --git a/runtime/dex/dex_file_exception_helpers.cc b/libdexfile/dex/dex_file_exception_helpers.cc
similarity index 100%
rename from runtime/dex/dex_file_exception_helpers.cc
rename to libdexfile/dex/dex_file_exception_helpers.cc
diff --git a/runtime/dex/dex_file_exception_helpers.h b/libdexfile/dex/dex_file_exception_helpers.h
similarity index 91%
rename from runtime/dex/dex_file_exception_helpers.h
rename to libdexfile/dex/dex_file_exception_helpers.h
index bd6cb7e..a05fd68 100644
--- a/runtime/dex/dex_file_exception_helpers.h
+++ b/libdexfile/dex/dex_file_exception_helpers.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_FILE_EXCEPTION_HELPERS_H_
-#define ART_RUNTIME_DEX_DEX_FILE_EXCEPTION_HELPERS_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_EXCEPTION_HELPERS_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_EXCEPTION_HELPERS_H_
 
 #include "dex_file.h"
 
@@ -65,4 +65,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_FILE_EXCEPTION_HELPERS_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_FILE_EXCEPTION_HELPERS_H_
diff --git a/runtime/dex/dex_file_loader.cc b/libdexfile/dex/dex_file_loader.cc
similarity index 100%
rename from runtime/dex/dex_file_loader.cc
rename to libdexfile/dex/dex_file_loader.cc
diff --git a/runtime/dex/dex_file_loader.h b/libdexfile/dex/dex_file_loader.h
similarity index 97%
rename from runtime/dex/dex_file_loader.h
rename to libdexfile/dex/dex_file_loader.h
index 508397c..41d9b16 100644
--- a/runtime/dex/dex_file_loader.h
+++ b/libdexfile/dex/dex_file_loader.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_FILE_LOADER_H_
-#define ART_RUNTIME_DEX_DEX_FILE_LOADER_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_LOADER_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_LOADER_H_
 
 #include <cstdint>
 #include <memory>
@@ -195,4 +195,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_FILE_LOADER_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_FILE_LOADER_H_
diff --git a/runtime/dex/dex_file_loader_test.cc b/libdexfile/dex/dex_file_loader_test.cc
similarity index 100%
rename from runtime/dex/dex_file_loader_test.cc
rename to libdexfile/dex/dex_file_loader_test.cc
diff --git a/runtime/dex/dex_file_reference.h b/libdexfile/dex/dex_file_reference.h
similarity index 90%
rename from runtime/dex/dex_file_reference.h
rename to libdexfile/dex/dex_file_reference.h
index 6f88290..3ac7781 100644
--- a/runtime/dex/dex_file_reference.h
+++ b/libdexfile/dex/dex_file_reference.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_FILE_REFERENCE_H_
-#define ART_RUNTIME_DEX_DEX_FILE_REFERENCE_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_REFERENCE_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_REFERENCE_H_
 
 #include <cstdint>
 
@@ -49,4 +49,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_FILE_REFERENCE_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_FILE_REFERENCE_H_
diff --git a/runtime/dex/dex_file_tracking_registrar.cc b/libdexfile/dex/dex_file_tracking_registrar.cc
similarity index 100%
rename from runtime/dex/dex_file_tracking_registrar.cc
rename to libdexfile/dex/dex_file_tracking_registrar.cc
diff --git a/runtime/dex/dex_file_tracking_registrar.h b/libdexfile/dex/dex_file_tracking_registrar.h
similarity index 93%
rename from runtime/dex/dex_file_tracking_registrar.h
rename to libdexfile/dex/dex_file_tracking_registrar.h
index 71b8ed7..8b7716e 100644
--- a/runtime/dex/dex_file_tracking_registrar.h
+++ b/libdexfile/dex/dex_file_tracking_registrar.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_FILE_TRACKING_REGISTRAR_H_
-#define ART_RUNTIME_DEX_DEX_FILE_TRACKING_REGISTRAR_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_
 
 #include <deque>
 #include <tuple>
@@ -78,4 +78,4 @@
 }  // namespace dex
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_FILE_TRACKING_REGISTRAR_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_
diff --git a/runtime/dex/dex_file_types.h b/libdexfile/dex/dex_file_types.h
similarity index 95%
rename from runtime/dex/dex_file_types.h
rename to libdexfile/dex/dex_file_types.h
index 2c508f9..2bb70ff 100644
--- a/runtime/dex/dex_file_types.h
+++ b/libdexfile/dex/dex_file_types.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_FILE_TYPES_H_
-#define ART_RUNTIME_DEX_DEX_FILE_TYPES_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_TYPES_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_TYPES_H_
 
 #include <limits>
 #include <ostream>
@@ -114,4 +114,4 @@
 
 }  // namespace std
 
-#endif  // ART_RUNTIME_DEX_DEX_FILE_TYPES_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_FILE_TYPES_H_
diff --git a/runtime/dex/dex_file_verifier.cc b/libdexfile/dex/dex_file_verifier.cc
similarity index 100%
rename from runtime/dex/dex_file_verifier.cc
rename to libdexfile/dex/dex_file_verifier.cc
diff --git a/runtime/dex/dex_file_verifier.h b/libdexfile/dex/dex_file_verifier.h
similarity index 98%
rename from runtime/dex/dex_file_verifier.h
rename to libdexfile/dex/dex_file_verifier.h
index 6cb5d4c..c4982c2 100644
--- a/runtime/dex/dex_file_verifier.h
+++ b/libdexfile/dex/dex_file_verifier.h
@@ -14,12 +14,11 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_FILE_VERIFIER_H_
-#define ART_RUNTIME_DEX_DEX_FILE_VERIFIER_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_VERIFIER_H_
+#define ART_LIBDEXFILE_DEX_DEX_FILE_VERIFIER_H_
 
 #include <unordered_set>
 
-#include "base/allocator.h"
 #include "base/hash_map.h"
 #include "dex_file.h"
 #include "dex_file_types.h"
@@ -254,4 +253,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_FILE_VERIFIER_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_FILE_VERIFIER_H_
diff --git a/runtime/dex/dex_file_verifier_test.cc b/libdexfile/dex/dex_file_verifier_test.cc
similarity index 100%
rename from runtime/dex/dex_file_verifier_test.cc
rename to libdexfile/dex/dex_file_verifier_test.cc
diff --git a/runtime/dex/dex_instruction-inl.h b/libdexfile/dex/dex_instruction-inl.h
similarity index 98%
rename from runtime/dex/dex_instruction-inl.h
rename to libdexfile/dex/dex_instruction-inl.h
index a6b8414..6bef18c 100644
--- a/runtime/dex/dex_instruction-inl.h
+++ b/libdexfile/dex/dex_instruction-inl.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_INSTRUCTION_INL_H_
-#define ART_RUNTIME_DEX_DEX_INSTRUCTION_INL_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_INL_H_
+#define ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_INL_H_
 
 #include "dex_instruction.h"
 
@@ -555,4 +555,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_INSTRUCTION_INL_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_INL_H_
diff --git a/runtime/dex/dex_instruction.cc b/libdexfile/dex/dex_instruction.cc
similarity index 100%
rename from runtime/dex/dex_instruction.cc
rename to libdexfile/dex/dex_instruction.cc
diff --git a/runtime/dex/dex_instruction.h b/libdexfile/dex/dex_instruction.h
similarity index 99%
rename from runtime/dex/dex_instruction.h
rename to libdexfile/dex/dex_instruction.h
index de14ed3..c953365 100644
--- a/runtime/dex/dex_instruction.h
+++ b/libdexfile/dex/dex_instruction.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_INSTRUCTION_H_
-#define ART_RUNTIME_DEX_DEX_INSTRUCTION_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_H_
+#define ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_H_
 
 #include <android-base/logging.h>
 
@@ -754,4 +754,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_INSTRUCTION_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_H_
diff --git a/runtime/dex/dex_instruction_iterator.h b/libdexfile/dex/dex_instruction_iterator.h
similarity index 97%
rename from runtime/dex/dex_instruction_iterator.h
rename to libdexfile/dex/dex_instruction_iterator.h
index c1b3118..db3ff95 100644
--- a/runtime/dex/dex_instruction_iterator.h
+++ b/libdexfile/dex/dex_instruction_iterator.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_INSTRUCTION_ITERATOR_H_
-#define ART_RUNTIME_DEX_DEX_INSTRUCTION_ITERATOR_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_ITERATOR_H_
+#define ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_ITERATOR_H_
 
 #include <iterator>
 
@@ -234,4 +234,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_INSTRUCTION_ITERATOR_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_ITERATOR_H_
diff --git a/runtime/dex/dex_instruction_list.h b/libdexfile/dex/dex_instruction_list.h
similarity index 98%
rename from runtime/dex/dex_instruction_list.h
rename to libdexfile/dex/dex_instruction_list.h
index aa63fad..9f0aba4 100644
--- a/runtime/dex/dex_instruction_list.h
+++ b/libdexfile/dex/dex_instruction_list.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_INSTRUCTION_LIST_H_
-#define ART_RUNTIME_DEX_DEX_INSTRUCTION_LIST_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_LIST_H_
+#define ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_LIST_H_
 
 // V(opcode, instruction_code, name, format, index, flags, extended_flags, verifier_flags);
 #define DEX_INSTRUCTION_LIST(V) \
@@ -304,5 +304,5 @@
   V(k4rcc) \
   V(k51l)
 
-#endif  // ART_RUNTIME_DEX_DEX_INSTRUCTION_LIST_H_
-#undef ART_RUNTIME_DEX_DEX_INSTRUCTION_LIST_H_  // the guard in this file is just for cpplint
+#endif  // ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_LIST_H_
+#undef ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_LIST_H_  // the guard in this file is just for cpplint
diff --git a/runtime/dex/dex_instruction_test.cc b/libdexfile/dex/dex_instruction_test.cc
similarity index 100%
rename from runtime/dex/dex_instruction_test.cc
rename to libdexfile/dex/dex_instruction_test.cc
diff --git a/runtime/dex/dex_instruction_utils.h b/libdexfile/dex/dex_instruction_utils.h
similarity index 97%
rename from runtime/dex/dex_instruction_utils.h
rename to libdexfile/dex/dex_instruction_utils.h
index 2750192..e7614ad 100644
--- a/runtime/dex/dex_instruction_utils.h
+++ b/libdexfile/dex/dex_instruction_utils.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_DEX_INSTRUCTION_UTILS_H_
-#define ART_RUNTIME_DEX_DEX_INSTRUCTION_UTILS_H_
+#ifndef ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_UTILS_H_
+#define ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_UTILS_H_
 
 #include "dex_instruction.h"
 
@@ -216,4 +216,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_DEX_INSTRUCTION_UTILS_H_
+#endif  // ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_UTILS_H_
diff --git a/runtime/dex/invoke_type.h b/libdexfile/dex/invoke_type.h
similarity index 88%
rename from runtime/dex/invoke_type.h
rename to libdexfile/dex/invoke_type.h
index 726d269..9b3af67 100644
--- a/runtime/dex/invoke_type.h
+++ b/libdexfile/dex/invoke_type.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_INVOKE_TYPE_H_
-#define ART_RUNTIME_DEX_INVOKE_TYPE_H_
+#ifndef ART_LIBDEXFILE_DEX_INVOKE_TYPE_H_
+#define ART_LIBDEXFILE_DEX_INVOKE_TYPE_H_
 
 #include <iosfwd>
 
@@ -35,4 +35,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_INVOKE_TYPE_H_
+#endif  // ART_LIBDEXFILE_DEX_INVOKE_TYPE_H_
diff --git a/runtime/dex/modifiers.cc b/libdexfile/dex/modifiers.cc
similarity index 100%
rename from runtime/dex/modifiers.cc
rename to libdexfile/dex/modifiers.cc
diff --git a/runtime/dex/modifiers.h b/libdexfile/dex/modifiers.h
similarity index 98%
rename from runtime/dex/modifiers.h
rename to libdexfile/dex/modifiers.h
index 2998f60..2425a58 100644
--- a/runtime/dex/modifiers.h
+++ b/libdexfile/dex/modifiers.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_MODIFIERS_H_
-#define ART_RUNTIME_DEX_MODIFIERS_H_
+#ifndef ART_LIBDEXFILE_DEX_MODIFIERS_H_
+#define ART_LIBDEXFILE_DEX_MODIFIERS_H_
 
 #include <stdint.h>
 
@@ -144,5 +144,5 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_MODIFIERS_H_
+#endif  // ART_LIBDEXFILE_DEX_MODIFIERS_H_
 
diff --git a/runtime/dex/standard_dex_file.cc b/libdexfile/dex/standard_dex_file.cc
similarity index 100%
rename from runtime/dex/standard_dex_file.cc
rename to libdexfile/dex/standard_dex_file.cc
diff --git a/runtime/dex/standard_dex_file.h b/libdexfile/dex/standard_dex_file.h
similarity index 96%
rename from runtime/dex/standard_dex_file.h
rename to libdexfile/dex/standard_dex_file.h
index e0e9f2f..9b13caa 100644
--- a/runtime/dex/standard_dex_file.h
+++ b/libdexfile/dex/standard_dex_file.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_
-#define ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_
+#ifndef ART_LIBDEXFILE_DEX_STANDARD_DEX_FILE_H_
+#define ART_LIBDEXFILE_DEX_STANDARD_DEX_FILE_H_
 
 #include <iosfwd>
 
@@ -115,4 +115,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_
+#endif  // ART_LIBDEXFILE_DEX_STANDARD_DEX_FILE_H_
diff --git a/runtime/dex/utf-inl.h b/libdexfile/dex/utf-inl.h
similarity index 95%
rename from runtime/dex/utf-inl.h
rename to libdexfile/dex/utf-inl.h
index 4f626a8..5355766 100644
--- a/runtime/dex/utf-inl.h
+++ b/libdexfile/dex/utf-inl.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_UTF_INL_H_
-#define ART_RUNTIME_DEX_UTF_INL_H_
+#ifndef ART_LIBDEXFILE_DEX_UTF_INL_H_
+#define ART_LIBDEXFILE_DEX_UTF_INL_H_
 
 #include "utf.h"
 
@@ -96,4 +96,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_UTF_INL_H_
+#endif  // ART_LIBDEXFILE_DEX_UTF_INL_H_
diff --git a/runtime/dex/utf.cc b/libdexfile/dex/utf.cc
similarity index 100%
rename from runtime/dex/utf.cc
rename to libdexfile/dex/utf.cc
diff --git a/runtime/dex/utf.h b/libdexfile/dex/utf.h
similarity index 97%
rename from runtime/dex/utf.h
rename to libdexfile/dex/utf.h
index 4adfc4a..c86b389 100644
--- a/runtime/dex/utf.h
+++ b/libdexfile/dex/utf.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_UTF_H_
-#define ART_RUNTIME_DEX_UTF_H_
+#ifndef ART_LIBDEXFILE_DEX_UTF_H_
+#define ART_LIBDEXFILE_DEX_UTF_H_
 
 #include "base/macros.h"
 
@@ -132,4 +132,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_UTF_H_
+#endif  // ART_LIBDEXFILE_DEX_UTF_H_
diff --git a/runtime/dex/utf_test.cc b/libdexfile/dex/utf_test.cc
similarity index 100%
rename from runtime/dex/utf_test.cc
rename to libdexfile/dex/utf_test.cc
diff --git a/libdexfile/generate-operator-out.py b/libdexfile/generate-operator-out.py
new file mode 120000
index 0000000..cc291d2
--- /dev/null
+++ b/libdexfile/generate-operator-out.py
@@ -0,0 +1 @@
+../tools/generate-operator-out.py
\ No newline at end of file
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 832d50e..e011c2e 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -14,83 +14,6 @@
 // limitations under the License.
 //
 
-cc_defaults {
-    name: "libdexfile_defaults",
-    defaults: ["art_defaults"],
-    host_supported: true,
-    srcs: [
-        "dex/compact_dex_debug_info.cc",
-        "dex/compact_dex_file.cc",
-        "dex/descriptors_names.cc",
-        "dex/dex_file.cc",
-        "dex/dex_file_exception_helpers.cc",
-        "dex/dex_file_loader.cc",
-        "dex/dex_file_tracking_registrar.cc",
-        "dex/dex_file_verifier.cc",
-        "dex/dex_instruction.cc",
-        "dex/modifiers.cc",
-        "dex/standard_dex_file.cc",
-        "dex/utf.cc",
-    ],
-
-    target: {
-        android: {
-            static_libs: [
-                "libziparchive",
-                "libz",
-                "libbase",
-            ],
-            shared_libs: [
-                "libutils",
-            ],
-        },
-        host: {
-            shared_libs: [
-                "libziparchive",
-                "libz",
-            ],
-        },
-    },
-    generated_sources: ["dexfile_operator_srcs"],
-    include_dirs: [
-        "external/zlib",
-    ],
-    shared_libs: [
-        "liblog",
-        // For common macros.
-        "libbase",
-        "libz",
-    ],
-
-    // Exporting "." would shadow the system elf.h with our elf.h,
-    // which in turn breaks any tools that reference this library.
-    // export_include_dirs: ["."],
-}
-
-gensrcs {
-    name: "dexfile_operator_srcs",
-    cmd: "$(location generate-operator-out.py) art/runtime $(in) > $(out)",
-    tool_files: ["generate-operator-out.py"],
-    srcs: [
-        "dex/dex_file.h",
-        "dex/dex_file_layout.h",
-        "dex/dex_instruction.h",
-        "dex/dex_instruction_utils.h",
-        "dex/invoke_type.h",
-    ],
-    output_extension: "operator_out.cc",
-}
-
-art_cc_library {
-    name: "libdexfile",
-    defaults: ["libdexfile_defaults"],
-    // Leave the symbols in the shared library so that stack unwinders can
-    // produce meaningful name resolution.
-    strip: {
-        keep_symbols: true,
-    },
-}
-
 // Keep the __jit_debug_register_code symbol as a unique symbol during ICF for architectures where
 // we use gold as the linker (arm, x86, x86_64). The symbol is used by the debuggers to detect when
 // new jit code is generated. We don't want it to be called when a different function with the same
@@ -133,9 +56,9 @@
         "common_throws.cc",
         "compiler_filter.cc",
         "debugger.cc",
+        "dex/art_dex_file_loader.cc",
         "dex/dex_file_annotations.cc",
         "dex/dex_file_layout.cc",
-        "dex/art_dex_file_loader.cc",
         "dex_to_dex_decompiler.cc",
         "elf_file.cc",
         "exec_utils.cc",
@@ -508,7 +431,10 @@
     // ART's macros.h depends on libbase's macros.h.
     // Note: runtime_options.h depends on cmdline. But we don't really want to export this
     //       generically. dex2oat takes care of it itself.
-    export_shared_lib_headers: ["libbase"],
+    export_shared_lib_headers: [
+        "libbase",
+        "libdexfile",
+    ],
 }
 
 gensrcs {
@@ -521,9 +447,9 @@
         "base/callee_save_type.h",
         "base/enums.h",
         "base/mutex.h",
-        "debugger.h",
         "base/unix_file/fd_file.h",
         "class_status.h",
+        "debugger.h",
         "dex/dex_file_layout.h",
         "gc_root.h",
         "gc/allocator_type.h",
@@ -638,13 +564,6 @@
         "class_table_test.cc",
         "compiler_filter_test.cc",
         "dex/art_dex_file_loader_test.cc",
-        "dex/code_item_accessors_test.cc",
-        "dex/compact_dex_debug_info_test.cc",
-        "dex/compact_dex_file_test.cc",
-        "dex/dex_file_loader_test.cc",
-        "dex/dex_file_verifier_test.cc",
-        "dex/dex_instruction_test.cc",
-        "dex/utf_test.cc",
         "entrypoints/math_entrypoints_test.cc",
         "entrypoints/quick/quick_trampoline_entrypoints_test.cc",
         "entrypoints_order_test.cc",
diff --git a/runtime/dex/art_dex_file_loader.cc b/runtime/dex/art_dex_file_loader.cc
index 08cf30d..0817cb4 100644
--- a/runtime/dex/art_dex_file_loader.cc
+++ b/runtime/dex/art_dex_file_loader.cc
@@ -25,10 +25,10 @@
 #include "base/stl_util.h"
 #include "base/systrace.h"
 #include "base/unix_file/fd_file.h"
-#include "compact_dex_file.h"
-#include "dex_file.h"
-#include "dex_file_verifier.h"
-#include "standard_dex_file.h"
+#include "dex/compact_dex_file.h"
+#include "dex/dex_file.h"
+#include "dex/dex_file_verifier.h"
+#include "dex/standard_dex_file.h"
 #include "zip_archive.h"
 
 namespace art {
diff --git a/runtime/dex/art_dex_file_loader.h b/runtime/dex/art_dex_file_loader.h
index b31d1e9..3585381 100644
--- a/runtime/dex/art_dex_file_loader.h
+++ b/runtime/dex/art_dex_file_loader.h
@@ -22,8 +22,8 @@
 #include <string>
 #include <vector>
 
-#include "dex_file_loader.h"
 #include "base/macros.h"
+#include "dex/dex_file_loader.h"
 
 namespace art {
 
diff --git a/runtime/dex/art_dex_file_loader_test.cc b/runtime/dex/art_dex_file_loader_test.cc
index f401381..25d4dd0 100644
--- a/runtime/dex/art_dex_file_loader_test.cc
+++ b/runtime/dex/art_dex_file_loader_test.cc
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 
-#include "dex_file.h"
-
 #include <sys/mman.h>
 
 #include <memory>
@@ -23,12 +21,13 @@
 #include "art_dex_file_loader.h"
 #include "base/stl_util.h"
 #include "base/unix_file/fd_file.h"
-#include "base64_test_util.h"
-#include "code_item_accessors-inl.h"
 #include "common_runtime_test.h"
-#include "descriptors_names.h"
-#include "dex_file-inl.h"
-#include "dex_file_loader.h"
+#include "dex/base64_test_util.h"
+#include "dex/code_item_accessors-inl.h"
+#include "dex/descriptors_names.h"
+#include "dex/dex_file.h"
+#include "dex/dex_file-inl.h"
+#include "dex/dex_file_loader.h"
 #include "mem_map.h"
 #include "os.h"
 #include "scoped_thread_state_change-inl.h"
diff --git a/runtime/dex/dex_file_annotations.cc b/runtime/dex/dex_file_annotations.cc
index e01890f..3431bb7 100644
--- a/runtime/dex/dex_file_annotations.cc
+++ b/runtime/dex/dex_file_annotations.cc
@@ -23,7 +23,7 @@
 #include "art_field-inl.h"
 #include "art_method-inl.h"
 #include "class_linker-inl.h"
-#include "dex_file-inl.h"
+#include "dex/dex_file-inl.h"
 #include "jni_internal.h"
 #include "jvalue-inl.h"
 #include "mirror/field.h"
diff --git a/runtime/dex/dex_file_annotations.h b/runtime/dex/dex_file_annotations.h
index 2677372..d7ebf84 100644
--- a/runtime/dex/dex_file_annotations.h
+++ b/runtime/dex/dex_file_annotations.h
@@ -17,7 +17,7 @@
 #ifndef ART_RUNTIME_DEX_DEX_FILE_ANNOTATIONS_H_
 #define ART_RUNTIME_DEX_DEX_FILE_ANNOTATIONS_H_
 
-#include "dex_file.h"
+#include "dex/dex_file.h"
 
 #include "handle.h"
 #include "mirror/dex_cache.h"
diff --git a/runtime/dex/dex_file_layout.cc b/runtime/dex/dex_file_layout.cc
index 312898d..d85d61d 100644
--- a/runtime/dex/dex_file_layout.cc
+++ b/runtime/dex/dex_file_layout.cc
@@ -19,8 +19,7 @@
 #include <sys/mman.h>
 
 #include "base/file_utils.h"
-#include "descriptors_names.h"
-#include "dex_file.h"
+#include "dex/dex_file.h"
 
 namespace art {
 
diff --git a/tools/cpp-define-generator/Android.bp b/tools/cpp-define-generator/Android.bp
index 57c9c09..f3342d3 100644
--- a/tools/cpp-define-generator/Android.bp
+++ b/tools/cpp-define-generator/Android.bp
@@ -28,7 +28,10 @@
         "art_debug_defaults",
         "art_defaults",
     ],
-    include_dirs: ["art/runtime"],
+    include_dirs: [
+        "art/libdexfile",
+        "art/runtime",
+    ],
     srcs: ["main.cc"],
     shared_libs: [
         "libbase",
diff --git a/tools/titrace/Android.bp b/tools/titrace/Android.bp
index 097622e..21f266c 100644
--- a/tools/titrace/Android.bp
+++ b/tools/titrace/Android.bp
@@ -40,9 +40,8 @@
     },
     header_libs: [
         "libopenjdkjvmti_headers",
-        "libart_runtime_headers", // for dex_instruction_list.h only
-        // "libbase_headers",
     ],
+    include_dirs: ["art/libdexfile"], // for dex_instruction_list.h only
     multilib: {
         lib32: {
             suffix: "32",