Cog is a virtual machine designed for Smalltalk and other similar dynamic languages. Cog builds on the Squeak virtual machine adding a stack-to-register-mapping just-in-time compiler, aggressive in-line message cacheing and effective optimization of Smalltalk’s first-class activation records. Cog is the virtual machine underlying Teleplace’s Croquet-based enterprise virtual collaboration spaces software, the fastest virtual machine for Squeak, and for Gilad Bracha’s Newspeak modular language inspired by Beta and Smalltalk. Like the original Squeak VM, Cog is implemented and developed in Smalltalk, and translated into a lower-level language to produce the production VM. Being a Smalltalk program it is a delight to develop. Cog is available under the MIT open source license and is unencumbered for commercial deployment.
Cog’s performance relative to the existing Squeak interpreter varies, depending on the benchmark chosen. As of early-2011, the Cog JIT uses strong inline cacheing techniques and stack-to-register mapping that results in a register-based calling convention for low-arity methods. Due to the complexity of the Squeak object representation it has a limited set of primitives implemented in machine code that, for example, exclude object allocation. Performance of the early-2011 JIT for the nbody, binarytrees and chameneos redux benchmarks from the computer language shootout is in the range of 4 to 6 times faster than the interpreter.
I am writing an occasional series of blog posts describing the implementation on this site. See the COG category at the left side of the page.
To start hacking Cog you’ll need to create a Squeak image with the Cog sources loaded.