diff options
53 files changed, 244 insertions, 116 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/libartbase/base/mem_map_test.cc b/libartbase/base/mem_map_test.cc index 813d90d0bd..e4e227f3b2 100644 --- a/libartbase/base/mem_map_test.cc +++ b/libartbase/base/mem_map_test.cc @@ -411,6 +411,12 @@ TEST_F(MemMapTest, MapFile32Bit) { #endif TEST_F(MemMapTest, MapAnonymousExactAddr) { + // TODO: The semantics of the MemMap::MapAnonymous() with a given address but without + // `reuse == true` or `reservation != nullptr` is weird. We should either drop support + // for it, or take it only as a hint and allow the result to be mapped elsewhere. + // Currently we're seeing failures with ASAN. b/118408378 + TEST_DISABLED_FOR_MEMORY_TOOL(); + CommonInit(); std::string error_msg; // Find a valid address. diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc index 5adfe42e56..f3f45d9c50 100644 --- a/openjdkjvmti/ti_redefine.cc +++ b/openjdkjvmti/ti_redefine.cc @@ -64,9 +64,12 @@ #include "jvmti_allocator.h" #include "linear_alloc.h" #include "mirror/array-alloc-inl.h" +#include "mirror/class-alloc-inl.h" #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..0cc5535f8e 100644 --- a/runtime/arch/stub_test.cc +++ b/runtime/arch/stub_test.cc @@ -27,8 +27,9 @@ #include "imt_conflict_table.h" #include "jni/jni_internal.h" #include "linear_alloc.h" -#include "mirror/class-inl.h" +#include "mirror/class-alloc-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 28a1924bf8..e240167ba8 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -90,6 +90,7 @@ #include "mirror/array-alloc-inl.h" #include "mirror/array-inl.h" #include "mirror/call_site.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "mirror/class.h" #include "mirror/class_ext.h" @@ -105,6 +106,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/class_table_test.cc b/runtime/class_table_test.cc index fdf6ad1fea..2270662260 100644 --- a/runtime/class_table_test.cc +++ b/runtime/class_table_test.cc @@ -24,7 +24,7 @@ #include "gc/accounting/card_table-inl.h" #include "gc/heap.h" #include "handle_scope-inl.h" -#include "mirror/class-inl.h" +#include "mirror/class-alloc-inl.h" #include "obj_ptr.h" #include "scoped_thread_state_change-inl.h" diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc index cfc0d283d1..fcf6bb25e3 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -50,8 +50,10 @@ #include "interpreter/unstarted_runtime.h" #include "jni/java_vm_ext.h" #include "jni/jni_internal.h" +#include "mirror/class-alloc-inl.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/debugger.cc b/runtime/debugger.cc index fcc5ce6acc..328a9bba40 100644 --- a/runtime/debugger.cc +++ b/runtime/debugger.cc @@ -54,6 +54,7 @@ #include "jni/jni_internal.h" #include "jvalue-inl.h" #include "mirror/array-alloc-inl.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "mirror/class.h" #include "mirror/class_loader.h" diff --git a/runtime/dex/dex_file_annotations.cc b/runtime/dex/dex_file_annotations.cc index 246cbca654..15398672b2 100644 --- a/runtime/dex/dex_file_annotations.cc +++ b/runtime/dex/dex_file_annotations.cc @@ -28,8 +28,10 @@ #include "jni/jni_internal.h" #include "jvalue-inl.h" #include "mirror/array-alloc-inl.h" +#include "mirror/class-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/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h index b45bb59f06..0b005e0851 100644 --- a/runtime/entrypoints/entrypoint_utils-inl.h +++ b/runtime/entrypoints/entrypoint_utils-inl.h @@ -33,6 +33,7 @@ #include "indirect_reference_table.h" #include "jni/jni_internal.h" #include "mirror/array-alloc-inl.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "mirror/object-inl.h" #include "mirror/throwable.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/gc/reference_queue_test.cc b/runtime/gc/reference_queue_test.cc index ce0807c0c6..c680fb5781 100644 --- a/runtime/gc/reference_queue_test.cc +++ b/runtime/gc/reference_queue_test.cc @@ -18,6 +18,7 @@ #include "common_runtime_test.h" #include "handle_scope-inl.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "reference_queue.h" #include "scoped_thread_state_change-inl.h" diff --git a/runtime/handle_scope_test.cc b/runtime/handle_scope_test.cc index f888482ae5..d72dbe6998 100644 --- a/runtime/handle_scope_test.cc +++ b/runtime/handle_scope_test.cc @@ -22,6 +22,7 @@ #include "gtest/gtest.h" #include "handle.h" #include "handle_scope-inl.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "mirror/object.h" #include "scoped_thread_state_change-inl.h" diff --git a/runtime/indirect_reference_table_test.cc b/runtime/indirect_reference_table_test.cc index 141feb434f..c5ae4c63f7 100644 --- a/runtime/indirect_reference_table_test.cc +++ b/runtime/indirect_reference_table_test.cc @@ -20,6 +20,7 @@ #include "class_linker-inl.h" #include "common_runtime_test.h" +#include "mirror/class-alloc-inl.h" #include "mirror/object-inl.h" #include "scoped_thread_state_change-inl.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..5def395007 100644 --- a/runtime/interpreter/unstarted_runtime.cc +++ b/runtime/interpreter/unstarted_runtime.cc @@ -46,10 +46,11 @@ #include "jvalue-inl.h" #include "mirror/array-alloc-inl.h" #include "mirror/array-inl.h" -#include "mirror/class.h" +#include "mirror/class-alloc-inl.h" #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..a8ee23a1d1 100644 --- a/runtime/interpreter/unstarted_runtime_test.cc +++ b/runtime/interpreter/unstarted_runtime_test.cc @@ -31,8 +31,10 @@ #include "handle_scope-inl.h" #include "interpreter/interpreter_common.h" #include "mirror/array-alloc-inl.h" +#include "mirror/class-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..b07d2c2690 100644 --- a/runtime/jni/jni_internal.cc +++ b/runtime/jni/jni_internal.cc @@ -45,11 +45,13 @@ #include "java_vm_ext.h" #include "jni_env_ext.h" #include "jvalue-inl.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "mirror/class_loader.h" #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/call_site.cc b/runtime/mirror/call_site.cc index 738106c0e4..7a23940bf8 100644 --- a/runtime/mirror/call_site.cc +++ b/runtime/mirror/call_site.cc @@ -16,7 +16,7 @@ #include "call_site.h" -#include "class-inl.h" +#include "class-alloc-inl.h" #include "class_root.h" #include "obj_ptr-inl.h" diff --git a/runtime/mirror/class-alloc-inl.h b/runtime/mirror/class-alloc-inl.h new file mode 100644 index 0000000000..d4a532e47d --- /dev/null +++ b/runtime/mirror/class-alloc-inl.h @@ -0,0 +1,84 @@ +/* + * 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_CLASS_ALLOC_INL_H_ +#define ART_RUNTIME_MIRROR_CLASS_ALLOC_INL_H_ + +#include "class-inl.h" + +#include "gc/heap-inl.h" +#include "object-inl.h" +#include "runtime.h" + +namespace art { +namespace mirror { + +inline void Class::CheckObjectAlloc() { + DCHECK(!IsArrayClass()) + << PrettyClass() + << "A array shouldn't be allocated through this " + << "as it requires a pre-fence visitor that sets the class size."; + DCHECK(!IsClassClass()) + << PrettyClass() + << "A class object shouldn't be allocated through this " + << "as it requires a pre-fence visitor that sets the class size."; + DCHECK(!IsStringClass()) + << PrettyClass() + << "A string shouldn't be allocated through this " + << "as it requires a pre-fence visitor that sets the class size."; + DCHECK(IsInstantiable()) << PrettyClass(); + // TODO: decide whether we want this check. It currently fails during bootstrap. + // DCHECK(!Runtime::Current()->IsStarted() || IsInitializing()) << PrettyClass(); + DCHECK_GE(this->object_size_, sizeof(Object)); +} + +template<bool kIsInstrumented, bool kCheckAddFinalizer> +inline ObjPtr<Object> Class::Alloc(Thread* self, gc::AllocatorType allocator_type) { + CheckObjectAlloc(); + gc::Heap* heap = Runtime::Current()->GetHeap(); + const bool add_finalizer = kCheckAddFinalizer && IsFinalizable(); + if (!kCheckAddFinalizer) { + DCHECK(!IsFinalizable()); + } + // Note that the this pointer may be invalidated after the allocation. + ObjPtr<Object> obj = + heap->AllocObjectWithAllocator<kIsInstrumented, false>(self, + this, + this->object_size_, + allocator_type, + VoidFunctor()); + if (add_finalizer && LIKELY(obj != nullptr)) { + heap->AddFinalizerReference(self, &obj); + if (UNLIKELY(self->IsExceptionPending())) { + // Failed to allocate finalizer reference, it means that the whole allocation failed. + obj = nullptr; + } + } + return obj; +} + +inline ObjPtr<Object> Class::AllocObject(Thread* self) { + return Alloc<true>(self, Runtime::Current()->GetHeap()->GetCurrentAllocator()); +} + +inline ObjPtr<Object> Class::AllocNonMovableObject(Thread* self) { + return Alloc<true>(self, Runtime::Current()->GetHeap()->GetCurrentNonMovingAllocator()); +} + +} // namespace mirror +} // namespace art + +#endif // ART_RUNTIME_MIRROR_CLASS_ALLOC_INL_H_ diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h index 50b1b903ab..9a4130d0d5 100644 --- a/runtime/mirror/class-inl.h +++ b/runtime/mirror/class-inl.h @@ -30,7 +30,6 @@ #include "dex/dex_file-inl.h" #include "dex/invoke_type.h" #include "dex_cache.h" -#include "gc/heap-inl.h" #include "iftable.h" #include "object-inl.h" #include "object_array.h" @@ -752,58 +751,6 @@ inline size_t Class::GetPrimitiveTypeSizeShift() { return size_shift; } -inline void Class::CheckObjectAlloc() { - DCHECK(!IsArrayClass()) - << PrettyClass() - << "A array shouldn't be allocated through this " - << "as it requires a pre-fence visitor that sets the class size."; - DCHECK(!IsClassClass()) - << PrettyClass() - << "A class object shouldn't be allocated through this " - << "as it requires a pre-fence visitor that sets the class size."; - DCHECK(!IsStringClass()) - << PrettyClass() - << "A string shouldn't be allocated through this " - << "as it requires a pre-fence visitor that sets the class size."; - DCHECK(IsInstantiable()) << PrettyClass(); - // TODO: decide whether we want this check. It currently fails during bootstrap. - // DCHECK(!Runtime::Current()->IsStarted() || IsInitializing()) << PrettyClass(); - DCHECK_GE(this->object_size_, sizeof(Object)); -} - -template<bool kIsInstrumented, bool kCheckAddFinalizer> -inline ObjPtr<Object> Class::Alloc(Thread* self, gc::AllocatorType allocator_type) { - CheckObjectAlloc(); - gc::Heap* heap = Runtime::Current()->GetHeap(); - const bool add_finalizer = kCheckAddFinalizer && IsFinalizable(); - if (!kCheckAddFinalizer) { - DCHECK(!IsFinalizable()); - } - // Note that the this pointer may be invalidated after the allocation. - ObjPtr<Object> obj = - heap->AllocObjectWithAllocator<kIsInstrumented, false>(self, - this, - this->object_size_, - allocator_type, - VoidFunctor()); - if (add_finalizer && LIKELY(obj != nullptr)) { - heap->AddFinalizerReference(self, &obj); - if (UNLIKELY(self->IsExceptionPending())) { - // Failed to allocate finalizer reference, it means that the whole allocation failed. - obj = nullptr; - } - } - return obj; -} - -inline ObjPtr<Object> Class::AllocObject(Thread* self) { - return Alloc<true>(self, Runtime::Current()->GetHeap()->GetCurrentAllocator()); -} - -inline ObjPtr<Object> Class::AllocNonMovableObject(Thread* self) { - return Alloc<true>(self, Runtime::Current()->GetHeap()->GetCurrentNonMovingAllocator()); -} - inline uint32_t Class::ComputeClassSize(bool has_embedded_vtable, uint32_t num_vtable_entries, uint32_t num_8bit_static_fields, diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h index cbe377e61b..74fca549ea 100644 --- a/runtime/mirror/class.h +++ b/runtime/mirror/class.h @@ -34,7 +34,7 @@ #include "object.h" #include "object_array.h" #include "read_barrier_option.h" -#include "thread.h" +#include "thread-current-inl.h" namespace art { diff --git a/runtime/mirror/class_ext.cc b/runtime/mirror/class_ext.cc index 44bf9891cd..67126307dc 100644 --- a/runtime/mirror/class_ext.cc +++ b/runtime/mirror/class_ext.cc @@ -20,12 +20,14 @@ #include "base/casts.h" #include "base/enums.h" #include "base/utils.h" +#include "class-alloc-inl.h" #include "class-inl.h" #include "class_root.h" #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..001469c117 100644 --- a/runtime/mirror/emulated_stack_frame.cc +++ b/runtime/mirror/emulated_stack_frame.cc @@ -18,11 +18,13 @@ #include "array-alloc-inl.h" #include "array-inl.h" -#include "class-inl.h" +#include "class-alloc-inl.h" #include "class_root.h" #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/field-inl.h b/runtime/mirror/field-inl.h index 2e263b9517..803b880701 100644 --- a/runtime/mirror/field-inl.h +++ b/runtime/mirror/field-inl.h @@ -20,7 +20,7 @@ #include "field.h" #include "art_field-inl.h" -#include "class-inl.h" +#include "class-alloc-inl.h" #include "class_root.h" #include "dex_cache-inl.h" diff --git a/runtime/mirror/method.cc b/runtime/mirror/method.cc index 910a1fc821..d7a1225d3c 100644 --- a/runtime/mirror/method.cc +++ b/runtime/mirror/method.cc @@ -18,7 +18,7 @@ #include "art_method.h" #include "class_root.h" -#include "mirror/class-inl.h" +#include "mirror/class-alloc-inl.h" #include "mirror/object-inl.h" #include "obj_ptr-inl.h" diff --git a/runtime/mirror/method_handle_impl.cc b/runtime/mirror/method_handle_impl.cc index 88ccbc947d..e8cacd97df 100644 --- a/runtime/mirror/method_handle_impl.cc +++ b/runtime/mirror/method_handle_impl.cc @@ -16,7 +16,7 @@ #include "method_handle_impl-inl.h" -#include "class-inl.h" +#include "class-alloc-inl.h" #include "class_root.h" namespace art { diff --git a/runtime/mirror/method_handles_lookup.cc b/runtime/mirror/method_handles_lookup.cc index d1e7a6dbfa..de17c8d056 100644 --- a/runtime/mirror/method_handles_lookup.cc +++ b/runtime/mirror/method_handles_lookup.cc @@ -16,7 +16,7 @@ #include "method_handles_lookup.h" -#include "class-inl.h" +#include "class-alloc-inl.h" #include "class_root.h" #include "dex/modifiers.h" #include "handle_scope.h" diff --git a/runtime/mirror/method_type.cc b/runtime/mirror/method_type.cc index bc62ebdc8b..6533656885 100644 --- a/runtime/mirror/method_type.cc +++ b/runtime/mirror/method_type.cc @@ -16,9 +16,11 @@ #include "method_type.h" -#include "class-inl.h" +#include "class-alloc-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..d8c7b1db30 100644 --- a/runtime/mirror/object_test.cc +++ b/runtime/mirror/object_test.cc @@ -26,6 +26,7 @@ #include "art_method-inl.h" #include "asm_support.h" #include "base/enums.h" +#include "class-alloc-inl.h" #include "class-inl.h" #include "class_linker-inl.h" #include "class_linker.h" @@ -39,6 +40,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/stack_trace_element.cc b/runtime/mirror/stack_trace_element.cc index 5a7575a027..01f2d764aa 100644 --- a/runtime/mirror/stack_trace_element.cc +++ b/runtime/mirror/stack_trace_element.cc @@ -16,7 +16,7 @@ #include "stack_trace_element.h" -#include "class-inl.h" +#include "class-alloc-inl.h" #include "class.h" #include "class_root.h" #include "gc/accounting/card_table-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..a349e3449b 100644 --- a/runtime/mirror/var_handle_test.cc +++ b/runtime/mirror/var_handle_test.cc @@ -20,6 +20,7 @@ #include <vector> #include "art_field-inl.h" +#include "class-alloc-inl.h" #include "class-inl.h" #include "class_linker-inl.h" #include "class_loader.h" @@ -28,6 +29,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..e78c245a30 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -30,12 +30,14 @@ #include "dex/utf.h" #include "hidden_api.h" #include "jni/jni_internal.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "mirror/class_loader.h" #include "mirror/field-inl.h" #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..337c084e6c 100644 --- a/runtime/native/java_lang_reflect_Constructor.cc +++ b/runtime/native/java_lang_reflect_Constructor.cc @@ -24,8 +24,10 @@ #include "class_root.h" #include "dex/dex_file_annotations.h" #include "jni/jni_internal.h" +#include "mirror/class-alloc-inl.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..ada0a64608 100644 --- a/runtime/native/java_lang_reflect_Executable.cc +++ b/runtime/native/java_lang_reflect_Executable.cc @@ -24,9 +24,11 @@ #include "dex/dex_file_annotations.h" #include "handle.h" #include "jni/jni_internal.h" +#include "mirror/class-alloc-inl.h" #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/reference_table_test.cc b/runtime/reference_table_test.cc index 3ea1714ee9..2acb2c7a82 100644 --- a/runtime/reference_table_test.cc +++ b/runtime/reference_table_test.cc @@ -27,6 +27,7 @@ #include "handle_scope-inl.h" #include "mirror/array-inl.h" #include "mirror/array-alloc-inl.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "mirror/class_loader.h" #include "mirror/string.h" diff --git a/runtime/reflection_test.cc b/runtime/reflection_test.cc index 00e298ead3..9fab7fbb90 100644 --- a/runtime/reflection_test.cc +++ b/runtime/reflection_test.cc @@ -25,6 +25,7 @@ #include "dex/descriptors_names.h" #include "jni/java_vm_ext.h" #include "jni/jni_internal.h" +#include "mirror/class-alloc-inl.h" #include "nativehelper/scoped_local_ref.h" #include "scoped_thread_state_change-inl.h" diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 7fa5607582..40c7301456 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -95,6 +95,7 @@ #include "linear_alloc.h" #include "memory_representation.h" #include "mirror/array.h" +#include "mirror/class-alloc-inl.h" #include "mirror/class-inl.h" #include "mirror/class_ext.h" #include "mirror/class_loader.h" diff --git a/runtime/thread.cc b/runtime/thread.cc index a3de4e2215..b5d214def4 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -77,8 +77,9 @@ #include "java_frame_root_info.h" #include "jni/java_vm_ext.h" #include "jni/jni_internal.h" -#include "mirror/class-inl.h" +#include "mirror/class-alloc-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" diff --git a/runtime/transaction_test.cc b/runtime/transaction_test.cc index da6998b8a5..3d9afa0f15 100644 --- a/runtime/transaction_test.cc +++ b/runtime/transaction_test.cc @@ -22,6 +22,7 @@ #include "common_runtime_test.h" #include "dex/dex_file.h" #include "mirror/array-alloc-inl.h" +#include "mirror/class-alloc-inl.h" #include "scoped_thread_state_change-inl.h" namespace art { |