Implementation Details

Java on Truffle operates, like other languages implemented with Truffle, both as a native executable or on top of HotSpot (currently possible on Linux only). In the first case, when the Java on Truffle runtime is compiled to a native executable, it does not require HotSpot to run Java. However it requires a standard core Java library (the rt.jar library for Java 8 or the lib/modules file for Java 11 as well as the associated native libraries: libjava, libnio, etc.).

Java on Truffle is a minified Java VM that implements all core components of a VM including:

Java on Truffle reuses all JARs and native libraries from GraalVM. All native libraries and methods are loaded/accessed/called via Truffle Native Function Interface (JNI). JNI handles are implemented in Java on Truffle, e.g., all Truffle NFI methods only receive and return primitives. Some methods are substituted for performance, e.g., Math.sqrt, System.arraycopy, avoiding the expensive transition to native.

Some native libraries might contain static data that would conflict if were used from multiple Java on Truffle contexts or even from both Java on Truffle and Java running on HotSpot. On Linux, Java on Truffle uses the capability of Truffle NFI to try to load libraries in isolated namespaces (dlmopen). This is only available on Linux with glibc and has many limitations. This mode is not used when running in a native executable since there will be no conflict with HotSpot.

Current Limitations