Clean up creating handles from `this`.
Make these member functions static and take an additional
parameter `Handle<.> h_this`. Callers mostly already have
a Handle<> to pass, so we avoid an extra StackHandleScope.
This pattern was already used for some functions.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing --interpreter
Change-Id: I4f4478b0526bcb2f3c23305d3b3cc4a65fff9ff5
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index b980a97..8fed3ca 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -5903,7 +5903,8 @@
CHECK(!klass->IsResolved());
// Retire the temporary class and create the correctly sized resolved class.
StackHandleScope<1> hs(self);
- auto h_new_class = hs.NewHandle(klass->CopyOf(self, class_size, imt, image_pointer_size_));
+ Handle<mirror::Class> h_new_class =
+ hs.NewHandle(mirror::Class::CopyOf(klass, self, class_size, imt, image_pointer_size_));
// Set arrays to null since we don't want to have multiple classes with the same ArtField or
// ArtMethod array pointers. If this occurs, it causes bugs in remembered sets since the GC
// may not see any references to the target space and clean the card for a class if another
@@ -6265,7 +6266,7 @@
} else if (klass->HasSuperClass()) {
const size_t super_vtable_length = klass->GetSuperClass()->GetVTableLength();
const size_t max_count = num_virtual_methods + super_vtable_length;
- StackHandleScope<2> hs(self);
+ StackHandleScope<3> hs(self);
Handle<mirror::Class> super_class(hs.NewHandle(klass->GetSuperClass()));
MutableHandle<mirror::PointerArray> vtable;
if (super_class->ShouldHaveEmbeddedVTable()) {
@@ -6289,16 +6290,16 @@
}
} else {
DCHECK(super_class->IsAbstract() && !super_class->IsArrayClass());
- ObjPtr<mirror::PointerArray> super_vtable = super_class->GetVTable();
+ Handle<mirror::PointerArray> super_vtable = hs.NewHandle(super_class->GetVTable());
CHECK(super_vtable != nullptr) << super_class->PrettyClass();
// We might need to change vtable if we have new virtual methods or new interfaces (since that
// might give us new default methods). See comment above.
if (num_virtual_methods == 0 && super_class->GetIfTableCount() == klass->GetIfTableCount()) {
- klass->SetVTable(super_vtable);
+ klass->SetVTable(super_vtable.Get());
return true;
}
- vtable = hs.NewHandle(
- ObjPtr<mirror::PointerArray>::DownCast(super_vtable->CopyOf(self, max_count)));
+ vtable = hs.NewHandle(ObjPtr<mirror::PointerArray>::DownCast(
+ mirror::Array::CopyOf(super_vtable, self, max_count)));
if (UNLIKELY(vtable == nullptr)) {
self->AssertPendingOOMException();
return false;
@@ -6434,7 +6435,8 @@
// Shrink vtable if possible
CHECK_LE(actual_count, max_count);
if (actual_count < max_count) {
- vtable.Assign(ObjPtr<mirror::PointerArray>::DownCast(vtable->CopyOf(self, actual_count)));
+ vtable.Assign(ObjPtr<mirror::PointerArray>::DownCast(
+ mirror::Array::CopyOf(vtable, self, actual_count)));
if (UNLIKELY(vtable == nullptr)) {
self->AssertPendingOOMException();
return false;
@@ -6692,8 +6694,10 @@
DCHECK(if_table != nullptr);
DCHECK(if_table->GetMethodArray(i) != nullptr);
// If we are working on a super interface, try extending the existing method array.
- method_array = ObjPtr<mirror::PointerArray>::DownCast(
- if_table->GetMethodArray(i)->Clone(self));
+ StackHandleScope<1u> hs(self);
+ Handle<mirror::PointerArray> old_array = hs.NewHandle(if_table->GetMethodArray(i));
+ method_array =
+ ObjPtr<mirror::PointerArray>::DownCast(mirror::Object::Clone(old_array, self));
} else {
method_array = AllocPointerArray(self, num_methods);
}
@@ -7113,7 +7117,7 @@
if (new_ifcount < ifcount) {
DCHECK_NE(num_interfaces, 0U);
iftable.Assign(ObjPtr<mirror::IfTable>::DownCast(
- iftable->CopyOf(self, new_ifcount * mirror::IfTable::kMax)));
+ mirror::IfTable::CopyOf(iftable, self, new_ifcount * mirror::IfTable::kMax)));
if (UNLIKELY(iftable == nullptr)) {
self->AssertPendingOOMException();
return false;
@@ -7431,7 +7435,7 @@
ObjPtr<mirror::PointerArray> UpdateVtable(
const std::unordered_map<size_t, ClassLinker::MethodTranslation>& default_translations,
- ObjPtr<mirror::PointerArray> old_vtable) REQUIRES_SHARED(Locks::mutator_lock_);
+ Handle<mirror::PointerArray> old_vtable) REQUIRES_SHARED(Locks::mutator_lock_);
void UpdateIfTable(Handle<mirror::IfTable> iftable) REQUIRES_SHARED(Locks::mutator_lock_);
@@ -7759,7 +7763,7 @@
ObjPtr<mirror::PointerArray> ClassLinker::LinkInterfaceMethodsHelper::UpdateVtable(
const std::unordered_map<size_t, ClassLinker::MethodTranslation>& default_translations,
- ObjPtr<mirror::PointerArray> old_vtable) {
+ Handle<mirror::PointerArray> old_vtable) {
// Update the vtable to the new method structures. We can skip this for interfaces since they
// do not have vtables.
const size_t old_vtable_count = old_vtable->GetLength();
@@ -7768,8 +7772,8 @@
default_methods_.size() +
default_conflict_methods_.size();
- ObjPtr<mirror::PointerArray> vtable =
- ObjPtr<mirror::PointerArray>::DownCast(old_vtable->CopyOf(self_, new_vtable_count));
+ ObjPtr<mirror::PointerArray> vtable = ObjPtr<mirror::PointerArray>::DownCast(
+ mirror::Array::CopyOf(old_vtable, self_, new_vtable_count));
if (UNLIKELY(vtable == nullptr)) {
self_->AssertPendingOOMException();
return nullptr;
@@ -8103,7 +8107,7 @@
self->EndAssertNoThreadSuspension(old_cause);
if (fill_tables) {
- vtable.Assign(helper.UpdateVtable(default_translations, vtable.Get()));
+ vtable.Assign(helper.UpdateVtable(default_translations, vtable));
if (UNLIKELY(vtable == nullptr)) {
// The helper has already called self->AssertPendingOOMException();
return false;