make Object.clone() work for arrays

This commit is contained in:
Joel Dice 2007-09-26 13:45:52 -06:00
parent 1207989f72
commit 770e48c197

View File

@ -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<void**>(clone) + 1,
reinterpret_cast<void**>(*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<object>(allocate(t, size));
memcpy(clone, *o, size);
} else {
clone = make(t, objectClass(t, *o));
memcpy(reinterpret_cast<void**>(clone) + 1,
reinterpret_cast<void**>(*o) + 1,
size - BytesPerWord);
}
return makeLocalReference(t, clone);
}