Skip to content

Commit

Permalink
[java-truffle] mention native images in README
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgill authored and kanaka committed Jul 11, 2021
1 parent 20b6677 commit 13bb041
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions impls/java-truffle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,3 +677,23 @@ It's also worth observing that the Truffle/GraalVM provide _other_ interesting b
that are not performance-related. I won't cover them here. I think the most interesting
non-performance benefit is the promise of interoperability with other Truffle languages.
## Bonus: AOT-compiled Mal
GraalVM can ahead-of-time compile Java into a stand-alone executable (with some caveats)
called a _native image_.
This works even for Truffle interpreters! With AOT-compiled Mal, we get all the JIT compilation
goodness of Truffle, _and_ we ditch the need for a Java runtime, **and** we skip the long JVM
start-up time! A GraalVM native image of our Mal interpreter is well suited for scripts and
command line applications.
The `make-native.sh` script can be used to compile a native image of any Mal step.
To run it, though, you'll need some additional
[prerequisites](https://www.graalvm.org/reference-manual/native-image/#prerequisites).

The `make-native.sh` script

* assumes you've already run `gradle build` to compile all Java classes
* takes as its only argument a step name, e.g. `step3_env`
** when no argument is supplied, `stepE_macros` is selected by default
* produces a `build/${STEP}` native image
8 changes: 8 additions & 0 deletions impls/java-truffle/make-native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

STEP=${1:-stepE_macros}

CP=$(gradle -q --console plain printClasspath)
native-image --macro:truffle --no-fallback --initialize-at-build-time \
-H:+TruffleCheckBlackListedMethods \
-cp "$CP" truffle.mal.$STEP build/$STEP

0 comments on commit 13bb041

Please sign in to comment.