Last updated at 8:23 am UTC on 13 February 2020
VMMaker comes with a built-in simulator for live testing and debugging of VM code in both little-endian or big-endian modes. The code may be found in:
The simulator works either in command line (aka reader) or in a Morphic Window. When running in a Morphic window, a tiny rectangle flashes at the top right corner to indicate that the simulation is on and waiting. The bottom left panel acts as a logger and the bottom right panel displays a synthetic timer tick. It also throws up the debugger menu on right click. This menu may be used to switch the log from bottom left panel to Transcript and vice versa, examine stack frames, methods and oop and so on.
- VMMaker-InterpreterSimulation - simulates Interpreter and StackInterpreter
- VMMaker-JITSimulation - simulates CoInterpreter and handles methods may have been compiled with JIT compiler (Cogit)
Simulating a VM session
The Morphic mode is very slow but it allows high-level development of VM. There are many ways of coping with the slowness of simulation
- Write code to save the image and follow it up with the test code. Run this using a single doIt. When the image is resumed, the test code will run and can be debugged.
- Save the image running the simulator after having reached some point, such as the start of a garbage collection. You can then rerun the code under test by reloading the image and resuming the simulation.
- You can clone a copy of the simulation to try something that may crash. If the clone does crash, you can revert to the parent.
- Use reader image (aka REPL mode) while working on primitives, optimizations which don't require graphical interactions.
Building Images for Simulation
The image/ subdirectory of opensmalltalk source distribution contains different build scripts to build a development image. The script will download the latest Squeak version (trunk), install VMMaker and associated packages and generate a development image. The reader image uses the command line as console while the vmmaker images using Morphic window and menus.
The Morphic development image contains a VM Simulation Workspace contains numerous examples of simulations of StackInterpreter or Cog VMs.
Working with Reader image
For testing the core classes, one can launch the reader image in headless mode. Input is read in chunk format. Results and debug logs are printed on the same console. Here are some examples:
Smalltalk quitPrimitive !
Smalltalk snapshot: true andQuit: true !
Smalltalk globals !
Symbol class superclass !
Smalltalk class methodDict keys !
Time millisecondsToRun: [Object allSubInstances size ] !
[Integer respondsTo: #factorial ] bench !
Constraints and Workaround
Cog can simuate 6505 images and some 6504 images, but it cannot simulate 6502 images. To workaround this constraint, one can open these images in Cog and save the image. The newly saved image will be in 6505 format and can be simulated in Cog.
- Sista VM Live Debugging in a Simulator
- Simulating the Cog VM