Truffle AOT Tutorial

Many statically compiled languages, like C are designed to be compilable without prior execution. By default, Truffle first interprets code before it is compiled. In order to improve warmup speed of static languages AOT compilation can be supported. The following tutorial describes how to support Truffle AOT in your language, how to trigger and test it.

Language Support

In order for languages to support AOT compilation the language needs to implement the RootNode.prepareForAOT() method. The language implementation can indicate support for AOT by returning a non null value in this method. The goal for implementing a root node for AOT is to prepare all the AST nodes such that they no longer deoptimize when they are compiled without prior execution.

Typical actions performed in an implementation of this method are:

Trigger AOT compilation

AOT compilation can be triggered and tested by using the --engine.CompileAOTOnCreate=true option. This will trigger AOT compilation for every created call target with a root node that supports AOT compilation. A root node supports AOT compilation if it returns a non null value in RootNode.prepareForAOT(). Note that enabling this flag will also disable background compilation which makes it not suitable for production usage.

Example Usage

Use the following documented and executable Truffle language as inspiration for AOT support: AOT Tutorial

The example is executable as mx unittest using mx unittest AOTTutorial.