summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2019-05-30 14:23:39 +0100
committer Vladimir Marko <vmarko@google.com> 2019-05-31 14:15:59 +0000
commit991cd5cc16267b74e390f640eb441102062babb6 (patch)
treed6112197d0bfec05d5a66da2b27578504385b9f5
parent78da5e255d1281412e9f7e4f0c9b4e90ba7f02b5 (diff)
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
-rw-r--r--runtime/class_linker.cc16
-rw-r--r--runtime/gc/heap.h26
-rw-r--r--runtime/mirror/array-alloc-inl.h4
-rw-r--r--runtime/mirror/class-alloc-inl.h9
-rw-r--r--runtime/mirror/class.cc4
-rw-r--r--runtime/mirror/object.cc9
-rw-r--r--runtime/mirror/string-alloc-inl.h10
7 files changed, 36 insertions, 42 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 333025e4c2..b980a97a71 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -467,7 +467,7 @@ bool ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b
// 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 @@ bool ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b
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 @@ bool ClassLinker::InitFromBootImage(std::string* error_msg) {
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 @@ ObjPtr<mirror::Class> ClassLinker::AllocClass(Thread* self,
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 7c5ae179c3..d2c5fcb8e1 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -223,7 +223,7 @@ class Heap {
~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 @@ class Heap {
!*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 @@ class Heap {
!*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 eb083f7b23..c1e0175c8c 100644
--- a/runtime/mirror/array-alloc-inl.h
+++ b/runtime/mirror/array-alloc-inl.h
@@ -144,14 +144,14 @@ inline ObjPtr<Array> Array::Alloc(Thread* self,
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 cab3c5174b..28612443be 100644
--- a/runtime/mirror/class-alloc-inl.h
+++ b/runtime/mirror/class-alloc-inl.h
@@ -54,13 +54,10 @@ inline ObjPtr<Object> Class::Alloc(Thread* self, gc::AllocatorType allocator_typ
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 ec07a50b0e..d6c10decff 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -1218,8 +1218,8 @@ ObjPtr<Class> Class::CopyOf(
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 4afabe2e91..2348213223 100644
--- a/runtime/mirror/object.cc
+++ b/runtime/mirror/object.cc
@@ -159,13 +159,10 @@ ObjPtr<Object> Object::Clone(Thread* self) {
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, &copy);
}
diff --git a/runtime/mirror/string-alloc-inl.h b/runtime/mirror/string-alloc-inl.h
index 32b6bb46f6..e2b08054ca 100644
--- a/runtime/mirror/string-alloc-inl.h
+++ b/runtime/mirror/string-alloc-inl.h
@@ -192,11 +192,11 @@ inline ObjPtr<String> String::Alloc(Thread* self,
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>