diff options
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; |