-
Notifications
You must be signed in to change notification settings - Fork 71
/
VMRememberedSet.class.st
567 lines (420 loc) · 14 KB
/
VMRememberedSet.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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
Class {
#name : #VMRememberedSet,
#superclass : #VMStructType,
#instVars : [
'manager',
'fudge',
'rootIndex',
'rememberedSetSize',
'rememberedSetLimit',
'rememberedSetArray',
'rememberedSetRedZone',
'numRememberedEphemerons',
'previousRememberedSetSize',
'doFullScan'
],
#category : #VMMaker
}
{ #category : #translation }
VMRememberedSet class >> filteredInstVarNames [
^ super filteredInstVarNames copyWithoutAll: #(manager)
]
{ #category : #translation }
VMRememberedSet class >> generateHeader: aBinaryBlock [
aBinaryBlock
value: 'vmRememberedSet.h'
value: (String streamContents: [ :s |
self printTypedefOn: s.
s cr ])
]
{ #category : #translation }
VMRememberedSet class >> instVarNamesAndTypesForTranslationDo: aBinaryBlock [
self filteredInstVarNames do: [ :aName |
aBinaryBlock value: aName value: (aName caseOf: {
['rememberedSetArray'] -> [#'sqInt *'].
} otherwise: [ #sqLong ]) ].
]
{ #category : #translation }
VMRememberedSet class >> needsTypeTag [
^true
]
{ #category : #translation }
VMRememberedSet class >> shouldBeGenerated [
^ false
]
{ #category : #initialization }
VMRememberedSet >> countNotNilObjects [
<inline: false>
| count |
count := 0.
0 to: self rememberedSetLimit do: [ :i |
"The remembered set might be initialized with 0"
((self objectAt: i) = manager nilObject or: [ (self objectAt: i) = 0 ]) ifTrue: [ ^ i ].
count := i ].
^ count
]
{ #category : #accessing }
VMRememberedSet >> doFullScan [
^ doFullScan
]
{ #category : #accessing }
VMRememberedSet >> doFullScan: aValue [
doFullScan := aValue
]
{ #category : #initialization }
VMRememberedSet >> emptyRememberedSet [
| oldObj |
oldObj := self objectOop.
oldObj = manager nilObject
ifFalse: [
manager rememberedSet: rootIndex oop: manager nilObject.
manager freeObject: oldObj ].
self initializeRememberedSetShouldStartEmpty: true.
]
{ #category : #'store check' }
VMRememberedSet >> forgetObject: objOop [
self assert: rememberedSetSize > 0.
self assert: (manager isRemembered: objOop).
manager setIsRememberedOf: objOop to: false.
objOop = (rememberedSetArray at: rememberedSetSize - 1) ifFalse:
[| index |
index := 0.
[index < rememberedSetSize] whileTrue:
[objOop = (rememberedSetArray at: index)
ifTrue:
[rememberedSetArray at: index put: (rememberedSetArray at: rememberedSetSize - 1).
index := rememberedSetSize]
ifFalse: [index := index + 1]]].
self setRememberedSetSize: rememberedSetSize - 1.
self assert: rememberedSetSize >= 0
]
{ #category : #accessing }
VMRememberedSet >> fudge [
^ fudge
]
{ #category : #accessing }
VMRememberedSet >> fudge: anObject [
fudge := anObject
]
{ #category : #'remembered set' }
VMRememberedSet >> growRememberedSet [
| obj numSlots newObj base |
<inline: false> "Don't ruin locality in remember:"
<var: #base type: #'sqInt *'>
obj := self objectOop.
numSlots := manager numSlotsOf: obj.
self assert: numSlots >= 1024.
newObj := manager allocatePinnedSlots: numSlots * 2.
newObj ifNil:
[newObj := manager allocatePinnedSlots: numSlots + 1024.
newObj ifNil:
[(manager growOldSpaceByAtLeast: (numSlots + 1024) * manager wordSize) ifNil: [self error: 'could not grow remembered set'].
newObj := manager allocatePinnedSlots: numSlots + 1024. "cannot fail"]].
manager rememberedSet: rootIndex oop: newObj.
base := self rememberedSetArrayPointerFromObject: newObj.
0 to: rememberedSetSize - 1 do:
[:i| base at: i put: (self rememberedSetArray at: i)].
"if growing in the middle of a GC, need to preserve marked status."
(manager isMarked: obj) ifTrue:
[manager
setIsMarkedOf: newObj to: true;
setIsMarkedOf: obj to: false].
manager freeObject: obj.
self rememberedSetArray: base.
self rememberedSetLimit: (manager numSlotsOf: newObj).
self setRememberedSetRedZone
]
{ #category : #initialization }
VMRememberedSet >> initialize [
rememberedSetSize := 0.
numRememberedEphemerons := 0.
fudge := 0.
doFullScan := false
]
{ #category : #initialization }
VMRememberedSet >> initializeRememberedSetShouldStartEmpty: shouldStartEmpty [
| obj |
obj := self objectOop.
(manager isInOldSpace: obj)
ifFalse: [
manager logWarn: 'Remembered Set is in an invalid position %p. Signal of a corrupted root table.' _: obj.
shouldStartEmpty
ifTrue: [
obj := manager nilObject.
manager logWarn: 'As it starts empty, we can ignore it' ]].
obj = manager nilObject
ifTrue:
[obj := manager allocatePinnedSlots: 1024.
manager rememberedSet: rootIndex oop: obj]
ifFalse: "The Spur32to64BitBootstrap failed to set the type of rememberedSetObj to 64-bit indexability.
This is unimportant except for simulation; rememberedSet is declared as sqInt *, but in to have
firstIndexableField: below answer a suitable type the format must be wordIndexableFormat."
[manager setFormatOf: obj to: manager wordIndexableFormat].
self assert: (manager formatOf: obj) = manager wordIndexableFormat.
self assert: (manager isPinned: obj).
self rememberedSetArray: (self rememberedSetArrayPointerFromObject: obj).
self rememberedSetLimit: (manager numSlotsOf: obj).
shouldStartEmpty
ifTrue: [rememberedSetSize := 0]
ifFalse: [rememberedSetSize := self countNotNilObjects].
self setRememberedSetRedZone
]
{ #category : #accessing }
VMRememberedSet >> isInRedZone [
^ rememberedSetSize >= rememberedSetRedZone
]
{ #category : #'store check' }
VMRememberedSet >> isInRememberedSet: objOop [
0 to: rememberedSetSize - 1 do:
[:i|
(rememberedSetArray at: i) = objOop ifTrue:
[^true]].
^false
]
{ #category : #accessing }
VMRememberedSet >> keepSameSize [
^ previousRememberedSetSize = rememberedSetSize
]
{ #category : #accessing }
VMRememberedSet >> manager: anObject [
<doNotGenerate>
manager := anObject
]
{ #category : #accessing }
VMRememberedSet >> moveLastObjectTo: anIndex [
rememberedSetArray
at: anIndex put: (rememberedSetArray at: rememberedSetSize - 1)
]
{ #category : #'debug support' }
VMRememberedSet >> moveNewEphemeron: ephemeron destinationIndex: destIndex [
rememberedSetArray
at: destIndex put: (rememberedSetArray at: numRememberedEphemerons);
at: numRememberedEphemerons put: ephemeron.
numRememberedEphemerons := numRememberedEphemerons + 1
]
{ #category : #accessing }
VMRememberedSet >> numRememberedEphemerons [
^ numRememberedEphemerons
]
{ #category : #accessing }
VMRememberedSet >> numRememberedEphemerons: anInteger [
numRememberedEphemerons := anInteger
]
{ #category : #accessing }
VMRememberedSet >> objectAt: anIndex [
<inline: true>
^ self rememberedSetArray at: anIndex
]
{ #category : #accessing }
VMRememberedSet >> objectOop [
^ manager objStackAt: rootIndex
]
{ #category : #accessing }
VMRememberedSet >> previousRememberedSetSize [
^ previousRememberedSetSize
]
{ #category : #'remembered set' }
VMRememberedSet >> referenceCountRememberedReferents: population maxRefCount: maxRefCount [
"Both reference count young objects reachable from the RT,
and count the populations of each ref count, in a single pass."
<var: 'population' declareC: 'long population[MaxRTRefCount + 1]'>
<inline: true>
0 to: rememberedSetSize - 1 do:
[:i| | elephant |
elephant := rememberedSetArray at: i.
(manager isForwarded: elephant) ifTrue:
[elephant := manager followForwarded: elephant.
(manager isImmediate: elephant) ifTrue: "take care if elephant forwarded to an immediate"
[elephant := manager nilObject]].
0 to: (manager numPointerSlotsOf: elephant) - 1 do:
[:j| | referent refCount |
referent := manager fetchPointer: j ofObject: elephant.
(manager isReallyYoung: referent) ifTrue:
[refCount := manager rtRefCountOf: referent.
refCount < maxRefCount ifTrue:
[refCount > 0 ifTrue:
[population at: refCount put: (population at: refCount) - 1].
refCount := refCount + 1.
manager rtRefCountOf: referent put: refCount.
population at: refCount put: (population at: refCount) + 1]]]].
]
{ #category : #'remembered set' }
VMRememberedSet >> relocateRememberedSet [
"For SpurPlanningCompactor"
self rememberedSetArray: (self rememberedSetArrayPointerFromObject: self objectOop)
]
{ #category : #'store check' }
VMRememberedSet >> remember: objOop [
"Add the argument to the remembered set and set its isRemembered bit to true.
Answer the argument for the benefit of the Cogit."
<api>
<inline: false>
self deny: (self isInRememberedSet: objOop).
manager setIsRememberedOf: objOop to: true.
^ self rememberWithoutMarkingAsRemembered: objOop
]
{ #category : #accessing }
VMRememberedSet >> rememberPreviousSize [
previousRememberedSetSize := rememberedSetSize
]
{ #category : #'store check' }
VMRememberedSet >> rememberWithoutMarkingAsRemembered: objOop [
<api>
<inline: false>
self assert: (manager isNonImmediate: objOop).
self deny: (manager getMemoryMap isYoungObject: objOop).
rememberedSetSize >= rememberedSetLimit ifTrue:
[self growRememberedSet.
doFullScan
ifFalse: [ manager scheduleScavenge ]].
rememberedSetArray at: rememberedSetSize put: objOop.
self setRememberedSetSize: rememberedSetSize + 1.
^objOop
]
{ #category : #accessing }
VMRememberedSet >> rememberedSetArray [
^ rememberedSetArray
]
{ #category : #accessing }
VMRememberedSet >> rememberedSetArray: anObject [
rememberedSetArray := anObject
]
{ #category : #initialization }
VMRememberedSet >> rememberedSetArrayPointerFromObject: anOop [
^ manager cCoerce: (manager firstIndexableField: anOop) to: 'usqInt *'
]
{ #category : #accessing }
VMRememberedSet >> rememberedSetLimit [
^rememberedSetLimit
]
{ #category : #accessing }
VMRememberedSet >> rememberedSetLimit: anObject [
rememberedSetLimit := anObject
]
{ #category : #accessing }
VMRememberedSet >> rememberedSetRedZone [
^ rememberedSetRedZone
]
{ #category : #accessing }
VMRememberedSet >> rememberedSetRedZone: anInteger [
rememberedSetRedZone := anInteger
]
{ #category : #accessing }
VMRememberedSet >> rememberedSetSize [
^rememberedSetSize
]
{ #category : #'debug support' }
VMRememberedSet >> rememberedSetWithIndexDo: aBlock [
self rememberedSetWithIndexDo: aBlock startingAt: 0
]
{ #category : #'debug support' }
VMRememberedSet >> rememberedSetWithIndexDo: aBlock startingAt: startIndex [
startIndex to: rememberedSetSize - 1 do: [ :i |
aBlock value: (rememberedSetArray at: i) value: i ]
]
{ #category : #accessing }
VMRememberedSet >> removeByIndexUsingPreviousSize: anIndex [
| newRememberedSetSize |
previousRememberedSetSize := previousRememberedSetSize - 1.
newRememberedSetSize := rememberedSetSize - 1.
rememberedSetArray
at: anIndex put: (rememberedSetArray at: previousRememberedSetSize);
at: previousRememberedSetSize
put: (rememberedSetArray at: newRememberedSetSize).
self setRememberedSetSize: newRememberedSetSize.
]
{ #category : #'debug support' }
VMRememberedSet >> removeLastEphemeronAndKeepIn: index [
numRememberedEphemerons := numRememberedEphemerons - 1.
rememberedSetArray
at: index
put: (rememberedSetArray at: numRememberedEphemerons)
]
{ #category : #accessing }
VMRememberedSet >> removeLastEphemeronAndMoveTo: index [
self removeLastEphemeronAndKeepIn: index.
self removeByIndexUsingPreviousSize: numRememberedEphemerons.
]
{ #category : #accessing }
VMRememberedSet >> removeLastEphemeronTo: index andSave: anOop [
self removeLastEphemeronAndKeepIn: index.
self save: anOop at: numRememberedEphemerons
]
{ #category : #accessing }
VMRememberedSet >> removeLastObject [
self setRememberedSetSize: rememberedSetSize - 1
]
{ #category : #accessing }
VMRememberedSet >> removeObjectAt: anIndex [
| newRememberedSetSize |
newRememberedSetSize := rememberedSetSize - 1.
rememberedSetArray
at: anIndex put: (rememberedSetArray at: newRememberedSetSize).
self setRememberedSetSize: newRememberedSetSize.
]
{ #category : #accessing }
VMRememberedSet >> replace: oldOop with: newOop [
self rememberedSetWithIndexDo: [ :oop :index |
oop = oldOop ifTrue: [
manager setIsRememberedOf: oldOop to: false.
manager setIsRememberedOf: newOop to: true.
^ self save: newOop at: index ] ]
]
{ #category : #accessing }
VMRememberedSet >> rootIndex [
^ rootIndex
]
{ #category : #accessing }
VMRememberedSet >> rootIndex: anIndex [
rootIndex := anIndex
]
{ #category : #accessing }
VMRememberedSet >> save: anOop at: index [
rememberedSetArray at: index put: anOop
]
{ #category : #'remembered set' }
VMRememberedSet >> setRememberedSetRedZone [
<inline: true>
self rememberedSetRedZone: ((self rememberedSetLimit - 4) max: self fudge)
]
{ #category : #initialization }
VMRememberedSet >> setRememberedSetSize: aNewValue [
"We want to guarantee that the first free position is a with 0"
rememberedSetSize := aNewValue.
aNewValue < rememberedSetLimit ifTrue: [ rememberedSetArray at: aNewValue put: 0 ].
]
{ #category : #'remembered set' }
VMRememberedSet >> shrinkRememberedSet [
| obj numSlots newObj base |
<inline: false>
<var: #base type: #'sqInt *'>
rememberedSetLimit >= 2048 ifFalse: [ ^ self ].
rememberedSetSize < (self rememberedSetLimit // 2)
ifFalse: [ ^ self ].
obj := self objectOop.
numSlots := ((manager numSlotsOf: obj) // 2) max: 2048.
newObj := manager allocatePinnedSlots: numSlots.
newObj ifNil:
[newObj := manager allocatePinnedSlots: numSlots.
newObj ifNil:
[(manager growOldSpaceByAtLeast: numSlots * manager wordSize) ifNil: [self error: 'could not shrink remembered set'].
newObj := manager allocatePinnedSlots: numSlots. "cannot fail"]].
manager rememberedSet: rootIndex oop: newObj.
base := self rememberedSetArrayPointerFromObject: newObj.
0 to: rememberedSetSize - 1 do:
[:i| base at: i put: (self rememberedSetArray at: i)].
"if growing in the middle of a GC, need to preserve marked status."
(manager isMarked: obj) ifTrue:
[manager
setIsMarkedOf: newObj to: true;
setIsMarkedOf: obj to: false].
manager freeObject: obj.
self rememberedSetArray: base.
self rememberedSetLimit: (manager numSlotsOf: newObj).
self setRememberedSetRedZone
]
{ #category : #scavenger }
VMRememberedSet >> startingLoop [
numRememberedEphemerons := 0.
previousRememberedSetSize := 0
]