diff options
author | 2019-05-28 16:39:29 +0100 | |
---|---|---|
committer | 2019-05-31 14:15:59 +0000 | |
commit | 3068d582eff4552ff260d7966fcbdc93e17d0207 (patch) | |
tree | bc894a414070a06ea2a231fb98607b57b8c3b0cb /runtime/mirror/object.cc | |
parent | 991cd5cc16267b74e390f640eb441102062babb6 (diff) |
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
Diffstat (limited to 'runtime/mirror/object.cc')
-rw-r--r-- | runtime/mirror/object.cc | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc index 2348213223..ede1c66577 100644 --- a/runtime/mirror/object.cc +++ b/runtime/mirror/object.cc @@ -151,19 +151,17 @@ class CopyObjectVisitor { DISALLOW_COPY_AND_ASSIGN(CopyObjectVisitor); }; -ObjPtr<Object> Object::Clone(Thread* self) { - CHECK(!IsClass()) << "Can't clone classes."; +ObjPtr<Object> Object::Clone(Handle<Object> h_this, Thread* self) { + CHECK(!h_this->IsClass()) << "Can't clone classes."; // Object::SizeOf gets the right size even if we're an array. Using c->AllocObject() here would // be wrong. gc::Heap* heap = Runtime::Current()->GetHeap(); - size_t num_bytes = SizeOf(); - StackHandleScope<1> hs(self); - Handle<Object> this_object(hs.NewHandle(this)); - CopyObjectVisitor visitor(&this_object, num_bytes); - 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()) { + size_t num_bytes = h_this->SizeOf(); + CopyObjectVisitor visitor(&h_this, num_bytes); + ObjPtr<Object> copy = heap->IsMovableObject(h_this.Get()) + ? heap->AllocObject(self, h_this->GetClass(), num_bytes, visitor) + : heap->AllocNonMovableObject(self, h_this->GetClass(), num_bytes, visitor); + if (h_this->GetClass()->IsFinalizable()) { heap->AddFinalizerReference(self, ©); } return copy; |