-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMSimulatedEnvironmentBuilder.class.st
200 lines (154 loc) · 4.87 KB
/
VMSimulatedEnvironmentBuilder.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
Class {
#name : #VMSimulatedEnvironmentBuilder,
#superclass : #Object,
#instVars : [
'interpreter',
'interpreterClass',
'initializationOptions',
'objectMemory',
'objectMemoryClass',
'wordSize',
'initialCodeSize',
'primitiveTraceLogSize',
'oldSpaceSize',
'initialAddress',
'stackSpaceSize',
'methodCacheSize',
'newSpaceSize',
'permSpaceSize',
'allocateMemory'
],
#category : #'VMMakerTests-Builders'
}
{ #category : #building }
VMSimulatedEnvironmentBuilder >> build [
self doBuildSimulator.
self doBuild
]
{ #category : #building }
VMSimulatedEnvironmentBuilder >> doBuild [
"100 k at least to put the class table in the old space.
Get total size be a multiple of 4K so Unicorn CPU emulator accepts it"
| memoryManager edenSize |
"Check #scavengerDenominator in SpurMemoryManager"
edenSize := (2 * 1024) + interpreter interpreterAllocationReserveBytes.
newSpaceSize := self roundToPageSize: (edenSize * 7 / 5).
stackSpaceSize := 9 * 4096.
methodCacheSize := 4096 * wordSize.
initialAddress := 16r1000000.
"Set it to bootstrapping to allow smaller memories"
memoryManager := MachineSimulatorMemoryManager new.
memoryManager initialAddress: initialAddress.
memoryManager wordSize: wordSize.
interpreter memoryManager: memoryManager.
objectMemory memoryManager: memoryManager.
objectMemory ensureMemoryMap.
objectMemory coInterpreter: interpreter.
(allocateMemory isNotNil and: [ allocateMemory not ])
ifTrue: [ ^ self ].
objectMemory
allocateMemoryOfSize: oldSpaceSize
newSpaceSize: newSpaceSize
stackSize: stackSpaceSize
codeSize: initialCodeSize
methodCacheSize: methodCacheSize
primitiveTraceLogSize: (self roundToPageSize: primitiveTraceLogSize)
rumpCStackSize: self rumpCStackSize
permSpaceSize: permSpaceSize.
"Set the allocated newSpaceSize"
newSpaceSize := objectMemory getMemoryMap newSpaceEnd - objectMemory getMemoryMap newSpaceStart.
objectMemory initializePostBootstrap.
objectMemory setHeapSizeAtPreviousGC.
self assert: objectMemory objectMemory scavenger eden size >= interpreter interpreterAllocationReserveBytes.
self assert: objectMemory objectMemory scavengeThreshold + interpreter interpreterAllocationReserveBytes <= objectMemory objectMemory scavenger eden limit.
objectMemory segmentManager collapseSegmentsPostSwizzle.
objectMemory segmentManager plantBridgeAtTheEndOfMemory.
objectMemory segmentManager assertBridge.
"Schedule a GC, so it does not try to schedule one"
objectMemory needGCFlag: 1.
]
{ #category : #building }
VMSimulatedEnvironmentBuilder >> doBuildSimulator [
objectMemory := objectMemoryClass simulatorClass new.
interpreterClass
initializeWithOptions: initializationOptions
objectMemoryClass: objectMemory class.
interpreter := interpreterClass basicNew
objectMemory: objectMemory;
basicInitialize.
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> initialCodeSize: anInteger [
initialCodeSize := anInteger
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> initializationOptions: aCollection [
initializationOptions := aCollection
]
{ #category : #initialization }
VMSimulatedEnvironmentBuilder >> initialize [
super initialize.
oldSpaceSize := 2048 * 1024.
permSpaceSize := 0.
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> interpreter [
^ interpreter
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> interpreterClass: aClass [
interpreterClass := aClass
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> memoryInitialAddress [
^ initialAddress
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> methodCacheSize [
^ methodCacheSize
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> newSpaceSize [
^ newSpaceSize
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> objectMemory [
^ objectMemory
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> objectMemoryClass: aClass [
objectMemoryClass := aClass
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> oldSpaceSize [
^ oldSpaceSize
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> permSpaceSize: anInteger [
permSpaceSize := anInteger
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> primitiveTraceLogSize: anInteger [
primitiveTraceLogSize := anInteger
]
{ #category : #helpers }
VMSimulatedEnvironmentBuilder >> roundToPageSize: anInteger [
"Unicorn simulator requires mapped memory to be multiple of 4096"
| pageSize remainder |
pageSize := 4096.
remainder := anInteger \\ pageSize.
remainder = 0 ifTrue: [ ^ anInteger ].
^ anInteger + (pageSize - remainder)
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> rumpCStackSize [
^ 4096.
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> stackSpaceSize [
^ stackSpaceSize
]
{ #category : #accessing }
VMSimulatedEnvironmentBuilder >> wordSize: anInteger [
wordSize := anInteger
]