-
Notifications
You must be signed in to change notification settings - Fork 67
/
VMSpurScavengerTest.class.st
760 lines (566 loc) · 26.9 KB
/
VMSpurScavengerTest.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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
Class {
#name : #VMSpurScavengerTest,
#superclass : #VMSpurInitializedOldSpaceTest,
#category : #'VMMakerTests-MemoryTests'
}
{ #category : #asserting }
VMSpurScavengerTest >> assertPastSpaceIsEmpty [
self
assert: memory pastSpaceStart
equals: memory scavenger pastSpace start
]
{ #category : #helpers }
VMSpurScavengerTest >> makeBaseFrameWithMethod: aMethodOop context: aContextOop receiver: aReceiverOop args: argsOops andStack: stackOops [
| page pointer |
page := memory coInterpreter stackPages newStackPage.
pointer := page baseAddress.
memory coInterpreter stackPointer: pointer + memory wordSize.
"Receiver"
memory coInterpreter push: aReceiverOop.
argsOops do: [ :e | memory coInterpreter push: e ].
"sender context"
memory coInterpreter push: memory nilObject.
"base frame's saved fp is null"
memory coInterpreter push: 0.
page
baseFP: memory coInterpreter stackPointer;
headFP: memory coInterpreter stackPointer.
"method"
memory coInterpreter push: aMethodOop.
"Flags: this stack frame is single. I.e., it has no context object.
Otherwise GC fails with an assertion looking for it in the heap"
memory coInterpreter push: (memory coInterpreter
encodeFrameFieldHasContext: (aContextOop ~= memory nilObject)
isBlock: false
numArgs: argsOops size).
"context"
memory coInterpreter push: aContextOop.
"rcvr"
memory coInterpreter push: aReceiverOop.
"frame stack => empty"
stackOops do: [ :e | memory coInterpreter push: e ].
"ip"
memory coInterpreter push: (aMethodOop + memory baseHeaderSize - 2).
page headSP: memory coInterpreter stackPointer.
memory coInterpreter setStackPageAndLimit: page.
memory coInterpreter setStackPointersFromPage: page.
memory coInterpreter popStack.
"Mark context as married by setting its sender to the frame pointer plus SmallInteger
tags and the InstructionPointer to the saved fp (which ensures correct alignment
w.r.t. the frame when we check for validity) plus SmallInteger tags."
(aContextOop ~= memory nilObject) ifTrue: [
memory
storePointerUnchecked: 0 "SenderIndex"
ofObject: aContextOop
withValue: (memory coInterpreter withSmallIntegerTags: page baseFP) ]
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testAllocatingObjectsBelowThresholdDoesNotScheduleScavenge [
| times |
times := ((memory scavengeThreshold - memory freeStart) / 16) floor.
times timesRepeat: [ self newZeroSizedObject ].
"We are just below the threshold and we do not need a GC"
self deny: memory needGCFlag
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testAllocatingObjectsBelowThresholdShouldBeYoung [
| times anObjectOop |
times := ((memory scavengeThreshold - memory freeStart) / 16) floor.
times timesRepeat: [ anObjectOop := self newZeroSizedObject ].
self assert: (memory isYoungObject: anObjectOop)
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testAllocatingObjectsOverThresholdShouldBeOld [
| times anObject |
times := ((memory scavengeThreshold - memory freeStart) / 16) floor.
times timesRepeat: [ self newZeroSizedObject ].
"We are just below the threshold and we do not need a GC"
"We will allocate a new one forcing the allocation in the old space and asking the GC"
anObject := memory
allocateSlots: 0
format: 0 "zero sized object"
classIndex: self zeroSizedObjectClassIndex.
self assert: (memory isOldObject: anObject)
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testAllocatingObjectsOverThresholdShouldScheduleScavenge [
| times |
times := ((memory scavengeThreshold - memory freeStart) / 16) floor.
times timesRepeat: [ self newZeroSizedObject ].
"We are just below the threshold and we do not need a GC"
"We will allocate a new one forcing the allocation in the old space and asking the GC"
memory
allocateSlots: 0
format: 0 "zero sized object"
classIndex: self zeroSizedObjectClassIndex.
self assert: memory needGCFlag
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testArgumentInStackShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
stackBuilder args: { newObjectOop }.
stackBuilder addNewFrame.
stackBuilder buildStack.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testContextInStackShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
stackBuilder addNewFrame method: methodBuilder newMethod buildMethod.
stackBuilder buildStack.
newObjectOop := interpreter
ensureFrameIsMarried: interpreter framePointer
SP: interpreter stackPointer.
newObjectHash := memory hashBitsOf: newObjectOop.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1. "TenureByAge"
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self
assert: (memory hashBitsOf: newObjectAddress)
equals: newObjectHash
]
{ #category : #'tests-5-scavenge-specialObjects' }
VMSpurScavengerTest >> testInterpreterMethodShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
memory coInterpreter method: newObjectOop.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-5-scavenge-specialObjects' }
VMSpurScavengerTest >> testInterpreterNewMethodShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
memory coInterpreter newMethod: newObjectOop.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-5-scavenge-specialObjects' }
VMSpurScavengerTest >> testInterpreterProfileMethodShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
memory coInterpreter profileMethod: newObjectOop.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-5-scavenge-specialObjects' }
VMSpurScavengerTest >> testInterpreterProfileProcessShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
memory coInterpreter profileProcess: newObjectOop.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-5-scavenge-specialObjects' }
VMSpurScavengerTest >> testInterpreterProfileSemaphoreShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
memory coInterpreter profileSemaphore: newObjectOop.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testMethodInStackShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
stackBuilder addNewFrame method: newObjectOop.
stackBuilder buildStack.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testMovingReferencedObjectShouldUpdateReference [
| rootObjectAddress newRootObjectAddress referencedObjectAddress referencedObjectHash |
rootObjectAddress := self newObjectWithSlots: 1.
referencedObjectAddress := self newZeroSizedObject.
referencedObjectHash := (memory hashBitsOf: referencedObjectAddress).
memory storePointer: 0 ofObject: rootObjectAddress withValue: referencedObjectAddress.
memory coInterpreter method: rootObjectAddress.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newRootObjectAddress := memory remapObj: rootObjectAddress.
self
assert: (memory hashBitsOf: (memory fetchPointer: 0 ofObject: newRootObjectAddress))
equals: referencedObjectHash
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testObjectInStackShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
stackBuilder addNewFrame stack: { newObjectOop }.
stackBuilder buildStack.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-6-scavenge-rememberedset' }
VMSpurScavengerTest >> testOldObjectIsNotRemembered [
| oldObjectAddress |
"Create an object, reference it, and move it to old space"
oldObjectAddress := self newObjectWithSlots: 1.
memory coInterpreter newMethod: oldObjectAddress.
memory flushNewSpace.
oldObjectAddress := memory remapObj: oldObjectAddress.
self deny: (memory isRemembered: oldObjectAddress).
]
{ #category : #'tests-6-scavenge-rememberedset' }
VMSpurScavengerTest >> testOldObjectReferenceToYoungObjectShouldBeRemappedAfterScanvenge [
| oldObjectAddress rememberedObjectAddress rememberedObjectHash newRememberedObjectAddress maybeMappedReferenceToYoungObject |
"Create an object, reference it, and move it to old space"
oldObjectAddress := self newObjectWithSlots: 1.
memory coInterpreter newMethod: oldObjectAddress.
memory flushNewSpace.
oldObjectAddress := memory remapObj: oldObjectAddress.
"Create a young object and reference it from the old object"
rememberedObjectAddress := self newZeroSizedObject.
rememberedObjectHash := memory hashBitsOf: rememberedObjectAddress.
memory storePointer: 0 ofObject: oldObjectAddress withValue: rememberedObjectAddress.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
maybeMappedReferenceToYoungObject := memory fetchPointer: 0 ofObject: oldObjectAddress.
newRememberedObjectAddress := memory remapObj: rememberedObjectAddress.
self assert: maybeMappedReferenceToYoungObject equals: newRememberedObjectAddress
]
{ #category : #'tests-6-scavenge-rememberedset' }
VMSpurScavengerTest >> testOverflowRememberedSetShouldMakeItGrow [
| oldObjectRootAddress originalLimit youngObjectAddress |
originalLimit := memory scavenger rememberedSetLimit.
"Create as many objects for the remembered set + 1"
oldObjectRootAddress := self newOldSpaceObjectWithSlots: originalLimit + 1.
1 to: originalLimit + 1 do: [ :i |
memory
storePointer: i - 1
ofObject: oldObjectRootAddress
withValue: (self newObjectWithSlots: 1).
].
"Flush them to the old space"
memory coInterpreter method: oldObjectRootAddress.
memory flushNewSpace.
"Make old objects reference a young object"
youngObjectAddress := self newZeroSizedObject.
1 to: originalLimit + 1 do: [ :i | | oldObjectAddress |
oldObjectAddress := memory fetchPointer: i - 1 ofObject: oldObjectRootAddress.
memory storePointer: 0
ofObject: oldObjectAddress
withValue: youngObjectAddress ].
self assert: memory scavenger rememberedSetLimit equals: originalLimit * 2
]
{ #category : #'tests-4-scavenge-stack' }
VMSpurScavengerTest >> testReceiverInStackShouldSurviveScanvenge [
| newObjectOop newObjectHash newObjectAddress |
newObjectOop := self newZeroSizedObject.
newObjectHash := (memory hashBitsOf: newObjectOop).
stackBuilder addNewFrame receiver: newObjectOop.
stackBuilder buildStack.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newObjectAddress := memory remapObj: newObjectOop.
self assert: (memory hashBitsOf: newObjectAddress) equals: newObjectHash
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testReferencedObjectShouldSurviveScavenge [
| rootObjectAddress rootObjectHash newRootObjectAddress referencedObjectAddress referencedObjectHash newReferencedObjectAddress |
rootObjectAddress := self newObjectWithSlots: 1.
rootObjectHash := (memory hashBitsOf: rootObjectAddress).
referencedObjectAddress := self newZeroSizedObject.
referencedObjectHash := (memory hashBitsOf: referencedObjectAddress).
memory storePointer: 0 ofObject: rootObjectAddress withValue: referencedObjectAddress.
memory coInterpreter method: rootObjectAddress.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newRootObjectAddress := memory remapObj: rootObjectAddress.
newReferencedObjectAddress := memory remapObj: referencedObjectAddress.
self assert: (memory hashBitsOf: newRootObjectAddress) equals: rootObjectHash.
self assert: (memory hashBitsOf: newReferencedObjectAddress) equals: referencedObjectHash
]
{ #category : #'tests-6-scavenge-rememberedset' }
VMSpurScavengerTest >> testRememberedObjectShouldSurviveScanvenge [
| oldObjectAddress rememberedObjectAddress rememberedObjectHash newRememberedObjectAddress |
"Create an object, reference it, and move it to old space"
oldObjectAddress := self newObjectWithSlots: 1.
memory coInterpreter newMethod: oldObjectAddress.
memory flushNewSpace.
oldObjectAddress := memory remapObj: oldObjectAddress.
"Create a young object and reference it from the old object"
rememberedObjectAddress := self newZeroSizedObject.
rememberedObjectHash := memory hashBitsOf: rememberedObjectAddress.
memory storePointer: 0 ofObject: oldObjectAddress withValue: rememberedObjectAddress.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1 "TenureByAge".
"Remap our object address to its new location"
newRememberedObjectAddress := memory remapObj: rememberedObjectAddress.
self assert: (memory hashBitsOf: newRememberedObjectAddress) equals: rememberedObjectHash
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testScavengeEmptyMemoryShouldExchangePastAndFutureSpaces [
| oldPastSpaceStart oldFutureSpaceStart |
oldPastSpaceStart := memory scavenger pastSpace start.
oldFutureSpaceStart := memory scavenger futureSpace start.
memory doScavenge: 1 "TenureByAge".
self assert: memory scavenger pastSpace start equals: oldFutureSpaceStart.
self assert: memory scavenger futureSpace start equals: oldPastSpaceStart.
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testScavengeNonSurvivorShouldEmptyEden [
"Nil should survive."
"A new object not referenced should not survive."
self newZeroSizedObject.
memory doScavenge: 1 "TenureByAge".
self assert: memory freeStart equals: memory scavenger eden start
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testScavengeNonSurvivorShouldOnlyCopySurvivorObjectToPastSpace [
"Only Nil should survive."
"A new object not referenced should not survive."
self newObjectWithSlots: 1.
memory doScavenge: 1 "TenureByAge".
self assertPastSpaceIsEmpty
]
{ #category : #'tests-7-scavenge-order' }
VMSpurScavengerTest >> testScavengeObjectInRememberedSetShouldBeInvertedToBeBeforeObjectInStack [
| objectInTheStack oldObjectAddress objectInRememberedSet |
"Create an object, reference it, and move it to old space"
oldObjectAddress := self newObjectWithSlots: 1.
memory coInterpreter newMethod: oldObjectAddress.
memory flushNewSpace.
oldObjectAddress := memory remapObj: oldObjectAddress.
"Instantiate first the object in the stack, then the object in the remembered set.
They will be inverted in memory when the scavenger copies them to future space"
objectInTheStack := self newZeroSizedObject.
objectInRememberedSet := self newZeroSizedObject.
stackBuilder addNewFrame method: objectInTheStack.
stackBuilder buildStack.
memory storePointer: 0 ofObject: oldObjectAddress withValue: objectInRememberedSet.
memory doScavenge: 1 "TenureByAge".
self assert: (memory remapObj: objectInRememberedSet) < (memory remapObj: objectInTheStack)
]
{ #category : #'tests-7-scavenge-order' }
VMSpurScavengerTest >> testScavengeObjectInRemembererdSetShouldBeBeforeObjectInStack [
| objectInTheStack oldObjectAddress objectInRememberedSet |
"Create an object, reference it, and move it to old space"
oldObjectAddress := self newObjectWithSlots: 1.
memory coInterpreter newMethod: oldObjectAddress.
memory flushNewSpace.
oldObjectAddress := memory remapObj: oldObjectAddress.
"Instantiate first the object in the remembered set, then the object in the stack.
They will be copied to future space in the same order by the scavenger"
objectInRememberedSet := self newZeroSizedObject.
objectInTheStack := self newZeroSizedObject.
stackBuilder addNewFrame method: objectInTheStack.
stackBuilder buildStack.
memory storePointer: 0 ofObject: oldObjectAddress withValue: objectInRememberedSet.
memory doScavenge: 1 "TenureByAge".
self assert: (memory remapObj: objectInRememberedSet) < (memory remapObj: objectInTheStack)
]
{ #category : #'tests-7-scavenge-order' }
VMSpurScavengerTest >> testScavengeObjectInStackShouldBeBeforeObjectInSpecialVariable [
| objectInTheStack objectInSpecialVariable |
objectInTheStack := self newZeroSizedObject.
objectInSpecialVariable := self newZeroSizedObject.
stackBuilder addNewFrame method: objectInTheStack.
stackBuilder buildStack.
memory coInterpreter method: objectInSpecialVariable.
memory doScavenge: 1 "TenureByAge".
self assert: (memory remapObj: objectInTheStack) < (memory remapObj: objectInSpecialVariable)
]
{ #category : #'tests-7-scavenge-order' }
VMSpurScavengerTest >> testScavengeObjectInStackShouldBeInvertedToBeBeforeObjectInSpecialVariable [
| objectInTheStack objectInSpecialVariable |
objectInSpecialVariable := self newZeroSizedObject.
objectInTheStack := self newZeroSizedObject.
stackBuilder addNewFrame method: objectInTheStack.
stackBuilder buildStack.
memory coInterpreter method: objectInSpecialVariable.
memory doScavenge: 1 "TenureByAge".
self assert: (memory remapObj: objectInTheStack) < (memory remapObj: objectInSpecialVariable)
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testScavengeShouldCopySurvivorObjectToPastSpace [
"Nil should survive.
It is referenced by the roots because many of their slots are nilled."
memory doScavenge: 1 "TenureByAge".
self assertPastSpaceIsEmpty
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testScavengeSurvivorShouldEmptyEden [
memory doScavenge: 1 "TenureByAge".
self assert: memory freeStart equals: memory scavenger eden start
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testScavengeTwiceShouldExchangePastAndFutureSpacesBackAndForth [
| oldPastSpaceStart oldFutureSpaceStart |
oldPastSpaceStart := memory scavenger pastSpace start.
oldFutureSpaceStart := memory scavenger futureSpace start.
2 timesRepeat: [ memory doScavenge: 1 "TenureByAge" ].
self assert: memory scavenger pastSpace start equals: oldPastSpaceStart.
self assert: memory scavenger futureSpace start equals: oldFutureSpaceStart.
]
{ #category : #'tests-7-scavenge-order' }
VMSpurScavengerTest >> testScavengedObjectsShouldBeCopiedInInstanceVariableOrder [
| rootObjectAddress objectThatShouldGoSecond objectThatShouldGoFirst |
rootObjectAddress := self newObjectWithSlots: 2.
objectThatShouldGoSecond := self newZeroSizedObject.
objectThatShouldGoFirst := self newZeroSizedObject.
memory storePointer: 0 ofObject: rootObjectAddress withValue: objectThatShouldGoFirst.
memory storePointer: 1 ofObject: rootObjectAddress withValue: objectThatShouldGoSecond.
memory coInterpreter method: rootObjectAddress.
memory doScavenge: 1 "TenureByAge".
self assert: (memory remapObj: objectThatShouldGoFirst) < (memory remapObj: objectThatShouldGoSecond)
]
{ #category : #'tests-7-scavenge-order' }
VMSpurScavengerTest >> testScavengedRootObjectsShouldBeCopiedBeforeOtherObjects [
| firstRootObjectAddress nonRootObjectAddress secondRootObjectAddress |
firstRootObjectAddress := self newObjectWithSlots: 1.
nonRootObjectAddress := self newZeroSizedObject.
secondRootObjectAddress := self newZeroSizedObject.
memory storePointer: 0 ofObject: firstRootObjectAddress withValue: nonRootObjectAddress.
memory coInterpreter method: firstRootObjectAddress.
memory coInterpreter newMethod: secondRootObjectAddress.
memory doScavenge: 1 "TenureByAge".
self assert: (memory remapObj: secondRootObjectAddress) < (memory remapObj: nonRootObjectAddress)
]
{ #category : #'tests-6-scavenge-rememberedset' }
VMSpurScavengerTest >> testStoreOldObjectInYoungObjectShouldNotRememberOldObject [
| oldObjectAddress youngObjectAddress |
"Create an object, reference it, and move it to old space"
oldObjectAddress := self newObjectWithSlots: 1.
memory coInterpreter newMethod: oldObjectAddress.
memory flushNewSpace.
oldObjectAddress := memory remapObj: oldObjectAddress.
"Create a young object and reference it from the old object"
youngObjectAddress := self newZeroSizedObject.
memory storePointer: 0 ofObject: youngObjectAddress withValue: oldObjectAddress.
self deny: (memory isRemembered: oldObjectAddress).
]
{ #category : #'tests-6-scavenge-rememberedset' }
VMSpurScavengerTest >> testStoreOldObjectInYoungObjectShouldNotRememberYoungObject [
| oldObjectAddress youngObjectAddress |
"Create an object, reference it, and move it to old space"
oldObjectAddress := self newObjectWithSlots: 1.
memory coInterpreter newMethod: oldObjectAddress.
memory flushNewSpace.
oldObjectAddress := memory remapObj: oldObjectAddress.
"Create a young object and reference it from the old object"
youngObjectAddress := self newZeroSizedObject.
memory storePointer: 0 ofObject: youngObjectAddress withValue: oldObjectAddress.
self deny: (memory isRemembered: youngObjectAddress).
]
{ #category : #'tests-6-scavenge-rememberedset' }
VMSpurScavengerTest >> testStoreYoungObjectInOldObjectShouldRememberOldObject [
| oldObjectAddress rememberedObjectAddress |
"Create an object, reference it, and move it to old space"
oldObjectAddress := self newObjectWithSlots: 1.
memory coInterpreter newMethod: oldObjectAddress.
memory flushNewSpace.
oldObjectAddress := memory remapObj: oldObjectAddress.
"Create a young object and reference it from the old object"
rememberedObjectAddress := self newZeroSizedObject.
memory storePointer: 0 ofObject: oldObjectAddress withValue: rememberedObjectAddress.
self assert: (memory isRemembered: oldObjectAddress).
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testUnreferencedObjectCycleShouldNotSurviveScavenge [
| objectA objectB |
objectA := self newObjectWithSlots: 1.
objectB := self newObjectWithSlots: 1.
memory
storePointer: 0
ofObject: objectA
withValue: objectB.
memory
storePointer: 0
ofObject: objectB
withValue: objectA.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1. "TenureByAge"
self assertPastSpaceIsEmpty
]
{ #category : #'tests-3-scavenge-basic' }
VMSpurScavengerTest >> testUnreferencedObjectGraphShouldNotSurviveScavenge [
| unreferencedRootObjectAddress referencedObjectAddress |
unreferencedRootObjectAddress := self newObjectWithSlots: 1.
referencedObjectAddress := self newZeroSizedObject.
memory
storePointer: 0
ofObject: unreferencedRootObjectAddress
withValue: referencedObjectAddress.
"Nil should survive, but newObjectOop should survive too.
Nil is referenced by the roots because many of their slots are nilled.
newObjectOop is referenced by the stack"
memory doScavenge: 1. "TenureByAge"
self assertPastSpaceIsEmpty
]
{ #category : #'tests-6-scavenge-rememberedset' }
VMSpurScavengerTest >> testYoungObjectIsNotRemembered [
| newObjectAddress |
newObjectAddress := self newObjectWithSlots: 1.
self deny: (memory isRemembered: newObjectAddress).
]