Reduce header files including header files.

Main focus is getting heap.h out of runtime.h.

Change-Id: I8d13dce8512816db2820a27b24f5866cc871a04b
diff --git a/runtime/arch/arm/quick_method_frame_info_arm.h b/runtime/arch/arm/quick_method_frame_info_arm.h
index 8d08190..83cacac 100644
--- a/runtime/arch/arm/quick_method_frame_info_arm.h
+++ b/runtime/arch/arm/quick_method_frame_info_arm.h
@@ -20,6 +20,7 @@
 #include "quick/quick_method_frame_info.h"
 #include "registers_arm.h"
 #include "runtime.h"  // for Runtime::CalleeSaveType.
+#include "utils.h"
 
 namespace art {
 namespace arm {
diff --git a/runtime/base/mutex-inl.h b/runtime/base/mutex-inl.h
index a9472f7..d20eb17 100644
--- a/runtime/base/mutex-inl.h
+++ b/runtime/base/mutex-inl.h
@@ -25,6 +25,8 @@
 
 #include "cutils/atomic-inline.h"
 #include "cutils/trace.h"
+
+#include "base/stringprintf.h"
 #include "runtime.h"
 #include "thread.h"
 
diff --git a/runtime/dex_file.h b/runtime/dex_file.h
index 1d5032d..8270a2b 100644
--- a/runtime/dex_file.h
+++ b/runtime/dex_file.h
@@ -26,7 +26,6 @@
 #include "globals.h"
 #include "invoke_type.h"
 #include "jni.h"
-#include "mem_map.h"
 #include "modifiers.h"
 #include "safe_map.h"
 
@@ -41,6 +40,7 @@
   class DexCache;
 }  // namespace mirror
 class ClassLinker;
+class MemMap;
 class Signature;
 template<class T> class Handle;
 class StringPiece;
diff --git a/runtime/dex_instruction.cc b/runtime/dex_instruction.cc
index 0494f22..0a71d62 100644
--- a/runtime/dex_instruction.cc
+++ b/runtime/dex_instruction.cc
@@ -20,6 +20,7 @@
 
 #include <iomanip>
 
+#include "base/stringprintf.h"
 #include "dex_file-inl.h"
 #include "utils.h"
 
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index 5d20096..0df8211 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -20,6 +20,7 @@
 #include <unistd.h>
 
 #include "base/logging.h"
+#include "base/stringprintf.h"
 #include "base/stl_util.h"
 #include "utils.h"
 #include "instruction_set.h"
diff --git a/runtime/fault_handler.h b/runtime/fault_handler.h
index 97d3c2f..026f5b9 100644
--- a/runtime/fault_handler.h
+++ b/runtime/fault_handler.h
@@ -29,7 +29,7 @@
 
 namespace mirror {
 class ArtMethod;
-}       // namespace mirror
+}  // namespace mirror
 
 class FaultHandler;
 
diff --git a/runtime/gc/accounting/space_bitmap.cc b/runtime/gc/accounting/space_bitmap.cc
index 3cb8d94..436a5b5 100644
--- a/runtime/gc/accounting/space_bitmap.cc
+++ b/runtime/gc/accounting/space_bitmap.cc
@@ -72,6 +72,12 @@
 }
 
 template<size_t kAlignment>
