Add default template args to Heap::Alloc*Object*().
Namely kInstrumented=true and kCheckLargeObject=true.
This is a follow-up after
https://android-review.googlesource.com/963693
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: I6c23e76f90f1892382c3bb8c331d12437bc23f89
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 333025e..b980a97 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -467,7 +467,7 @@
// Allocate the object as non-movable so that there are no cases where Object::IsClass returns
// the incorrect result when comparing to-space vs from-space.
Handle<mirror::Class> java_lang_Class(hs.NewHandle(ObjPtr<mirror::Class>::DownCast(
- heap->AllocNonMovableObject<true>(self, nullptr, class_class_size, VoidFunctor()))));
+ heap->AllocNonMovableObject(self, nullptr, class_class_size, VoidFunctor()))));
CHECK(java_lang_Class != nullptr);
java_lang_Class->SetClassFlags(mirror::kClassFlagClass);
java_lang_Class->SetClass(java_lang_Class.Get());
@@ -496,10 +496,10 @@
java_lang_Object->SetObjectSize(sizeof(mirror::Object));
// Allocate in non-movable so that it's possible to check if a JNI weak global ref has been
// cleared without triggering the read barrier and unintentionally mark the sentinel alive.
- runtime->SetSentinel(heap->AllocNonMovableObject<true>(self,
- java_lang_Object.Get(),
- java_lang_Object->GetObjectSize(),
- VoidFunctor()));
+ runtime->SetSentinel(heap->AllocNonMovableObject(self,
+ java_lang_Object.Get(),
+ java_lang_Object->GetObjectSize(),
+ VoidFunctor()));
// Initialize the SubtypeCheck bitstring for java.lang.Object and java.lang.Class.
if (kBitstringSubtypeCheckEnabled) {
@@ -1064,7 +1064,7 @@
java_lang_Object->SetObjectSize(sizeof(mirror::Object));
// Allocate in non-movable so that it's possible to check if a JNI weak global ref has been
// cleared without triggering the read barrier and unintentionally mark the sentinel alive.
- runtime->SetSentinel(heap->AllocNonMovableObject<true>(
+ runtime->SetSentinel(heap->AllocNonMovableObject(
self, java_lang_Object, java_lang_Object->GetObjectSize(), VoidFunctor()));
const std::vector<std::string>& boot_class_path_locations = runtime->GetBootClassPathLocations();
@@ -2561,8 +2561,8 @@
gc::Heap* heap = Runtime::Current()->GetHeap();
mirror::Class::InitializeClassVisitor visitor(class_size);
ObjPtr<mirror::Object> k = (kMovingClasses && kMovable) ?
- heap->AllocObject<true>(self, java_lang_Class, class_size, visitor) :
- heap->AllocNonMovableObject<true>(self, java_lang_Class, class_size, visitor);
+ heap->AllocObject(self, java_lang_Class, class_size, visitor) :
+ heap->AllocNonMovableObject(self, java_lang_Class, class_size, visitor);
if (UNLIKELY(k == nullptr)) {
self->AssertPendingOOMException();
return nullptr;
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 7c5ae17..d2c5fcb 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -223,7 +223,7 @@
~Heap();
// Allocates and initializes storage for an object instance.
- template <bool kInstrumented, typename PreFenceVisitor>
+ template <bool kInstrumented = true, typename PreFenceVisitor>
mirror::Object* AllocObject(Thread* self,
ObjPtr<mirror::Class> klass,
size_t num_bytes,
@@ -233,14 +233,14 @@
!*pending_task_lock_,
!*backtrace_lock_,
!Roles::uninterruptible_) {
- return AllocObjectWithAllocator<kInstrumented, true>(self,
- klass,
- num_bytes,
- GetCurrentAllocator(),
- pre_fence_visitor);
+ return AllocObjectWithAllocator<kInstrumented>(self,
+ klass,
+ num_bytes,
+ GetCurrentAllocator(),
+ pre_fence_visitor);
}
- template <bool kInstrumented, typename PreFenceVisitor>
+ template <bool kInstrumented = true, typename PreFenceVisitor>
mirror::Object* AllocNonMovableObject(Thread* self,
ObjPtr<mirror::Class> klass,
size_t num_bytes,
@@ -250,14 +250,14 @@
!*pending_task_lock_,
!*backtrace_lock_,
!Roles::uninterruptible_) {
- return AllocObjectWithAllocator<kInstrumented, true>(self,
- klass,
- num_bytes,
- GetCurrentNonMovingAllocator(),
- pre_fence_visitor);
+ return AllocObjectWithAllocator<kInstrumented>(self,
+ klass,
+ num_bytes,
+ GetCurrentNonMovingAllocator(),
+ pre_fence_visitor);
}
- template <bool kInstrumented, bool kCheckLargeObject, typename PreFenceVisitor>
+ template <bool kInstrumented = true, bool kCheckLargeObject = true, typename PreFenceVisitor>
ALWAYS_INLINE mirror::Object* AllocObjectWithAllocator(Thread* self,
ObjPtr<mirror::Class> klass,
size_t byte_count,
diff --git a/runtime/mirror/array-alloc-inl.h b/runtime/mirror/array-alloc-inl.h
index eb083f7..c1e0175 100644
--- a/runtime/mirror/array-alloc-inl.h
+++ b/runtime/mirror/array-alloc-inl.h
@@ -144,14 +144,14 @@
if (!kFillUsable) {
SetLengthVisitor visitor(component_count);
result = ObjPtr<Array>::DownCast(
- heap->AllocObjectWithAllocator<kIsInstrumented, true>(
+ heap->AllocObjectWithAllocator<kIsInstrumented>(
self, array_class, size, allocator_type, visitor));
} else {
SetLengthToUsableSizeVisitor visitor(component_count,
DataOffset(1U << component_size_shift).SizeValue(),
component_size_shift);
result = ObjPtr<Array>::DownCast(
- heap->AllocObjectWithAllocator<kIsInstrumented, true>(
+ heap->AllocObjectWithAllocator<kIsInstrumented>(
self, array_class, size, allocator_type, visitor));
}
if (kIsDebugBuild && result != nullptr && Runtime::Current()->IsStarted()) {
diff --git a/runtime/mirror/class-alloc-inl.h b/runtime/mirror/class-alloc-inl.h
index cab3c51..2861244 100644
--- a/runtime/mirror/class-alloc-inl.h
+++ b/runtime/mirror/class-alloc-inl.h
@@ -54,13 +54,10 @@
if (!kCheckAddFinalizer) {
DCHECK(!IsFinalizable());
}
- // Note that the this pointer may be invalidated after the allocation.
+ // 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());
+ heap->AllocObjectWithAllocator<kIsInstrumented, /*kCheckLargeObject=*/ false>(
+ self, this, this->object_size_, allocator_type, VoidFunctor());
if (add_finalizer && LIKELY(obj != nullptr)) {
heap->AddFinalizerReference(self, &obj);
if (UNLIKELY(self->IsExceptionPending())) {
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index ec07a50..d6c10de 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -1218,8 +1218,8 @@
CopyClassVisitor visitor(self, &h_this, new_length, sizeof(Class), imt, pointer_size);
ObjPtr<mirror::Class> java_lang_Class = GetClassRoot<mirror::Class>(runtime->GetClassLinker());
ObjPtr<Object> new_class = kMovingClasses ?
- heap->AllocObject<true>(self, java_lang_Class, new_length, visitor) :
- heap->AllocNonMovableObject<true>(self, java_lang_Class, new_length, visitor);
+ heap->AllocObject(self, java_lang_Class, new_length, visitor) :
+ heap->AllocNonMovableObject(self, java_lang_Class, new_length, visitor);
if (UNLIKELY(new_class == nullptr)) {
self->AssertPendingOOMException();
return nullptr;
diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc
index 4afabe2..2348213 100644
--- a/runtime/mirror/object.cc
+++ b/runtime/mirror/object.cc
@@ -159,13 +159,10 @@
size_t num_bytes = SizeOf();
StackHandleScope<1> hs(self);
Handle<Object> this_object(hs.NewHandle(this));
- ObjPtr<Object> copy;
CopyObjectVisitor visitor(&this_object, num_bytes);
- if (heap->IsMovableObject(this)) {
- copy = heap->AllocObject<true>(self, GetClass(), num_bytes, visitor);
- } else {
- copy = heap->AllocNonMovableObject<true>(self, GetClass(), num_bytes, visitor);
- }
+ ObjPtr<Object> copy = heap->IsMovableObject(this)
+ ? heap->AllocObject(self, GetClass(), num_bytes, visitor)
+ : heap->AllocNonMovableObject(self, GetClass(), num_bytes, visitor);
if (this_object->GetClass()->IsFinalizable()) {
heap->AddFinalizerReference(self, ©);
}
diff --git a/runtime/mirror/string-alloc-inl.h b/runtime/mirror/string-alloc-inl.h
index 32b6bb4..e2b0805 100644
--- a/runtime/mirror/string-alloc-inl.h
+++ b/runtime/mirror/string-alloc-inl.h
@@ -192,11 +192,11 @@
gc::Heap* heap = runtime->GetHeap();
return ObjPtr<String>::DownCast(
- heap->AllocObjectWithAllocator<kIsInstrumented, true>(self,
- string_class,
- alloc_size,
- allocator_type,
- pre_fence_visitor));
+ heap->AllocObjectWithAllocator<kIsInstrumented>(self,
+ string_class,
+ alloc_size,
+ allocator_type,
+ pre_fence_visitor));
}
template <bool kIsInstrumented>