Klein Metacircular Virtual Machine Kit

Adam Spitz, Alex Ausch, and David Ungar

What is this?

Klein is (or will be, someday, hopefully) a virtual machine for the Self language, written entirely in Self, and a development environment for that VM. (The project is named after the Klein bottle.)

How to download and build Klein

What's done and what's not yet done

Why build a VM this way?

For a more thorough description of the principles behind Klein, see our OOPSLA 2005 paper, "Constructing a Metacircular Virtual Machine in an Exploratory Programming Environment". There are also a few posts about Klein on the Self blog.

In constructing Klein, we have attempted to adhere to various principles, including object-orientation, metacircularity, heavy code reuse, reactiveness, and mirror-based reflection. We expect these principles to yield many benefits, including:

  • A simpler, more malleable VM (because it is written almost entirely in a high-level language).
  • Less replicated code (because the VM and the applications running on top of it are written in the same language and can share code, as can the VM and its development environment).
  • Better performance (because the VM will be able to do optimizations across the entire code base, including the VM code itself - imagine being able to inline the hotspots of the VM right up into an application).
  • Faster turnaround when making changes to the VM (because the VM will no longer be tied to C++ and its compilation system).


June 22, 2009: Inlining compiler progress

I've written an inlining compiler (which was a lot of fun! I'd never done that before), and it seems to work correctly. I'm already using it statically to inline a (hard-coded) list of some of the most frequent message-sends. The GC and the compiler run significantly faster now (though still not fast - there's a lot more performance work left to be done).

Between inlining and lazy primitive-failblock creation, Klein is cloning way fewer blocks than it used to, which is nice.

I also hooked up the compiler so that it runs dynamically when it encounters an uncompiled method. So the time to build the Klein bootstrap image (which is mostly spent compiling) shouldn't grow any more, and we might even be able to shrink it (because there are a lot of uninvoked nmethods). That's a very good thing, because the build time has gotten way out of hand - it's up to about 40 minutes on my machine, which is very frustrating.

The next step that I want to take is to get the compiler to dynamically recompile hotspots at runtime. But probably the next step that I should take is to figure out a way to avoid precompiling all those uninvoked nmethods. Anybody out there feel like doing the cool dynamic-recompilation work while I do the boring build-time-optimization work? :)

-- Adam

April 6, 2009: First GC test case passes

It's been a while since I've done any work on Klein, but I took a couple of weeks to play around with it, and I think I just got the garbage collector to pass its first couple of test cases.

I haven't done any fancy tests yet; all I did to test it was shrink edenSpace, so that the the tests would run out of memory partway through, plus I added a test that creates a bunch of large garbage objects (more than twice as many as will fit into edenSpace). The tests run to completion (invoking the GC several times along the way).

It's not well-tested, it's not pretty, and it's certainly not fast. (On my machine, the GC pauses are on the order of ten minutes for a 16 MB edenSpace. Most of that time is spent recycling the dead OIDs.) And the collector is just a simple scavenger - it doesn't do anything except copy the live objects from edenSpace up to tenuredSpace (and there's no collector yet for tenuredSpace).

But still, I'm excited. :)

-- Adam

August 14, 2006: Version 0.1 released

The Klein project hasn't been active at Sun since late 2005, and it was looking like Sun had no further interest in funding it, so we asked for permission to open-source it.

There is a lot of work left to be done before Klein will be a usable VM for Self. For example, garbage collection has not been implemented yet. Also, the VM runs very, very slowly - we have put almost no effort into optimizing the generated code. And so far, the VM runs only on the PowerPC architecture (though the development environment can be run on any system that runs Self). This release is not intended to be used as a practical VM; our hope is that it will be of interest to people who are interested in developing metacircular virtual machines for dynamic object-oriented languages.

-- David, Adam, and Alex

Get Klein at SourceForge.net. Fast, secure and Free Open Source software downloads