-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMSelectorIndexDereferenceRoutineTest.class.st
103 lines (76 loc) · 3.39 KB
/
VMSelectorIndexDereferenceRoutineTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Class {
#name : #VMSelectorIndexDereferenceRoutineTest,
#superclass : #VMSimpleStackBasedCogitAbstractTest,
#pools : [
'VMClassIndices'
],
#category : #'VMMakerTests-JitTests'
}
{ #category : #tests }
VMSelectorIndexDereferenceRoutineTest >> test32BitsDoesNotGenerateRoutine [
"32 bit platforms use a direct selector reference and not an index"
self wordSize = 4 ifFalse: [ ^ self skip ].
cogit objectRepresentation maybeGenerateSelectorIndexDereferenceRoutine.
self assert: cogit ceDereferenceSelectorIndex isNil
]
{ #category : #tests }
VMSelectorIndexDereferenceRoutineTest >> test64BitsGeneratesRoutine [
"64 bit platforms use a selector index and a routine to map it to the real selector"
self wordSize = 8 ifFalse: [ ^ self skip ].
cogit objectRepresentation maybeGenerateSelectorIndexDereferenceRoutine.
self assert: cogit ceDereferenceSelectorIndex notNil
]
{ #category : #tests }
VMSelectorIndexDereferenceRoutineTest >> testNegativeSelectorIndexIsLookedUpInSpecialSelectorTable [
"64 bit platforms use a selector index and a routine to map it to the real selector"
| index specialSelectorsArray twoComplementIndex |
self wordSize = 8 ifFalse: [ ^ self skip ].
cogit objectRepresentation maybeGenerateSelectorIndexDereferenceRoutine.
"Smalltalk 1-based array index where the selector should be."
index := 3.
"Setup a special selector array with enough space for `index` pairs of objects.
Each pair has a selector and its arity.
Put as selector some marker object such as false"
specialSelectorsArray := self newOldSpaceObjectWithSlots: index * 2.
memory coInterpreter
specialSelectorArray: specialSelectorsArray;
specialSelector: (index - 1 "0-based") put: memory falseObject.
twoComplementIndex := 16rffffffffffffffff - index + 1.
machineSimulator classRegisterValue: twoComplementIndex.
machineSimulator baseRegisterValue: cogit varBaseAddress.
self runFrom: cogit ceDereferenceSelectorIndex until: callerAddress.
self assert: machineSimulator classRegisterValue equals: memory falseObject
]
{ #category : #tests }
VMSelectorIndexDereferenceRoutineTest >> testPositiveSelectorIndexIsLookedUpInMethodLiterals [
"64 bit platforms use a selector index and a routine to map it to the real selector"
| index method builder cogMethod |
self wordSize = 8 ifFalse: [ ^ self skip ].
self setUpCogMethodEntry.
"We need enough opcodes to generate the routine"
cogit allocateOpcodes: 80 bytecodes: 0.
cogit objectRepresentation
maybeGenerateSelectorIndexDereferenceRoutine.
"Smalltalk 1-based array index where the selector should be."
index := 3.
"Create a compiled bytecode method with a marker object at a given index, and a machine code method linked to it."
method := methodBuilder
literalAt: index put: memory falseObject;
buildMethod.
cogMethod := self
generateCogMethod: [ cogit RetN: 0 ]
selector: memory nilObject.
cogit coInterpreter rawHeaderOf: method put: cogMethod asInteger.
cogMethod methodObject: method.
builder := self machineCodeFrameBuilder.
builder returnAddress: callerAddress.
builder method: cogMethod.
builder buildFrame.
machineSimulator classRegisterValue: index.
machineSimulator baseRegisterValue: cogit varBaseAddress.
self prepareCall.
self runFrom: cogit ceDereferenceSelectorIndex until: callerAddress.
self
assert: machineSimulator classRegisterValue
equals: memory falseObject
]