src/JavaVM.st
branchjk_new_structure
changeset 1377 79eafebce880
parent 1374 82d8ffc58498
child 1381 145a1ff31ee8
equal deleted inserted replaced
1376:c4b2cf1467c3 1377:79eafebce880
  2626     ^ ExceptionDebugPatterns
  2626     ^ ExceptionDebugPatterns
  2627     "
  2627     "
  2628     ExceptionDebug must be set in order to ExceptionDebugPatterns work
  2628     ExceptionDebug must be set in order to ExceptionDebugPatterns work
  2629 
  2629 
  2630     ExceptionDebug := true.
  2630     ExceptionDebug := true.
       
  2631     ExceptionDebug := false.
  2631     ExceptionDebugPatterns add: 'java/lang/SecurityException*'.
  2632     ExceptionDebugPatterns add: 'java/lang/SecurityException*'.
  2632     ExceptionDebugPatterns add: 'java/net/ConnectException*'.
  2633     ExceptionDebugPatterns add: 'java/net/ConnectException*'.
  2633     ExceptionDebugPatterns add: 'java/lang/IllegalArgumentException'.
  2634     ExceptionDebugPatterns add: 'java/lang/IllegalArgumentException'.
  2634     ExceptionDebugPatterns add: 'java/lang/ClassNotFoundException'.
  2635     ExceptionDebugPatterns add: 'java/lang/ClassNotFoundException'.
  2635     ExceptionDebugPatterns add: 'java/io/IOException'.
  2636     ExceptionDebugPatterns add: 'java/io/IOException'.
  6831 
  6832 
  6832     jString := nativeContext receiver.
  6833     jString := nativeContext receiver.
  6833     ^ Java intern:jString
  6834     ^ Java intern:jString
  6834 !
  6835 !
  6835 
  6836 
  6836 _java_lang_System_arraycopy: nativeContext 
  6837 _java_lang_System_arraycopy: nativeContext
       
  6838 
  6837     <javanative: 'java/lang/System' name: 'arraycopy'>
  6839     <javanative: 'java/lang/System' name: 'arraycopy'>
  6838     | srcArray  srcIdx  dstArray  dstIdx  srcArrayCC  dstArrayCC  count  dstEndIdx |
  6840 
  6839     srcArray := nativeContext argAt: 1.
  6841     |srcArray srcIdx dstArray dstIdx srcArrayCC dstArrayCC count dstEndIdx|
  6840     srcArray isNil ifTrue: [ ^ self throwNullPointerException ].     
  6842 
  6841     srcArray isJavaArray ifFalse: [ "mh 29.11.11 dirty ugly hack, pretend that java string is char array"
  6843     srcArray := nativeContext argAt:1.
  6842     (self canCast:srcArray class to: (self classNamed:'java/lang/String')) ifTrue: [srcArray := srcArray instVarNamed: #value] ifFalse: [
  6844     srcArray isNil ifTrue:[
  6843     ^ self throwArrayStoreException: srcArray] ].
  6845         ^ self throwNullPointerException
  6844     srcIdx := nativeContext argAt: 2.
  6846     ].
  6845     dstArray := nativeContext argAt: 3.
  6847     srcArray isJavaArray ifFalse:[
  6846     dstArray isNil ifTrue: [ ^ self throwNullPointerException ].
  6848         ^ self throwArrayStoreException:srcArray
  6847     dstArray isJavaArray ifFalse: [ ^ self throwArrayStoreException: dstArray ].
  6849     ].
       
  6850     srcIdx := nativeContext argAt:2.
       
  6851     dstArray := nativeContext argAt:3.
       
  6852     dstArray isNil ifTrue:[
       
  6853         ^ self throwNullPointerException
       
  6854     ].
       
  6855     dstArray isJavaArray ifFalse:[
       
  6856         ^ self throwArrayStoreException:dstArray
       
  6857     ].
       
  6858 
  6848     srcArrayCC := srcArray class javaComponentClass.
  6859     srcArrayCC := srcArray class javaComponentClass.
  6849     dstArrayCC := dstArray class javaComponentClass.
  6860     dstArrayCC := dstArray class javaComponentClass.
  6850     srcArrayCC isJavaPrimitiveType == dstArrayCC isJavaPrimitiveType ifTrue: [
  6861 
  6851         srcArrayCC isJavaPrimitiveType ifTrue: [
  6862     srcArrayCC isJavaPrimitiveType == dstArrayCC isJavaPrimitiveType 
  6852             srcArrayCC ~~ dstArrayCC ifTrue: [ ^ self throwArrayStoreException: dstArray ]
  6863         ifTrue:
       
  6864             [srcArrayCC isJavaPrimitiveType
       
  6865                 ifTrue:
       
  6866                     [srcArrayCC ~~ dstArrayCC ifTrue:
       
  6867                         [^ self throwArrayStoreException:dstArray]].
       
  6868             ]
       
  6869         ifFalse:
       
  6870             [^ self throwArrayStoreException:dstArray].
       
  6871 
       
  6872     dstIdx := nativeContext argAt:4.
       
  6873     count := nativeContext argAt:5.
       
  6874 
       
  6875     count < 0 ifTrue:[
       
  6876         ^ self throwArrayIndexOutOfBoundsException:(srcIdx + count - 1)        
       
  6877     ].
       
  6878 
       
  6879     ((srcIdx < 0) or:[srcIdx + count > srcArray size]) ifTrue:[
       
  6880         srcArray size == 0 ifTrue:[
       
  6881             srcArray isVariable ifFalse:[
       
  6882                 ^ self throwArrayStoreException:srcArray
       
  6883             ]
  6853         ].
  6884         ].
  6854     ] ifFalse: [ ^ self throwArrayStoreException: dstArray ].
  6885         ^ self throwArrayIndexOutOfBoundsException:(srcIdx + count - 1)
  6855     dstIdx := nativeContext argAt: 4.
  6886     ].
  6856     count := nativeContext argAt: 5.
  6887     ((dstIdx < 0) or:[dstIdx + count > dstArray size]) ifTrue:[
  6857     count < 0 ifTrue: [
  6888         dstArray size == 0 ifTrue:[
  6858         ^ self throwArrayIndexOutOfBoundsException: (srcIdx + count - 1)
  6889             dstArray isVariable ifFalse:[
  6859     ].
  6890                 ^ self throwArrayStoreException:dstArray
  6860     ((srcIdx < 0) or: [ srcIdx + count > srcArray size ]) ifTrue: [
  6891             ]
  6861         srcArray size == 0 ifTrue: [
       
  6862             srcArray isVariable ifFalse: [ ^ self throwArrayStoreException: srcArray ]
       
  6863         ].
  6892         ].
  6864         ^ self throwArrayIndexOutOfBoundsException: (srcIdx + count - 1)
  6893         ^ self throwArrayIndexOutOfBoundsException:(dstIdx + count - 1)
  6865     ].
  6894     ].
  6866     ((dstIdx < 0) or: [ dstIdx + count > dstArray size ]) ifTrue: [
  6895 
  6867         dstArray size == 0 ifTrue: [
       
  6868             dstArray isVariable ifFalse: [ ^ self throwArrayStoreException: dstArray ]
       
  6869         ].
       
  6870         ^ self throwArrayIndexOutOfBoundsException: (dstIdx + count - 1)
       
  6871     ].
       
  6872     dstEndIdx := dstIdx + count.
  6896     dstEndIdx := dstIdx + count.
  6873     dstIdx := dstIdx + 1.
  6897     dstIdx := dstIdx + 1.       "/ ST uses 1-based indexing
  6874     srcIdx := srcIdx + 1.
  6898     srcIdx := srcIdx + 1.       "/ ST uses 1-based indexing
  6875     (srcArray class isBytes and: [ dstArray class isBytes ]) ifTrue: [
  6899 
  6876         dstArray 
  6900 
  6877             replaceBytesFrom: dstIdx
  6901 
  6878             to: dstEndIdx
  6902     (srcArray class isBytes and:[dstArray class isBytes]) ifTrue:[
  6879             with: srcArray
  6903         dstArray replaceBytesFrom:dstIdx to:dstEndIdx with:srcArray startingAt:srcIdx.
  6880             startingAt: srcIdx.
  6904     ] ifFalse:[
  6881     ] ifFalse: [
  6905         dstArrayCC isJavaPrimitiveType ifFalse:[
  6882         dstArrayCC isJavaPrimitiveType ifFalse: [
       
  6883             "Copy from array iff src=dst to avoid overwriting a data when copying"
  6906             "Copy from array iff src=dst to avoid overwriting a data when copying"
  6884             srcArray == dstArray ifTrue: [ srcArray := srcArray copy ].
  6907             srcArray == dstArray ifTrue:[srcArray := srcArray copy].
  6885             1 to: count do: [
  6908             1 to: count do:[:i|
  6886                 :i | 
       
  6887                 | obj |
  6909                 | obj |
  6888                 obj := srcArray at: srcIdx + i - 1.
  6910 
  6889                 (obj notNil and: [ (self canCast: obj class to: dstArrayCC) not ]) ifTrue: [
  6911                 obj := srcArray at:srcIdx + i - 1.
  6890                     ^ self throwArrayStoreException: dstArray
  6912 
       
  6913                 (obj notNil and:[(self canCast: obj class to: dstArrayCC) not]) ifTrue:[
       
  6914                     ^ self throwArrayStoreException:dstArray
  6891                 ].
  6915                 ].
  6892                 dstArray at: dstIdx + i - 1 put: (srcArray at: srcIdx + i - 1)
  6916                 dstArray at: dstIdx + i - 1 put: (srcArray at:srcIdx + i - 1)
  6893             ]
  6917             ]
  6894         ] ifTrue: [
  6918         ] ifTrue:[
  6895             dstArray 
  6919             dstArray replaceFrom:dstIdx to:dstEndIdx with:srcArray startingAt:srcIdx.
  6896                 replaceFrom: dstIdx
       
  6897                 to: dstEndIdx
       
  6898                 with: srcArray
       
  6899                 startingAt: srcIdx.
       
  6900         ]
  6920         ]
  6901     ].
  6921     ].
  6902     ^ nil.
  6922     ^ nil.
  6903 
  6923 
  6904     "Modified: / 08-09-2011 / 15:25:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  6924     "Modified: / 08-09-2011 / 15:25:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  6905     "Modified: / 29-11-2011 / 12:17:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
       
  6906 !
  6925 !
  6907 
  6926 
  6908 _java_lang_System_currentTimeMillis: nativeContext
  6927 _java_lang_System_currentTimeMillis: nativeContext
  6909 
  6928 
  6910     <javanative: 'java/lang/System' name: 'currentTimeMillis'>
  6929     <javanative: 'java/lang/System' name: 'currentTimeMillis'>