ART: Add object-array-alloc-inl.h

In an effort to reduce the (transitive) proliferation of heap-inl
add a specific inline header for object array allocation.

Bug: 118385392
Test: mmma art
Test: m test-art-host
Change-Id: I0d7c40ed53708d4c759190961b40f0cac3fe696d
diff --git a/runtime/arch/stub_test.cc b/runtime/arch/stub_test.cc
index de19317..41b26a4 100644
--- a/runtime/arch/stub_test.cc
+++ b/runtime/arch/stub_test.cc
@@ -29,6 +29,7 @@
 #include "linear_alloc.h"
 #include "mirror/class-inl.h"
 #include "mirror/string-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "scoped_thread_state_change-inl.h"
 
 namespace art {
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 032d9f3..627ac17 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -105,6 +105,7 @@
 #include "mirror/method_type.h"
 #include "mirror/object-inl.h"
 #include "mirror/object-refvisitor-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/object_reference.h"
 #include "mirror/object_reference-inl.h"
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index af71727..91636dc 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -46,6 +46,7 @@
 #include "mirror/method_handles_lookup.h"
 #include "mirror/method_type.h"
 #include "mirror/object-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/proxy.h"
 #include "mirror/reference.h"
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index cfc0d28..8fdf8aa 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -52,6 +52,7 @@
 #include "jni/jni_internal.h"
 #include "mirror/class-inl.h"
 #include "mirror/class_loader.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "native/dalvik_system_DexFile.h"
 #include "noop_compiler_callbacks.h"
 #include "runtime-inl.h"
diff --git a/runtime/dex/dex_file_annotations.cc b/runtime/dex/dex_file_annotations.cc
index 246cbca..c5c7daa 100644
--- a/runtime/dex/dex_file_annotations.cc
+++ b/runtime/dex/dex_file_annotations.cc
@@ -30,6 +30,7 @@
 #include "mirror/array-alloc-inl.h"
 #include "mirror/field.h"
 #include "mirror/method.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "oat_file.h"
 #include "obj_ptr-inl.h"
diff --git a/runtime/gc/heap_test.cc b/runtime/gc/heap_test.cc
index a133a10..f6db070 100644
--- a/runtime/gc/heap_test.cc
+++ b/runtime/gc/heap_test.cc
@@ -21,6 +21,7 @@
 #include "handle_scope-inl.h"
 #include "mirror/class-inl.h"
 #include "mirror/object-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "scoped_thread_state_change-inl.h"
 
diff --git a/runtime/gc/heap_verification_test.cc b/runtime/gc/heap_verification_test.cc
index 3754129..7835c29 100644
--- a/runtime/gc/heap_verification_test.cc
+++ b/runtime/gc/heap_verification_test.cc
@@ -21,6 +21,7 @@
 #include "class_root.h"
 #include "handle_scope-inl.h"
 #include "mirror/object-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/string.h"
 #include "runtime.h"
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index 9857249..d5902ec 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -34,6 +34,8 @@
 #include "mirror/class.h"
 #include "mirror/emulated_stack_frame.h"
 #include "mirror/method_handle_impl-inl.h"
+#include "mirror/object_array-alloc-inl.h"
+#include "mirror/object_array-inl.h"
 #include "mirror/var_handle.h"
 #include "reflection-inl.h"
 #include "reflection.h"
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index eae3fbc..0568bfc 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -50,6 +50,7 @@
 #include "mirror/field-inl.h"
 #include "mirror/method.h"
 #include "mirror/object-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/string-inl.h"
 #include "nativehelper/scoped_local_ref.h"
diff --git a/runtime/interpreter/unstarted_runtime_test.cc b/runtime/interpreter/unstarted_runtime_test.cc
index 727c5f3..daaa05d 100644
--- a/runtime/interpreter/unstarted_runtime_test.cc
+++ b/runtime/interpreter/unstarted_runtime_test.cc
@@ -33,6 +33,7 @@
 #include "mirror/array-alloc-inl.h"
 #include "mirror/class_loader.h"
 #include "mirror/object-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/string-inl.h"
 #include "runtime.h"
diff --git a/runtime/jni/jni_internal.cc b/runtime/jni/jni_internal.cc
index 52509fd..6893ca7 100644
--- a/runtime/jni/jni_internal.cc
+++ b/runtime/jni/jni_internal.cc
@@ -50,6 +50,7 @@
 #include "mirror/field-inl.h"
 #include "mirror/method.h"
 #include "mirror/object-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/string-inl.h"
 #include "mirror/throwable.h"
diff --git a/runtime/method_handles_test.cc b/runtime/method_handles_test.cc
index d123754..6a7eb8c 100644
--- a/runtime/method_handles_test.cc
+++ b/runtime/method_handles_test.cc
@@ -22,6 +22,7 @@
 #include "handle_scope-inl.h"
 #include "jvalue-inl.h"
 #include "mirror/method_type.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "reflection.h"
 #include "scoped_thread_state_change-inl.h"
diff --git a/runtime/mirror/array.cc b/runtime/mirror/array.cc
index e67c713..05e397d 100644
--- a/runtime/mirror/array.cc
+++ b/runtime/mirror/array.cc
@@ -27,6 +27,7 @@
 #include "gc/accounting/card_table-inl.h"
 #include "handle_scope-inl.h"
 #include "object-inl.h"
+#include "object_array-alloc-inl.h"
 #include "object_array-inl.h"
 #include "thread.h"
 
diff --git a/runtime/mirror/class_ext.cc b/runtime/mirror/class_ext.cc
index 44bf989..516566b 100644
--- a/runtime/mirror/class_ext.cc
+++ b/runtime/mirror/class_ext.cc
@@ -25,7 +25,8 @@
 #include "dex/dex_file-inl.h"
 #include "gc/accounting/card_table-inl.h"
 #include "object-inl.h"
-#include "object_array.h"
+#include "object_array-alloc-inl.h"
+#include "object_array-inl.h"
 #include "stack_trace_element.h"
 #include "well_known_classes.h"
 
diff --git a/runtime/mirror/emulated_stack_frame.cc b/runtime/mirror/emulated_stack_frame.cc
index a1c536b..f3b5e6f 100644
--- a/runtime/mirror/emulated_stack_frame.cc
+++ b/runtime/mirror/emulated_stack_frame.cc
@@ -23,6 +23,8 @@
 #include "jvalue-inl.h"
 #include "method_handles-inl.h"
 #include "method_handles.h"
+#include "object_array-alloc-inl.h"
+#include "object_array-inl.h"
 #include "reflection-inl.h"
 
 namespace art {
diff --git a/runtime/mirror/method_type.cc b/runtime/mirror/method_type.cc
index bc62ebd..0c32244 100644
--- a/runtime/mirror/method_type.cc
+++ b/runtime/mirror/method_type.cc
@@ -19,6 +19,8 @@
 #include "class-inl.h"
 #include "class_root.h"
 #include "method_handles.h"
+#include "object_array-alloc-inl.h"
+#include "object_array-inl.h"
 
 namespace art {
 namespace mirror {
diff --git a/runtime/mirror/method_type_test.cc b/runtime/mirror/method_type_test.cc
index 2bdea72..a8411d9 100644
--- a/runtime/mirror/method_type_test.cc
+++ b/runtime/mirror/method_type_test.cc
@@ -25,6 +25,7 @@
 #include "class_root.h"
 #include "common_runtime_test.h"
 #include "handle_scope-inl.h"
+#include "object_array-alloc-inl.h"
 #include "object_array-inl.h"
 #include "scoped_thread_state_change-inl.h"
 
diff --git a/runtime/mirror/object_array-alloc-inl.h b/runtime/mirror/object_array-alloc-inl.h
new file mode 100644
index 0000000..8e96d9f
--- /dev/null
+++ b/runtime/mirror/object_array-alloc-inl.h
@@ -0,0 +1,82 @@
+/*
+ * 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_MIRROR_OBJECT_ARRAY_ALLOC_INL_H_
+#define ART_RUNTIME_MIRROR_OBJECT_ARRAY_ALLOC_INL_H_
+
+#include "object_array.h"
+
+#include "array-alloc-inl.h"
+#include "array-inl.h"
+#include "class.h"
+#include "dex/primitive.h"
+#include "gc/heap-inl.h"
+#include "handle_scope-inl.h"
+#include "obj_ptr-inl.h"
+#include "object-inl.h"
+#include "runtime.h"
+
+namespace art {
+namespace mirror {
+
+template<class T>
+inline ObjPtr<ObjectArray<T>> ObjectArray<T>::Alloc(Thread* self,
+                                                    ObjPtr<Class> object_array_class,
+                                                    int32_t length,
+                                                    gc::AllocatorType allocator_type) {
+  ObjPtr<Array> array = Array::Alloc<true>(self,
+                                           object_array_class,
+                                           length,
+                                           ComponentSizeShiftWidth(kHeapReferenceSize),
+                                           allocator_type);
+  if (UNLIKELY(array == nullptr)) {
+    return nullptr;
+  }
+  DCHECK_EQ(array->GetClass()->GetComponentSizeShift(),
+            ComponentSizeShiftWidth(kHeapReferenceSize));
+  return array->AsObjectArray<T>();
+}
+
+template<class T>
+inline ObjPtr<ObjectArray<T>> ObjectArray<T>::Alloc(Thread* self,
+                                                    ObjPtr<Class> object_array_class,
+                                                    int32_t length) {
+  return Alloc(self,
+               object_array_class,
+               length,
+               Runtime::Current()->GetHeap()->GetCurrentAllocator());
+}
+
+template<class T>
+inline ObjPtr<ObjectArray<T>> ObjectArray<T>::CopyOf(Thread* self, int32_t new_length) {
+  DCHECK_GE(new_length, 0);
+  // We may get copied by a compacting GC.
+  StackHandleScope<1> hs(self);
+  Handle<ObjectArray<T>> h_this(hs.NewHandle(this));
+  gc::Heap* heap = Runtime::Current()->GetHeap();
+  gc::AllocatorType allocator_type = heap->IsMovableObject(this) ? heap->GetCurrentAllocator() :
+      heap->GetCurrentNonMovingAllocator();
+  ObjPtr<ObjectArray<T>> new_array = Alloc(self, GetClass(), new_length, allocator_type);
+  if (LIKELY(new_array != nullptr)) {
+    new_array->AssignableMemcpy(0, h_this.Get(), 0, std::min(h_this->GetLength(), new_length));
+  }
+  return new_array;
+}
+
+}  // namespace mirror
+}  // namespace art
+
+#endif  // ART_RUNTIME_MIRROR_OBJECT_ARRAY_ALLOC_INL_H_
diff --git a/runtime/mirror/object_array-inl.h b/runtime/mirror/object_array-inl.h
index 4198d36..98cc4a8 100644
--- a/runtime/mirror/object_array-inl.h
+++ b/runtime/mirror/object_array-inl.h
@@ -23,49 +23,18 @@
 
 #include "android-base/stringprintf.h"
 
-#include "array-alloc-inl.h"
 #include "array-inl.h"
 #include "base/utils.h"
 #include "class.h"
-#include "gc/heap.h"
-#include "handle_scope-inl.h"
 #include "obj_ptr-inl.h"
 #include "object-inl.h"
 #include "runtime.h"
-#include "thread.h"
+#include "thread-current-inl.h"
 #include "write_barrier-inl.h"
 
 namespace art {
 namespace mirror {
 
-template<class T>
-inline ObjPtr<ObjectArray<T>> ObjectArray<T>::Alloc(Thread* self,
-                                                    ObjPtr<Class> object_array_class,
-                                                    int32_t length,
-                                                    gc::AllocatorType allocator_type) {
-  ObjPtr<Array> array = Array::Alloc<true>(self,
-                                           object_array_class,
-                                           length,
-                                           ComponentSizeShiftWidth(kHeapReferenceSize),
-                                           allocator_type);
-  if (UNLIKELY(array == nullptr)) {
-    return nullptr;
-  }
-  DCHECK_EQ(array->GetClass()->GetComponentSizeShift(),
-            ComponentSizeShiftWidth(kHeapReferenceSize));
-  return array->AsObjectArray<T>();
-}
-
-template<class T>
-inline ObjPtr<ObjectArray<T>> ObjectArray<T>::Alloc(Thread* self,
-                                                    ObjPtr<Class> object_array_class,
-                                                    int32_t length) {
-  return Alloc(self,
-               object_array_class,
-               length,
-               Runtime::Current()->GetHeap()->GetCurrentAllocator());
-}
-
 template<class T> template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption>
 inline T* ObjectArray<T>::Get(int32_t i) {
   if (!CheckIsValidIndex<kVerifyFlags>(i)) {
@@ -349,22 +318,6 @@
 }
 
 template<class T>
-inline ObjPtr<ObjectArray<T>> ObjectArray<T>::CopyOf(Thread* self, int32_t new_length) {
-  DCHECK_GE(new_length, 0);
-  // We may get copied by a compacting GC.
-  StackHandleScope<1> hs(self);
-  Handle<ObjectArray<T>> h_this(hs.NewHandle(this));
-  gc::Heap* heap = Runtime::Current()->GetHeap();
-  gc::AllocatorType allocator_type = heap->IsMovableObject(this) ? heap->GetCurrentAllocator() :
-      heap->GetCurrentNonMovingAllocator();
-  ObjPtr<ObjectArray<T>> new_array = Alloc(self, GetClass(), new_length, allocator_type);
-  if (LIKELY(new_array != nullptr)) {
-    new_array->AssignableMemcpy(0, h_this.Get(), 0, std::min(h_this->GetLength(), new_length));
-  }
-  return new_array;
-}
-
-template<class T>
 inline MemberOffset ObjectArray<T>::OffsetOfElement(int32_t i) {
   return MemberOffset(DataOffset(kHeapReferenceSize).Int32Value() + (i * kHeapReferenceSize));
 }
diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc
index 71bf033..e6a2523 100644
--- a/runtime/mirror/object_test.cc
+++ b/runtime/mirror/object_test.cc
@@ -39,6 +39,7 @@
 #include "iftable-inl.h"
 #include "obj_ptr.h"
 #include "object-inl.h"
+#include "object_array-alloc-inl.h"
 #include "object_array-inl.h"
 #include "scoped_thread_state_change-inl.h"
 #include "string-inl.h"
diff --git a/runtime/mirror/var_handle.cc b/runtime/mirror/var_handle.cc
index 4391910..085dcab 100644
--- a/runtime/mirror/var_handle.cc
+++ b/runtime/mirror/var_handle.cc
@@ -27,6 +27,7 @@
 #include "jvalue-inl.h"
 #include "method_handles-inl.h"
 #include "method_type.h"
+#include "object_array-alloc-inl.h"
 #include "obj_ptr-inl.h"
 #include "well_known_classes.h"
 
diff --git a/runtime/mirror/var_handle_test.cc b/runtime/mirror/var_handle_test.cc
index 9df96dd..9563079 100644
--- a/runtime/mirror/var_handle_test.cc
+++ b/runtime/mirror/var_handle_test.cc
@@ -28,6 +28,7 @@
 #include "handle_scope-inl.h"
 #include "jvalue-inl.h"
 #include "method_type.h"
+#include "object_array-alloc-inl.h"
 #include "object_array-inl.h"
 #include "reflection.h"
 #include "scoped_thread_state_change-inl.h"
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index 6d94fa1..7e4579e 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -36,6 +36,7 @@
 #include "mirror/method.h"
 #include "mirror/method_handles_lookup.h"
 #include "mirror/object-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/string-inl.h"
 #include "native_util.h"
diff --git a/runtime/native/java_lang_reflect_Array.cc b/runtime/native/java_lang_reflect_Array.cc
index 452a66d..ff94593 100644
--- a/runtime/native/java_lang_reflect_Array.cc
+++ b/runtime/native/java_lang_reflect_Array.cc
@@ -24,6 +24,7 @@
 #include "handle_scope-inl.h"
 #include "jni/jni_internal.h"
 #include "mirror/class-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object-inl.h"
 #include "native_util.h"
 #include "scoped_fast_native_object_access-inl.h"
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc
index 4b4d6e3..a288c72 100644
--- a/runtime/native/java_lang_reflect_Constructor.cc
+++ b/runtime/native/java_lang_reflect_Constructor.cc
@@ -26,6 +26,7 @@
 #include "jni/jni_internal.h"
 #include "mirror/class-inl.h"
 #include "mirror/method.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object-inl.h"
 #include "native_util.h"
 #include "reflection.h"
diff --git a/runtime/native/java_lang_reflect_Executable.cc b/runtime/native/java_lang_reflect_Executable.cc
index a10db91..918730b 100644
--- a/runtime/native/java_lang_reflect_Executable.cc
+++ b/runtime/native/java_lang_reflect_Executable.cc
@@ -27,6 +27,7 @@
 #include "mirror/class-inl.h"
 #include "mirror/method.h"
 #include "mirror/object-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "native_util.h"
 #include "reflection.h"
diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc
index 895b2f9..b9ac88d 100644
--- a/runtime/native/java_lang_reflect_Field.cc
+++ b/runtime/native/java_lang_reflect_Field.cc
@@ -30,6 +30,7 @@
 #include "jvalue-inl.h"
 #include "mirror/class-inl.h"
 #include "mirror/field-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "native_util.h"
 #include "reflection-inl.h"
 #include "scoped_fast_native_object_access-inl.h"
diff --git a/runtime/native/java_lang_reflect_Method.cc b/runtime/native/java_lang_reflect_Method.cc
index 87fda6b..c65541d 100644
--- a/runtime/native/java_lang_reflect_Method.cc
+++ b/runtime/native/java_lang_reflect_Method.cc
@@ -27,7 +27,7 @@
 #include "jni/jni_internal.h"
 #include "mirror/class-inl.h"
 #include "mirror/object-inl.h"
-#include "mirror/object_array-inl.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "native_util.h"
 #include "reflection.h"
 #include "scoped_fast_native_object_access-inl.h"
diff --git a/runtime/thread.cc b/runtime/thread.cc
index a3de4e2..738152d 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -79,6 +79,7 @@
 #include "jni/jni_internal.h"
 #include "mirror/class-inl.h"
 #include "mirror/class_loader.h"
+#include "mirror/object_array-alloc-inl.h"
 #include "mirror/object_array-inl.h"
 #include "mirror/stack_trace_element.h"
 #include "monitor.h"