-
Notifications
You must be signed in to change notification settings - Fork 65
/
Spur64BitMMLECoSimulator.class.st
336 lines (284 loc) · 10.4 KB
/
Spur64BitMMLECoSimulator.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
Class {
#name : #Spur64BitMMLECoSimulator,
#superclass : #Spur64BitCoMemoryManager,
#traits : 'TVMSpurMemoryManagerSimulator',
#classTraits : 'TVMSpurMemoryManagerSimulator classTrait',
#instVars : [
'parent',
'bootstrapping'
],
#category : #'VMMaker-SpurMemoryManagerSimulation'
}
{ #category : #accessing }
Spur64BitMMLECoSimulator >> bootstrapping [
^bootstrapping
]
{ #category : #accessing }
Spur64BitMMLECoSimulator >> bootstrapping: aBoolean [
bootstrapping := aBoolean.
segmentManager initForBootstrap
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> byteAt: byteAddress [
| lowBits long32 |
lowBits := byteAddress bitAnd: 3.
long32 := self uint32AtPointer: byteAddress - lowBits.
^(long32 bitShift: -8 * lowBits) bitAnd: 16rFF
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> byteAt: byteAddress put: byte [
| lowBits long32 longAddress mask value |
memoryManager unsignedByteAt: byteAddress put: byte.
^ byte
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> 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' }
Spur64BitMMLECoSimulator >> byteSwapped32IfBigEndian: w [
^w bitAnd: 16rFFFFFFFF
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> byteSwapped64IfBigEndian: w [
^w bitAnd: 16rFFFFFFFFFFFFFFFF
]
{ #category : #'debug support' }
Spur64BitMMLECoSimulator >> checkHeapIntegrity: excludeUnmarkedObjs classIndicesShouldBeValid: classIndicesShouldBeValid [
"Almost all of the time spent in SourMemoryManager>>checkHeapIntegrity:classIndicesShouldBeValid: used to go into the asserts in fetchPointer:ofObject: in the simulator class overrides.
Since we know here the indices used are valid we temporarily remove them to claw back that poerformance."
^self withSimulatorFetchPointerMovedAsideDo:
[super checkHeapIntegrity: excludeUnmarkedObjs classIndicesShouldBeValid: classIndicesShouldBeValid]
]
{ #category : #initialization }
Spur64BitMMLECoSimulator >> coInterpreter: aCoInterpreter cogit: aCogit [
coInterpreter := aCoInterpreter.
cogit := aCogit.
scavenger coInterpreter: aCoInterpreter.
compactor coInterpreter: aCoInterpreter
]
{ #category : #'debug support' }
Spur64BitMMLECoSimulator >> eek [
self halt
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> endianness [
^#little
]
{ #category : #'float primitives' }
Spur64BitMMLECoSimulator >> fetchFloatAt: floatBitsAddress into: aFloat [
aFloat at: 2 put: (self uint32AtPointer: floatBitsAddress).
aFloat at: 1 put: (self uint32AtPointer: floatBitsAddress+4)
]
{ #category : #'object access' }
Spur64BitMMLECoSimulator >> 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 : #accessing }
Spur64BitMMLECoSimulator >> freeStart [
"freeStart = 16r328C68 ifTrue: [self halt]."
^super freeStart
]
{ #category : #'gc - global' }
Spur64BitMMLECoSimulator >> 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' }
Spur64BitMMLECoSimulator >> 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' }
Spur64BitMMLECoSimulator >> halfWordHighInLong32: long32 [
"Used by Balloon"
^long32 bitAnd: 16rFFFF
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> halfWordLowInLong32: long32 [
"Used by Balloon"
^long32 bitShift: -16
]
{ #category : #'header format' }
Spur64BitMMLECoSimulator >> 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' }
Spur64BitMMLECoSimulator >> heapMapAtWord: address [
^heapMap heapMapAtWord: address asInteger
]
{ #category : #initialization }
Spur64BitMMLECoSimulator >> initialize [
super initialize.
bootstrapping := false
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> intAt: byteAddress [
^self long32At: byteAddress
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> intAt: byteAddress put: a64BitValue [
^self long32At: byteAddress put: (a64BitValue bitAnd: 16rFFFFFFFF)
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> long32At: byteAddress [
^ memoryManager uint32AtPointer: byteAddress
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> long32At: byteAddress put: a32BitValue [
"Note: Adjusted for Smalltalk's 1-based array indexing."
"(byteAddress = 16r183FB00 and: [a32BitValue = 16r3FFFFC]) ifTrue:
[self halt]."
"(byteAddress between: 16r33FBB8 and: 16r33FBCF) ifTrue:
[self halt]."
^ memoryManager unsignedLong32At: byteAddress put: a32BitValue
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> 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' }
Spur64BitMMLECoSimulator >> long64At: byteAddress put: a64BitValue [
byteAddress \\ 8 ~= 0 ifTrue: [self unalignedAccessError].
memoryManager unsignedLong64At: byteAddress put: a64BitValue.
^a64BitValue
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> longAt: byteAddress [
"Answer the 64-bit word at byteAddress which must be 0 mod 4."
^ memoryManager long64At: byteAddress
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> longAt: byteAddress put: a64BitValue [
"Store an unsigned word-sized value at byteAddress which must be 0 mod 8."
^memoryManager unsignedLong64At: byteAddress put: a64BitValue
]
{ #category : #'gc - global' }
Spur64BitMMLECoSimulator >> markAndTrace: objOop [
"objOop = 16rB26020 ifTrue: [self halt].
objOop = 16rB25FD8 ifTrue: [self halt].
objOop = 16rB26010 ifTrue: [self halt]."
^super markAndTrace: objOop
]
{ #category : #initialization }
Spur64BitMMLECoSimulator >> nextLongFrom: aStream [
"Read a 32- or 64-bit quantity from the given (binary) stream."
^aStream nextLittleEndianNumber: self wordSize
]
{ #category : #initialization }
Spur64BitMMLECoSimulator >> nextWord32From: aStream [
"Read a 32-bit quantity from the given (binary) stream."
^aStream nextLittleEndianNumber: 4
]
{ #category : #accessing }
Spur64BitMMLECoSimulator >> parent [
^ parent
]
{ #category : #accessing }
Spur64BitMMLECoSimulator >> parent: anObject [
parent := anObject
]
{ #category : #'debug support' }
Spur64BitMMLECoSimulator >> 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' }
Spur64BitMMLECoSimulator >> 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:
[coInterpreter cr; print: 'scavenge '; print: statScavenges; tab; flush.
CloneOnScavenge ifTrue:
[coInterpreter cloneSimulation objectMemory scavengingGCTenuringIf: tenuringCriterion.
Smalltalk garbageCollect]].
^super scavengingGCTenuringIf: tenuringCriterion
]
{ #category : #'header access' }
Spur64BitMMLECoSimulator >> 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 : #'memory access' }
Spur64BitMMLECoSimulator >> shortAt: byteAddress [
"Return the half-word at byteAddress which must be even."
| lowBits long |
lowBits := byteAddress bitAnd: 2.
long := self uint32AtPointer: byteAddress - lowBits.
^ lowBits = 2
ifTrue: [ long bitShift: -16 ]
ifFalse: [ long bitAnd: 16rFFFF ]
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> 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 uint32AtPointer: byteAddress.
self uint32AtPointer: byteAddress
put: ((long bitAnd: 16rFFFF0000) bitOr: a16BitValue)]
ifFalse: "storing into MS word"
[longAddress := byteAddress - 2.
long := self uint32AtPointer: longAddress.
self uint32AtPointer: longAddress
put: ((long bitAnd: 16rFFFF) bitOr: (a16BitValue bitShift: 16))].
^a16BitValue
]
{ #category : #'float primitives' }
Spur64BitMMLECoSimulator >> storeFloatAt: floatBitsAddress from: aFloat [
self uint32AtPointer: floatBitsAddress put: (aFloat at: 2).
self uint32AtPointer: floatBitsAddress+4 put: (aFloat at: 1)
]
{ #category : #'memory access' }
Spur64BitMMLECoSimulator >> vmEndianness [
"1 = big, 0 = little"
^0
]