diff options
author | 2018-10-24 15:18:21 -0700 | |
---|---|---|
committer | 2018-10-26 08:44:12 -0700 | |
commit | 52ecb65ae9e1ad6fe7f58beecc88cdc08e08f0c4 (patch) | |
tree | 7a8ee84cad0df34ab33bdcb0115fc0c79d6c83be | |
parent | c2099b0b0c052dd61137b9cf5f9f8b30bab1a7a8 (diff) |
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
33 files changed, 120 insertions, 50 deletions
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index 7f94a298eb..dd781c288f 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -36,6 +36,8 @@ #include "jit/jit_code_cache.h" #include "mirror/class_loader.h" #include "mirror/dex_cache.h" +#include "mirror/object_array-alloc-inl.h" +#include "mirror/object_array-inl.h" #include "nodes.h" #include "optimizing_compiler.h" #include "reference_type_propagation.h" diff --git a/compiler/optimizing/intrinsic_objects.cc b/compiler/optimizing/intrinsic_objects.cc index 3c20ad698b..0374b4e332 100644 --- a/compiler/optimizing/intrinsic_objects.cc +++ b/compiler/optimizing/intrinsic_objects.cc @@ -21,6 +21,7 @@ #include "class_root.h" #include "handle.h" #include "obj_ptr-inl.h" +#include "mirror/object_array-alloc-inl.h" #include "mirror/object_array-inl.h" namespace art { diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc index 60a4a32e7e..be620587b0 100644 --- a/dex2oat/linker/image_writer.cc +++ b/dex2oat/linker/image_writer.cc @@ -66,6 +66,7 @@ #include "mirror/method.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/string-inl.h" #include "oat.h" diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc index 5adfe42e56..412e62c6f2 100644 --- a/openjdkjvmti/ti_redefine.cc +++ b/openjdkjvmti/ti_redefine.cc @@ -67,6 +67,8 @@ #include "mirror/class-inl.h" #include "mirror/class_ext.h" #include "mirror/object.h" +#include "mirror/object_array-alloc-inl.h" +#include "mirror/object_array-inl.h" #include "nativehelper/scoped_local_ref.h" #include "non_debuggable_classes.h" #include "object_lock.h" diff --git a/runtime/arch/stub_test.cc b/runtime/arch/stub_test.cc index de1931794f..41b26a4e71 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 032d9f3bd7..627ac1711b 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 af71727975..91636dc7e9 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 cfc0d283d1..8fdf8aa0cd 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 246cbca654..c5c7daa47a 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 a133a1058c..f6db070fac 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 375412930b..7835c2969a 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 9857249384..d5902ecbec 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 eae3fbc9ed..0568bfc870 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 727c5f3f22..daaa05d7df 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 52509fde66..6893ca75ae 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 d123754e47..6a7eb8c8e1 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 e67c7139ab..05e397db95 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 44bf9891cd..516566b6bc 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 a1c536b519..f3b5e6f0e7 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 bc62ebdc8b..0c3224494c 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 2bdea72f14..a8411d9e10 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 0000000000..8e96d9fc19 --- /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 4198d36778..98cc4a886c 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 @@ inline void ObjectArray<T>::AssignableCheckingMemcpy(int32_t dst_pos, } 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 71bf03372e..e6a2523b40 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 43919107b4..085dcab5a8 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 9df96ddbd1..9563079bab 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 6d94fa1922..7e4579e059 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 452a66dca2..ff94593cdf 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 4b4d6e332c..a288c72950 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 a10db9115f..918730b980 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 895b2f9fd7..b9ac88d999 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 87fda6bf5d..c65541d70b 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 a3de4e2215..738152d693 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" |