-
Notifications
You must be signed in to change notification settings - Fork 67
/
VMSpurOldSpaceGarbageCollectorTest.class.st
689 lines (519 loc) · 23.3 KB
/
VMSpurOldSpaceGarbageCollectorTest.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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
Class {
#name : #VMSpurOldSpaceGarbageCollectorTest,
#superclass : #VMSpurInitializedOldSpaceTest,
#instVars : [
'objectStackLimit'
],
#category : #'VMMakerTests-MemoryTests'
}
{ #category : #assertion }
VMSpurOldSpaceGarbageCollectorTest >> assertHashOf: anOop equals: aHash [
self assert: (memory hashBitsOf: anOop) equals: aHash
]
{ #category : #helpers }
VMSpurOldSpaceGarbageCollectorTest >> deltaFreeSpaceAfterGC: aBlock [
| initialSpace lastObjectToBeRemembered sizeOfLastObject |
"The planning compactor frees object by sliding, and therefore does not reclaim memory if there is only dead objects in the oldspace."
"The free objects are only reclaimed when there is a object after it."
"We allocate objects during the setup"
memory fullGC.
initialSpace := memory totalFreeListBytes.
aBlock value.
lastObjectToBeRemembered := self newOldSpaceObjectWithSlots: 0.
self keepObjectInVMVariable1: lastObjectToBeRemembered.
sizeOfLastObject := memory bytesInObject: lastObjectToBeRemembered.
memory fullGC.
^ initialSpace - sizeOfLastObject - memory totalFreeListBytes
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> initializationOptions [
^ super initializationOptions , {
#ObjStackPageSlots . objectStackLimit }
]
{ #category : #testing }
VMSpurOldSpaceGarbageCollectorTest >> isValidFirstBridge [
^ memory segmentManager
isValidSegmentBridge: (memory segmentManager bridgeAt: 0)
]
{ #category : #running }
VMSpurOldSpaceGarbageCollectorTest >> runCaseManaged [
^ self runCase
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> setUp [
objectStackLimit := 10.
super setUp.
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAllocateObjectBiggerThanSizeOfFreeSpace [
| anObjectOop slotsNumber |
slotsNumber := memory totalFreeOldSpace / memory wordSize.
anObjectOop := self newObjectWithSlots: slotsNumber.
self assert: anObjectOop isNil
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAllocateObjectBiggerThanSizeOfFreeSpaceShouldPlanifyGC [
| anObjectOop slotsNumber |
slotsNumber := memory totalFreeOldSpace / memory wordSize.
anObjectOop := self newObjectWithSlots: slotsNumber.
self assert: memory needGCFlag
]
{ #category : #testCompactor }
VMSpurOldSpaceGarbageCollectorTest >> testAllocateObjectRightBeforeOverflowingFreeChunk [
| chuckSize chunk next object free |
"before GC:
dead object
free chunk with overflow header
after GC:
free chunk
free chunk with overflow header
Note: this scenario expects the free chunks to not be coallesced.
Improve this test if the memory manager become more efficient."
memory fullGC.
"Allocate a contiguous chunk of memory to be splited into entities"
chuckSize := 512*8.
chunk := next := memory allocateOldSpaceChunkOfBytes: chuckSize.
"first entity is an object to be free"
object := next := memory initializeHeaderOfStartAddress: next numSlots: 5 format: memory arrayFormat classIndex: memory arrayClassIndexPun pinned: false.
next := memory objectAfter: next.
"second entity is a free chunk with an overflow header"
free := next := memory freeChunkWithBytes: chunk + chuckSize - next at: next.
next := memory objectAfter: next.
self assert: (memory isFreeObject: object) not.
self assert: (memory isFreeObject: free).
memory fullGC.
self assert: (memory isFreeObject: object).
self assert: (memory isFreeObject: free).
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAllocateObjectWithFreeSpaceSize [
| anObjectOop slotsNumber |
slotsNumber := memory totalFreeOldSpace - (self objectHeaderSize * 2) / memory wordSize.
anObjectOop := self newOldSpaceObjectWithSlots: slotsNumber. "Big object have 2 wordSize of header"
self assert: anObjectOop isNotNil
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAllocateObjectWithFreeSpaceSizeShouldBeZero [
| anObjectOop slotsNumber |
slotsNumber := memory totalFreeOldSpace - (self objectHeaderSize * 2) / memory wordSize.
anObjectOop := self newObjectWithSlots: slotsNumber. "Big object have 2 wordSize of header"
self assert: memory totalFreeOldSpace equals: 0
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAllocateObjectWithFreeSpaceSizeShouldPlanifyGC [
| anObjectOop slotsNumber |
slotsNumber := memory totalFreeOldSpace / memory wordSize.
anObjectOop := self newObjectWithSlots: slotsNumber - 2. "Big object have 2 wordSize of header"
self assert: memory needGCFlag
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAnOldObjectNotReferencedShouldBeCollected [
| deltaFreeSpace |
deltaFreeSpace := self deltaFreeSpaceAfterGC: [
self newOldSpaceObjectWithSlots: 0 ].
self assert: deltaFreeSpace equals: 0
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAnOldObjectReferencedFromNewObjectShouldBeCollected [
| deltaFreeSpace |
deltaFreeSpace := self deltaFreeSpaceAfterGC: [
| oldObj newObj |
oldObj := self newOldSpaceObjectWithSlots: 0.
newObj := self newObjectWithSlots: 1.
memory storePointer: 0 ofObject: newObj withValue: oldObj ].
self assert: deltaFreeSpace equals: 0
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAnOldObjectReferencedFromRememberedPermObjectShouldBeKept [
| oldObjectSize deltaFreeSpace |
deltaFreeSpace := self deltaFreeSpaceAfterGC: [ | permOop oldOop |
permOop := self newPermanentObjectWithSlots: 1.
oldOop := self newOldSpaceObjectWithSlots: 0.
oldObjectSize := memory bytesInObject: oldOop.
memory storePointer: 0 ofObject: permOop withValue: oldOop ].
self assert: deltaFreeSpace equals: oldObjectSize
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAnOldObjectReferencedFromUnreferencedCycleObjectShouldBeCollected [
| deltaFreeSpace |
deltaFreeSpace := self deltaFreeSpaceAfterGC: [
| obj1 obj2 |
obj1 := self newOldSpaceObjectWithSlots: 1.
obj2 := self newOldSpaceObjectWithSlots: 1.
memory storePointer: 0 ofObject: obj1 withValue: obj2.
memory storePointer: 0 ofObject: obj2 withValue: obj1 ].
self assert: deltaFreeSpace equals: 0
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAnOldObjectReferencedFromVMVariableShouldBeKept [
| oldOop objectSize deltaFreeSpace |
deltaFreeSpace := self deltaFreeSpaceAfterGC: [
oldOop := self newOldSpaceObjectWithSlots: 0.
objectSize := memory bytesInObject: oldOop.
self keepObjectInVMVariable2: oldOop ].
self deny: (memory isFreeObject: oldOop).
self assert: deltaFreeSpace equals: objectSize
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testAnOldObjectReferencedFromVMVariableShouldBeMoved [
| anObjectOop hash |
1 timesRepeat: [ self newOldSpaceObjectWithSlots: 0 ].
anObjectOop := self newOldSpaceObjectWithSlots: 0.
self keepObjectInVMVariable1: anObjectOop.
hash := memory hashBitsOf: anObjectOop.
memory fullGC.
"after this point anObjectOop cannot be used anymore as it has been moved by the compacting phase.
We have to use the hash instead."
self deny: anObjectOop equals: self keptObjectInVMVariable1.
self assertHashOf: self keptObjectInVMVariable1 equals: hash
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testArrayOfPermanentObjectsPointingToOldObjectsIsCorrectlyMantained [
| deltaFreeSpace arrayOfPerms objectsSize aPermObject anOldObject originalRememberedSetSize afteRememberedSetSize numberOfObjects originalNewRememberedSetSize afteNewRememberedSetSize |
originalRememberedSetSize := memory bytesInObject: memory getFromPermToOldSpaceRememberedSet objectOop.
originalNewRememberedSetSize := memory bytesInObject: memory getFromPermToNewSpaceRememberedSet objectOop.
numberOfObjects := 4096.
deltaFreeSpace := self deltaFreeSpaceAfterGC: [
arrayOfPerms := self newOldSpaceArrayWithSlots: numberOfObjects.
objectsSize := memory bytesInObject: arrayOfPerms.
0 to: numberOfObjects - 1 do: [ :i |
anOldObject := self newOldSpaceObjectWithSlots: 0.
aPermObject := self newPermanentObjectWithSlots: 1.
objectsSize := objectsSize + (memory bytesInObject: anOldObject).
memory storePointer: 0 ofObject: aPermObject withValue: anOldObject.
memory storePointer: i ofObject: arrayOfPerms withValue: aPermObject ].
self keepObjectInVMVariable2: arrayOfPerms ].
afteRememberedSetSize := memory bytesInObject: memory getFromPermToOldSpaceRememberedSet objectOop.
afteNewRememberedSetSize := memory bytesInObject: memory getFromPermToNewSpaceRememberedSet objectOop.
self assert: deltaFreeSpace equals: objectsSize + (afteRememberedSetSize - originalRememberedSetSize) + (afteNewRememberedSetSize - originalNewRememberedSetSize)
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testArrayOfPermanentObjectsPointingToOldObjectsIsCorrectlyMantainedWhenObjectsMoved [
| numberOfObjects originalHashes permArray anOldObject |
numberOfObjects := 4096.
originalHashes := Array new: numberOfObjects.
self deltaFreeSpaceAfterGC: [
permArray := self newPermanentObjectWithSlots: numberOfObjects.
"Objects to be collected"
self newOldSpaceObjectWithSlots: 0.
self newOldSpaceObjectWithSlots: 0.
1 to: numberOfObjects do: [ :i |
anOldObject := self newOldSpaceObjectWithSlots: 0.
originalHashes at: i put: (memory hashBitsOf: anOldObject).
memory storePointer: (i - 1) ofObject: permArray withValue: anOldObject ]].
1 to: numberOfObjects do: [ :i |
self assert: (originalHashes at: i) equals: (memory hashBitsOf: (memory fetchPointer: i - 1 ofObject: permArray))]
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> testCompactEphemeronQueuePass1 [
| ephemeron |
"Hole, then mourn queue"
self newOldSpaceObjectWithSlots: 0.
memory initializeMournQueue.
"Hole, then ephemeron. Does not really need to be an ephemeron for this tests, any object does it"
self newOldSpaceObjectWithSlots: 0.
ephemeron := self newOldSpaceObjectWithSlots: 0.
self keepObjectInVMVariable1: ephemeron.
memory push: ephemeron onObjStack: memory mournQueue.
"Compact in one pass"
memory garbageCollectForSnapshot.
self assert: (memory sizeOfObjStack: memory mournQueue) equals: 1.
self assert: memory dequeueMourner equals: self keptObjectInVMVariable1.
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> testCompactEphemeronQueuePass2 [
| ephemeron |
"For first compaction pass"
"Hole, then mourn queue"
self newOldSpaceObjectWithSlots: 0.
memory initializeMournQueue.
"For second compaction pass"
"Hole, then ephemeron. Does not really need to be an ephemeron for this tests, any object does it"
self newOldSpaceObjectWithSlots: 0.
ephemeron := self newOldSpaceObjectWithSlots: 0.
self keepObjectInVMVariable1: ephemeron.
memory push: ephemeron onObjStack: memory mournQueue.
"Set the number of objects to compact per compact Phase.
We set N=1 to make two compaction phases.
The first phase will compact the mourn queue.
The second phase will compact the ephemeron."
memory compactor savedFirstFieldSpaceMaxSlots: 1.
"Compact"
memory garbageCollectForSnapshot.
self assert: (memory sizeOfObjStack: memory mournQueue) equals: 1.
self assert: memory dequeueMourner equals: self keptObjectInVMVariable1.
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testDoNotCollectRoots [
memory fullGC.
self deny: (memory isFreeObject: (memory nilObject)).
self deny: (memory isFreeObject: (memory trueObject)).
self deny: (memory isFreeObject: (memory falseObject)).
self deny: (memory isFreeObject: (memory freeListsObj)).
]
{ #category : #'tests-OldSpaceSize' }
VMSpurOldSpaceGarbageCollectorTest >> testDoubleForwardToYoungs [
| obj1 obj2 obj3 arrFrom arrTo arrFrom2 arrTo2 |
obj1 := self newObjectWithSlots: 1.
obj2 := self newOldSpaceObjectWithSlots: 1.
obj3 := self newOldSpaceObjectWithSlots: 1.
arrFrom := self newArrayWithSlots: 1.
arrTo := self newArrayWithSlots: 1.
memory storePointer: 0 ofObject: arrFrom withValue: obj2.
memory storePointer: 0 ofObject: arrTo withValue: obj1.
memory become: arrFrom with: arrTo twoWay: false copyHash: false.
"obj2 forwards to obj1, but since obj1 is newspace, obj2 is remembered"
arrFrom2 := self newOldSpaceArrayWithSlots: 1.
arrTo2 := self newOldSpaceArrayWithSlots: 1.
memory storePointer: 0 ofObject: arrFrom2 withValue: obj3.
memory storePointer: 0 ofObject: arrTo2 withValue: obj2.
"Here, arrFrom2 & arrTo2 (oldspace) contains only oldspace."
memory become: arrFrom2 with: arrTo2 twoWay: false copyHash: false.
"We want arrFrom2 & arrTo2 points to obj1 and be remembered"
self assert: (memory fetchPointer: 0 ofObject: arrFrom2) equals: obj1.
self assert: (memory isRemembered: arrFrom2).
self assert: (memory fetchPointer: 0 ofObject: arrTo2) equals: obj1.
self assert: (memory isRemembered: arrTo2).
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> testEphemeronDiscoverKey [
| roots ephemeron1 ephemeron2 ephemeron3 key1 key2 key3 |
"roots: E1 E2 K2
E1 key: K1
E2 Key: K2 value: K1.
E3 key: K3.
We assume the the scaning order E1 E2 E3 K2.
* E1 is marked but not scanned since K1 is not marked, E1 instead is put on unscannedEphemerons for future processing.
* Same for E2 because K2 is not marked.
* Same for E3 because K3 is not marked.
* K2 is then marked.
Then
* E1 remains on unscannedEphemerons because K1 is still unmarked.
* E2 is removed from unscannedEphemerons because K2 is marked. This triggers a scan on E2, that marks K1.
* E3 remains on unscannedEphemerons because K3 is still unmarked.
Then
* E1 is removed from unscannedEphemerons because K1 is marked. This triggers a scan on E1, that does nothing here.
* E3 remains on unscannedEphemerons because K3 is still unmarked.
Then
* E3 remains on unscannedEphemerons because K3 is still unmarked.
Then
* E3 is fired, removed from unscannedEphemerons, and scanned (that does nothing here).
Then
* unscannedEphemerons is empty, we leave
"
"Note: roots are stored in reverse order because slots are scanned from the last one to the first one"
roots := self newOldSpaceArrayWithSlots: 4. "K2 E3 E2 E1"
self keepObjectInVMVariable1: roots.
ephemeron1 := self newOldEphemeronObjectWithSlots: 1. "K1"
memory storePointer: 3 ofObject: roots withValue: ephemeron1.
key1 := self newOldSpaceObjectWithSlots: 0.
memory storePointer: 0 ofObject: ephemeron1 withValue: key1.
ephemeron2 := self newOldEphemeronObjectWithSlots: 2. "K2 K1"
memory storePointer: 2 ofObject: roots withValue: ephemeron2.
key2 := self newOldSpaceObjectWithSlots: 0.
memory storePointer: 0 ofObject: roots withValue: key2.
memory storePointer: 0 ofObject: ephemeron2 withValue: key2.
memory storePointer: 1 ofObject: ephemeron2 withValue: key1.
ephemeron3 := self newOldEphemeronObjectWithSlots: 1. "K3"
memory storePointer: 1 ofObject: roots withValue: ephemeron3.
key3 := self newOldSpaceObjectWithSlots: 0.
memory storePointer: 0 ofObject: ephemeron3 withValue: key3.
memory setCheckForLeaks: 63 "all".
memory fullGC.
self assert: memory coInterpreter pendingFinalizationSignals equals: 1.
self assert: memory dequeueMourner equals: ephemeron3.
self assert: memory dequeueMourner equals: nil.
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> testEphemeronOverflowUnscannedEphemeronQueue [
"This test Fires more ephemerons than those that fit in a single page of the mourn queue.
All ephemerons should be put in the mourn queue.
The mourn queue should grow with new pages to make them all fit.
Then we test we can extract all the objects from the queue"
| ephemeronKey ephemeronContainer mourned numberJustOverLimit |
self createEphemeronClass.
ephemeronKey := self newZeroSizedObject.
ephemeronContainer := self newObjectWithSlots: 10.
numberJustOverLimit := 10.
1 to: numberJustOverLimit do: [ :i | | ephemeronObjectOop |
ephemeronObjectOop := self newEphemeronObject.
memory
storePointer: 0 "zero based"
ofObject: ephemeronObjectOop
withValue: ephemeronKey.
memory
storePointer: i - 1 "zero based"
ofObject: ephemeronContainer
withValue: ephemeronObjectOop
].
"Force object to not be collected by putting them in special variables"
self keepObjectInVMVariable1: ephemeronContainer.
self assert: memory validObjStacks.
memory unscannedEphemeronsQueueInitialSize: numberJustOverLimit - 1.
memory fullGC.
mourned := 0.
[ memory dequeueMourner notNil ] whileTrue: [ mourned := mourned + 1 ].
self
assert: mourned
equals: numberJustOverLimit
]
{ #category : #tests }
VMSpurOldSpaceGarbageCollectorTest >> testEphemeronWithImmediateKeyShouldNotFail [
| ephemeron1 key |
ephemeron1 := self newEphemeronObjectWithSlots: 5.
self keepObjectInVMVariable1: ephemeron1.
key := memory integerObjectOf: 15.
memory storePointer: 0 ofObject: ephemeron1 withValue: key.
memory setCheckForLeaks: 63. "all"
memory fullGC.
self
assert:
(memory fetchInteger: 0 ofObject: self keptObjectInVMVariable1)
equals: 15
]
{ #category : #tests }
VMSpurOldSpaceGarbageCollectorTest >> testGrowOldSpace [
| freespace freespace2 slotsNumber anObjectOop |
memory fullGC.
freespace := memory totalFreeOldSpace.
slotsNumber := freespace / memory wordSize.
memory growOldSpaceByAtLeast: slotsNumber.
freespace2 := memory totalFreeOldSpace.
self assert: freespace*2 <= freespace2.
anObjectOop := self newObjectWithSlots: slotsNumber.
self deny: anObjectOop equals: nil.
self assert: freespace2 - (memory bytesInObject: anObjectOop) equals: memory totalFreeOldSpace.
memory fullGC.
self assert: freespace equals: memory totalFreeOldSpace.
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> testMournQueue [
| roots keyObj ephemeronObj |
roots := self newArrayWithSlots: 1.
self keepObjectInVMVariable1: roots.
keyObj := self newObjectWithSlots: 1.
ephemeronObj := self newOldEphemeronObjectWithSlots: 1.
memory storePointer: 0 ofObject: ephemeronObj withValue: keyObj.
memory storePointer: 0 ofObject: roots withValue: ephemeronObj.
memory fullGC.
self assert: memory dequeueMourner equals: ephemeronObj.
self assert: memory dequeueMourner equals: nil.
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> testMournQueue2 [
| roots keyObj ephemeronObj keyObj2 ephemeronObj2 |
"This test covers a diferent path in the CG code than testMournQueue."
roots := self newArrayWithSlots: 3.
self keepObjectInVMVariable1: roots.
keyObj := self newObjectWithSlots: 1.
ephemeronObj := self newOldEphemeronObjectWithSlots: 1.
memory storePointer: 0 ofObject: ephemeronObj withValue: keyObj.
memory storePointer: 0 ofObject: roots withValue: ephemeronObj.
keyObj2 := self newObjectWithSlots: 1.
ephemeronObj2 := self newOldEphemeronObjectWithSlots: 1.
memory storePointer: 0 ofObject: ephemeronObj2 withValue: keyObj2.
memory storePointer: 1 ofObject: roots withValue: keyObj2.
memory storePointer: 2 ofObject: roots withValue: ephemeronObj2.
memory fullGC.
self assert: memory dequeueMourner equals: ephemeronObj.
self assert: memory dequeueMourner equals: nil.
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> testMultiPageMournQueue [
"This test Fires more ephemerons than those that fit in a single page of the mourn queue.
All ephemerons should be put in the mourn queue.
The mourn queue should grow with new pages to make them all fit.
Then we test we can extract all the objects from the queue"
| ephemeronKey ephemeronContainer mourned numberJustOverLimit |
self createEphemeronClass.
numberJustOverLimit := objectStackLimit + 1.
ephemeronKey := self newZeroSizedObject.
ephemeronContainer := self newArrayWithSlots: numberJustOverLimit.
1 to: numberJustOverLimit do: [ :i | | ephemeronObjectOop |
ephemeronObjectOop := self newEphemeronObject.
memory
storePointer: 0 "zero based"
ofObject: ephemeronObjectOop
withValue: ephemeronKey.
memory
storePointer: i - 1 "zero based"
ofObject: ephemeronContainer
withValue: ephemeronObjectOop
].
"Force object to not be collected by putting them in special variables"
self keepObjectInVMVariable1: ephemeronContainer.
self assert: memory validObjStacks.
memory fullGC.
mourned := 0.
[ memory dequeueMourner notNil ] whileTrue: [ mourned := mourned + 1 ].
self
assert: mourned
equals: numberJustOverLimit
]
{ #category : #tests }
VMSpurOldSpaceGarbageCollectorTest >> testNewRootEphemeronHoldsAnotherEphemeronAsKeyThenFullGC [
| ephemeron1 ephemeron2 |
ephemeron1 := self newEphemeronObjectWithSlots: 5.
self keepObjectInVMVariable1: ephemeron1.
ephemeron2 := self newEphemeronObjectWithSlots: 3.
self keepObjectInVMVariable2: ephemeron2.
memory storePointer: 0 ofObject: ephemeron1 withValue: ephemeron2.
memory setCheckForLeaks: 63 "all".
memory fullGC
]
{ #category : #tests }
VMSpurOldSpaceGarbageCollectorTest >> testNewRootEphemeronHoldsOldNonRootEphemeronAsNonKeyThenFullGC [
| ephemeron1 ephemeron2 |
ephemeron1 := self newEphemeronObjectWithSlots: 17.
self keepObjectInVMVariable1: ephemeron1.
ephemeron2 := self newOldEphemeronObjectWithSlots: 7.
memory storePointer: 1 "Not the key" ofObject: ephemeron1 withValue: ephemeron2.
memory setCheckForLeaks: 63 "all".
memory fullGC
]
{ #category : #tests }
VMSpurOldSpaceGarbageCollectorTest >> testNewRootEphemeronIsHeldsByOldNonRootEphemeronAsNonKeyThenFullGC [
| ephemeron1 ephemeron2 |
ephemeron1 := self newEphemeronObjectWithSlots: 6.
self keepObjectInVMVariable1: ephemeron1.
memory fullGC.
ephemeron1 := self keptObjectInVMVariable1.
ephemeron2 := self newOldEphemeronObjectWithSlots: 15.
memory storePointer: 10 "Not the key" ofObject: ephemeron2 withValue: ephemeron1.
memory setCheckForLeaks: 63 "all".
memory fullGC
]
{ #category : #ephemerons }
VMSpurOldSpaceGarbageCollectorTest >> testPageLimitMournQueue [
"This test Fires more ephemerons than those that fit in a single page of the mourn queue.
All ephemerons should be put in the mourn queue.
The mourn queue should grow with new pages to make them all fit.
Then we test we can extract all the objects from the queue"
| ephemeronKey ephemeronContainer mourned objStackLimit numberJustBelowLimit |
self createEphemeronClass.
numberJustBelowLimit := objectStackLimit - 1.
ephemeronKey := self newZeroSizedObject.
ephemeronContainer := self newArrayWithSlots: numberJustBelowLimit.
objStackLimit := numberJustBelowLimit.
1 to: objStackLimit do: [ :i | | ephemeronObjectOop |
ephemeronObjectOop := self newEphemeronObject.
memory
storePointer: 0 "zero based"
ofObject: ephemeronObjectOop
withValue: ephemeronKey.
memory
storePointer: i - 1 "zero based"
ofObject: ephemeronContainer
withValue: ephemeronObjectOop
].
"Force object to not be collected by putting them in special variables"
self keepObjectInVMVariable1: ephemeronContainer.
self assert: memory validObjStacks.
memory compactor recordMovements.
memory fullGC.
mourned := 0.
[ memory dequeueMourner notNil ] whileTrue: [ mourned := mourned + 1 ].
self
assert: mourned
equals: objStackLimit
]