SqueakVM specialists: how hard is it to add an extra
reference to all
objects? On Squeak level? On VM level?
I would like to hear a little more about what this 'machine' actually is. Is it a lexical closure? Would all objects need to have this 'machine' reference?
Squeak object headers are of variable size. there are 3 different sizes so it uses 2 bits in the baseHeader to define the header size. 1 word, 2 words, or 3 words are the possibilities, and the fourth value is for dead objects, I believe. Stephen added an extra word for his LOOM impl, and basically all the code that reads or writes the headers would need to be changed to deal with it.
You are correct about header sizes and bit usages. Coaxing squeak into having extra headers is straightforward, but time consuming. You'll have an additional challenge by adding a pointer field (because you'll need GC to trace it). I'd also recommend that you bone up on the InterpreterSimulator and use SystemTracer2 (on SqueakMap) for making your new images and testing your new interpreter. The InterpreterSimulator is an invaluable debugging tool.
Since it is a pointer field, I'd probably explore adding the word *below* the base header because that will be the least impact on GC...however, it's also something that I've never attempted. I have added non-pointer headers to every object above the base header and I've added the ability to insert a "state manager" between an object and its class (path of least resistance). If you added a pointer field above the base header, you're going to have to do some very tricky things with GC to get it to traverse that field (similar to the way GC currently deals with the class header).
In an ideal world, I'd move the class header below the base header, but this probably wasn't done because not every object has a class header and testing that fact on every inst var access would probably be expensive. If you eliminated compact classes, then it would make sense to move the class header below the base header (note, I have not done that in my Chango VM even though I did eliminate compact classes).
If absolutely every object is going to have this pointer and it is a pointer, I would start with a design that puts this pointer after the base header. If only some of the objects in the image will have this pointer, you might try a similar hack that I did which inserts your object between an object and its class. Finally, you can put a pointer above the header, but it's going to make for some ugly looking code in GC.
- Stephen
squeak-e@lists.squeakfoundation.org