Simulation Environment - pharo-project/pharo-vm GitHub Wiki
The VM simulation environment, described in two decades of smalltalk vm development and Cross-ISA Testing of the Pharo VM: Lessons Learned While Porting to ARMv8 can be obtained in many different ways.
The VM simulation environment can help during the VM development on two aspects
- 1- mere interpretation of an image execution.
- 2- test execution.
The raw interpretation of a Pharo image (1 above) is powerful but you will quickly face problems for example executing FFI calls. This solution works if you succeed to get an image saved just a few messages before the point you want to explore.
The execution of tests (2 above) is much more reliable and this is our suggested approach. There the similation environment is managed by the tests and in general you do not have to fight with Pharo runtime configuration to get the tests executed.
Dependencies
The current simulation environment and VM generator runs on top in Pharo 12. If you're not interested on working in JIT simulation, a standard Pharo development environment is enough.
If you're interested on JIT simulation, you will need to install
-
the LLVM disassembler. Just get it from your friend package manager. On mac this is
brew install llvm. -
the Unicorn machine code simulation library. To install this library, go to https://github.com/pharo-project/unicorn/tree/pharo-vm-unicorn2 (pay attention to the branch) and follow the build instructions (usually boiled down to a
make install).
git clone
git co pharo-vm-unicorn2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make install
Testing your configuration
Now you can execute the VMMaker image and check that one JIT test is working.
./build/build/dist/Pharo.app/Contents/MacOS/Pharo ./build/build/vmmaker/image/VMMaker.image --interactive --no-default-preferences
Pick for example testUnAlignedStackWriteShouldGenerateError and it should be green.
Building from the VM git repository
If you're starting from a clone of of the VM git repository, one possibility is to create a simulator environment by using our automated CMake process. Basically you will build the image of the simulation (the same as the vm generator).
$ cmake -B /path/to/build/directory -S /path/to/git/repo
$ cmake --build /path/to/build/directory --target vmmaker
That will create an image with the simulation environment on /path/to/build/directory/build/vmmaker/image and download in /path/to/build/directory/build/vmmaker/vm a virtual machine with the corresponding version.
Starting from a normal Pharo image
An alternative approach, when starting from a standard Pharo image, is to load the vm git repository inside Pharo through Iceberg.
This can be done either by cloning or by importing an already cloned repository.
Then, the BaselineOfVMMaker should be installed through Metacello.
Launching the Simulator
The simulator can be launched through the following scripts. It can be parameterized with the word size, class to use as memory manager, set of bytecodes, and then the image to be launched.
Launching the Stack Interpreter Simulator
The following script launches the non-JIT simulation currently implemented by StackInterpreterSimulator.
Notice that you may face rapidly an error because the image startup will invoke many C function.
You can, for example, disable the InternetConfiguration and the FreeTypeSetting startUp methods.
An alternative is to save the image in a way that the startUp methods are not invoked.
But this shows that the process can require a lot of tweaks and energy.
| options stackInterpreterSimulator |
VMStackPages initialize.
options := {
#ObjectMemory -> #Spur64BitCoMemoryManager.
#BytesPerWord -> 8
} asDictionary.
stackInterpreterSimulator := StackInterpreterSimulator newWithOptions: options.
stackInterpreterSimulator openOn: Smalltalk imagePath extraMemory: 100000.
stackInterpreterSimulator run.
Launching the Cog VM Simulator
The followin script launches the JIT simulation implemented in CogVMSimulator.
| options cogVMSimulator |
VMStackPages initialize.
options := {
#COGVM -> true.
#ObjectMemory -> #Spur64BitCoMemoryManager.
#ISA -> #aarch64.
#BytesPerWord -> 8
} asDictionary.
cogVMSimulator := CogVMSimulator newWithOptions: options.
cogVMSimulator openOn: Smalltalk imagePath extraMemory: 100000.
cogVMSimulator run.