Interconnecting Java and Native Code with the FFM API

The Java platform has always provided a rich set of libraries for developers to reach beyond the boundaries of the JVM, from databases (JDBC) to web services (HTTP client). Previously, accessing foreign memory (i.e., memory not managed by the JVM) and invoking foreign functions (i.e., code outside the JVM) in Java was hard and unsafe.

The Foreign Function & Memory Access API (FFM API), delivered in Java SE 22, reduced the impedance mismatch between Java applications and native libraries in three steps. First, the FFM API provides a rich API to model a region of off-heap memory as a memory segment. Second, the FFM API provides a rich API to describe and link native functions. Third, access to native libraries can be simplified even further with the use of a tool (jextract) that mechanically generates the FFM API artifacts needed to access said libraries.

The presentation showcases fundamental FFM principles as well as Java integration with native graphic libraries and AI frameworks.

Make sure to check the JavaOne 2025 playlist.