From 770e48c197b15fdaa2aeb2e5445f9b3623c6e369 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 26 Sep 2007 13:45:52 -0600 Subject: [PATCH] make Object.clone() work for arrays --- src/builtin.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index 271288f6fd..44209e5f4c 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -101,10 +101,20 @@ Java_java_lang_Object_clone(Thread* t, jclass, jobject o) { ENTER(t, Thread::ActiveState); - object clone = make(t, objectClass(t, *o)); - memcpy(reinterpret_cast(clone) + 1, - reinterpret_cast(*o) + 1, - (baseSize(t, *o, objectClass(t, *o)) - 1) * BytesPerWord); + object class_ = objectClass(t, *o); + unsigned size = baseSize(t, *o, class_) * BytesPerWord; + object clone; + + if (classArrayElementSize(t, class_)) { + clone = static_cast(allocate(t, size)); + memcpy(clone, *o, size); + } else { + clone = make(t, objectClass(t, *o)); + memcpy(reinterpret_cast(clone) + 1, + reinterpret_cast(*o) + 1, + size - BytesPerWord); + } + return makeLocalReference(t, clone); }