+std::string SpaceBitmap<kAlignment>::Dump() const {
+  return StringPrintf("%s: %p-%p", name_.c_str(), reinterpret_cast<void*>(HeapBegin()),
+                      reinterpret_cast<void*>(HeapLimit()));
+}
+
+template<size_t kAlignment>
 void SpaceBitmap<kAlignment>::Clear() {
   if (bitmap_begin_ != NULL) {
     // This returns the memory to the system.  Successive page faults will return zeroed memory.
diff --git a/runtime/gc/accounting/space_bitmap.h b/runtime/gc/accounting/space_bitmap.h
index 50d15c6..0849171 100644
--- a/runtime/gc/accounting/space_bitmap.h
+++ b/runtime/gc/accounting/space_bitmap.h
@@ -26,7 +26,6 @@
 #include "base/mutex.h"
 #include "gc_allocator.h"
 #include "globals.h"
-#include "mem_map.h"
 #include "object_callbacks.h"
 
 namespace art {
@@ -34,6 +33,7 @@
 namespace mirror {
   class Object;
 }  // namespace mirror
+class MemMap;
 
 namespace gc {
 namespace accounting {
@@ -183,10 +183,7 @@
     name_ = name;
   }
 
-  std::string Dump() const {
-    return StringPrintf("%s: %p-%p", name_.c_str(), reinterpret_cast<void*>(HeapBegin()),
-                        reinterpret_cast<void*>(HeapLimit()));
-  }
+  std::string Dump() const;
 
   const void* GetObjectWordAddress(const mirror::Object* obj) const {
     uintptr_t addr = reinterpret_cast<uintptr_t>(obj);
diff --git a/runtime/instrumentation.h b/runtime/instrumentation.h
index 5630862..2dd2cd7 100644
--- a/runtime/instrumentation.h
+++ b/runtime/instrumentation.h
@@ -17,15 +17,15 @@
 #ifndef ART_RUNTIME_INSTRUMENTATION_H_
 #define ART_RUNTIME_INSTRUMENTATION_H_
 
+#include <stdint.h>
+#include <set>
+#include <list>
+
 #include "atomic.h"
 #include "base/macros.h"
 #include "base/mutex.h"
 #include "object_callbacks.h"
 
-#include <stdint.h>
-#include <set>
-#include <list>
-
 namespace art {
 namespace mirror {
   class ArtField;
diff --git a/runtime/jni_internal-inl.h b/runtime/jni_internal-inl.h
new file mode 100644
index 0000000..6cf9a61
--- /dev/null
+++ b/runtime/jni_internal-inl.h
@@ -0,0 +1,47 @@
+/*
+ * 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_RUNTIME_JNI_INTERNAL_INL_H_
+#define ART_RUNTIME_JNI_INTERNAL_INL_H_
+
+#include "jni_internal.h"
+
+#include "utils.h"
+
+namespace art {
+
+template<typename T>
+inline T JNIEnvExt::AddLocalReference(mirror::Object* obj) {
+  IndirectRef ref = locals.Add(local_ref_cookie, obj);
+
+  // TODO: fix this to understand PushLocalFrame, so we can turn it on.
+  if (false) {
+    if (check_jni) {
+      size_t entry_count = locals.Capacity();
+      if (entry_count > 16) {
+        locals.Dump(LOG(WARNING) << "Warning: more than 16 JNI local references: "
+            << entry_count << " (most recent was a " << PrettyTypeOf(obj) << ")\n");
+        // TODO: LOG(FATAL) in a later release?
+      }
+    }
+  }
+
+  return reinterpret_cast<T>(ref);
+}
+
+}  // namespace art
+
+#endif  // ART_RUNTIME_JNI_INTERNAL_INL_H_
diff --git a/runtime/jni_internal.h b/runtime/jni_internal.h
index 4072da4..abb71b7 100644
--- a/runtime/jni_internal.h
+++ b/runtime/jni_internal.h
@@ -24,7 +24,6 @@
 #include "indirect_reference_table.h"
 #include "object_callbacks.h"
 #include "reference_table.h"
-#include "runtime.h"
 
 #include <iosfwd>
 #include <string>
@@ -45,6 +44,7 @@
 union JValue;
 class Libraries;
 class ParsedOptions;
+class Runtime;
 class ScopedObjectAccess;
 template<class T> class Handle;
 class Thread;
@@ -216,25 +216,6 @@
   DISALLOW_COPY_AND_ASSIGN(ScopedJniEnvLocalRefState);
 };
 
-template<typename T>
-inline T JNIEnvExt::AddLocalReference(mirror::Object* obj) {
-  IndirectRef ref = locals.Add(local_ref_cookie, obj);
-
-  // TODO: fix this to understand PushLocalFrame, so we can turn it on.
-  if (false) {
-    if (check_jni) {
-      size_t entry_count = locals.Capacity();
-      if (entry_count > 16) {
-        locals.Dump(LOG(WARNING) << "Warning: more than 16 JNI local references: "
-            << entry_count << " (most recent was a " << PrettyTypeOf(obj) << ")\n");
-        // TODO: LOG(FATAL) in a later release?
-      }
-    }
-  }
-
-  return reinterpret_cast<T>(ref);
-}
-
 }  // namespace art
 
 std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
diff --git a/runtime/mirror/object_array-inl.h b/runtime/mirror/object_array-inl.h
index 9b6e901..c7540dc 100644
--- a/runtime/mirror/object_array-inl.h
+++ b/runtime/mirror/object_array-inl.h
@@ -19,6 +19,7 @@
 
 #include "object_array.h"
 
+#include "base/stringprintf.h"
 #include "gc/heap.h"
 #include "mirror/art_field.h"
 #include "mirror/class.h"
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index 29868e3..cff5ec3 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -15,13 +15,16 @@
  */
 
 #include "parsed_options.h"
-#include "utils.h"
+
 #ifdef HAVE_ANDROID_OS
 #include "cutils/properties.h"
 #endif
 
+#include "base/stringpiece.h"
 #include "debugger.h"
+#include "gc/heap.h"
 #include "monitor.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/runtime/parsed_options.h b/runtime/parsed_options.h
index a27eec6..d0f3c12 100644
--- a/runtime/parsed_options.h
+++ b/runtime/parsed_options.h
@@ -19,6 +19,7 @@
 
 #include <string>
 
+#include "gc/collector_type.h"
 #include "runtime.h"
 #include "trace.h"
 
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index f16eddf..89058c8 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -44,6 +44,7 @@
 #include "atomic.h"
 #include "class_linker.h"
 #include "debugger.h"
+#include "fault_handler.h"
 #include "gc/accounting/card_table-inl.h"
 #include "gc/heap.h"
 #include "gc/space/space.h"
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 808d706..8776a59 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -25,26 +25,21 @@
 #include <utility>
 #include <vector>
 
-#include "base/macros.h"
-#include "base/stringpiece.h"
-#include "gc/collector_type.h"
-#include "gc/heap.h"
-#include "globals.h"
-#include "instruction_set.h"
 #include "instrumentation.h"
+#include "instruction_set.h"
 #include "jobject_comparator.h"
 #include "object_callbacks.h"
+#include "offsets.h"
 #include "profiler_options.h"
 #include "quick/quick_method_frame_info.h"
 #include "runtime_stats.h"
 #include "safe_map.h"
-#include "fault_handler.h"
 
 namespace art {
 
 namespace gc {
   class Heap;
-}
+}  // namespace gc
 namespace mirror {
   class ArtMethod;
   class ClassLoader;
@@ -65,7 +60,10 @@
 class JavaVMExt;
 class MonitorList;
 class MonitorPool;
+class NullPointerHandler;
 class SignalCatcher;
+class StackOverflowHandler;
+class SuspensionHandler;
 class ThreadList;
 class Trace;
 class Transaction;
diff --git a/runtime/scoped_thread_state_change.h b/runtime/scoped_thread_state_change.h
index d56495e..7ce68c6 100644
--- a/runtime/scoped_thread_state_change.h
+++ b/runtime/scoped_thread_state_change.h
@@ -18,6 +18,7 @@
 #define ART_RUNTIME_SCOPED_THREAD_STATE_CHANGE_H_
 
 #include "base/casts.h"
+#include "jni_internal-inl.h"
 #include "thread-inl.h"
 #include "verify_object.h"
 
diff --git a/runtime/thread-inl.h b/runtime/thread-inl.h
index fc886d5..b1180bd 100644
--- a/runtime/thread-inl.h
+++ b/runtime/thread-inl.h
@@ -21,9 +21,11 @@
 
 #include <pthread.h>
 
+#include "cutils/atomic-inline.h"
+
 #include "base/casts.h"
 #include "base/mutex-inl.h"
-#include "cutils/atomic-inline.h"
+#include "gc/heap.h"
 #include "jni_internal.h"
 
 namespace art {
diff --git a/runtime/utils.cc b/runtime/utils.cc
index f562252..dd64e52 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -552,6 +552,18 @@
   }
 }
 
+std::string PrintableChar(uint16_t ch) {
+  std::string result;
+  result += '\'';
+  if (NeedsEscaping(ch)) {
+    StringAppendF(&result, "\\u%04x", ch);
+  } else {
+    result += ch;
+  }
+  result += '\'';
+  return result;
+}
+
 std::string PrintableString(const std::string& utf) {
   std::string result;
   result += '"';
diff --git a/runtime/utils.h b/runtime/utils.h
index 7be5d44..6a4198f 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -23,7 +23,6 @@
 #include <vector>
 
 #include "base/logging.h"
-#include "base/stringprintf.h"
 #include "globals.h"
 #include "instruction_set.h"
 #include "primitive.h"
@@ -205,17 +204,7 @@
   return (ch < ' ' || ch > '~');
 }
 
-static inline std::string PrintableChar(uint16_t ch) {
-  std::string result;
-  result += '\'';
-  if (NeedsEscaping(ch)) {
-    StringAppendF(&result, "\\u%04x", ch);
-  } else {
-    result += ch;
-  }
-  result += '\'';
-  return result;
-}
+std::string PrintableChar(uint16_t ch);
 
 // Returns an ASCII string corresponding to the given UTF-8 string.
 // Java escapes are used for non-ASCII characters.
diff --git a/runtime/verifier/instruction_flags.h b/runtime/verifier/instruction_flags.h
index e50ba13..f8abca0 100644
--- a/runtime/verifier/instruction_flags.h
+++ b/runtime/verifier/instruction_flags.h
@@ -17,11 +17,11 @@
 #ifndef ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
 #define ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
 
-#include "base/logging.h"
-
 #include <stdint.h>
 #include <string>
 
+#include "base/logging.h"
+
 namespace art {
 namespace verifier {
 
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index b5c07aa..8d46812 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -507,6 +507,11 @@
   return *failure_message;
 }
 
+std::ostream& MethodVerifier::LogVerifyInfo() {
+  return info_messages_ << "VFY: " << PrettyMethod(dex_method_idx_, *dex_file_)
+                        << '[' << reinterpret_cast<void*>(work_insn_idx_) << "] : ";
+}
+
 void MethodVerifier::PrependToLastFailMessage(std::string prepend) {
   size_t failure_num = failure_messages_.size();
   DCHECK_NE(failure_num, 0U);
diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h
index a23e80d..451c9e2 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -29,9 +29,8 @@
 #include "dex_instruction.h"
 #include "instruction_flags.h"
 #include "method_reference.h"
-#include "mirror/object.h"
 #include "reg_type.h"
-#include "reg_type_cache-inl.h"
+#include "reg_type_cache.h"
 #include "register_line.h"
 #include "safe_map.h"
 
@@ -170,10 +169,7 @@
   std::ostream& Fail(VerifyError error);
 
   // Log for verification information.
-  std::ostream& LogVerifyInfo() {
-    return info_messages_ << "VFY: " << PrettyMethod(dex_method_idx_, *dex_file_)
-                          << '[' << reinterpret_cast<void*>(work_insn_idx_) << "] : ";
-  }
+  std::ostream& LogVerifyInfo();
 
   // Dump the failures encountered by the verifier.
   std::ostream& DumpFailures(std::ostream& os);
diff --git a/runtime/verifier/reg_type.h b/runtime/verifier/reg_type.h
index a23b8c4..64001d3 100644
--- a/runtime/verifier/reg_type.h
+++ b/runtime/verifier/reg_type.h
@@ -17,18 +17,18 @@
 #ifndef ART_RUNTIME_VERIFIER_REG_TYPE_H_
 #define ART_RUNTIME_VERIFIER_REG_TYPE_H_
 
-#include "base/macros.h"
-#include "globals.h"
-#include "object_callbacks.h"
-#include "primitive.h"
-
-#include "jni.h"
-
 #include <limits>
 #include <stdint.h>
 #include <set>
 #include <string>
 
+#include "jni.h"
+
+#include "base/macros.h"
+#include "globals.h"
+#include "object_callbacks.h"
+#include "primitive.h"
+
 namespace art {
 namespace mirror {
 class Class;
diff --git a/runtime/verifier/register_line-inl.h b/runtime/verifier/register_line-inl.h
index b3a2847..0989cd0 100644
--- a/runtime/verifier/register_line-inl.h
+++ b/runtime/verifier/register_line-inl.h
@@ -18,7 +18,9 @@
 #define ART_RUNTIME_VERIFIER_REGISTER_LINE_INL_H_
 
 #include "register_line.h"
+
 #include "method_verifier.h"
+#include "reg_type_cache-inl.h"
 
 namespace art {
 namespace verifier {
diff --git a/runtime/verifier/register_line.cc b/runtime/verifier/register_line.cc
index a3e3e3b..d21f39b 100644
--- a/runtime/verifier/register_line.cc
+++ b/runtime/verifier/register_line.cc
@@ -16,6 +16,7 @@
 
 #include "register_line.h"
 
+#include "base/stringprintf.h"
 #include "dex_instruction-inl.h"
 #include "method_verifier.h"
 #include "register_line-inl.h"