[MacRuby-devel] Looking for info on MacRuby's JIT

Vincent Isambart vincent.isambart at gmail.com
Mon Dec 7 17:46:56 PST 2009


> Greetings. New to this list, and to MacRuby. I was just skimming over the
> source code from trunk, but wasn't able to find a document that describes
> the current design of Roxor. I only found requirements, build instructions,
> coding styles and the like.

There's currently no documentation on the inner workings of MacRuby.
Any help is welcome ;-)
Most knowledge is in the code or Laurent's head (and a bit in other
commiters' head ;-)). Feel free to ask questions on the ML, though
answers may take some time.

> The thing I find very confusing is that in vm.cpp, RoxorCore::RoxorCore(),
> there's a call to ee->DisableLazyCompilation(). This disables LLVM JIT's
> lazy compilation.

Yes I added it to be sure that LLVM does not use its lazy compilation
mechanism (that is know not to work correctly in multiple threads).
It's not needed in MacRuby because we do it our own way.

> I must have
> missed something...but if Roxor JIT compiles a method upon first invocation,
> where is this behavior implemented.

In JIT mode, the conversion of Ruby code to LLVM code (or more
strictly speaking LLVM C++ objects) is done as soon as a Ruby script
is loaded. But LLVM's optimization phase and native code generation of
a function is only done when this function is called.

The place where it's done is hard to find though: it's done using a
functionality of the Objective-C runtime: we define the
"resolveClassMethod:" and "resolveInstanceMethod:" on NSObject (in
vm.cpp, in Init_PreVM)
http://developer.apple.com/mac/library/documentation/cocoa/reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/clm/NSObject/resolveClassMethod:
There are also a few other cases where we compile a method even if
it's not called, for instance when a method is aliased or a module
included.

For blocks it's done in dispatcher.cpp, in rb_vm_prepare_block. That's
a function called just before any block is given to a function.

In AOT mode, of course, we always compile and optimize everything
(blocks and methods) beforehand.


More information about the MacRuby-devel mailing list