-
Notifications
You must be signed in to change notification settings - Fork 65
/
CogMethod.class.st
413 lines (326 loc) · 10.7 KB
/
CogMethod.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
"
I am a native Cog method or polymorphic inline cache. If the former I have been produced by compiling a bytecoded CompiledMethod into machine code by the JIT, and I have a circular reference to that CompiledMethod. The CompiledMethod's header field is a pointer to me, the CogMethod, and my methodHeader field holds the compiled method's actual header. My objectHeader field looks like a single word object with a compact header with the mark bit set so as to placate the GC, i.e. make a CogMethod look like an object so that the reference to a CogMethod from a compiled method doesn't break the GC. The cmType, stackCheckOffset, cmNumArgs & cmNumTemps fields are early in the structure because we place dummy two-word CogMethod headers within a method for each block within it to record this information for each block method (see my superclass CogBlockMethod). In this case the objectHeader field is overlaid by the homeOffset and startpc fields. The objectHeader field is also used to hold the relocation distance when compacting methods since when functioning as an obhject header it is a constant value and so can easily be reinitialized. See Cogit class>>structureOfACogMethod for more information.
In C I look like
typedef struct {
sqInt objectHeader;
unsigned cmNumArgs : 8;
unsigned cmType : 3;
unsigned cmRefersToYoung : 1;
unsigned cmIsUnlinked : 1;
unsigned cmUsageCount : 3;
unsigned stackCheckOffset : 16;
unsigned short blockSize;
unsigned short blockEntryOffset;
sqInt methodObject;
sqInt methodHeader;
sqInt selector;
} CogMethod;
Note that in a 64-bit system all fields from cmNumArgs through blockEntry fit in a single 64-bit word.
My instances are not actually used. The methods exist only as input to Slang. The simulator uses my surrogates (CogMethodSurrogate32 and CogMethodSurrogate64.
"
Class {
#name : #CogMethod,
#superclass : #VMStructType,
#instVars : [
'objectHeader',
'homeOffset',
'startpc',
'padToWord',
'cmNumArgs',
'cmType',
'cmRefersToYoung',
'cpicHasMNUCaseOrCMIsFullBlock',
'cmUsageCount',
'cmUsesPenultimateLit',
'cbUsesInstVars',
'cmUnusedFlags',
'stackCheckOffset',
'blockSize',
'picUsage',
'methodObject',
'methodHeader',
'selector'
],
#pools : [
'CogMethodConstants',
'VMBasicConstants',
'VMBytecodeConstants'
],
#category : #'VMMaker-JIT'
}
{ #category : #accessing }
CogMethod class >> alignedByteSize [
self shouldNotImplement
]
{ #category : #accessing }
CogMethod class >> alignedByteSizeOf: anObject forClient: aVMClass [
^aVMClass cogit cogMethodSurrogateClass alignedByteSize
]
{ #category : #translation }
CogMethod class >> cogMethodHeader [
^ String streamContents: [ :s | self printTypedefOn: s ]
]
{ #category : #'class initialization' }
CogMethod class >> initialize [
"CogMethod initialize"
"see instVarNamesAndTypesForTranslationDo:"
CMMaxUsageCount := (2 raisedTo: 3) - 1.
MaxStackCheckOffset := (2 raisedTo: 12) - 1.
MaxMethodSize := (2 raisedTo: 16) - 1
]
{ #category : #translation }
CogMethod class >> instVarNamesAndTypesForTranslationDo: aBinaryBlock [
"enumerate aBinaryBlock with the names and C type strings for the
inst vars to include in a CogMethod or CogBlockMethod struct."
self allInstVarNames do:
[:ivn|
"Notionally objectHeader is in a union with homeOffset and startpc but
we don't have any convenient support for unions. So hack, hack, hack, hack."
(#('homeOffset' 'startpc' 'padToWord') includes: ivn) ifFalse:
[aBinaryBlock
value: ivn
value: (ivn caseOf: {
['objectHeader'] -> [VMClass objectMemoryClass baseHeaderSize = 8
ifTrue: [#sqLong]
ifFalse: [#sqInt]].
['cmNumArgs'] -> [#(unsigned ' : 8')]. "SqueakV3 needs only 5 bits"
['cmType'] -> [#(unsigned ' : 3')].
['cmRefersToYoung'] -> [#(unsigned #Boolean ' : 1')].
['cpicHasMNUCaseOrCMIsFullBlock']
-> [#(unsigned #Boolean ' : 1')].
['cmUsageCount'] -> [#(unsigned ' : 3')]. "See CMMaxUsageCount in initialize"
['cmUsesPenultimateLit'] -> [#(unsigned #Boolean ' : 1')].
['cbUsesInstVars'] -> [#(unsigned #Boolean ' : 1')].
['cmUnusedFlags'] -> [#(unsigned ' : 2')].
['stackCheckOffset'] -> [#(unsigned ' : 12')]. "See MaxStackCheckOffset in initialize. a.k.a. cPICNumCases"
['blockSize'] -> [#'unsigned short']. "See MaxMethodSize in initialize"
['picUsage'] -> [#'unsigned short'].
['homeOffset'] -> [#'unsigned short'].
['startpc'] -> [#'unsigned short'].
['padToWord'] -> [#(#BaseHeaderSize 8 'unsigned int')].
['counters'] -> [#usqInt]} "See SistaCogMethod"
otherwise:
[#sqInt])]]
]
{ #category : #translation }
CogMethod class >> isAccessor: aSelector [
"Answer if aSelector is simply an accessor method for one of our fields."
^(#(cPICNumCases cPICNumCases: nextOpenPIC nextOpenPIC:) includes: aSelector)
or: [super isAccessor: aSelector]
]
{ #category : #'code generation' }
CogMethod class >> offsetForInstVar: instVarName [
"Hack to offset accesses to variables by certain values. The inst vars following
the objectHeader must be offset by the baseHeaderSize."
^(#('objectHeader' 'homeOffset' 'startpc' 'padToWord') includes: instVarName) ifFalse:
['baseHeaderSize']
]
{ #category : #accessing }
CogMethod class >> surrogateClass [
self shouldNotImplement
]
{ #category : #accessing }
CogMethod >> blockSize [
"Answer the value of blockSize"
^ blockSize
]
{ #category : #accessing }
CogMethod >> blockSize: anObject [
"Set the value of blockSize"
^blockSize := anObject
]
{ #category : #accessing }
CogMethod >> cPICNumCases [
"Answer the value of cPICNumCases (a.k.a. stackCheckOffset)"
<cmacro: ' stackCheckOffset'>
^stackCheckOffset
]
{ #category : #accessing }
CogMethod >> cPICNumCases: anObject [
"Set the value of cPICNumCases (a.k.a. stackCheckOffset)"
<cmacro: 'Hack hack hack hack i.e. the getter macro does all the work'>
^stackCheckOffset := anObject
]
{ #category : #accessing }
CogMethod >> cbUsesInstVars [
^cbUsesInstVars
]
{ #category : #accessing }
CogMethod >> cbUsesInstVars: anObject [
^cbUsesInstVars := anObject
]
{ #category : #accessing }
CogMethod >> cmIsFullBlock [
"Answer the value of cpicHasMNUCaseOrCMIsFullBlock"
<inline: true>
^SistaV1BytecodeSet
ifTrue: [self cpicHasMNUCaseOrCMIsFullBlock]
ifFalse: [false]
]
{ #category : #accessing }
CogMethod >> cmNumArgs [
"Answer the value of cmNumArgs"
^cmNumArgs
]
{ #category : #accessing }
CogMethod >> cmNumArgs: anObject [
"Set the value of cmNumArgs"
^cmNumArgs := anObject
]
{ #category : #accessing }
CogMethod >> cmRefersToYoung [
"Answer the value of cmRefersToYoung"
^cmRefersToYoung
]
{ #category : #accessing }
CogMethod >> cmRefersToYoung: anObject [
"Set the value of cmRefersToYoung"
^cmRefersToYoung := anObject
]
{ #category : #accessing }
CogMethod >> cmType [
"Answer the value of cmType"
^cmType
]
{ #category : #accessing }
CogMethod >> cmType: anInteger [
"Set the value of cmType"
^cmType := anInteger
]
{ #category : #accessing }
CogMethod >> cmUsageCount [
"Answer the value of cmUsageCount"
^cmUsageCount
]
{ #category : #accessing }
CogMethod >> cmUsageCount: anInteger [
"Set the value of cmUsageCount"
^cmUsageCount := anInteger
]
{ #category : #accessing }
CogMethod >> cmUsesPenultimateLit [
"Answer the value of cmUsesPenultimateLit"
^cmUsesPenultimateLit
]
{ #category : #accessing }
CogMethod >> cmUsesPenultimateLit: anObject [
"Set the value of cmUsesPenultimateLit"
^cmUsesPenultimateLit := anObject
]
{ #category : #testing }
CogMethod >> containsAddress: anAddress [
"is anAddress within my bounds; not a test of addresses referred to within instructions in the method"
<inline: true>
^self asUnsignedInteger <= anAddress asUnsignedInteger
and: [self asUnsignedInteger + self blockSize >= anAddress asUnsignedInteger]
]
{ #category : #accessing }
CogMethod >> counters [
^ 0
]
{ #category : #accessing }
CogMethod >> cpicHasMNUCase [
"Answer if the receiver has an MNU case."
<inline: true>
^SistaV1BytecodeSet
ifTrue: [self cpicHasMNUCaseOrCMIsFullBlock and: [self cmType = CMPolymorphicIC]]
ifFalse: [cpicHasMNUCaseOrCMIsFullBlock]
]
{ #category : #accessing }
CogMethod >> cpicHasMNUCase: anObject [
"Set if the receiver has an MNU case."
<inline: true>
^cpicHasMNUCaseOrCMIsFullBlock := anObject
]
{ #category : #accessing }
CogMethod >> cpicHasMNUCaseOrCMIsFullBlock [
"Answer the value of cpicHasMNUCaseOrCMIsFullBlock"
^cpicHasMNUCaseOrCMIsFullBlock
]
{ #category : #accessing }
CogMethod >> cpicHasMNUCaseOrCMIsFullBlock: anObject [
"Set the value of cpicHasMNUCaseOrCMIsFullBlock"
^cpicHasMNUCaseOrCMIsFullBlock := anObject
]
{ #category : #accessing }
CogMethod >> methodHeader [
"Answer the value of methodHeader"
^ methodHeader
]
{ #category : #accessing }
CogMethod >> methodHeader: anObject [
"Set the value of methodHeader"
^methodHeader := anObject
]
{ #category : #accessing }
CogMethod >> methodObject [
"Answer the value of methodObject"
^methodObject
]
{ #category : #accessing }
CogMethod >> methodObject: anObject [
"Set the value of methodObject"
^methodObject := anObject
]
{ #category : #accessing }
CogMethod >> nextOpenPIC [
"Answer the value of nextOpenPIC (a.k.a. methodObject)"
<cmacro: ' methodObject'>
^methodObject
]
{ #category : #accessing }
CogMethod >> nextOpenPIC: anObject [
"Set the value of nextOpenPIC (a.k.a. methodObject)"
<cmacro: 'Hack hack hack hack i.e. the getter macro does all the work'>
^methodObject := anObject
]
{ #category : #accessing }
CogMethod >> objectHeader [
"Answer the value of objectHeader"
^objectHeader
]
{ #category : #accessing }
CogMethod >> objectHeader: anObject [
"Set the value of objectHeader"
^objectHeader := anObject
]
{ #category : #accessing }
CogMethod >> picUsage [
"Answer the value of blockEntryOffset"
^picUsage
]
{ #category : #accessing }
CogMethod >> picUsage: anObject [
"Set the value of blockEntryOffset"
^picUsage := anObject
]
{ #category : #accessing }
CogMethod >> selector [
"Answer the value of selector"
^ selector
]
{ #category : #accessing }
CogMethod >> selector: anObject [
"Set the value of selector"
^selector := anObject
]
{ #category : #accessing }
CogMethod >> stackCheckOffset [
"Answer the value of stackCheckOffset"
^stackCheckOffset
]
{ #category : #accessing }
CogMethod >> stackCheckOffset: anObject [
"Set the value of stackCheckOffset"
^stackCheckOffset := anObject
]
{ #category : #accessing }
CogMethod >> startpc [
"Answer the value of startpc"
^startpc
]
{ #category : #accessing }
CogMethod >> startpc: anObject [
"Set the value of startpc"
^startpc := anObject
]