I never actually wanted to be a VM guy.
I fell in love with Smalltalk because it was simple and powerful and it fit the way I thought. (Later I fell in love with Self because it was even more so. ;)) The languages that I like best are the ones that are designed for human beings (rather than for computers or drones or mathematicians).
But every so often I have a language idea I’d like to try out – and to do that, it helps to be able to tinker with VMs. Unfortunately, VMs these days tend to be written in languages like C – and thanks to all the cool optimization technologies needed to make a language like Self run fast, they tend to be fairly hefty chunks of C, too. The Self VM is over 100,000 lines of C++, and I’m kinda scared of it.
So I dream of having a VM that’s simple and malleable and debuggable and written in a high-level language, but also includes enough Self-style optimization technology that it can make a really pure OO language run well. That’s one of the reasons why I was so excited about Klein – one of our goals was to produce a VM like that, written almost entirely in full object-oriented Self, and a VM-development environment that’s as comfortable and interactive as a regular Self or Smalltalk application-development environment. (So far, it seems to me like the “fully OO” part has been working out pretty well, but the interactiveness part has proven to be a major challenge – the project is still plagued by long compile times. I think it’s solvable, though.)
There hasn’t been any serious work done on Klein since Sun cancelled the project back in late 2005, but I pulled out the code a few months ago and started spending my spare time working on it. There’s nothing in there really worth seeing yet – I’m still working out the bugs in the inlining compiler that I just wrote, so everything’s kinda broken right now. (I’m hoping to have the inlining compiler working dynamically soon, though, at which point it’ll be interesting to see how much of a difference it makes, since practically everything in Klein, right down to the innermost loops of the GC, is written in an OO style with lots of message sends.) But one of the reasons I’m writing this post is because I’m wondering whether there’s anybody out there who feels like doing some hacking on Klein – there’s lots of fun stuff to be done, and I’d welcome the help.
I’m also wondering whether there’s another VM out there that’s further along towards fulfilling Klein’s goals. (I haven’t been keeping up with the VM world over the past few years.) Maybe Exupery?
And my third wondering is whether there’d be interest in Klein outside the Self community. If Klein ever does become a usable Self VM, it ought to be usable for other OO languages too, especially Smalltalk. If there was interest in the Smalltalk community in having a Klein-style VM, I’d make it a higher priority to teach Klein to handle non-LIFO blocks, which was one of the main obstacles preventing Mario Wolczko’s Smalltalk-to-Self translator from being a production-ready Smalltalk. (Sometimes I think about doing that for the current Self VM, just because I envy the size of the Smalltalk community – it’d be nice to be able to use Smalltalk libraries inside Self. Plus it might be kinda fun to work in a system with Smalltalk objects and Self objects living side-by-side – though the purist in me thinks it’d be a shame to complexify Self with all those unnecessary “class” things. 😉 But that’s a topic for another blog post.)
Anyway, that’s what’s going on with Klein these days. I’m not sure whether it’s worth pursuing or not. Working on the GC and the inlining compiler has been kinda fun (turns out that being a VM guy isn’t so bad after all), but I’m more likely to keep going with it if I know that people are actually interested in it.
Slate has an SSA-based instruction set VM now, and some primitive inlining setup along with generational GC. Maybe now is the time that we should collaborate further, since Slate and Self aren’t that far apart.
Yeah, I’d love to have a Klein that can run Slate, or a Slate that’s built like Klein. 🙂 I’d better read the PMD papers again, but maybe you can quickly refresh my memory: How much complexity does multiple dispatch add to the VM, and does it impose any significant runtime overhead on code that only uses single dispatch? If it’s not much, then it sounds like it’d be something that I’d like to have in a general dynamic-OO-language VM.
Blog comments are not the best place for deep technical discussions, but it is relatively easy to extend a Self VM to handle multiple dispatch in the Slate style. This is possible because Slate doesn’t allow generic functions (where none of the arguments have their types defined) and uses argument order to select among alternative implementations.
In a way, Self already uses multiple dispatch thanks to “code splitting” (not sure if recent compiler still implement this). Any method with an argument that mostly just send another message to that argument will get compiled into a switch/case with the bodies depending on both the type of the receiver and of the argument.
One thing that would make Klein more approachable would be to divide it into smaller packages. When I looked at the sources there seemed to be a mix of different experiments and of hand crafted code with generated stuff.
Eliot Miranda is currently working on adding adaptive compilation to Squeak (I think – he is doing at least dynamic compilation):
http://www.mirandabanda.org/cogblog/
I described my interest in a Klein-like system back in 1999:
http://www.merlintec.com/vmworkshop99/jecel.txt
Any work in this area is still something I am very interested in.
Yeah, it’s true – there’s a fair amount of cleanup work to be done on Klein. 🙂 I’ll do that once I get this new compiler working.
I’d better take a closer look at Cog – thanks!
Your work is appreciated. I’m not a VM guy either, and quite a bit of that is the N,000+ lines of C that goes with most VM’s. Anything that makes the VM more accessible is great.
Thanks again for the work.
Adam, I’m so pleased that you are interested on working on Klein! Please keep me posted on the inlining compiler! Have fun!!
I am no VM guy but wouldn’t something like pypy be a route to go for a vm.
PyPy is the most ambitious project out there in that it tries to use partial evaluation as a general framework for the kinds of optimizations Self does “manually”.
If they can pull it off, then all kinds of interesting things will become possible. Meanwhile, there is plenty of room for “plain” reflective systems like Klein.
Check out Newspeak (newspeaklanguage.org)
I’ve been playing around with metacircular implementations of JavaScript at http://cscott.net/Projects/TurtleScript/