forked from pharo-project/pharo-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
158 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
smalltalksrc/VMMakerTests/VMSimulatedEnvironmentBuilder.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
Class { | ||
#name : #VMSimulatedEnvironmentBuilder, | ||
#superclass : #Object, | ||
#instVars : [ | ||
'interpreter', | ||
'interpreterClass', | ||
'initializationOptions', | ||
'objectMemory', | ||
'objectMemoryClass', | ||
'wordSize', | ||
'initialCodeSize', | ||
'primitiveTraceLogSize' | ||
], | ||
#category : #'VMMakerTests-Builders' | ||
} | ||
|
||
{ #category : #building } | ||
VMSimulatedEnvironmentBuilder >> build [ | ||
|
||
objectMemory := objectMemoryClass simulatorClass new. | ||
|
||
interpreterClass | ||
initializeWithOptions: initializationOptions | ||
objectMemoryClass: objectMemory class. | ||
|
||
interpreter := interpreterClass basicNew | ||
objectMemory: objectMemory; | ||
basicInitialize. | ||
|
||
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" | ||
| oldSpaceSize newSpaceSize stackSpaceSize methodCacheSize rumpCStackSize initialAddress memoryManager edenSize | | ||
oldSpaceSize := 2048 * 1024. | ||
|
||
"Check #scavengerDenominator in SpurMemoryManager" | ||
edenSize := 2 * 1024 + interpreter interpreterAllocationReserveBytes. | ||
newSpaceSize := self roundToPageSize: (edenSize * 7 / 5). | ||
stackSpaceSize := 9 * 4096. | ||
methodCacheSize := 4096 * wordSize. | ||
rumpCStackSize := 0. | ||
|
||
initialAddress := 16r1000000. | ||
|
||
"Set it to bootstrapping to allow smaller memories" | ||
memoryManager := MachineSimulatorMemoryManager new. | ||
memoryManager initialAddress: initialAddress. | ||
memoryManager wordSize: wordSize. | ||
|
||
interpreter memoryManager: memoryManager. | ||
objectMemory createMemoryMap. | ||
|
||
objectMemory memoryManager: memoryManager. | ||
objectMemory coInterpreter: interpreter. | ||
|
||
objectMemory | ||
allocateMemoryOfSize: oldSpaceSize | ||
newSpaceSize: newSpaceSize | ||
stackSize: stackSpaceSize | ||
codeSize: initialCodeSize | ||
methodCacheSize: methodCacheSize | ||
primitiveTraceLogSize: (self roundToPageSize: primitiveTraceLogSize) | ||
rumpCStackSize: rumpCStackSize | ||
initialAddress: initialAddress. | ||
|
||
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 : #accessing } | ||
VMSimulatedEnvironmentBuilder >> initialCodeSize: anInteger [ | ||
initialCodeSize := anInteger | ||
] | ||
|
||
{ #category : #accessing } | ||
VMSimulatedEnvironmentBuilder >> initializationOptions: aCollection [ | ||
initializationOptions := aCollection | ||
] | ||
|
||
{ #category : #accessing } | ||
VMSimulatedEnvironmentBuilder >> interpreter [ | ||
^ interpreter | ||
] | ||
|
||
{ #category : #accessing } | ||
VMSimulatedEnvironmentBuilder >> interpreterClass: aClass [ | ||
interpreterClass := aClass | ||
] | ||
|
||
{ #category : #accessing } | ||
VMSimulatedEnvironmentBuilder >> objectMemory [ | ||
^ objectMemory | ||
] | ||
|
||
{ #category : #accessing } | ||
VMSimulatedEnvironmentBuilder >> objectMemoryClass: aClass [ | ||
objectMemoryClass := aClass | ||
] | ||
|
||
{ #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 >> wordSize: anInteger [ | ||
wordSize := anInteger | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters