-
Notifications
You must be signed in to change notification settings - Fork 71
/
VMFrameBuilder.class.st
386 lines (314 loc) · 9.13 KB
/
VMFrameBuilder.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
"
I represent a frame in a stack which is in a page.
I am representing a frame.
I am able to push myself on the interpreter stack's provided when I'm asked to do so.
I only know my own state.
I have a specific inspector
I am currently used only in the #VMStackBuilder, which configures my instances, and is asking me to push myself on the interpreter.
API
I required an interpreter/memory to be able to initialize myself, so initialization is done using #initializeWithInterpreter:.
Configuring is done by using accessing protocol's methods.
When ready, tell me to push myself with #pushYourself.
Internal Representation and Key Implementation Points.
Unfinished comment.
Instance Variables
interpreter: <Interpreter> Stack or Cog, it shouldn't matter. Allows interaction with the current *simulation* interpreter
memory: <SpurMemorySomething> Same as interpreter, but for memory *simulation* version
Configuring of the frame.
args: <Object>
context: <Object>
instructionPointer: <Object>
method: <Object>
receiver: <Object>
senderContext: <Object>
temps: <Object>
stack: <Object>
This IVs are present solely for inspection purpose.
flags: <SmallInteger?> This is calculated by the VM, and should not be set by hand.
callerFP: <VMFrambeBuilder?> When the stack builder is pushing several frames, it links them.
When it links them, it gives the last frame the previous caller Frame, for debug purpose.
"
Class {
#name : #VMFrameBuilder,
#superclass : #VMAbstractBuilder,
#instVars : [
'method',
'context',
'receiver',
'temps',
'stack',
'instructionPointer',
'callerFrame',
'flags',
'previousFrameArgsSize',
'argumentSize',
'myFramePointer',
'myStackPointer',
'vmMethodBuilder',
'methodBuilder',
'isSuspended'
],
#category : #'VMMakerTests-Builders'
}
{ #category : #inspect }
VMFrameBuilder >> adaptAddressToMemory: anInteger [
anInteger = memory nilObject ifTrue: [ ^ #nilObject ].
anInteger = memory trueObject ifTrue: [ ^ #trueObject ].
anInteger = memory falseObject ifTrue: [ ^ #falseObject ].
^ anInteger
"^ memory integerObjectOf: anInteger"
]
{ #category : #inspect }
VMFrameBuilder >> adaptAddressToMemoryIfInteger: anAssociation [
anAssociation value isInteger
ifTrue: [ anAssociation value: (self adaptAddressToMemory: anAssociation value) ]
]
{ #category : #accessing }
VMFrameBuilder >> argumentSize [
^ argumentSize
]
{ #category : #accessing }
VMFrameBuilder >> argumentSize: anObject [
argumentSize := anObject
]
{ #category : #configuring }
VMFrameBuilder >> beActive [
isSuspended := false
]
{ #category : #configuring }
VMFrameBuilder >> beSuspended [
isSuspended := true
]
{ #category : #configuring }
VMFrameBuilder >> beSuspendedAt: anInstructionPointer [
instructionPointer := anInstructionPointer.
self beSuspended
]
{ #category : #accessing }
VMFrameBuilder >> callerFrame [
^ callerFrame
]
{ #category : #accessing }
VMFrameBuilder >> callerFrame: aFrame [
callerFrame := aFrame
]
{ #category : #accessing }
VMFrameBuilder >> context [
^ context
]
{ #category : #accessing }
VMFrameBuilder >> context: anObject [
context := anObject
]
{ #category : #accessing }
VMFrameBuilder >> flags [
^ flags
]
{ #category : #accessing }
VMFrameBuilder >> flags: anObject [
flags := anObject
]
{ #category : #accessing }
VMFrameBuilder >> framePointer [
^ myFramePointer
]
{ #category : #initialization }
VMFrameBuilder >> initializeWithInterpreter: anInterpreter andMemory: aMemory andMethodBuilder: aMethodBuilder [
memory := aMemory.
interpreter := anInterpreter. "allow to not care if it's for a cog or stack interpreter"
methodBuilder := aMethodBuilder.
method := memory nilObject.
context := memory nilObject.
receiver := memory nilObject.
temps := OrderedCollection new.
stack := OrderedCollection new.
instructionPointer := 0.
isSuspended := false.
previousFrameArgsSize := 0. " set by the StackBuilder"
argumentSize := 0.
]
{ #category : #inspect }
VMFrameBuilder >> inspectFrameIn: aBuilder [
<inspectorPresentationOrder: 0 title: 'Items'>
| items |
items :={
#stack -> stack.
#temps -> temps.
#receiver -> receiver.
#context -> context.
#flags -> flags.
#method -> method.
#'caller''s method ip' -> nil.
#'callerFP' -> callerFrame.
" #arguments -> args."
#receiver -> receiver.
}.
^ aBuilder newTable
addColumn: (SpStringTableColumn
title: 'Key'
evaluated: [ :each | StObjectPrinter asTruncatedTextFrom: each key ])
beSortable;
addColumn: (SpStringTableColumn
title: 'Value'
evaluated: [ :each | StObjectPrinter asTruncatedTextFrom: each value ])
beSortable;
items: items;
yourself
]
{ #category : #accessing }
VMFrameBuilder >> instructionPointer [
^ instructionPointer
]
{ #category : #context }
VMFrameBuilder >> isMarried [
| contextOop |
contextOop := interpreter frameContext: myFramePointer.
^ contextOop = memory nilObject
ifTrue: [ false ]
ifFalse: [ interpreter isStillMarriedContext: contextOop ]
]
{ #category : #context }
VMFrameBuilder >> isSingle [
| contextOop |
contextOop := interpreter frameContext: myFramePointer.
^ contextOop = memory nilObject
ifTrue: [ true ]
ifFalse: [
"this means that it was married, and that the context stack entry wasn't cleared"
interpreter isSingleContext: contextOop ]
]
{ #category : #testing }
VMFrameBuilder >> isSuspended [
^ isSuspended
]
{ #category : #context }
VMFrameBuilder >> marryToContext [
^ interpreter ensureFrameIsMarried: myFramePointer SP: myStackPointer
]
{ #category : #accessing }
VMFrameBuilder >> method [
^ method
]
{ #category : #accessing }
VMFrameBuilder >> method: anOop [
method := anOop
]
{ #category : #accessing }
VMFrameBuilder >> previousFrameArgsSize [
^ previousFrameArgsSize
]
{ #category : #accessing }
VMFrameBuilder >> previousFrameArgsSize: anObject [
previousFrameArgsSize := anObject
]
{ #category : #building }
VMFrameBuilder >> pushCurrentFramesStack [
"push to the stack all objects in the frame stack"
stack do: [ :oop | interpreter push: oop ].
]
{ #category : #building }
VMFrameBuilder >> pushFlags [
"Flags: this stack frame is single. I.e., it has no context object.
Otherwise GC fails with an assertion looking for it in the heap"
flags := (interpreter
encodeFrameFieldHasContext: context ~= memory nilObject
isBlock: false
numArgs: previousFrameArgsSize).
interpreter push: flags
]
{ #category : #building }
VMFrameBuilder >> pushFrame [
interpreter push: receiver.
temps do: [ :oop | interpreter push: oop ].
]
{ #category : #building }
VMFrameBuilder >> pushYourself [
self setVariablesFromCompiledMethod.
interpreter push: method.
interpreter push: context.
self pushFlags.
self pushFrame.
self pushCurrentFramesStack.
"context ~= memory nilObject
ifTrue: [ memory
storePointerUnchecked: 0
ofObject: context
withValue: (interpreter withSmallIntegerTags: page baseFP) ""SenderIndex"" ]."
isSuspended ifTrue: [
interpreter push: instructionPointer ].
myStackPointer:= interpreter stackPointer.
myFramePointer := interpreter framePointer.
^ myFramePointer
]
{ #category : #accessing }
VMFrameBuilder >> receiver [
^ receiver
]
{ #category : #accessing }
VMFrameBuilder >> receiver: anObject [
receiver := anObject
]
{ #category : #building }
VMFrameBuilder >> setArgsFromMethod [
| argNumber |
argNumber := interpreter argumentCountOf: method.
argNumber = argumentSize ifFalse: [
argumentSize = 0
ifTrue: [ argumentSize := argNumber ]
ifFalse: [ self error: 'Set temporaries do not match the number of arguments from the method oop.' ]]
]
{ #category : #building }
VMFrameBuilder >> setInstructionPointerBeforeFirstBytecode [
"If possible, setting IP to before the first bytecode, so it is ready for fetchNextBytecode"
(instructionPointer = 0 ) ifFalse: [ ^ self ].
instructionPointer := methodBuilder bytecodeAt: 0 forMethod: method.
interpreter instructionPointer: instructionPointer
]
{ #category : #building }
VMFrameBuilder >> setTempsFromMethod [
| tempNumber |
tempNumber := interpreter tempCountOf: method.
tempNumber = temps size ifFalse: [
temps isEmpty
ifTrue: [ temps := OrderedCollection new: tempNumber withAll: memory nilObject ]
ifFalse: [ self error: 'Set temporaries do not match the number of temporaries from the method oop.' ]]
]
{ #category : #building }
VMFrameBuilder >> setVariablesFromCompiledMethod [
(memory isCompiledMethod: method) ifFalse: [ ^ self ].
self setInstructionPointerBeforeFirstBytecode.
self setTempsFromMethod.
self setArgsFromMethod
]
{ #category : #accessing }
VMFrameBuilder >> stack [
^ stack
]
{ #category : #accessing }
VMFrameBuilder >> stack: anObject [
stack := anObject
]
{ #category : #accessing }
VMFrameBuilder >> stackPointer [
^ myStackPointer
]
{ #category : #accessing }
VMFrameBuilder >> tempAt: anIndex put: anOop [
self collection: temps at: anIndex put: anOop
]
{ #category : #accessing }
VMFrameBuilder >> temps [
^ temps
]
{ #category : #accessing }
VMFrameBuilder >> temps: anObject [
temps := anObject
]
{ #category : #accessing }
VMFrameBuilder >> vmMethodBuilder [
^ vmMethodBuilder
]
{ #category : #accessing }
VMFrameBuilder >> vmMethodBuilder: anObject [
vmMethodBuilder := anObject
]