Clean up some includes.

Remove some unnecessary includes from header files, replace
others with forward references and add includes to source
files as needed. Reduce dependency on stack.h by pulling
StackReference<> out to its own file.

Test: m test-art-host
Change-Id: I0fb182145e328870cbd918b0ef6ae2950223c1b2
diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h
index fd396c4..78a8afb 100644
--- a/compiler/optimizing/code_generator.h
+++ b/compiler/optimizing/code_generator.h
@@ -23,8 +23,6 @@
 #include "base/arena_object.h"
 #include "base/bit_field.h"
 #include "base/enums.h"
-#include "compiled_method.h"
-#include "driver/compiler_options.h"
 #include "globals.h"
 #include "graph_visualizer.h"
 #include "locations.h"
@@ -54,6 +52,7 @@
 class Assembler;
 class CodeGenerator;
 class CompilerDriver;
+class CompilerOptions;
 class LinkerPatch;
 class ParallelMoveResolver;
 
diff --git a/compiler/optimizing/code_generator_mips.cc b/compiler/optimizing/code_generator_mips.cc
index e0de03b..8f2fc26 100644
--- a/compiler/optimizing/code_generator_mips.cc
+++ b/compiler/optimizing/code_generator_mips.cc
@@ -20,6 +20,7 @@
 #include "arch/mips/instruction_set_features_mips.h"
 #include "art_method.h"
 #include "code_generator_utils.h"
+#include "compiled_method.h"
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "entrypoints/quick/quick_entrypoints_enum.h"
 #include "gc/accounting/card_table.h"
diff --git a/compiler/optimizing/optimizing_cfi_test.cc b/compiler/optimizing/optimizing_cfi_test.cc
index 8c0231e..a1e923b 100644
--- a/compiler/optimizing/optimizing_cfi_test.cc
+++ b/compiler/optimizing/optimizing_cfi_test.cc
@@ -19,6 +19,7 @@
 
 #include "arch/instruction_set.h"
 #include "cfi_test.h"
+#include "driver/compiler_options.h"
 #include "gtest/gtest.h"
 #include "optimizing/code_generator.h"
 #include "optimizing/optimizing_unit_test.h"
diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc
index 6effc30..81163e2 100644
--- a/compiler/optimizing/sharpening.cc
+++ b/compiler/optimizing/sharpening.cc
@@ -20,6 +20,7 @@
 #include "base/enums.h"
 #include "class_linker.h"
 #include "code_generator.h"
+#include "driver/compiler_options.h"
 #include "driver/dex_compilation_unit.h"
 #include "utils/dex_cache_arrays_layout-inl.h"
 #include "driver/compiler_driver.h"
diff --git a/compiler/optimizing/x86_memory_gen.cc b/compiler/optimizing/x86_memory_gen.cc
index 8aa315a..4e25683 100644
--- a/compiler/optimizing/x86_memory_gen.cc
+++ b/compiler/optimizing/x86_memory_gen.cc
@@ -16,6 +16,7 @@
 
 #include "x86_memory_gen.h"
 #include "code_generator.h"
