diff options
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/lang/natObject.cc | 5 | ||||
-rw-r--r-- | libjava/java/lang/natSystem.cc | 46 |
2 files changed, 6 insertions, 45 deletions
diff --git a/libjava/java/lang/natObject.cc b/libjava/java/lang/natObject.cc index 22632c5..0ca5a58 100644 --- a/libjava/java/lang/natObject.cc +++ b/libjava/java/lang/natObject.cc @@ -84,7 +84,10 @@ java::lang::Object::clone (void) r = _Jv_NewObjectArray (array->length, comp, NULL); eltsize = sizeof (jobject); } - size = sizeof (__JArray) + array->length * eltsize; + // We can't use sizeof on __JArray because we must account for + // alignment of the element type. + size = (_Jv_GetArrayElementFromElementType (array, comp) - (char *) array + + array->length * eltsize); } else { diff --git a/libjava/java/lang/natSystem.cc b/libjava/java/lang/natSystem.cc index 268c1cc..4e4316a 100644 --- a/libjava/java/lang/natSystem.cc +++ b/libjava/java/lang/natSystem.cc @@ -124,52 +124,10 @@ java::lang::System::arraycopy (jobject src, jint src_offset, const size_t size = (prim ? src_comp->size() : sizeof elements((jobjectArray)src)[0]); - // In an ideal world we would do this via a virtual function in - // __JArray. However, we can't have virtual functions in - // __JArray due to the need to copy an array's virtual table in - // _Jv_FindArrayClass. - // We can't just pick a single subtype of __JArray to use due to - // alignment concerns. - char *src_elts = NULL; - if (! prim) - src_elts = (char *) elements ((jobjectArray) src); - else if (src_comp == JvPrimClass (byte)) - src_elts = (char *) elements ((jbyteArray) src); - else if (src_comp == JvPrimClass (short)) - src_elts = (char *) elements ((jshortArray) src); - else if (src_comp == JvPrimClass (int)) - src_elts = (char *) elements ((jintArray) src); - else if (src_comp == JvPrimClass (long)) - src_elts = (char *) elements ((jlongArray) src); - else if (src_comp == JvPrimClass (boolean)) - src_elts = (char *) elements ((jbooleanArray) src); - else if (src_comp == JvPrimClass (char)) - src_elts = (char *) elements ((jcharArray) src); - else if (src_comp == JvPrimClass (float)) - src_elts = (char *) elements ((jfloatArray) src); - else if (src_comp == JvPrimClass (double)) - src_elts = (char *) elements ((jdoubleArray) src); + char *src_elts = _Jv_GetArrayElementFromElementType (src, src_comp); src_elts += size * src_offset; - char *dst_elts = NULL; - if (! prim) - dst_elts = (char *) elements ((jobjectArray) dst); - else if (dst_comp == JvPrimClass (byte)) - dst_elts = (char *) elements ((jbyteArray) dst); - else if (dst_comp == JvPrimClass (short)) - dst_elts = (char *) elements ((jshortArray) dst); - else if (dst_comp == JvPrimClass (int)) - dst_elts = (char *) elements ((jintArray) dst); - else if (dst_comp == JvPrimClass (long)) - dst_elts = (char *) elements ((jlongArray) dst); - else if (dst_comp == JvPrimClass (boolean)) - dst_elts = (char *) elements ((jbooleanArray) dst); - else if (dst_comp == JvPrimClass (char)) - dst_elts = (char *) elements ((jcharArray) dst); - else if (dst_comp == JvPrimClass (float)) - dst_elts = (char *) elements ((jfloatArray) dst); - else if (dst_comp == JvPrimClass (double)) - dst_elts = (char *) elements ((jdoubleArray) dst); + char *dst_elts = _Jv_GetArrayElementFromElementType (dst, dst_comp); dst_elts += size * dst_offset; #if HAVE_MEMMOVE |