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

Vincent Isambart vincent.isambart at gmail.com
Thu Dec 10 03:57:40 PST 2009


Sorry for the late reply.

> MacRuby's VM is called Roxor. Currently in the code in trunk doesn't use
> any interpreter mode; Ruby code is always compiled before is can be run.

Yes. There are plans to add a simple interpreter to be faster with simple evals. It would interpret directly the Ruby parse tree for a very restricted number of nodes. And we would fallback on the compiler for complicated code.

But I don't think it's high on Laurent's priority list.

> Compilation can be done in either JIT or AOT mode.

Yes

> (I thought there was an experimental branch that actually used LLVM's
> interpreter to speed up eval, what happened to that?)

Laurent did indeed have a version at one time using LLVM's interpreter but it has was discarded. I don't remember the exact reason, but it was probably multiple limitations in LLVM's interpreter.

> JIT mode is the default mode. A translation unit is a Ruby source file.
> As a Ruby source file gets loaded, it's first parsed by a modified parser
> taken from MRI 1.9, and turned into NODE*, pretty much the same as the
> original Ruby AST.

Yes, we try to modify the parser as little as possible.
The main modifications are for the GC. In the grammar itself, the only modification is to allow declaration of methods with keyword arguments def foo(arg1, bar: arg2); end.
There may also have been changes on MRI's parser done after we forked it that have not been put back in MacRuby yet.

> Then, RoxorCompiler will compile AST into LLVM IR,
> which is kept and JITted later on demand.
> Because in MacRuby all Ruby classes inherit from NSObject, MacRuby uses
> mechanism from the Objective-C runtime to drive the lazy compilation
> behavior: original implementations of NSObject's resolveClassMethod: and
> resolveInstanceMethod: are replaced with MacRuby's own ones, which act as
> a hook and call the JIT when method implementations are being resolved.
> For normal Ruby methods, resolveClassMethod_imp() and
> resolveInstanceMethod_imp() both call RoxorCore::resolve_method(), which
> calls RoxorCore::resolve_methods(), which calls RoxorCore::resolve_method(),
> and that'll call RoxorCore::compile() which compiles LLVM IR into native
> code.
> 
> In AOT mode, Ruby code gets parsed in Ruby AST, compiled into LLVM IR by
> RoxorAOTCompiler, and then the LLVM bitcode is dumped to a temporary file.
> The bitcode is then translated into assembly by llc, then assembled by
> invoking gcc, and then optionally linked with other stuff.

That sounds right :-)
We may one day do what llc does ourselves to compile a bit faster and reduce the size of the distribution (as LLVM is pretty big and linked statically to both macruby and llc), but well it's a very very low priority task.


More information about the MacRuby-devel mailing list