-
Notifications
You must be signed in to change notification settings - Fork 71
/
VMSpurOldSpaceTest.class.st
865 lines (630 loc) · 30.6 KB
/
VMSpurOldSpaceTest.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
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
Class {
#name : #VMSpurOldSpaceTest,
#superclass : #VMSpurInitializedOldSpaceTest,
#category : #'VMMakerTests-MemoryTests'
}
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testAllocateAllFreeMemoryShouldLeaveNoFreeMemory [
memory allocateOldSpaceChunkOfBytes: memory totalFreeListBytes.
self assert: memory totalFreeListBytes equals: 0
]
{ #category : #'tests-8-allocation-strategy-list-bestfit' }
VMSpurOldSpaceTest >> testAllocateBestFitInListShouldAddLeftoverInList [
self createFreeChunkOfSize: 120.
self createFreeChunkOfSize: 160.
"Not exact, nor multiple of a power of 2"
memory allocateOldSpaceChunkOfBytes: 96.
self denyFreeListEmpty: (self freeListForSize: 24)
]
{ #category : #'tests-8-allocation-strategy-list-bestfit' }
VMSpurOldSpaceTest >> testAllocateBestFitInListShouldRemoveSmallerNodeFromLists [
self createFreeChunkOfSize: 120.
self createFreeChunkOfSize: 160.
"Not exact, nor multiple of a power of 2"
memory allocateOldSpaceChunkOfBytes: 96.
self assertFreeListEmpty: (self freeListForSize: 120)
]
{ #category : #'tests-8-allocation-strategy-list-bestfit' }
VMSpurOldSpaceTest >> testAllocateBestFitInListShouldReuseSmallerAddress [
| smallerAddress newAddress |
smallerAddress := self createFreeChunkOfSize: 120.
self createFreeChunkOfSize: 160.
"Not exact, nor multiple of a power of 2"
newAddress := memory allocateOldSpaceChunkOfBytes: 96.
self assert: newAddress equals: smallerAddress
]
{ #category : #'tests-8-allocation-strategy-list-bestfit' }
VMSpurOldSpaceTest >> testAllocateBestFitInListShouldUseIgnoreBiggerChunk [
self createFreeChunkOfSize: 120.
self createFreeChunkOfSize: 160.
"Not exact, nor multiple of a power of 2"
memory allocateOldSpaceChunkOfBytes: 96.
self denyFreeListEmpty: (self freeListForSize: 160)
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testAllocateChunkOfMemoryShouldHaveSoMuchMemoryLessAfter [
| someBytes freeBytesBefore |
someBytes := 32.
freeBytesBefore := memory totalFreeListBytes.
memory allocateOldSpaceChunkOfBytes: someBytes.
self assert: memory totalFreeListBytes equals: freeBytesBefore - someBytes
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testAllocateExactBiggerChunkShouldNotReuseSmallFreeChunk [
| secondAddress newAddress |
secondAddress := memory allocateOldSpaceChunkOfBytes: 160.
memory freeChunkWithBytes: 160 at: secondAddress.
newAddress := memory allocateOldSpaceChunkOfBytes: 240.
self deny: newAddress equals: secondAddress
]
{ #category : #'tests-6-allocation-strategy-list-exact' }
VMSpurOldSpaceTest >> testAllocateExactFitInListShouldIgnoreBiggerChunks [
self createFreeChunkOfSize: 160.
self createFreeChunkOfSize: 200.
memory allocateOldSpaceChunkOfBytes: 160.
self assertFreeListEmpty: (self freeListForSize: 160).
self denyFreeListEmpty: (self freeListForSize: 200)
]
{ #category : #'tests-6-allocation-strategy-list-exact' }
VMSpurOldSpaceTest >> testAllocateExactFitInListShouldRemoveNodeFromList [
| secondAddress |
secondAddress := memory allocateOldSpaceChunkOfBytes: 160.
memory freeChunkWithBytes: 160 at: secondAddress.
memory allocateOldSpaceChunkOfBytes: 160.
self assert: (self freeListForSize: 160) equals: 0
]
{ #category : #'tests-6-allocation-strategy-list-exact' }
VMSpurOldSpaceTest >> testAllocateExactFitInListShouldReuseAddress [
| secondAddress newAddress |
secondAddress := self createFreeChunkOfSize: 160.
newAddress := memory allocateOldSpaceChunkOfBytes: 160.
self assert: newAddress equals: secondAddress
]
{ #category : #'tests-9-allocation-strategy-tree' }
VMSpurOldSpaceTest >> testAllocateExactFitTreeRootShouldRemoveRootFromTree [
memory allocateOldSpaceChunkOfBytes: (memory bytesInObject: self freeTreeRootOop).
self assert: self freeTreeRootOop equals: 0
]
{ #category : #'tests-9-allocation-strategy-tree' }
VMSpurOldSpaceTest >> testAllocateExactTreeRootShouldReuseRootAddress [
| oldRootAddress newAddress |
oldRootAddress := self freeTreeRootStartAddress.
newAddress := memory allocateOldSpaceChunkOfBytes: (memory bytesInObject: self freeTreeRootOop).
self assert: newAddress equals: oldRootAddress
]
{ #category : #'tests-4-free-tree' }
VMSpurOldSpaceTest >> testAllocateHalfOfTreeNodeShouldSplitIt [
| size childAddress smallerChildOop largerChildOop aBitBiggerThanHalf |
size := 1600. "Big enough size to be in the tree"
childAddress := memory allocateOldSpaceChunkOfBytes: size.
memory freeChunkWithBytes: size at: childAddress.
aBitBiggerThanHalf := size / 2 + 8. "node a bit bigger than half"
childAddress := memory allocateOldSpaceChunkOfBytes: aBitBiggerThanHalf.
memory freeChunkWithBytes: aBitBiggerThanHalf at: childAddress.
smallerChildOop := self smallerNodeOf: self freeTreeRootOop.
self assert: (memory bytesInObject: smallerChildOop) equals: (size - aBitBiggerThanHalf).
largerChildOop := self largerNodeOf: smallerChildOop.
self assert: (memory bytesInObject: largerChildOop) equals: aBitBiggerThanHalf
]
{ #category : #'tests-4-free-tree' }
VMSpurOldSpaceTest >> testAllocateInFreeTreeShouldChangeRoot [
| freeRootOopBeforeAllocation |
freeRootOopBeforeAllocation := self freeTreeRootOop.
memory allocateOldSpaceChunkOfBytes: 800 "Big enough to be in the tree".
self deny: freeRootOopBeforeAllocation equals: self freeTreeRootOop
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testAllocateManyChunksShouldKeepSingleFreeEntry [
"Allocation should be contiguous because we have a single big chunk of memory to take memory from"
memory allocateOldSpaceChunkOfBytes: 160.
memory allocateOldSpaceChunkOfBytes: 160.
memory allocateOldSpaceChunkOfBytes: 160.
self assert: memory allFreeObjects size equals: 1
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testAllocateMoreThanFreeMemoryShouldFailReturningNil [
| address |
address := memory allocateOldSpaceChunkOfBytes: memory totalFreeListBytes + 1.
self assert: address isNil
]
{ #category : #'tests-9-allocation-strategy-tree' }
VMSpurOldSpaceTest >> testAllocatePartOfTreeRootShouldAddBigLeftOverAsFreeTreeRoot [
| leftOverSize |
leftOverSize := 64 * 8 "more than 63 slots".
memory allocateOldSpaceChunkOfBytes: (memory totalFreeListBytes - leftOverSize).
self assert: (memory bytesInObject: self freeTreeRootOop) equals: leftOverSize
]
{ #category : #'tests-9-allocation-strategy-tree' }
VMSpurOldSpaceTest >> testAllocatePartOfTreeRootShouldAddSmallLeftOverInFreeList [
| leftOverSize |
leftOverSize := 120.
memory allocateOldSpaceChunkOfBytes: (memory totalFreeListBytes - leftOverSize).
self denyFreeListEmpty: (self freeListForSize: leftOverSize)
]
{ #category : #'tests-9-allocation-strategy-tree' }
VMSpurOldSpaceTest >> testAllocatePartOfTreeRootShouldReuseRootAddress [
| oldRootAddress newAddress |
oldRootAddress := self freeTreeRootStartAddress.
"At this point we can allocate whatever we want, only the tree has space, so we will take space from the tree anyways"
self assert: 120 < (memory bytesInObject: self freeTreeRootOop).
newAddress := memory allocateOldSpaceChunkOfBytes: 120.
self assert: newAddress equals: oldRootAddress
]
{ #category : #'tests-7-allocation-strategy-list-power' }
VMSpurOldSpaceTest >> testAllocatePowerInListShouldAddLeftoverInList [
| sizeToAllocate powerOfSizeToAllocate leftOverSize |
sizeToAllocate := 80.
powerOfSizeToAllocate := sizeToAllocate * (2 ** 2).
leftOverSize := powerOfSizeToAllocate - sizeToAllocate.
self createFreeChunkOfSize: powerOfSizeToAllocate.
memory allocateOldSpaceChunkOfBytes: sizeToAllocate.
self denyFreeListEmpty: (self freeListForSize: leftOverSize)
]
{ #category : #'tests-7-allocation-strategy-list-power' }
VMSpurOldSpaceTest >> testAllocatePowerInListShouldIgnoreNonPowers [
| sizeToAllocate powerOfSizeToAllocate nonMultipleAddress newAddress |
"bitSize * allocationUnit equals maxChunckSize in the freeList
The freeList has bitsPerWords slots.
Each slots contains a pointer (wordsize), which behaves as a linked list.
Each linked list contains links free chunks of the same size.
The nodeSize of each list equals index * allocationUnit.
For example in 32 bits the free list will have 31 slots (1 for reserved for the tree).
The last linked list is stored at index 31 (0 based) and will contain nodes of size 248 (index * 8)."
sizeToAllocate := 10 * wordSize.
powerOfSizeToAllocate := sizeToAllocate * (2 ** 2).
nonMultipleAddress := self createFreeChunkOfSize: 120.
self createFreeChunkOfSize: powerOfSizeToAllocate.
newAddress := memory allocateOldSpaceChunkOfBytes: sizeToAllocate.
self deny: newAddress equals: nonMultipleAddress.
]
{ #category : #'tests-7-allocation-strategy-list-power' }
VMSpurOldSpaceTest >> testAllocatePowerInListShouldRemoveNodeFromList [
| sizeToAllocate powerOfSizeToAllocate |
sizeToAllocate := 10 * wordSize.
powerOfSizeToAllocate := sizeToAllocate * (2 ** 2).
self createFreeChunkOfSize: powerOfSizeToAllocate.
memory allocateOldSpaceChunkOfBytes: sizeToAllocate.
self assertFreeListEmpty: (self freeListForSize: powerOfSizeToAllocate)
]
{ #category : #'tests-7-allocation-strategy-list-power' }
VMSpurOldSpaceTest >> testAllocatePowerInListShouldReuseMultipleAddress [
| sizeToAllocate freeMultipleAddress newAddress powerOfSizeToAllocate |
sizeToAllocate := 80.
powerOfSizeToAllocate := sizeToAllocate * (2 ** 2).
freeMultipleAddress := self createFreeChunkOfSize: powerOfSizeToAllocate.
newAddress := memory allocateOldSpaceChunkOfBytes: sizeToAllocate.
self assert: newAddress equals: freeMultipleAddress
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testAllocateSmallerChunkShouldReusePartiallyFreeChunk [
| secondAddress newAddress |
secondAddress := memory allocateOldSpaceChunkOfBytes: 160.
memory freeChunkWithBytes: 160 at: secondAddress.
newAddress := memory allocateOldSpaceChunkOfBytes: 80.
self assert: newAddress equals: secondAddress
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testAllocatedChunkAddressesShouldBeInAllocationOrder [
| secondAddress thirdAddress |
memory allocateOldSpaceChunkOfBytes: 160.
secondAddress := memory allocateOldSpaceChunkOfBytes: 160.
thirdAddress := memory allocateOldSpaceChunkOfBytes: 160.
self assert: secondAddress < thirdAddress
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testAllocatedChunkOfMemoryShouldRemoveSpaceFromFreeList [
| freeChunkStartAddress allocatedSize |
allocatedSize := 16.
freeChunkStartAddress := self freeTreeRootStartAddress.
memory allocateOldSpaceChunkOfBytes: allocatedSize.
self
assert: self freeTreeRootStartAddress
equals: freeChunkStartAddress + allocatedSize
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testAllocatedChunkOfMemoryShouldStartWhereFreeChunkStarted [
| freeChunkStartAddressBeforeAllocation allocatedAddress |
freeChunkStartAddressBeforeAllocation := self freeTreeRootStartAddress.
allocatedAddress := memory allocateOldSpaceChunkOfBytes: 16.
self
assert: allocatedAddress
equals: freeChunkStartAddressBeforeAllocation
]
{ #category : #'tests-4-free-tree' }
VMSpurOldSpaceTest >> testAllocationLargerThanFreeListLimitShouldUseFreeTree [
| firstAddress byteSize smallerNodeOop |
byteSize := memory numFreeLists * memory allocationUnit.
firstAddress := memory allocateOldSpaceChunkOfBytes: byteSize.
memory freeChunkWithBytes: byteSize at: firstAddress.
smallerNodeOop := self smallerNodeOf: self freeTreeRootOop.
self assert: smallerNodeOop equals: firstAddress
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testAllocationShouldNotLeaveFreeChunkSmallerThanLiliputian [
| newAddress freeLargeSpaceAddressBeforeAllocation freeAddress |
freeAddress := memory allocateOldSpaceChunkOfBytes: 32.
memory freeChunkWithBytes: 32 at: freeAddress.
"Allocating 24 bytes should not reuse the 32bytes free chunk because it will leave a free chunk < 16bytes (a liliputian)"
freeLargeSpaceAddressBeforeAllocation := self freeTreeRootStartAddress.
newAddress := memory allocateOldSpaceChunkOfBytes: 24.
self assert: newAddress equals: freeLargeSpaceAddressBeforeAllocation
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testChildNodeShouldHaveRootAsParent [
| smallerChild freeTreeRoot parentNode |
memory freeChunkWithBytes: 800 at: (memory allocateOldSpaceChunkOfBytes: 800).
freeTreeRoot := memory freeLists at: 0.
smallerChild := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: freeTreeRoot.
parentNode := memory fetchPointer: memory freeChunkParentIndex ofFreeChunk: smallerChild.
self assert: parentNode equals: freeTreeRoot
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testChildSiblingNodesInFreeTreeShouldHavePrevious [
| freeTreeRoot size child1 child2 nextChildOop child3 siblingOop previousOop |
size := 800.
child1 := memory allocateOldSpaceChunkOfBytes: size.
child2 := memory allocateOldSpaceChunkOfBytes: size.
child3 := memory allocateOldSpaceChunkOfBytes: size.
memory freeChunkWithBytes: size at: child1.
memory freeChunkWithBytes: size at: child2.
memory freeChunkWithBytes: size at: child3.
freeTreeRoot := memory freeLists at: 0.
nextChildOop := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: freeTreeRoot.
previousOop := memory fetchPointer: memory freeChunkPrevIndex ofFreeChunk: nextChildOop.
self assert: previousOop equals: 0.
siblingOop := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: nextChildOop.
previousOop := memory fetchPointer: memory freeChunkPrevIndex ofFreeChunk: siblingOop.
self assert: previousOop equals: nextChildOop.
siblingOop := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: nextChildOop.
previousOop := memory fetchPointer: memory freeChunkPrevIndex ofFreeChunk: siblingOop.
self assert: previousOop equals: nextChildOop.
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testChildSiblingNodesInFreeTreeShouldNotHaveLarger [
| freeTreeRoot size child1 child2 nextChildOop child3 largerOop largerThanSmaller siblingOop |
size := 800.
child1 := memory allocateOldSpaceChunkOfBytes: size.
child2 := memory allocateOldSpaceChunkOfBytes: size.
child3 := memory allocateOldSpaceChunkOfBytes: size.
"Create a smaller than smaller chunk to check that this is not propagated to smaller siblings"
largerThanSmaller := memory allocateOldSpaceChunkOfBytes: 808.
memory freeChunkWithBytes: size at: child1.
memory freeChunkWithBytes: size at: child2.
memory freeChunkWithBytes: size at: child3.
memory freeChunkWithBytes: 808 at: largerThanSmaller.
freeTreeRoot := memory freeLists at: 0.
nextChildOop := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: freeTreeRoot.
largerOop := memory fetchPointer: memory freeChunkLargerIndex ofFreeChunk: nextChildOop.
self assert: (memory startOfObject: largerOop) equals: largerThanSmaller.
siblingOop := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: nextChildOop.
largerOop := memory fetchPointer: memory freeChunkLargerIndex ofFreeChunk: siblingOop.
self assert: largerOop equals: 0.
siblingOop := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: siblingOop.
largerOop := memory fetchPointer: memory freeChunkLargerIndex ofFreeChunk: siblingOop.
self assert: largerOop equals: 0.
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testChildSiblingNodesInFreeTreeShouldNotHaveParent [
| freeTreeRoot size child1 child2 nextChild child3 parentOop |
size := 800.
child1 := memory allocateOldSpaceChunkOfBytes: size.
child2 := memory allocateOldSpaceChunkOfBytes: size.
child3 := memory allocateOldSpaceChunkOfBytes: size.
memory freeChunkWithBytes: size at: child1.
memory freeChunkWithBytes: size at: child2.
memory freeChunkWithBytes: size at: child3.
freeTreeRoot := memory freeLists at: 0.
nextChild := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: freeTreeRoot.
parentOop := memory fetchPointer: memory freeChunkParentIndex ofFreeChunk: nextChild.
self assert: parentOop equals: freeTreeRoot.
nextChild := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: nextChild.
parentOop := memory fetchPointer: memory freeChunkParentIndex ofFreeChunk: nextChild.
self assert: parentOop equals: 0.
nextChild := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: nextChild.
parentOop := memory fetchPointer: memory freeChunkParentIndex ofFreeChunk: nextChild.
self assert: parentOop equals: 0.
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testChildSiblingNodesInFreeTreeShouldNotHaveSmaller [
| freeTreeRoot size child1 child2 nextChildOop child3 smallerOop smallerThanSmaller siblingOop |
size := 800.
child1 := memory allocateOldSpaceChunkOfBytes: size.
child2 := memory allocateOldSpaceChunkOfBytes: size.
child3 := memory allocateOldSpaceChunkOfBytes: size.
"Create a smaller than smaller chunk to check that this is not propagated to smaller siblings"
smallerThanSmaller := memory allocateOldSpaceChunkOfBytes: 792.
memory freeChunkWithBytes: size at: child1.
memory freeChunkWithBytes: size at: child2.
memory freeChunkWithBytes: size at: child3.
memory freeChunkWithBytes: 792 at: smallerThanSmaller.
freeTreeRoot := memory freeLists at: 0.
nextChildOop := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: freeTreeRoot.
smallerOop := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: nextChildOop.
self assert: (memory startOfObject: smallerOop) equals: smallerThanSmaller.
siblingOop := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: nextChildOop.
smallerOop := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: siblingOop.
self assert: smallerOop equals: 0.
siblingOop := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: siblingOop.
smallerOop := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: siblingOop.
self assert: smallerOop equals: 0.
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testDeallocateShouldNotChangeRoot [
| freeRoot address |
address := memory allocateOldSpaceChunkOfBytes: 800.
freeRoot := memory freeLists at: 0.
memory freeChunkWithBytes: 800 at: address.
self assert: freeRoot equals: (memory freeLists at: 0)
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testEqualSizeChildNodeInFreeTreeShouldBeInsertedAfterHead [
| smallerChild freeTreeRoot size child1 child2 nextChild child3 |
size := 800.
child1 := memory allocateOldSpaceChunkOfBytes: size.
child2 := memory allocateOldSpaceChunkOfBytes: size.
child3 := memory allocateOldSpaceChunkOfBytes: size.
memory freeChunkWithBytes: size at: child1.
memory freeChunkWithBytes: size at: child2.
memory freeChunkWithBytes: size at: child3.
freeTreeRoot := memory freeLists at: 0.
smallerChild := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: freeTreeRoot.
self assert: smallerChild equals: child1.
nextChild := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: child1.
self assert: nextChild equals: child3.
nextChild := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: child3.
self assert: nextChild equals: child2.
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testEqualSizeChildNodeShouldBeNextNode [
| smallerChild freeTreeRoot size child1 child2 nextChild |
size := 800.
child1 := memory allocateOldSpaceChunkOfBytes: size.
child2 := memory allocateOldSpaceChunkOfBytes: size.
memory freeChunkWithBytes: size at: child1.
memory freeChunkWithBytes: size at: child2.
freeTreeRoot := memory freeLists at: 0.
smallerChild := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: freeTreeRoot.
self assert: smallerChild equals: child1.
nextChild := memory fetchPointer: memory freeChunkNextIndex ofFreeChunk: child1.
self assert: nextChild equals: child2.
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testFalseObjectIsNotAnArray [
self deny: (memory isArray: memory falseObject).
]
{ #category : #'tests-3-free-lists' }
VMSpurOldSpaceTest >> testFreeAChunkShouldBePutAsHeadOfFreeList [
| firstAddress secondAddress freeListHead chunkSize |
chunkSize := 32.
firstAddress := memory allocateOldSpaceChunkOfBytes: chunkSize.
secondAddress := memory allocateOldSpaceChunkOfBytes: chunkSize.
memory freeChunkWithBytes: chunkSize at: firstAddress.
memory freeChunkWithBytes: chunkSize at: secondAddress.
freeListHead := self freeListForSize: chunkSize.
self assert: freeListHead equals: secondAddress
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testFreeChunkDoesNotGetMergedWithExistingFreeChunks [
| secondAddress |
secondAddress := memory allocateOldSpaceChunkOfBytes: 160.
memory freeChunkWithBytes: 160 at: secondAddress.
self assert: memory allFreeObjects size equals: 2
]
{ #category : #'tests-3-free-lists' }
VMSpurOldSpaceTest >> testFreeChunkShouldKnowNextChunkOfSameSize [
| firstAddress secondAddress freeListHead nextFreeChunk allocationSize |
allocationSize := 32.
firstAddress := memory allocateOldSpaceChunkOfBytes: allocationSize.
secondAddress := memory allocateOldSpaceChunkOfBytes: allocationSize.
memory freeChunkWithBytes: allocationSize at: firstAddress.
memory freeChunkWithBytes: allocationSize at: secondAddress.
freeListHead := self freeListForSize: allocationSize.
nextFreeChunk := self nextNodeOf: freeListHead.
self assert: nextFreeChunk equals: firstAddress
]
{ #category : #'tests-3-free-lists' }
VMSpurOldSpaceTest >> testFreeChunkShouldKnowPreviousChunkOfSameSize [
| firstAddress secondAddress freeListHead nextFreeChunk allocationSize previousFreeChunk |
allocationSize := 32.
firstAddress := memory allocateOldSpaceChunkOfBytes: allocationSize.
secondAddress := memory allocateOldSpaceChunkOfBytes: allocationSize.
memory freeChunkWithBytes: allocationSize at: firstAddress.
memory freeChunkWithBytes: allocationSize at: secondAddress.
freeListHead := self freeListForSize: allocationSize.
nextFreeChunk := self nextNodeOf: freeListHead.
previousFreeChunk := self previousNodeOf: nextFreeChunk.
self assert: previousFreeChunk equals: freeListHead
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testFreeChunksWithSameSizeShouldBeListedAsDifferentFreeChunks [
| secondAddress newAddress |
secondAddress := memory allocateOldSpaceChunkOfBytes: 160.
memory freeChunkWithBytes: 160 at: secondAddress.
newAddress := memory allocateOldSpaceChunkOfBytes: 80.
memory freeChunkWithBytes: 80 at: newAddress.
self assert: memory allFreeObjects size equals: 3
]
{ #category : #'tests-3-free-lists' }
VMSpurOldSpaceTest >> testFreeChunksWithSameSizeShouldShareSingleHead [
| secondAddress allocationSize firstAddress |
allocationSize := 32.
firstAddress := memory allocateOldSpaceChunkOfBytes: allocationSize.
secondAddress := memory allocateOldSpaceChunkOfBytes: allocationSize.
memory freeChunkWithBytes: allocationSize at: firstAddress.
memory freeChunkWithBytes: allocationSize at: secondAddress.
self assert: memory allFreeListHeads size equals: 1
]
{ #category : #'tests-3-free-lists' }
VMSpurOldSpaceTest >> testFreeListsShouldBeIndexedBySlotSize [
| firstAddress freeListHead |
2 to: memory numFreeLists - 1 do: [ :numberOfSlots | | byteSize |
byteSize := numberOfSlots * memory allocationUnit.
firstAddress := memory allocateOldSpaceChunkOfBytes: byteSize.
memory freeChunkWithBytes: byteSize at: firstAddress.
freeListHead := memory freeLists at: numberOfSlots.
self assert: freeListHead equals: firstAddress
]
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testInitialFreeListShouldBeEmpty [
2 to: memory numFreeLists - 1 do: [ :numberOfSlots |
self
assert: (memory freeLists at: numberOfSlots)
equals: 0
]
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testInitialFreeTreeRootHasNoLargerNode [
| bigChunk nextNode |
bigChunk := self freeTreeRootOop.
nextNode := self largerNodeOf: bigChunk.
self assert: nextNode equals: 0.
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testInitialFreeTreeRootHasNoNextNode [
| bigChunk nextNode |
bigChunk := self freeTreeRootOop.
nextNode := self nextNodeOf: bigChunk.
self assert: nextNode equals: 0.
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testInitialFreeTreeRootHasNoParentNode [
| bigChunk nextNode |
bigChunk := self freeTreeRootOop.
nextNode := self parentNodeOf: bigChunk.
self assert: nextNode equals: 0.
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testInitialFreeTreeRootHasNoPreviousNode [
| bigChunk nextNode |
bigChunk := self freeTreeRootOop.
nextNode := self previousNodeOf: bigChunk.
self assert: nextNode equals: 0.
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testInitialFreeTreeRootHasNoSmallerNode [
| bigChunk nextNode |
bigChunk := self freeTreeRootOop.
nextNode := self smallerNodeOf: bigChunk.
self assert: nextNode equals: 0.
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testInitialFreeTreeRootIsFreeObject [
self assert: (memory isFreeObject: self freeTreeRootOop)
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testInitialFreeTreeRootSizeShouldBeTotalFreeSpace [
self
assert: (memory bytesInObject: self freeTreeRootOop)
equals: memory totalFreeListBytes
]
{ #category : #'tests-4-free-tree' }
VMSpurOldSpaceTest >> testLargeFreeChunkInFreeTreeNodeShouldStoreChunkOop [
| firstAddress byteSize smallerNodeOop |
byteSize := 256 "large chunk min size" * memory allocationUnit.
firstAddress := memory allocateOldSpaceChunkOfBytes: byteSize.
memory freeChunkWithBytes: byteSize at: firstAddress.
smallerNodeOop := self smallerNodeOf: self freeTreeRootOop.
self assert: (memory startOfObject: smallerNodeOop) equals: firstAddress
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testNewBigFreeChunkShouldBeFreeTreeChild [
| firstAddress freeRoot rootSize moreThanHalf newRoot largerChildOop |
freeRoot := memory freeLists at: 0.
rootSize := memory bytesInObject: freeRoot.
moreThanHalf := ((rootSize / memory allocationUnit) / 2) ceiling + 1 * memory allocationUnit.
"Create a free chunk of more than half of the root, the root has changed"
firstAddress := memory allocateOldSpaceChunkOfBytes: moreThanHalf.
memory freeChunkWithBytes: moreThanHalf at: firstAddress.
newRoot := memory freeLists at: 0.
"Nodes in the free tree are organized as oops. Each oop points to the base header of the object"
largerChildOop := memory fetchPointer: memory freeChunkLargerIndex ofFreeChunk: newRoot.
"instead, the address returned by allocateOldSpaceChunkOfBytes: returns always an address, not an oop."
"To get the real address where the oop starts use #startOfObject:"
self assert: (memory startOfObject: largerChildOop) equals: firstAddress
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testNewBigFreeChunkShouldHaveRootAsParent [
| firstAddress freeRoot rootSize moreThanHalf newRoot largerChildOop parentNodeOop |
freeRoot := memory freeLists at: 0.
rootSize := memory bytesInObject: freeRoot.
moreThanHalf := ((rootSize / memory allocationUnit) / 2) ceiling + 1 * memory allocationUnit.
self assert: moreThanHalf > (rootSize / 2).
"Create a free chunk of more than half of the root, the root has changed"
firstAddress := memory allocateOldSpaceChunkOfBytes: moreThanHalf.
memory freeChunkWithBytes: moreThanHalf at: firstAddress.
newRoot := memory freeLists at: 0.
"Nodes in the free tree are organized as oops. Each oop points to the base header of the object"
largerChildOop := memory fetchPointer: memory freeChunkLargerIndex ofFreeChunk: newRoot.
parentNodeOop := memory fetchPointer: memory freeChunkParentIndex ofFreeChunk: largerChildOop.
self assert: parentNodeOop equals: newRoot
]
{ #category : #'tests-1-startup' }
VMSpurOldSpaceTest >> testNewMemoryShouldHaveSingleFreeObject [
self assert: memory allFreeObjects size equals: 1
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testNewObjectShouldBeOld [
| oop |
oop := memory allocateSlotsInOldSpace: 0 format: 0 classIndex: self zeroSizedObjectClassIndex.
self assert: (memory getMemoryMap isOldObject: oop)
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testNilObjectIsNotAnArray [
self deny: (memory isArray: memory nilObject).
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testNilObjectObjectFormatIsZero [
self assert: (memory formatOf: memory nilObject) equals: 0.
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testPartiallyReusingFreeChunkShouldKeepNumberOfEntriesInFreeList [
| secondAddress freeChunksBefore |
secondAddress := memory allocateOldSpaceChunkOfBytes: 160.
memory freeChunkWithBytes: 160 at: secondAddress.
freeChunksBefore := memory allFreeObjects size.
memory allocateOldSpaceChunkOfBytes: 80.
self assert: memory allFreeObjects size equals: freeChunksBefore.
]
{ #category : #'tests-2-allocation-basic' }
VMSpurOldSpaceTest >> testReuseFreeChunkShouldRemoveEntryFromFreeList [
| secondAddress |
secondAddress := memory allocateOldSpaceChunkOfBytes: 160.
memory freeChunkWithBytes: 160 at: secondAddress.
memory allocateOldSpaceChunkOfBytes: 160.
self assert: memory allFreeObjects size equals: 1
]
{ #category : #'tests-3-free-lists' }
VMSpurOldSpaceTest >> testSingleFreeChunkListNextShouldBeZero [
| firstAddress freeListHead allocationSize |
allocationSize := 32.
firstAddress := memory allocateOldSpaceChunkOfBytes: allocationSize.
memory freeChunkWithBytes: allocationSize at: firstAddress.
freeListHead := self freeListForSize: allocationSize.
self assert: (self nextNodeOf: freeListHead) equals: 0
]
{ #category : #'tests-3-free-lists' }
VMSpurOldSpaceTest >> testSingleFreeChunkListPreviousShouldBeZero [
| firstAddress freeListHead allocationSize |
allocationSize := 32.
firstAddress := memory allocateOldSpaceChunkOfBytes: allocationSize.
memory freeChunkWithBytes: allocationSize at: firstAddress.
freeListHead := self freeListForSize: allocationSize.
self assert: (self previousNodeOf: freeListHead) equals: 0
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testSmallerChildNodeShouldBeFreeTreeChild [
| smallerChild freeTreeRoot parentNode smallerSize rootSize |
smallerSize := 800.
rootSize := memory bytesInObject: (memory freeLists at: 0).
self assert: smallerSize < (rootSize / 2).
memory freeChunkWithBytes: smallerSize at: (memory allocateOldSpaceChunkOfBytes: smallerSize).
freeTreeRoot := memory freeLists at: 0.
smallerChild := memory fetchPointer: memory freeChunkSmallerIndex ofFreeChunk: freeTreeRoot.
parentNode := memory fetchPointer: memory freeChunkParentIndex ofFreeChunk: smallerChild.
self assert: parentNode equals: freeTreeRoot
]
{ #category : #'tests-5-allocation-strategy' }
VMSpurOldSpaceTest >> testTrueObjectIsNotAnArray [
self deny: (memory isArray: memory trueObject).
]