mu is an implementation of a template JIT compiler integrated in the OCaml interpreter. It aims at showing that an (almost) zero-assembly approach to equipping language interpreters with simple but useful JIT compilers is feasible and desirable. mu is a proof-of-concept and is not meant for production use.
mu currently works only on Ubuntu Linux 22.04 LTS. It works both on the x86_64 and on the aarch64 versions of the operating system. It compiles with gcc and clang.
mu is sufficiently robust to fully bootstrap its own OCaml environment and to pass all the tests in the OCaml test suite, except one.
mu comes as a modified version of the OCaml environment version 4.05.0. Building mu is just a matter of
$ ./configure $ make world.opt
This will build the whole OCaml environment, including the modified ocamlrun interpreter, that contains the JIT compiler.
We do not advise to install mu on your production machine, but instead to run it from its build directory. Supposing that this is, for instance, /home/me/ocaml, you can compile an OCaml source, say fibonacci.ml, and run it as follows:
$ /home/me/ocaml/boot/ocamlrun /home/me/ocaml/boot/ocamlc -nostdlib -I /home/me/ocaml/stdlib ... fibonacci.ml $ /home/me/ocaml/boot/ocamlrun a.out
If you want to run the interpreter alone (i.e., disable the JIT compiler) ocamlrun supports a -nojit option.
If you are interested in studying the code, most of the fun happens in the following files:
-
byterun/interp.c
-
byterun/jit.c
-
byterun/startup.c