-
Notifications
You must be signed in to change notification settings - Fork 71
/
VMStackFrame.class.st
175 lines (138 loc) · 4.48 KB
/
VMStackFrame.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
Class {
#name : #VMStackFrame,
#superclass : #Object,
#instVars : [
'framePointer',
'interpreter'
],
#pools : [
'VMStackFrameOffsets'
],
#category : #'VMMakerTests-Visualisation'
}
{ #category : #'instance creation' }
VMStackFrame class >> newFramePointer: anInteger withInterpreter: aStackInterpreterSimulatorLSB [
^self new
framePointer: anInteger;
interpreter: aStackInterpreterSimulatorLSB;
yourself
]
{ #category : #'instance creation' }
VMStackFrame class >> virtualMachine: aVirtualMachine fp: anInteger [
^ self newFramePointer: anInteger withInterpreter: aVirtualMachine
]
{ #category : #accessing }
VMStackFrame >> bytecodeMethod [
^ VMBytecodeMethod newOnInterpreter: interpreter methodOop: self method
]
{ #category : #accessing }
VMStackFrame >> caller [
| callerContext |
"If the caller FP is different than zero, it is just a stack frame, return it"
self callerFP ~= 0 ifTrue: [
^ VMStackFrame
newFramePointer: self callerFP
withInterpreter: interpreter ].
"Get the caller frame context. If nil, we finished".
callerContext := interpreter frameCallerContext: framePointer.
(interpreter objectMemory isForwarded: callerContext) ifTrue:
[callerContext := interpreter objectMemory followForwarded: callerContext].
callerContext = interpreter objectMemory nilObject
ifTrue: [ ^ nil ].
"If the context is married get its espouse frame"
((interpreter isMarriedOrWidowedContext: callerContext)
and: [interpreter
checkIsStillMarriedContext: callerContext
currentFP: interpreter framePointer])
ifTrue: [
^ VMStackFrame
newFramePointer: (interpreter frameOfMarriedContext: callerContext)
withInterpreter: interpreter ].
"At this point, the caller context is not married, so it is either widowed or single.
Return a special ContextFrame"
^ VMContext newOnContext: callerContext withInterpreter: interpreter
]
{ #category : #accessing }
VMStackFrame >> callerContext [
^ interpreter frameCallerContext: framePointer
]
{ #category : #accessing }
VMStackFrame >> callerFP [
^ interpreter frameCallerFP: framePointer
]
{ #category : #accessing }
VMStackFrame >> context [
^VMContext newOnContext: (interpreter frameContext: framePointer) withInterpreter: interpreter
]
{ #category : #accessing }
VMStackFrame >> description [
| selector |
selector := interpreter findSelectorOfMethod: self methodOop.
^ interpreter stringOf: selector
]
{ #category : #accesing }
VMStackFrame >> framePointer: anInteger [
framePointer := anInteger
]
{ #category : #testing }
VMStackFrame >> hasContext [
^interpreter frameHasContext: framePointer
]
{ #category : #accessing }
VMStackFrame >> instructionPointer [
^ interpreter framePointer = framePointer
ifTrue: [ interpreter instructionPointer ]
ifFalse: [ interpreter frameCallerSavedIP: ( interpreter findFrameAbove: framePointer inPage: self stackPage) ]
]
{ #category : #acccessing }
VMStackFrame >> interpreter: aStackInterpreterSimulatorLSB [
interpreter := aStackInterpreterSimulatorLSB
]
{ #category : #testing }
VMStackFrame >> isMachineCodeFrame [
^ interpreter isMachineCodeFrame: framePointer
]
{ #category : #accessing }
VMStackFrame >> machineCodeMethod [
| methodSurrogate |
methodSurrogate := interpreter cogMethodZone methodFor: self method.
^ VMMachineCodeMethod newOnInterpreter: interpreter cogMethodSurrogate: methodSurrogate
]
{ #category : #accessing }
VMStackFrame >> method [
^ interpreter iframeMethod: framePointer
]
{ #category : #accessing }
VMStackFrame >> methodOop [
^ interpreter frameMethodObject: framePointer
]
{ #category : #accessing }
VMStackFrame >> receiver [
^ interpreter framePointer = framePointer
ifTrue: [ interpreter receiver ]
ifFalse: [ self halt. interpreter frameCallerSavedIP: ( interpreter findFrameAbove: framePointer inPage: self stackPage) ]
]
{ #category : #accessing }
VMStackFrame >> sender [
^ VMStackFrame newFramePointer:(interpreter frameCallerFP: framePointer) withInterpreter: interpreter
]
{ #category : #accessing }
VMStackFrame >> sourceCode [
^ self isMachineCodeFrame
ifTrue: [ self machineCodeMethod disassemble ]
ifFalse: [ self bytecodeMethod disassemble ]
]
{ #category : #accessing }
VMStackFrame >> stack [
| stack currentFrame |
stack := OrderedCollection new.
currentFrame := self.
[ currentFrame notNil ] whileTrue: [
stack add: currentFrame.
currentFrame := currentFrame caller ].
^ stack
]
{ #category : #accessing }
VMStackFrame >> stackPage [
^interpreter stackPages stackPageFor: framePointer.
]