diff options
36 files changed, 118 insertions, 66 deletions
diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc index 412e62c6f2..f3f45d9c50 100644 --- a/openjdkjvmti/ti_redefine.cc +++ b/openjdkjvmti/ti_redefine.cc @@ -64,6 +64,7 @@ #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" diff --git a/runtime/arch/stub_test.cc b/runtime/arch/stub_test.cc index 41b26a4e71..0cc5535f8e 100644 --- a/runtime/arch/stub_test.cc +++ b/runtime/arch/stub_test.cc @@ -27,7 +27,7 @@ #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" diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 0748c2b172..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" 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 8fdf8aa0cd..fcf6bb25e3 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -50,6 +50,7 @@ #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" 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 c5c7daa47a..15398672b2 100644 --- a/runtime/dex/dex_file_annotations.cc +++ b/runtime/dex/dex_file_annotations.cc @@ -28,6 +28,7 @@ #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" 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/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/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc index 0568bfc870..5def395007 100644 --- a/runtime/interpreter/unstarted_runtime.cc +++ b/runtime/interpreter/unstarted_runtime.cc @@ -46,7 +46,7 @@ #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" diff --git a/runtime/interpreter/unstarted_runtime_test.cc b/runtime/interpreter/unstarted_runtime_test.cc index daaa05d7df..a8ee23a1d1 100644 --- a/runtime/interpreter/unstarted_runtime_test.cc +++ b/runtime/interpreter/unstarted_runtime_test.cc @@ -31,6 +31,7 @@ #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" diff --git a/runtime/jni/jni_internal.cc b/runtime/jni/jni_internal.cc index 6893ca75ae..b07d2c2690 100644 --- a/runtime/jni/jni_internal.cc +++ b/runtime/jni/jni_internal.cc @@ -45,6 +45,7 @@ #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" 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 516566b6bc..67126307dc 100644 --- a/runtime/mirror/class_ext.cc +++ b/runtime/mirror/class_ext.cc @@ -20,6 +20,7 @@ #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" diff --git a/runtime/mirror/emulated_stack_frame.cc b/runtime/mirror/emulated_stack_frame.cc index f3b5e6f0e7..001469c117 100644 --- a/runtime/mirror/emulated_stack_frame.cc +++ b/runtime/mirror/emulated_stack_frame.cc @@ -18,7 +18,7 @@ #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" 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 0c3224494c..6533656885 100644 --- a/runtime/mirror/method_type.cc +++ b/runtime/mirror/method_type.cc @@ -16,7 +16,7 @@ #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" diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc index e6a2523b40..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" 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_test.cc b/runtime/mirror/var_handle_test.cc index 9563079bab..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" diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 7e4579e059..e78c245a30 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -30,6 +30,7 @@ #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" diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc index a288c72950..337c084e6c 100644 --- a/runtime/native/java_lang_reflect_Constructor.cc +++ b/runtime/native/java_lang_reflect_Constructor.cc @@ -24,6 +24,7 @@ #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" diff --git a/runtime/native/java_lang_reflect_Executable.cc b/runtime/native/java_lang_reflect_Executable.cc index 918730b980..ada0a64608 100644 --- a/runtime/native/java_lang_reflect_Executable.cc +++ b/runtime/native/java_lang_reflect_Executable.cc @@ -24,6 +24,7 @@ #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" 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 738152d693..b5d214def4 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -77,7 +77,7 @@ #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" 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 { |