ART: Add class-alloc-inl.h
In an effort to reduce the (transitive) proliferation of heap-inl
add a specific inline header for class instance allocation.
Bug: 118385392
Test: mmma art
Test: m test-art-host
Change-Id: I32529f0221a836452c58687330a91ac0d5fde162
diff --git a/runtime/arch/stub_test.cc b/runtime/arch/stub_test.cc
index 41b26a4..0cc5535 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 627ac17..0247e4e 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 fdf6ad1..2270662 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 8fdf8aa..fcf6bb2 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 fcc5ce6..328a9bb 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 c5c7daa..1539867 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 b45bb59..0b005e0 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 ce0807c..c680fb5 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 f888482..d72dbe6 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 141feb4..c5ae4c6 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 0568bfc..5def395 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 daaa05d..a8ee23a 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 6893ca7..b07d2c2 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 738106c..7a23940 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 0000000..d4a532e
--- /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 50b1b90..9a4130d 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 @@
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 cbe377e..74fca54 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 516566b..6712630 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 f3b5e6f..001469c 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 2e263b9..803b880 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 910a1fc..d7a1225 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 88ccbc9..e8cacd9 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 d1e7a6d..de17c8d 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 0c32244..6533656 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 e6a2523..d8c7b1d 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 5a7575a..01f2d76 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 9563079..a349e34 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 7e4579e..e78c245 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 a288c72..337c084 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 918730b..ada0a64 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 3ea1714..2acb2c7 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 00e298e..9fab7fb 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 7fa5607..40c7301 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 738152d..b5d214d 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 da6998b..3d9afa0 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 {