[llvm-commits] CVS: llvm-java/runtime/runtime.c
Alkis Evlogimenos
alkis at cs.uiuc.edu
Fri Mar 25 18:40:59 PST 2005
Changes in directory llvm-java/runtime:
runtime.c updated: 1.21 -> 1.22
---
Log message:
Fix ArrayCopyOverlap.
---
Diffs of the changes: (+8 -1)
runtime.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletion(-)
Index: llvm-java/runtime/runtime.c
diff -u llvm-java/runtime/runtime.c:1.21 llvm-java/runtime/runtime.c:1.22
--- llvm-java/runtime/runtime.c:1.21 Tue Mar 15 19:11:05 2005
+++ llvm-java/runtime/runtime.c Fri Mar 25 20:40:48 2005
@@ -367,10 +367,12 @@
jint length) {
struct llvm_java_bytearray* srcArray = (struct llvm_java_bytearray*) srcObj;
struct llvm_java_bytearray* dstArray = (struct llvm_java_bytearray*) dstObj;
+ unsigned nbytes = length * srcObj->vtable->typeinfo.elementSize;
jbyte* src = srcArray->data;
jbyte* dst = dstArray->data;
+ // FIXME: Need to perform a proper type check here.
if (srcObj->vtable->typeinfo.elementSize !=
dstObj->vtable->typeinfo.elementSize)
llvm_java_throw(NULL);
@@ -378,7 +380,12 @@
src += srcStart * srcObj->vtable->typeinfo.elementSize;
dst += dstStart * dstObj->vtable->typeinfo.elementSize;
- memcpy(dst, src, length * srcObj->vtable->typeinfo.elementSize);
+ // If arrays do not overlap use memcpy.
+ if ((dst > src ? dst - src : src - dst) > nbytes)
+ memcpy(dst, src, nbytes);
+ // If arrays overlap use memmove.
+ else
+ memmove(dst, src, nbytes);
}
void Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jobject clazz,
More information about the llvm-commits
mailing list