+#include "driver/compiler_options.h"
 
 namespace art {
 namespace x86 {
diff --git a/runtime/arch/arm/entrypoints_init_arm.cc b/runtime/arch/arm/entrypoints_init_arm.cc
index 492a12d..cb8edff 100644
--- a/runtime/arch/arm/entrypoints_init_arm.cc
+++ b/runtime/arch/arm/entrypoints_init_arm.cc
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 
+#include <math.h>
+#include <string.h>
+
 #include "entrypoints/jni/jni_entrypoints.h"
 #include "entrypoints/quick/quick_alloc_entrypoints.h"
 #include "entrypoints/quick/quick_default_externs.h"
diff --git a/runtime/arch/arm64/entrypoints_init_arm64.cc b/runtime/arch/arm64/entrypoints_init_arm64.cc
index 55b09c3..c2078f0 100644
--- a/runtime/arch/arm64/entrypoints_init_arm64.cc
+++ b/runtime/arch/arm64/entrypoints_init_arm64.cc
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 
+#include <math.h>
+#include <string.h>
+
 #include "entrypoints/jni/jni_entrypoints.h"
 #include "entrypoints/quick/quick_alloc_entrypoints.h"
 #include "entrypoints/quick/quick_default_externs.h"
diff --git a/runtime/arch/mips/entrypoints_init_mips.cc b/runtime/arch/mips/entrypoints_init_mips.cc
index 09f8849..38aa67c 100644
--- a/runtime/arch/mips/entrypoints_init_mips.cc
+++ b/runtime/arch/mips/entrypoints_init_mips.cc
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <string.h>
+
 #include "atomic.h"
 #include "entrypoints/jni/jni_entrypoints.h"
 #include "entrypoints/quick/quick_alloc_entrypoints.h"
diff --git a/runtime/arch/mips64/entrypoints_init_mips64.cc b/runtime/arch/mips64/entrypoints_init_mips64.cc
index 34b0638..a037905 100644
--- a/runtime/arch/mips64/entrypoints_init_mips64.cc
+++ b/runtime/arch/mips64/entrypoints_init_mips64.cc
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <string.h>
+
 #include "atomic.h"
 #include "entrypoints/jni/jni_entrypoints.h"
 #include "entrypoints/quick/quick_alloc_entrypoints.h"
diff --git a/runtime/arch/x86/entrypoints_init_x86.cc b/runtime/arch/x86/entrypoints_init_x86.cc
index bdf11da..0a10a3c 100644
--- a/runtime/arch/x86/entrypoints_init_x86.cc
+++ b/runtime/arch/x86/entrypoints_init_x86.cc
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <math.h>
+
 #include "entrypoints/jni/jni_entrypoints.h"
 #include "entrypoints/quick/quick_alloc_entrypoints.h"
 #include "entrypoints/quick/quick_default_externs.h"
diff --git a/runtime/arch/x86_64/entrypoints_init_x86_64.cc b/runtime/arch/x86_64/entrypoints_init_x86_64.cc
index 42b9699..8c425d5 100644
--- a/runtime/arch/x86_64/entrypoints_init_x86_64.cc
+++ b/runtime/arch/x86_64/entrypoints_init_x86_64.cc
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <math.h>
+
 #include "entrypoints/jni/jni_entrypoints.h"
 #include "entrypoints/quick/quick_alloc_entrypoints.h"
 #include "entrypoints/quick/quick_default_externs.h"
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 62b88a2..b25087c 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -29,7 +29,6 @@
 #include "modifiers.h"
 #include "mirror/object.h"
 #include "read_barrier_option.h"
-#include "stack.h"
 #include "utils.h"
 
 namespace art {
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 90c678c..24d73ef 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -42,6 +42,7 @@
 #include "dex_file_verifier.h"
 #include "globals.h"
 #include "handle_scope-inl.h"
+#include "jvalue.h"
 #include "leb128.h"
 #include "mirror/field.h"
 #include "mirror/method.h"
@@ -68,6 +69,11 @@
   {'0', '3', '8', '\0'}
 };
 
+struct DexFile::AnnotationValue {
+  JValue value_;
+  uint8_t type_;
+};
+
 bool DexFile::GetChecksum(const char* filename, uint32_t* checksum, std::string* error_msg) {
   CHECK(checksum != nullptr);
   uint32_t magic;
diff --git a/runtime/dex_file.h b/runtime/dex_file.h
index 767f921..56e5ecc 100644
--- a/runtime/dex_file.h
+++ b/runtime/dex_file.h
@@ -19,7 +19,6 @@
 
 #include <memory>
 #include <string>
-#include <unordered_map>
 #include <vector>
 
 #include "base/logging.h"
@@ -28,7 +27,6 @@
 #include "globals.h"
 #include "invoke_type.h"
 #include "jni.h"
-#include "jvalue.h"
 #include "mirror/object_array.h"
 #include "modifiers.h"
 #include "utf.h"
@@ -398,11 +396,6 @@
     DISALLOW_COPY_AND_ASSIGN(AnnotationItem);
   };
 
-  struct AnnotationValue {
-    JValue value_;
-    uint8_t type_;
-  };
-
   enum AnnotationResultStyle {  // private
     kAllObjects,
     kPrimitivesOrObjects,
@@ -1022,10 +1015,6 @@
   mirror::ObjectArray<mirror::Object>* ProcessAnnotationSetRefList(Handle<mirror::Class> klass,
       const AnnotationSetRefList* set_ref_list, uint32_t size) const
       REQUIRES_SHARED(Locks::mutator_lock_);
-  bool ProcessAnnotationValue(Handle<mirror::Class> klass, const uint8_t** annotation_ptr,
-                              AnnotationValue* annotation_value, Handle<mirror::Class> return_class,
-                              DexFile::AnnotationResultStyle result_style) const
-      REQUIRES_SHARED(Locks::mutator_lock_);
   mirror::Object* ProcessEncodedAnnotation(Handle<mirror::Class> klass,
                                            const uint8_t** annotation) const
       REQUIRES_SHARED(Locks::mutator_lock_);
@@ -1203,6 +1192,12 @@
   // whether the string contains the separator character.
   static bool IsMultiDexLocation(const char* location);
 
+  struct AnnotationValue;
+
+  bool ProcessAnnotationValue(Handle<mirror::Class> klass, const uint8_t** annotation_ptr,
+                              AnnotationValue* annotation_value, Handle<mirror::Class> return_class,
+                              DexFile::AnnotationResultStyle result_style) const
+      REQUIRES_SHARED(Locks::mutator_lock_);
 
   // The base address of the memory mapping.
   const uint8_t* const begin_;
diff --git a/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc b/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc
index d680c5d..5b9d03b 100644
--- a/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc
@@ -23,7 +23,6 @@
 #include "mirror/object_array-inl.h"
 #include "mirror/object-inl.h"
 #include "quick_exception_handler.h"
-#include "stack.h"
 #include "thread.h"
 #include "verifier/method_verifier.h"
 
diff --git a/runtime/handle.h b/runtime/handle.h
index 69f8ef0..d4c13d4 100644
--- a/runtime/handle.h
+++ b/runtime/handle.h
@@ -20,8 +20,10 @@
 #include "base/casts.h"
 #include "base/logging.h"
 #include "base/macros.h"
+#include "base/mutex.h"
 #include "base/value_object.h"
-#include "stack.h"
+#include "jni.h"
+#include "stack_reference.h"
 
 namespace art {
 
diff --git a/runtime/handle_scope.h b/runtime/handle_scope.h
index ff36571..37eed99 100644
--- a/runtime/handle_scope.h
+++ b/runtime/handle_scope.h
@@ -22,8 +22,9 @@
 #include "base/enums.h"
 #include "base/logging.h"
 #include "base/macros.h"
+#include "base/mutex.h"
 #include "handle.h"
-#include "stack.h"
+#include "stack_reference.h"
 #include "verify_object.h"
 
 namespace art {
diff --git a/runtime/image-inl.h b/runtime/image-inl.h
index 28620db..669649e 100644
--- a/runtime/image-inl.h
+++ b/runtime/image-inl.h
@@ -21,6 +21,7 @@
 
 #include "art_method.h"
 #include "imtable.h"
+#include "read_barrier-inl.h"
 
 namespace art {
 
diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h
index 44e0e2a..417a185 100644
--- a/runtime/jit/jit.h
+++ b/runtime/jit/jit.h
@@ -31,6 +31,7 @@
 
 class ArtMethod;
 struct RuntimeArgumentMap;
+union JValue;
 
 namespace jit {
 
diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
index 9ce4a02..9ed0e7e 100644
--- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
+++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
@@ -23,7 +23,6 @@
 #include "scoped_fast_native_object_access.h"
 #include "ScopedLocalRef.h"
 #include "ScopedPrimitiveArray.h"
-#include "stack.h"
 #include "thread_list.h"
 
 namespace art {
diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc
index 9e1109e..55aba2b 100644
--- a/runtime/quick_exception_handler.cc
+++ b/runtime/quick_exception_handler.cc
@@ -30,6 +30,7 @@
 #include "mirror/class_loader.h"
 #include "mirror/throwable.h"
 #include "oat_quick_method_header.h"
+#include "stack.h"
 #include "stack_map.h"
 #include "verifier/method_verifier.h"
 
diff --git a/runtime/quick_exception_handler.h b/runtime/quick_exception_handler.h
index 9d16ead..5592126 100644
--- a/runtime/quick_exception_handler.h
+++ b/runtime/quick_exception_handler.h
@@ -20,7 +20,7 @@
 #include "base/logging.h"
 #include "base/macros.h"
 #include "base/mutex.h"
-#include "stack.h"  // StackReference
+#include "stack_reference.h"
 
 namespace art {
 
@@ -29,8 +29,10 @@
 }  // namespace mirror
 class ArtMethod;
 class Context;
+class OatQuickMethodHeader;
 class Thread;
 class ShadowFrame;
+class StackVisitor;
 
 // Manages exception delivery for Quick backend.
 class QuickExceptionHandler {
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index 44e9bf5..f2af3da 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -29,7 +29,7 @@
 #include "mirror/object_array-inl.h"
 #include "nth_caller_visitor.h"
 #include "scoped_thread_state_change.h"
-#include "stack.h"
+#include "stack_reference.h"
 #include "well_known_classes.h"
 
 namespace art {
diff --git a/runtime/stack.h b/runtime/stack.h
index 5dee147..e9ed497 100644
--- a/runtime/stack.h
+++ b/runtime/stack.h
@@ -25,9 +25,9 @@
 #include "base/mutex.h"
 #include "dex_file.h"
 #include "gc_root.h"
-#include "mirror/object_reference.h"
 #include "quick/quick_method_frame_info.h"
 #include "read_barrier.h"
+#include "stack_reference.h"
 #include "verify_object.h"
 
 namespace art {
@@ -45,6 +45,7 @@
 class ShadowFrame;
 class StackVisitor;
 class Thread;
+union JValue;
 
 // The kind of vreg being accessed in calls to Set/GetVReg.
 enum VRegKind {
@@ -61,11 +62,6 @@
 };
 std::ostream& operator<<(std::ostream& os, const VRegKind& rhs);
 
-// A reference from the shadow stack to a MirrorType object within the Java heap.
-template<class MirrorType>
-class MANAGED StackReference : public mirror::CompressedReference<MirrorType> {
-};
-
 // Forward declaration. Just calls the destructor.
 struct ShadowFrameDeleter;
 using ShadowFrameAllocaUniquePtr = std::unique_ptr<ShadowFrame, ShadowFrameDeleter>;
diff --git a/runtime/stack_reference.h b/runtime/stack_reference.h
new file mode 100644
index 0000000..3d37b76
--- /dev/null
+++ b/runtime/stack_reference.h
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+#ifndef ART_RUNTIME_STACK_REFERENCE_H_
+#define ART_RUNTIME_STACK_REFERENCE_H_
+
+#include "base/macros.h"
+#include "mirror/object_reference.h"
+
+namespace art {
+
+// A reference from the shadow stack to a MirrorType object within the Java heap.
+template<class MirrorType>
+class PACKED(4) StackReference : public mirror::CompressedReference<MirrorType> {
+};
+
+}  // namespace art
+
+#endif  // ART_RUNTIME_STACK_REFERENCE_H_
diff --git a/runtime/utf.h b/runtime/utf.h
index 51a6ade..cbb32fa 100644
--- a/runtime/utf.h
+++ b/runtime/utf.h
@@ -18,7 +18,6 @@
 #define ART_RUNTIME_UTF_H_
 
 #include "base/macros.h"
-#include "base/mutex.h"
 
 #include <stddef.h>
 #include <stdint.h>
@@ -31,11 +30,6 @@
  */
 namespace art {
 
-namespace mirror {
-  template<class T> class PrimitiveArray;
-  typedef PrimitiveArray<uint16_t> CharArray;
-}  // namespace mirror
-
 /*
  * Returns the number of UTF-16 characters in the given modified UTF-8 string.
  */
@@ -80,9 +74,6 @@
 /*
  * The java.lang.String hashCode() algorithm.
  */
-int32_t ComputeUtf16Hash(mirror::CharArray* chars, int32_t offset, size_t char_count)
-    REQUIRES_SHARED(Locks::mutator_lock_);
-
 template<typename MemoryType>
 int32_t ComputeUtf16Hash(const MemoryType* chars, size_t char_count) {
   uint32_t hash = 0;
diff --git a/runtime/verifier/reg_type.h b/runtime/verifier/reg_type.h
index 00635a8..c3ed77a 100644
--- a/runtime/verifier/reg_type.h
+++ b/runtime/verifier/reg_type.h
@@ -35,6 +35,7 @@
 namespace art {
 namespace mirror {
 class Class;
+class ClassLoader;
 }  // namespace mirror
 
 class ArenaBitVector;
diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc
index ee2ee1a..fd1ba02 100644
--- a/test/common/runtime_state.cc
+++ b/test/common/runtime_state.cc
@@ -22,12 +22,10 @@
 #include "jit/jit.h"
 #include "jit/jit_code_cache.h"
 #include "mirror/class-inl.h"
-#include "nth_caller_visitor.h"
 #include "oat_quick_method_header.h"
 #include "runtime.h"
 #include "scoped_thread_state_change.h"
 #include "ScopedUtfChars.h"
-#include "stack.h"
 #include "thread-inl.h"
 
 namespace art {