/ocaml

The core OCaml system: compilers, runtime system, base libraries

Primary LanguageOCamlOtherNOASSERTION

mu: An experimental JIT compiler for OCaml

Enso

Overview

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.

Platforms

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.

Maturity

mu is sufficiently robust to fully bootstrap its own OCaml environment and to pass all the tests in the OCaml test suite, except one.

Building

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.

Installing and running

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.

Studying the code

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

Contact

You can contact the author at pietro dot braione at unimib dot it.