More work on Smalltalk bytecode interpreter.
--- a/JavaByteCodeProcessor.st Tue Mar 15 15:46:32 2016 +0000
+++ b/JavaByteCodeProcessor.st Wed Mar 16 00:43:52 2016 +0000
@@ -1505,12 +1505,11 @@
^ self subclassResponsibility
!
-iload
- "raise an error: must be redefined in concrete subclass(es)"
-
- ^ self subclassResponsibility
+iload
+ self iload: self fetchIndex
"Created: / 17-03-2011 / 15:06:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 16-03-2016 / 00:22:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
iload: arg
@@ -1694,10 +1693,10 @@
!
istore
-
- ^ self subclassResponsibility
+ self istore: self fetchIndex
"Created: / 17-03-2011 / 16:36:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 16-03-2016 / 00:21:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
istore: arg
--- a/examples/tomcat6/ApacheTomcat6.st Tue Mar 15 15:46:32 2016 +0000
+++ b/examples/tomcat6/ApacheTomcat6.st Wed Mar 16 00:43:52 2016 +0000
@@ -254,10 +254,8 @@
| pp wd i p parser startup commands |
-
-
-
"Search for package path, bit hacky but..."
+ (OperatingSystem pathOfSTXExecutable endsWith: 'tomcat6') ifFalse:[
wd := Filename currentDirectory.
pp := nil.
p := wd.
@@ -268,21 +266,16 @@
ifTrue:[pp := p]].
pp
ifNil:
- [Stderr nextPutAll: 'ERROR: Cannot find package path'.
+ [Stderr nextPutLine: 'ERROR: Cannot find package path'.
Smalltalk exit: 16]
ifNotNil:
[Smalltalk packagePath add: pp pathName].
-
-
-
-
+ ].
self setupSignalHandlers.
- parser := CmdLineParser autoload; new.
- CmdLineOptionError autoload.
-
+ parser := CmdLineParser new.
[
commands := parser parse: argv for: self.
] on:CmdLineOptionError do:[:ex|
--- a/experiments/JavaByteCodeInterpreter.st Tue Mar 15 15:46:32 2016 +0000
+++ b/experiments/JavaByteCodeInterpreter.st Wed Mar 16 00:43:52 2016 +0000
@@ -1553,9 +1553,15 @@
!
ifnonnull
- "raise an error: must be redefined in concrete subclass(es)"
-
- ^ self shouldImplement
+ | value target |
+
+ value := self pop.
+ target := self fetchIndex2.
+ value notNil ifTrue:[
+ self relativeJump: target.
+ ]
+
+ "Modified: / 16-03-2016 / 00:18:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
ifnull
@@ -1592,12 +1598,6 @@
"Created: / 14-03-2011 / 17:22:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
-iload
- "raise an error: must be redefined in concrete subclass(es)"
-
- ^ self shouldImplement
-!
-
iload: idx
"
loads an int value from a local variable #index
@@ -1692,18 +1692,28 @@
| methodRef methodToBeInvoked methodReceiver methodNumArgs methodArgs result |
methodRef := constantPool at: self fetchIndex2.
- methodToBeInvoked := methodRef resolvedValue.
- methodReceiver := self pop.
+ methodToBeInvoked := methodRef resolve.
methodNumArgs := methodToBeInvoked javaNumArgs.
methodArgs := Array new: methodNumArgs.
methodNumArgs to: 1
by: -1
do: [:index | methodArgs at: index put: self pop ].
+ methodReceiver := self pop.
result := self
interpretInner: methodToBeInvoked
receiver: methodReceiver
arguments: methodArgs.
- self pushRef: result.
+ methodToBeInvoked returnsDouble ifTrue:[
+ self pushDouble: result
+ ] ifFalse:[
+ methodToBeInvoked returnsLong ifTrue:[
+ self pushLong: result
+ ] ifFalse:[
+ methodToBeInvoked returnsVoid ifFalse: [
+ self pushRef: result
+ ]
+ ]
+ ].
"
Description
@@ -1776,7 +1786,7 @@
than nargs local variables may be required to pass nargs argument values to the invoked method."
"Modified: / 31-03-2011 / 16:34:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 02-03-2016 / 00:22:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 16-03-2016 / 00:14:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
invstatic
@@ -1799,11 +1809,19 @@
].
result := self
interpretInner:methodToBeInvoked
- receiver:receiver
+ receiver:methodToBeInvoked javaClass
arguments:args.
- methodToBeInvoked returnsVoid ifFalse:[
- self pushConstant:result
- ].
+ methodToBeInvoked returnsDouble ifTrue:[
+ self pushDouble: result
+ ] ifFalse:[
+ methodToBeInvoked returnsLong ifTrue:[
+ self pushLong: result
+ ] ifFalse:[
+ methodToBeInvoked returnsVoid ifFalse: [
+ self pushRef: result
+ ]
+ ]
+ ].
"
Description
@@ -1863,7 +1881,7 @@
"Created: / 24-02-2011 / 10:37:05 / Marcel Hlopko <hlopik@gmail.com>"
"Modified: / 25-02-2011 / 00:18:30 / Marcel Hlopko <hlopik@gmail.com>"
"Modified: / 04-06-2011 / 18:13:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 04-08-2014 / 15:54:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 16-03-2016 / 00:13:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
invvirt
@@ -1875,7 +1893,6 @@
| methodOwner methodRef resolvedMethod methodNumArgs args result |
methodRef := constantPool at: self fetchIndex2.
- methodOwner := self pop.
resolvedMethod := methodRef resolve.
methodNumArgs := resolvedMethod javaNumArgs.
args := Array new: methodNumArgs.
@@ -1883,12 +1900,21 @@
:index |
args at: index put: self pop
].
+ methodOwner := self pop.
result := self
interpretInner: (methodOwner class lookupMethodFor: resolvedMethod selector)
receiver: methodOwner
arguments: args.
- resolvedMethod returnsVoid ifFalse: [
- self pushConstant: result
+ resolvedMethod returnsDouble ifTrue:[
+ self pushDouble: result
+ ] ifFalse:[
+ resolvedMethod returnsLong ifTrue:[
+ self pushLong: result
+ ] ifFalse:[
+ resolvedMethod returnsVoid ifFalse: [
+ self pushRef: result
+ ]
+ ]
].
"
@@ -1961,6 +1987,7 @@
values to the invoked method."
"Modified: / 04-06-2011 / 18:13:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 16-03-2016 / 00:13:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
ior
@@ -2096,12 +2123,6 @@
"Created: / 14-03-2011 / 17:19:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
-istore
- "superclass JavaByteCodeProcessor says that I am responsible to implement this method"
-
- ^ self shouldImplement
-!
-
istore: idx
"store int value into variable #index
stack: value -> nothing
@@ -2244,9 +2265,21 @@
!
lcmp
- "raise an error: must be redefined in concrete subclass(es)"
-
- ^ self shouldImplement
+ | l1 l2 |
+
+ l1 := self popLong.
+ l2 := self popLong.
+ l1 = l2 ifTrue:[
+ self pushInt: 0
+ ] ifFalse:[
+ l1 > l2 ifTrue:[
+ self pushInt: 1
+ ] ifFalse:[
+ self pushInt:-1
+ ].
+ ].
+
+ "Modified: / 15-03-2016 / 23:37:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
lconst: arg
@@ -2269,8 +2302,15 @@
Push item from runtime constant pool
stack: nothing -> value
args: index"
-
- self pushRef: (constantPool at: self fetchIndex).
+
+ | constantOrRef |
+
+ constantOrRef := constantPool at: self fetchIndex.
+ (constantOrRef isNumber or:[ constantOrRef isJavaObject"java.lang.String"]) ifFalse:[
+ constantOrRef := constantOrRef resolve.
+ ].
+ self pushRef: constantOrRef.
+
"
Description
@@ -2289,6 +2329,7 @@
The ldc instruction can only be used to push a value of type float taken from the float value set (3.3.2) because a constant of type float in the constant pool (4.4.4) must be taken from the float value set."
"Modified: / 14-03-2011 / 16:04:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 15-03-2016 / 23:53:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
ldc2
@@ -2584,11 +2625,12 @@
stack: nothing -> objectRef
args: indexByte1 indexByte2"
- | classRef result |
+ | classRef objectRef |
classRef := constantPool at: self fetchIndex2.
self breakPoint:#mh_instructions.
- result := (JavaVM classForName: classRef name) new.
+ objectRef := (JavaVM classForName: classRef name) basicNew.
+ self pushRef: objectRef
"
Description
@@ -2621,8 +2663,8 @@
the uninitialized instance."
"Created: / 25-02-2011 / 00:17:39 / Marcel Hlopko <hlopik@gmail.com>"
- "Modified: / 24-02-2011 / 22:13:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 13-03-2011 / 17:18:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 15-03-2016 / 23:26:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
newarray
--- a/experiments/JavaByteCodeInterpreterTests.st Tue Mar 15 15:46:32 2016 +0000
+++ b/experiments/JavaByteCodeInterpreterTests.st Wed Mar 16 00:43:52 2016 +0000
@@ -65,6 +65,22 @@
"Modified: / 16-03-2011 / 14:43:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!JavaByteCodeInterpreterTests methodsFor:'private'!
+
+invoke: methodName class: aClass receiver: receiver args: args
+ | method result |
+
+ method := aClass lookupMethodFor: methodName.
+ result := JavaByteCodeInterpreter new
+ interpret: method
+ receiver: receiver
+ arguments: args.
+ ^ result.
+
+ "Created: / 10-03-2011 / 23:30:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 17-03-2011 / 17:32:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
!JavaByteCodeInterpreterTests methodsFor:'tests'!
testAnd
@@ -193,6 +209,221 @@
"Modified: / 16-03-2011 / 21:48:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
+testGetBoolean
+ | result expResult inst |
+ inst := self loadSimpleClassWithManyReferences new.
+ expResult := 1.
+ result := self
+ invoke: #'getBoolean()Z'
+ class: inst class
+ receiver: inst
+ args: nil.
+ self assertFalse: (result isNil).
+ self assertTrue: (result = expResult).
+
+ "
+ Deassembling getBoolean
+ 1: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.mocks.SimpleClassWithManyReferences]
+ 2: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
+ 5: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
+ 7: AALOAD (50) ARGS: [] STACK: [arrayRef, index -> value]
+ 8: CHECKCAST (192) ARGS: [java.lang.Boolean] STACK: [objectRef -> objectRef]
+ 11: INVVIRT (182) ARGS: [JavaMethodRef (java.lang.Boolean 'booleanValue'()Z)] STACK: [objectRef, [arg1, arg2, ...] -> ..]
+ 14: IRETURN (172) ARGS: [] STACK: [value -> EMPTY]"
+
+ "Created: / 14-03-2011 / 21:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-03-2011 / 17:45:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:05:21 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testGetByte
+ | result expResult |
+ expResult := 11.
+ result := self
+ invoke: #'getByte()B'
+ class: self loadSimpleClassWithManyReferences
+ receiver: self loadSimpleClassWithManyReferences new
+ args: nil.
+ self assertFalse: (result isNil).
+ self assertTrue: (result = expResult).
+
+ "0 aload_0
+ 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
+ 4 bipush 7
+ 6 aaload
+ 7 checkcast 17 [java.lang.Byte]
+ 10 invokevirtual 31 [JavaMethodRef (java.lang.Byte 'byteValue'()B)]
+ 13 ireturn"
+
+ "Created: / 14-03-2011 / 21:34:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 16-03-2011 / 22:04:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:05:27 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testGetChar
+ | result expResult |
+ expResult := 97.
+ result := self
+ invoke: #'getChar()C'
+ class: self loadSimpleClassWithManyReferences
+ receiver: self loadSimpleClassWithManyReferences new
+ args: nil.
+ self assertFalse: (result isNil).
+ self assertTrue: (result = expResult).
+
+ "0 aload_0
+ 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
+ 4 iconst_3
+ 5 aaload
+ 6 checkcast 25 [java.lang.Character]
+ 9 invokevirtual 26 [JavaMethodRef (java.lang.Character 'charValue'()C)]
+ 12 ireturn"
+
+ "Created: / 14-03-2011 / 21:31:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-03-2011 / 17:45:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:05:31 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testGetDateArray
+ | result |
+ "again - you're comparing java array with st array - watch out"
+ "/ expResult := #( nil nil nil ).
+ result := self
+ invoke: #'getDateArray()[Ljava/util/Date;'
+ class: self loadSimpleClassWithManyReferences
+ receiver: self loadSimpleClassWithManyReferences new
+ args: nil.
+ self assertFalse: (result isNil).
+
+ "/ self assertTrue: (result = expResult).
+ "0 aload_0
+ 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
+ 4 bipush 8
+ 6 aaload
+ 7 checkcast 32 [UnresolvedClass([Ljava.util.Date;)]
+ 10 checkcast 32 [UnresolvedClass([Ljava.util.Date;)]
+ 13 areturn"
+
+ "Created: / 14-03-2011 / 21:35:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-03-2011 / 17:59:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:05:37 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testGetDouble
+ | result |
+ result := self
+ invoke: #'getDouble()Ljava/lang/Double;'
+ class: self loadSimpleClassWithManyReferences
+ receiver: self loadSimpleClassWithManyReferences new
+ args: nil.
+ self assertFalse: (result isNil).
+
+ "0 aload_0
+ 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
+ 4 iconst_2
+ 5 aaload
+ 6 checkcast 24 [java.lang.Double]
+ 9 areturn"
+
+ "Created: / 14-03-2011 / 21:30:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 22-03-2011 / 17:10:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:05:42 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testGetInt
+ | result expResult |
+ expResult := 1.
+ result := self
+ invoke: #'getInt()I'
+ class: self loadSimpleClassWithManyReferences
+ receiver: self loadSimpleClassWithManyReferences new
+ args: nil.
+ self assertFalse: (result isNil).
+ self assertTrue: (result = expResult).
+
+ "0 aload_0
+ 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
+ 4 iconst_1
+ 5 aaload
+ 6 checkcast 13 [java.lang.Integer]
+ 9 invokevirtual 23 [JavaMethodRef (java.lang.Integer 'intValue'()I)]
+ 12 ireturn"
+
+ "Created: / 14-03-2011 / 21:30:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 16-03-2011 / 22:05:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:05:48 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testGetLong
+ | result expResult |
+ expResult := 10.
+ result := self
+ invoke: #'getLong()J'
+ class: self loadSimpleClassWithManyReferences
+ receiver: self loadSimpleClassWithManyReferences new
+ args: nil.
+ self assertFalse: (result isNil).
+ self assertTrue: (result = expResult).
+
+ "0 aload_0
+ 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
+ 4 iconst_4
+ 5 aaload
+ 6 checkcast 27 [java.lang.Long]
+ 9 invokevirtual 28 [JavaMethodRef (java.lang.Long 'longValue'()J)]
+ 12 lreturn"
+
+ "Created: / 14-03-2011 / 21:32:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 16-03-2011 / 22:05:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:05:56 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testGetShort
+ | result expResult |
+ expResult := 1.
+ result := self
+ invoke: #'getShort()S'
+ class: self loadSimpleClassWithManyReferences
+ receiver: self loadSimpleClassWithManyReferences new
+ args: nil.
+ self assertFalse: (result isNil).
+ self assertTrue: (result = expResult).
+
+ "0 aload_0
+ 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
+ 4 bipush 6
+ 6 aaload
+ 7 checkcast 14 [java.lang.Short]
+ 10 invokevirtual 30 [JavaMethodRef (java.lang.Short 'shortValue'()S)]
+ 13 ireturn"
+
+ "Created: / 14-03-2011 / 21:33:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 16-03-2011 / 22:06:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:06:01 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testGetString
+ | result |
+ result := self
+ invoke: #'getString()Ljava/lang/String;'
+ class: self loadSimpleClassWithManyReferences
+ receiver: self loadSimpleClassWithManyReferences new
+ args: nil.
+ self assertFalse: (result isNil).
+
+ "Modified: / 28-03-2011 / 22:40:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:06:05 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
testInc2
| result expResult |
@@ -262,6 +493,21 @@
"Modified: / 16-03-2011 / 21:48:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
+testLookupSwitch
+ | result expResult |
+
+ expResult := -1.
+ result := self
+ invoke: #'switchInt(I)I'
+ class: self loadSwitchExamplesClass
+ receiver: self loadSwitchExamplesClass new
+ args: #(-1000).
+ self assertFalse: (result isNil).
+ self assertTrue: (result = expResult).
+
+ "Created: / 21-03-2011 / 13:51:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
testMultipy
| result expResult |
@@ -370,6 +616,45 @@
"Modified: / 16-03-2011 / 21:52:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
+testSetBoolean
+ | inst |
+ inst := self loadSimpleClassWithManyReferences new.
+ self
+ invoke: #'setBoolean(I)V'
+ class: inst class
+ receiver: inst
+ args: #( 5 ).
+ self
+ invoke: #'setBoolean(I)V'
+ class: inst class
+ receiver: inst
+ args: #( 4 ).
+
+ "
+ 1: ILOAD_1 (27) ARGS: [] STACK: [.. -> FIELD 1: 'Arg 1']
+ 2: ICONST_2 (5) ARGS: [] STACK: [.. -> 2]
+ 3: IREM (112) ARGS: [] STACK: [value, value -> result]
+ 4: IFNE (154) ARGS: [JMP to: 20] STACK: [value -> ..]
+ 7: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.mocks.SimpleClassWithManyReferences]
+ 8: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
+ 11: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
+ 13: GETSTATIC (178) ARGS: [JavaFieldRef (java.lang.Boolean 'TRUE'Ljava/lang/Boolean; offs=29)] STACK: [.. -> objectRef]
+ 16: AASTORE (83) ARGS: [] STACK: [arrayRef, index, value -> ..]
+ 17: GOTO (167) ARGS: [JMP to: 31] STACK: [.. -> ..]
+ 20: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.mocks.SimpleClassWithManyReferences]
+ 21: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
+ 24: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
+ 26: ICONST_0 (3) ARGS: [] STACK: [.. -> 0]
+ 27: INVSTATIC (184) ARGS: [JavaMethodRef (java.lang.Boolean 'valueOf'(Z)Ljava/lang/Boolean;)] STACK: [[arg1, arg2, ...] -> ..]
+ 30: AASTORE (83) ARGS: [] STACK: [arrayRef, index, value -> ..]
+ 31: RETURN (177) ARGS: [] STACK: [.. -> EMPTY]"
+
+ "Created: / 21-03-2011 / 18:53:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 22-03-2011 / 12:18:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 21-12-2012 / 19:06:14 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified (format): / 02-03-2016 / 07:48:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
testSetterAndGettersDouble
| result expResult crate |
crate := self loadCrateJavaClass new.
@@ -985,6 +1270,21 @@
"Modified: / 16-03-2011 / 21:59:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
+testTableSwitch
+ | result expResult |
+
+ expResult := 1.
+ result := self
+ invoke: #'switchChar(C)I'
+ class: self loadSwitchExamplesClass
+ receiver: self loadSwitchExamplesClass new
+ args: #($b).
+ self assertFalse: (result isNil).
+ self assertTrue: (result = expResult).
+
+ "Created: / 21-03-2011 / 13:51:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
testUnsignedBitShiftLeft
| result expResult |
@@ -1022,175 +1322,8 @@
"Modified: / 16-03-2011 / 21:59:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
-!JavaByteCodeInterpreterTests methodsFor:'tests-helpers'!
-
-invoke: methodName class: aClass receiver: receiver args: args
- | method result |
-
- method := aClass lookupMethodFor: methodName.
- result := JavaByteCodeInterpreter new
- interpret: method
- receiver: receiver
- arguments: args.
- ^ result.
-
- "Created: / 10-03-2011 / 23:30:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 17-03-2011 / 17:32:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-! !
-
!JavaByteCodeInterpreterTests methodsFor:'tests2'!
-testGetBoolean
- | result expResult inst |
- inst := self loadSimpleClassWithManyReferences new.
- expResult := 1.
- result := self
- invoke: #'getBoolean()Z'
- class: inst class
- receiver: inst
- args: nil.
- self assertFalse: (result isNil).
- self assertTrue: (result = expResult).
-
- "
- Deassembling getBoolean
- 1: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.mocks.SimpleClassWithManyReferences]
- 2: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
- 5: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
- 7: AALOAD (50) ARGS: [] STACK: [arrayRef, index -> value]
- 8: CHECKCAST (192) ARGS: [java.lang.Boolean] STACK: [objectRef -> objectRef]
- 11: INVVIRT (182) ARGS: [JavaMethodRef (java.lang.Boolean 'booleanValue'()Z)] STACK: [objectRef, [arg1, arg2, ...] -> ..]
- 14: IRETURN (172) ARGS: [] STACK: [value -> EMPTY]"
-
- "Created: / 14-03-2011 / 21:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-03-2011 / 17:45:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:05:21 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-testGetByte
- | result expResult |
- expResult := 11.
- result := self
- invoke: #'getByte()B'
- class: self loadSimpleClassWithManyReferences
- receiver: self loadSimpleClassWithManyReferences new
- args: nil.
- self assertFalse: (result isNil).
- self assertTrue: (result = expResult).
-
- "0 aload_0
- 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
- 4 bipush 7
- 6 aaload
- 7 checkcast 17 [java.lang.Byte]
- 10 invokevirtual 31 [JavaMethodRef (java.lang.Byte 'byteValue'()B)]
- 13 ireturn"
-
- "Created: / 14-03-2011 / 21:34:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 16-03-2011 / 22:04:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:05:27 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-testGetChar
- | result expResult |
- expResult := 97.
- result := self
- invoke: #'getChar()C'
- class: self loadSimpleClassWithManyReferences
- receiver: self loadSimpleClassWithManyReferences new
- args: nil.
- self assertFalse: (result isNil).
- self assertTrue: (result = expResult).
-
- "0 aload_0
- 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
- 4 iconst_3
- 5 aaload
- 6 checkcast 25 [java.lang.Character]
- 9 invokevirtual 26 [JavaMethodRef (java.lang.Character 'charValue'()C)]
- 12 ireturn"
-
- "Created: / 14-03-2011 / 21:31:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-03-2011 / 17:45:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:05:31 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-testGetDateArray
- | result |
- "again - you're comparing java array with st array - watch out"
- "/ expResult := #( nil nil nil ).
- result := self
- invoke: #'getDateArray()[Ljava/util/Date;'
- class: self loadSimpleClassWithManyReferences
- receiver: self loadSimpleClassWithManyReferences new
- args: nil.
- self assertFalse: (result isNil).
-
- "/ self assertTrue: (result = expResult).
- "0 aload_0
- 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
- 4 bipush 8
- 6 aaload
- 7 checkcast 32 [UnresolvedClass([Ljava.util.Date;)]
- 10 checkcast 32 [UnresolvedClass([Ljava.util.Date;)]
- 13 areturn"
-
- "Created: / 14-03-2011 / 21:35:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-03-2011 / 17:59:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:05:37 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-testGetDouble
- | result |
- result := self
- invoke: #'getDouble()Ljava/lang/Double;'
- class: self loadSimpleClassWithManyReferences
- receiver: self loadSimpleClassWithManyReferences new
- args: nil.
- self assertFalse: (result isNil).
-
- "0 aload_0
- 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
- 4 iconst_2
- 5 aaload
- 6 checkcast 24 [java.lang.Double]
- 9 areturn"
-
- "Created: / 14-03-2011 / 21:30:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 22-03-2011 / 17:10:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:05:42 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-testGetInt
- | result expResult |
- expResult := 1.
- result := self
- invoke: #'getInt()I'
- class: self loadSimpleClassWithManyReferences
- receiver: self loadSimpleClassWithManyReferences new
- args: nil.
- self assertFalse: (result isNil).
- self assertTrue: (result = expResult).
-
- "0 aload_0
- 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
- 4 iconst_1
- 5 aaload
- 6 checkcast 13 [java.lang.Integer]
- 9 invokevirtual 23 [JavaMethodRef (java.lang.Integer 'intValue'()I)]
- 12 ireturn"
-
- "Created: / 14-03-2011 / 21:30:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 16-03-2011 / 22:05:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:05:48 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
testGetIntArray
<skip>
| result expResult |
@@ -1206,7 +1339,7 @@
invoke: #'setIntArray([I)V'
class: self loadSimpleClassWithManyReferences
receiver: self loadSimpleClassWithManyReferences new
- args: result.
+ args: (Array with: result).
"/self assertTrue: (result = expResult).
"0 aload_0
@@ -1220,70 +1353,7 @@
"Created: / 14-03-2011 / 21:33:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 21-03-2011 / 18:53:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 21-12-2012 / 19:05:52 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
-!
-
-testGetLong
- | result expResult |
- expResult := 10.
- result := self
- invoke: #'getLong()J'
- class: self loadSimpleClassWithManyReferences
- receiver: self loadSimpleClassWithManyReferences new
- args: nil.
- self assertFalse: (result isNil).
- self assertTrue: (result = expResult).
-
- "0 aload_0
- 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
- 4 iconst_4
- 5 aaload
- 6 checkcast 27 [java.lang.Long]
- 9 invokevirtual 28 [JavaMethodRef (java.lang.Long 'longValue'()J)]
- 12 lreturn"
-
- "Created: / 14-03-2011 / 21:32:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 16-03-2011 / 22:05:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:05:56 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-testGetShort
- | result expResult |
- expResult := 1.
- result := self
- invoke: #'getShort()S'
- class: self loadSimpleClassWithManyReferences
- receiver: self loadSimpleClassWithManyReferences new
- args: nil.
- self assertFalse: (result isNil).
- self assertTrue: (result = expResult).
-
- "0 aload_0
- 1 getfield 3 [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
- 4 bipush 6
- 6 aaload
- 7 checkcast 14 [java.lang.Short]
- 10 invokevirtual 30 [JavaMethodRef (java.lang.Short 'shortValue'()S)]
- 13 ireturn"
-
- "Created: / 14-03-2011 / 21:33:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 16-03-2011 / 22:06:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:06:01 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-testGetString
- | result |
- result := self
- invoke: #'getString()Ljava/lang/String;'
- class: self loadSimpleClassWithManyReferences
- receiver: self loadSimpleClassWithManyReferences new
- args: nil.
- self assertFalse: (result isNil).
-
- "Modified: / 28-03-2011 / 22:40:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:06:05 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 15-03-2016 / 22:45:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
testInitSimpleClassWithManyReferences
@@ -1308,75 +1378,6 @@
args: nil.
"Created: / 21-12-2012 / 19:05:09 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
-!
-
-testLookupSwitch
- | result expResult |
-
- expResult := -1.
- result := self
- invoke: #'switchInt(I)I'
- class: self loadSwitchExamplesClass
- receiver: self loadSwitchExamplesClass new
- args: #(-1000).
- self assertFalse: (result isNil).
- self assertTrue: (result = expResult).
-
- "Created: / 21-03-2011 / 13:51:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-!
-
-testSetBoolean
- | inst |
- inst := self loadSimpleClassWithManyReferences new.
- self
- invoke: #'setBoolean(I)V'
- class: inst class
- receiver: inst
- args: #( 5 ).
- self
- invoke: #'setBoolean(I)V'
- class: inst class
- receiver: inst
- args: #( 4 ).
-
- "
- 1: ILOAD_1 (27) ARGS: [] STACK: [.. -> FIELD 1: 'Arg 1']
- 2: ICONST_2 (5) ARGS: [] STACK: [.. -> 2]
- 3: IREM (112) ARGS: [] STACK: [value, value -> result]
- 4: IFNE (154) ARGS: [JMP to: 20] STACK: [value -> ..]
- 7: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.mocks.SimpleClassWithManyReferences]
- 8: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
- 11: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
- 13: GETSTATIC (178) ARGS: [JavaFieldRef (java.lang.Boolean 'TRUE'Ljava/lang/Boolean; offs=29)] STACK: [.. -> objectRef]
- 16: AASTORE (83) ARGS: [] STACK: [arrayRef, index, value -> ..]
- 17: GOTO (167) ARGS: [JMP to: 31] STACK: [.. -> ..]
- 20: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.mocks.SimpleClassWithManyReferences]
- 21: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.mocks.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
- 24: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
- 26: ICONST_0 (3) ARGS: [] STACK: [.. -> 0]
- 27: INVSTATIC (184) ARGS: [JavaMethodRef (java.lang.Boolean 'valueOf'(Z)Ljava/lang/Boolean;)] STACK: [[arg1, arg2, ...] -> ..]
- 30: AASTORE (83) ARGS: [] STACK: [arrayRef, index, value -> ..]
- 31: RETURN (177) ARGS: [] STACK: [.. -> EMPTY]"
-
- "Created: / 21-03-2011 / 18:53:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 22-03-2011 / 12:18:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
- "Modified: / 21-12-2012 / 19:06:14 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
- "Modified (format): / 02-03-2016 / 07:48:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-testTableSwitch
- | result expResult |
-
- expResult := 1.
- result := self
- invoke: #'switchChar(C)I'
- class: self loadSwitchExamplesClass
- receiver: self loadSwitchExamplesClass new
- args: #($b).
- self assertFalse: (result isNil).
- self assertTrue: (result = expResult).
-
- "Created: / 21-03-2011 / 13:51:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaByteCodeInterpreterTests class methodsFor:'documentation'!
--- a/tests/java/src/stx/libjava/tests/mocks/SimpleClassWithManyReferences.java Tue Mar 15 15:46:32 2016 +0000
+++ b/tests/java/src/stx/libjava/tests/mocks/SimpleClassWithManyReferences.java Wed Mar 16 00:43:52 2016 +0000
@@ -14,7 +14,7 @@
values[2] = 1.1;
values[3] = 'a';
values[4] = 10l;
- values[5] = new Integer[5];
+ values[5] = new int[5];
values[6] = new Short("1");
values[7] = new Byte("11");
values[8] = new Date[3];
@@ -68,19 +68,19 @@
values[9] = false;
}
}
-
+
public void setDate(long milis) {
((Date[]) values[8])[0] = new Date(milis);
}
-
+
public void setByte(byte b) {
values[7] = b;
}
-
+
public void setIntArray(int[] array) {
values[5] = array;
}
-
+
public void setDouble(double d) {
values[2] = d;
}
@@ -88,7 +88,7 @@
public void setShort(short s) {
values[6] = s;
}
-
+
public void setChar(char c) {
values[3] = c;
}