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/mirror/class.cc b/runtime/mirror/class.cc
index d6c10de..a36fe12 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -94,14 +94,12 @@
}
}
-ObjPtr<ClassExt> Class::EnsureExtDataPresent(Thread* self) {
- ObjPtr<ClassExt> existing(GetExtData());
+ObjPtr<ClassExt> Class::EnsureExtDataPresent(Handle<Class> h_this, Thread* self) {
+ ObjPtr<ClassExt> existing(h_this->GetExtData());
if (!existing.IsNull()) {
return existing;
}
- StackHandleScope<3> hs(self);
- // Handlerize 'this' since we are allocating here.
- Handle<Class> h_this(hs.NewHandle(this));
+ StackHandleScope<2> hs(self);
// Clear exception so we can allocate.
Handle<Throwable> throwable(hs.NewHandle(self->GetException()));
self->ClearException();
@@ -172,7 +170,7 @@
}
}
- ObjPtr<ClassExt> ext(h_this->EnsureExtDataPresent(self));
+ ObjPtr<ClassExt> ext(EnsureExtDataPresent(h_this, self));
if (!ext.IsNull()) {
self->AssertPendingException();
ext->SetVerifyError(self->GetException());
@@ -1205,12 +1203,13 @@
DISALLOW_COPY_AND_ASSIGN(CopyClassVisitor);
};
-ObjPtr<Class> Class::CopyOf(
- Thread* self, int32_t new_length, ImTable* imt, PointerSize pointer_size) {
+ObjPtr<Class> Class::CopyOf(Handle<Class> h_this,
+ Thread* self,
+ int32_t new_length,
+ ImTable* imt,
+ PointerSize pointer_size) {
DCHECK_GE(new_length, static_cast<int32_t>(sizeof(Class)));
// We may get copied by a compacting GC.
- StackHandleScope<1> hs(self);
- Handle<Class> h_this(hs.NewHandle(this));
Runtime* runtime = Runtime::Current();
gc::Heap* heap = runtime->GetHeap();
// The num_bytes (3rd param) is sizeof(Class) as opposed to SizeOf()