JavaVM: improvements in java.lang.System.arraycopy native jk_new_structure
authorvranyj1
Thu, 23 Jun 2011 08:34:19 +0000
branchjk_new_structure
changeset 864 45d54ed8b273
parent 863 135fa7c03356
child 865 82615f7deade
JavaVM: improvements in java.lang.System.arraycopy native
src/JavaVM.st
--- a/src/JavaVM.st	Wed Jun 22 21:43:46 2011 +0000
+++ b/src/JavaVM.st	Thu Jun 23 08:34:19 2011 +0000
@@ -2932,8 +2932,10 @@
 
 throwArrayStoreException:badArray
     ^ self
-	throwExceptionClassName:'java.lang.ArrayStoreException'
-	 withMessage:('bad array store: ' , badArray printString)
+        throwExceptionClassName:'java.lang.ArrayStoreException'
+         withMessage:('bad array store: ' , badArray class printString)
+
+    "Modified: / 23-06-2011 / 09:19:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 throwClassCastException
@@ -4791,17 +4793,37 @@
 
     <javanative: 'java/lang/System' name: 'arraycopy'>
 
-        |srcArray srcIdx dstArray dstIdx count dstEndIdx|
+    |srcArray srcIdx dstArray dstIdx srcArrayCC dstArrayCC count dstEndIdx|
 
     srcArray := nativeContext argAt:1.
     srcArray isNil ifTrue:[
         ^ self throwNullPointerException
     ].
+    srcArray isJavaArray ifFalse:[
+        ^ self throwArrayStoreException:srcArray
+    ].
     srcIdx := nativeContext argAt:2.
     dstArray := nativeContext argAt:3.
     dstArray isNil ifTrue:[
         ^ self throwNullPointerException
     ].
+    dstArray isJavaArray ifFalse:[
+        ^ self throwArrayStoreException:dstArray
+    ].
+
+    srcArrayCC := srcArray class javaComponentClass.
+    dstArrayCC := dstArray class javaComponentClass.
+
+    srcArrayCC isJavaPrimitiveType == dstArrayCC isJavaPrimitiveType 
+        ifTrue:
+            [srcArrayCC isJavaPrimitiveType
+                ifTrue:
+                    [srcArrayCC ~~ dstArrayCC ifTrue:
+                        [^ self throwArrayStoreException:dstArray]].
+            ]
+        ifFalse:
+            [^ self throwArrayStoreException:dstArray].
+
     dstIdx := nativeContext argAt:4.
     count := nativeContext argAt:5.
 
@@ -4832,6 +4854,8 @@
         dstArray replaceFrom:dstIdx to:dstEndIdx with:srcArray startingAt:srcIdx.
     ].
     ^ nil.
+
+    "Modified: / 23-06-2011 / 09:17:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_System_currentTimeMillis: nativeContext