-
Notifications
You must be signed in to change notification settings - Fork 71
/
VMImageReadingTest.class.st
203 lines (133 loc) · 5.76 KB
/
VMImageReadingTest.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
Class {
#name : #VMImageReadingTest,
#superclass : #VMAbstractImageFormatTest,
#instVars : [
'originalNilObjectIdentityHash',
'permanentObject',
'originalPermanentObjectIdentityHash'
],
#category : #'VMMakerTests-ImageFormat'
}
{ #category : #query }
VMImageReadingTest >> dataFrom: fileName [
^ self imageFileName asFileReference / fileName
]
{ #category : #accessing }
VMImageReadingTest >> initializationOptions [
^ super initializationOptions , { #CloneOnGC. false. #CloneOnScavenge. false }
]
{ #category : #utilities }
VMImageReadingTest >> loadImage [
environmentBuilder := VMSimulatedEnvironmentBuilder new.
environmentBuilder
interpreterClass: self interpreterClass;
objectMemoryClass: self memoryClass;
initializationOptions: self initializationOptions;
wordSize: self wordSize.
environmentBuilder doBuildSimulator.
interpreter := environmentBuilder interpreter.
memory := environmentBuilder objectMemory.
interpreter openOn: self imageFileName extraMemory: 0.
]
{ #category : #query }
VMImageReadingTest >> metadataFrom: fileName [
| writtenHeader |
writtenHeader := (self imageFileName asFileReference / fileName) contents.
^ STON fromString: writtenHeader
]
{ #category : #utilities }
VMImageReadingTest >> saveImage [
memory garbageCollectForSnapshot.
self assert: interpreter successful.
super saveImage.
memory postSnapshot.
]
{ #category : #initialization }
VMImageReadingTest >> setUp [
super setUp.
"ByteArrayClass is asserted while loading image"
memory classByteArray: (self newClassInOldSpaceWithSlots: 0 instSpec: (memory byteFormatForNumBytes: 0)).
memory ensureBehaviorHash: memory classByteArray.
originalNilObjectIdentityHash := memory hashBitsOf: memory nilObject.
]
{ #category : #tests }
VMImageReadingTest >> testMovingObjectsToPermSpaceReduceOldSpace [
| obj magicNumber initSegmentSize initPermSpaceSize finalSegmentSize finalPermSpaceSize |
imageReaderClass ~= ComposedImageReader ifTrue: [ ^ self skip ].
magicNumber := 77.
obj := self newOldSpaceArrayWithSlots: magicNumber.
memory splObj: 4 put: obj. "Store object in SpecialObjects Array to keep it"
self saveImage.
memory allOldSpaceObjectsDo: [ :oop | "Remap"
(memory numSlotsOf: oop) = magicNumber ifTrue: [ obj := oop ] ].
initSegmentSize := (self dataFrom: 'seg0.data') size.
initPermSpaceSize := (self dataFrom: 'permSpace.data') size.
self assert: initSegmentSize > 0.
self assert: initPermSpaceSize equals: 0.
self assert: (self metadataFrom: 'seg0.ston') dataSize equals: initSegmentSize.
self assert: (self metadataFrom: 'permSpace.ston') dataSize equals: initPermSpaceSize.
"------------------------------------------------------------------------------"
self assert: (memory numSlotsOf: obj) equals: 77.
memory moveToPermSpace: obj.
self saveImage.
finalSegmentSize := (self dataFrom: 'seg0.data') size.
finalPermSpaceSize := (self dataFrom: 'permSpace.data') size.
self assert: finalPermSpaceSize < initSegmentSize.
self assert: finalPermSpaceSize > 0.
self assert: (self metadataFrom: 'seg0.ston') dataSize equals: finalSegmentSize.
self assert: (self metadataFrom: 'permSpace.ston') dataSize equals: finalPermSpaceSize
]
{ #category : #tests }
VMImageReadingTest >> testReadingSTONHeader [
| headerStruct headerFile |
imageReaderClass ~= ComposedImageReader ifTrue: [ ^ self skip ].
self saveImage.
headerStruct := SpurImageHeaderStruct new.
headerFile := (self imageFileName asFileReference / 'header.ston') readStream.
imageReader readSTONFrom: headerFile into: headerStruct .
headerFile position: 0.
self assert: (self stonPretty: headerStruct) equals: headerFile contents.
]
{ #category : #tests }
VMImageReadingTest >> testSavedImageSavesObjectFromOldSpace [
self saveImage.
self loadImage.
self assert: originalNilObjectIdentityHash equals: (memory hashBitsOf: memory nilObject).
]
{ #category : #tests }
VMImageReadingTest >> testSavedImageSavesObjectFromPermanentSpace [
"Only valid in the new format"
imageWriterClass = SpurImageWriter ifTrue: [ ^ self skip ].
permanentObject := self newPermanentByteObjectOfSize: 14.
originalPermanentObjectIdentityHash := memory hashBitsOf: permanentObject.
self saveImage.
self loadImage.
self assert: originalPermanentObjectIdentityHash equals: (memory hashBitsOf: permanentObject).
]
{ #category : #tests }
VMImageReadingTest >> testSavingImageWithThreeSegmentsIsCorrectlySqueezed [
| firstNewSegmentSize secondNewSegmentSize obj newObj originalObjHash |
firstNewSegmentSize := memory growOldSpaceByAtLeast: 12 * 1024.
secondNewSegmentSize := memory growOldSpaceByAtLeast: 12 * 1024.
self assert: memory segmentManager numSegments equals: 3.
self assert: (memory segmentManager segments at: 1) segSize equals: firstNewSegmentSize.
self assert: (memory segmentManager segments at: 2) segSize equals: secondNewSegmentSize.
obj := self newOldSpaceObjectWithSlots: (firstNewSegmentSize / 2) // memory wordSize.
memory splObj: 4 put: obj. "Store object in SpecialObjects Array to keep it"
originalObjHash := memory hashBitsOf: obj.
"Ensure the object is created in the last segment".
self assert: obj > (memory segmentManager segments at: 2) segStart.
self assert: obj < (memory segmentManager segments at: 2) segLimit.
self saveImage.
self loadImage.
self assert: memory segmentManager numSegments equals: 1.
newObj := memory splObj: 4.
self assert: originalObjHash equals: (memory hashBitsOf: newObj).
]
{ #category : #tests }
VMImageReadingTest >> testSavingPermanentSpaceObjectsInSpurFormatFails [
imageWriterClass = SpurImageWriter ifFalse: [ ^ self skip ].
permanentObject := self newPermanentByteObjectOfSize: 14.
originalPermanentObjectIdentityHash := memory hashBitsOf: permanentObject.
self should: [ self saveImage ] raise: PrimitiveFailed
]