-
Notifications
You must be signed in to change notification settings - Fork 67
/
Spur32BitMMLECoSimulator.class.st
423 lines (365 loc) · 13.4 KB
/
Spur32BitMMLECoSimulator.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
414
415
416
417
418
419
420
421
422
423
Class {
#name : #Spur32BitMMLECoSimulator,
#superclass : #Spur32BitCoMemoryManager,
#instVars : [
'parent',
'bootstrapping'
],
#category : #'VMMaker-SpurMemoryManagerSimulation'
}
{ #category : #accessing }
Spur32BitMMLECoSimulator >> bootstrapping [
^bootstrapping
]
{ #category : #accessing }
Spur32BitMMLECoSimulator >> bootstrapping: aBoolean [
bootstrapping := aBoolean.
segmentManager initForBootstrap
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> byteAt: byteAddress [
| lowBits long32 |
lowBits := byteAddress bitAnd: 3.
long32 := memoryManager uint32AtPointer: byteAddress - lowBits.
^(long32 bitShift: -8 * lowBits) bitAnd: 16rFF
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> byteAt: byteAddress put: byte [
| lowBits long32 longAddress mask value |
lowBits := byteAddress bitAnd: 3.
longAddress := byteAddress - lowBits.
long32 := self uint32AtPointer: longAddress.
mask := (16rFF bitShift: 8 * lowBits) bitInvert.
value := byte bitShift: 8 * lowBits.
self uint32AtPointer: longAddress put: ((long32 bitAnd: mask) bitOr: value).
^byte
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> byteAtPointer: pointer [
"This gets implemented by Macros in C, where its types will also be checked.
pointer is a raw address."
^self byteAt: pointer
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> byteSwapped32IfBigEndian: w [
^w bitAnd: 16rFFFFFFFF
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> byteSwapped64IfBigEndian: w [
^w bitAnd: 16rFFFFFFFFFFFFFFFF
]
{ #category : #initialization }
Spur32BitMMLECoSimulator >> coInterpreter: aCoInterpreter cogit: aCogit [
coInterpreter := aCoInterpreter.
cogit := aCogit.
scavenger coInterpreter: aCoInterpreter.
compactor coInterpreter: aCoInterpreter
]
{ #category : #'simulation only' }
Spur32BitMMLECoSimulator >> cogCodeBase [
^Cogit guardPageSize
]
{ #category : #'debug support' }
Spur32BitMMLECoSimulator >> eek [
self halt
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> endianness [
^#little
]
{ #category : #'float primitives' }
Spur32BitMMLECoSimulator >> fetchFloatAt: floatBitsAddress into: aFloat [
aFloat at: 2 put: (self uint32AtPointer: floatBitsAddress).
aFloat at: 1 put: (self uint32AtPointer: floatBitsAddress+4)
]
{ #category : #'object access' }
Spur32BitMMLECoSimulator >> fetchPointer: fieldIndex ofObject: objOop [
self assert: (self isForwarded: objOop) not.
self assert: (fieldIndex >= 0 and: [fieldIndex < (self numSlotsOfAny: objOop)
or: [fieldIndex = 0 "forwarders"]]).
^super fetchPointer: fieldIndex ofObject: objOop
]
{ #category : #'object format' }
Spur32BitMMLECoSimulator >> firstIndexableField: objOop [
"NOTE: overridden from SpurMemoryManager to add coercion to CArray, so please duplicate any changes.
There are only two important cases, both for objects with named inst vars, i.e. formats 2,3 & 5.
The first indexable field for formats 2 & 5 is the slot count (by convention, even though that's off the end
of the object). For 3 we must go to the class."
| fmt classFormat |
<returnTypeC: #'void *'>
fmt := self formatOf: objOop.
fmt <= self lastPointerFormat ifTrue: "pointer; may need to delve into the class format word"
[(fmt between: self indexablePointersFormat and: self weakArrayFormat) ifTrue:
[classFormat := self formatOfClass: (self fetchClassOfNonImm: objOop).
^self cCoerce: (self pointerForOop: objOop
+ self baseHeaderSize
+ ((self fixedFieldsOfClassFormat: classFormat) << self shiftForWord))
to: #'oop *'].
^self cCoerce: (self pointerForOop: objOop + self baseHeaderSize)
to: #'oop *'].
"All bit objects, and indeed CompiledMethod, though this is a no-no, start at 0"
self assert: (fmt >= self sixtyFourBitIndexableFormat and: [fmt < self firstCompiledMethodFormat]).
^self
cCoerce: (self pointerForOop: objOop + self baseHeaderSize)
to: (fmt < self firstByteFormat
ifTrue:
[fmt = self sixtyFourBitIndexableFormat
ifTrue: ["64 bit field objects" #'long long *']
ifFalse:
[fmt < self firstShortFormat
ifTrue: ["32 bit field objects" #'int *']
ifFalse: ["16-bit field objects" #'short *']]]
ifFalse: ["byte objects (including CompiledMethod" #'char *'])
]
{ #category : #'spur bootstrap' }
Spur32BitMMLECoSimulator >> freeLists [
^freeLists
]
{ #category : #accessing }
Spur32BitMMLECoSimulator >> freeStart [
"freeStart = 16r1163E0 ifTrue: [self halt]."
^super freeStart
]
{ #category : #'gc - global' }
Spur32BitMMLECoSimulator >> globalGarbageCollect [
"If we're /not/ a clone, clone the VM and push it over the cliff.
If it survives, destroy the clone and continue. We should be OK until next time."
parent ifNil:
[coInterpreter cr; print: 'GC number '; print: statFullGCs; tab; flush.
CloneOnGC ifTrue:
[coInterpreter cloneSimulation objectMemory globalGarbageCollect.
Smalltalk garbageCollect]].
^super globalGarbageCollect
]
{ #category : #'growing/shrinking memory' }
Spur32BitMMLECoSimulator >> growOldSpaceByAtLeast: minAmmount [
"Attempt to grow memory by at least minAmmount.
Answer the size of the new segment, or nil if the attempt failed.
Override to not grow during the Spur image bootstrap."
^bootstrapping ifFalse:
[super growOldSpaceByAtLeast: minAmmount]
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> halfWordHighInLong32: long32 [
"Used by Balloon"
^long32 bitAnd: 16rFFFF
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> halfWordLowInLong32: long32 [
"Used by Balloon"
^long32 bitShift: -16
]
{ #category : #'header format' }
Spur32BitMMLECoSimulator >> headerForSlots: numSlots format: formatField classIndex: classIndex [
"The header format in LSB is
MSB: | 2 bits |
| 22: identityHash |
| 8: slotSize |
| 3 bits |
| 5: format |
| 2 bits |
| 22: classIndex | : LSB"
self assert: (numSlots bitAnd: self numSlotsMask) = numSlots.
self assert: (formatField bitAnd: self formatMask) = formatField.
self assert: (classIndex bitAnd: self classIndexMask) = classIndex.
^super headerForSlots: numSlots format: formatField classIndex: classIndex
]
{ #category : #'debug support' }
Spur32BitMMLECoSimulator >> heapMapAtWord: address [
^heapMap heapMapAtWord: address asInteger
]
{ #category : #initialization }
Spur32BitMMLECoSimulator >> initialize [
super initialize.
bootstrapping := false
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> intAt: byteAddress [
^self longAt: byteAddress
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> intAt: byteAddress put: a32BitValue [
^self longAt: byteAddress put: (a32BitValue bitAnd: 16rFFFFFFFF)
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> long32At: byteAddress [
"Answer the 32-bit word at byteAddress which must be 0 mod 4."
^self longAt: byteAddress
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> long32At: byteAddress put: a32BitValue [
"Store the 32-bit value at byteAddress which must be 0 mod 4."
^self longAt: byteAddress put: a32BitValue
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> long64At: byteAddress [
"memory is a Bitmap, a 32-bit indexable array of bits"
| hiWord loWord |
byteAddress \\ 8 ~= 0 ifTrue: [self unalignedAccessError].
loWord := memoryManager uint32AtPointer: byteAddress.
hiWord := memoryManager uint32AtPointer: byteAddress + 4.
^hiWord = 0
ifTrue: [loWord]
ifFalse: [(hiWord bitShift: 32) + loWord]
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> long64At: byteAddress put: a64BitValue [
byteAddress \\ 8 ~= 0 ifTrue: [self unalignedAccessError].
self
longAt: byteAddress put: (a64BitValue bitAnd: 16rffffffff);
longAt: byteAddress + 4 put: a64BitValue >> 32.
^a64BitValue
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> longAt: byteAddress [
^memoryManager long32At: byteAddress
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> longAt: byteAddress put: a32BitValue [
"Note: Adjusted for Smalltalk's 1-based array indexing."
"(byteAddress = 16r101348 and: [a32BitValue = 16r53]) ifTrue:
[self halt]."
"((byteAddress between: 16rda8ac and: 16rda8c0)
or: [byteAddress between: 16r8eb98 and: 16r8ebb0]) ifTrue:
[self halt]."
^ memoryManager uint32AtPointer: byteAddress put: a32BitValue
]
{ #category : #'gc - global' }
Spur32BitMMLECoSimulator >> markAndTrace: objOop [
"objOop = 16rB26020 ifTrue: [self halt].
objOop = 16rB25FD8 ifTrue: [self halt].
objOop = 16rB26010 ifTrue: [self halt]."
^super markAndTrace: objOop
]
{ #category : #initialization }
Spur32BitMMLECoSimulator >> nextLongFrom: aStream [
"Read a 32- or 64-bit quantity from the given (binary) stream."
^aStream nextLittleEndianNumber: self wordSize
]
{ #category : #initialization }
Spur32BitMMLECoSimulator >> nextWord32From: aStream [
"Read a 32-bit quantity from the given (binary) stream."
^aStream nextLittleEndianNumber: 4
]
{ #category : #'spur bootstrap' }
Spur32BitMMLECoSimulator >> numClassTablePages [
^numClassTablePages
]
{ #category : #accessing }
Spur32BitMMLECoSimulator >> parent [
^ parent
]
{ #category : #accessing }
Spur32BitMMLECoSimulator >> parent: anObject [
parent := anObject
]
{ #category : #'debug support' }
Spur32BitMMLECoSimulator >> runLeakCheckerFor: gcModes excludeUnmarkedObjs: excludeUnmarkedObjs classIndicesShouldBeValid: classIndicesShouldBeValid [
(gcModes anyMask: checkForLeaks) ifTrue: [
coInterpreter transcript
nextPutAll: 'leak-checking...';
flush ].
^ super
runLeakCheckerFor: gcModes
excludeUnmarkedObjs: excludeUnmarkedObjs
classIndicesShouldBeValid: classIndicesShouldBeValid
]
{ #category : #'gc - global' }
Spur32BitMMLECoSimulator >> scavengingGCTenuringIf: tenuringCriterion [
"If we're /not/ a clone, clone the VM and push it over the cliff.
If it survives, destroy the clone and continue. We should be OK until next time."
(self leakCheckNewSpaceGC and: [ parent isNil ]) ifTrue: [
CloneOnScavenge ifTrue: [
coInterpreter cloneSimulation objectMemory scavengingGCTenuringIf:
tenuringCriterion.
Smalltalk garbageCollect ] ].
^ super scavengingGCTenuringIf: tenuringCriterion
]
{ #category : #'header access' }
Spur32BitMMLECoSimulator >> setIsMarkedOf: objOop to: aBoolean [
"objOop = 16rB26020 ifTrue: [self halt]."
super setIsMarkedOf: objOop to: aBoolean.
"(aBoolean
and: [(self isContextNonImm: objOop)
and: [(coInterpreter
checkIsStillMarriedContext: objOop
currentFP: coInterpreter framePointer)
and: [(coInterpreter stackPages stackPageFor: (coInterpreter frameOfMarriedContext: objOop)) trace = 0]]]) ifTrue:
[self halt]"
]
{ #category : #'debug support' }
Spur32BitMMLECoSimulator >> setUpForUseByFacade: aCurrentImageCoInterpreterFacade [
"Make sure that eden etc are initialized, so that methods can be printed.
This is really to make addressCouldBeObj: et al work."
<doNotGenerate>
self edenBytes: 0.
self setHeapBase: self freeStart
memoryLimit: self endOfMemory
endOfMemory: self endOfMemory
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> shortAt: byteAddress [
"Return the half-word at byteAddress which must be even."
| lowBits long |
lowBits := byteAddress bitAnd: 2.
long := self longAt: byteAddress - lowBits.
^ lowBits = 2
ifTrue: [ long bitShift: -16 ]
ifFalse: [ long bitAnd: 16rFFFF ]
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> shortAt: byteAddress put: a16BitValue [
"Return the half-word at byteAddress which must be even."
| lowBits long longAddress |
lowBits := byteAddress bitAnd: 2.
lowBits = 0
ifTrue: "storing into LS word"
[long := self longAt: byteAddress.
self longAt: byteAddress
put: ((long bitAnd: 16rFFFF0000) bitOr: a16BitValue)]
ifFalse: "storing into MS word"
[longAddress := byteAddress - 2.
long := self longAt: longAddress.
self longAt: longAddress
put: ((long bitAnd: 16rFFFF) bitOr: (a16BitValue bitShift: 16))].
^a16BitValue
]
{ #category : #'float primitives' }
Spur32BitMMLECoSimulator >> storeFloatAt: floatBitsAddress from: aFloat [
self long32At: floatBitsAddress put: (aFloat at: 2).
self long32At: floatBitsAddress+4 put: (aFloat at: 1)
]
{ #category : #'ad-hoc tests' }
Spur32BitMMLECoSimulator >> testObjStackDo [
| size them seqA seqB seqC rs |
ExpensiveAsserts := true.
self initializeWeaklingStack; emptyObjStack: weaklingStack.
self assert: (self topOfObjStack: weaklingStack) isNil.
self assert: (self capacityOfObjStack: weaklingStack) >= ObjStackLimit.
seqA := (1 to: ObjStackLimit * 5 // 2) collect: [:i| self integerObjectOf: i].
seqA do: [:it| self noCheckPush: it onObjStack: weaklingStack].
them := Set new.
size := self objStack: weaklingStack from: 0 do: [:it| them add: it].
self assert: size = seqA size.
self assert: (them asSortedCollection asArray = seqA).
self assert: (self isValidObjStack: weaklingStack).
seqB := (ObjStackLimit * 5 // 2 + 1 to: ObjStackLimit * 10 // 2) collect: [:i| self integerObjectOf: i].
self assert: seqA size = seqB size.
rs := seqB readStream.
them := Set new.
size := self objStack: weaklingStack from: 0 do:
[:it|
them add: it.
self noCheckPush: rs next onObjStack: weaklingStack].
self assert: size = seqA size.
self assert: rs atEnd.
self objStack: weaklingStack from: size do:
[:it| them add: it].
seqC := (seqA, seqB) sort.
self assert: them asSortedCollection asArray = seqC
]
{ #category : #'memory access' }
Spur32BitMMLECoSimulator >> vmEndianness [
"1 = big, 0 = little"
^0
]