Version
- GraalVM for JDK 23 (Latest)
- GraalVM for JDK 24 (Early Access)
- GraalVM for JDK 21
- GraalVM for JDK 17
- Archives
- Dev Build
Interoperability with Native Code
You can use Native Image to convert Java code into a native shared library and call it from a native (C/C++) application just like any C function. There are two mechanisms for calling natively compiled Java methods:
- JNI Invocation API, an API to load the JVM into an arbitrary native application. The advantage of using JNI Invocation API is support for multiple, isolated execution environments within the same process.
- Native Image C API, an API specific to GraalVM Native Image. The advantage of using Native Image C API is that you can determine what your API will look like, but parameter and return types must be non-object types.
Related Documentation #
- Build a Native Shared Library
- Embedding Truffle Languages– a blog post by Kevin Menard where he compares both mechanisms in Native Image for exposing Java methods
- Java Native Interface (JNI) on Native Image
- JNI Invocation API
- Native Image C API