12 Foreign Function and Memory API
The Foreign Function and Memory (FFM) API enables Java programs to interoperate with code and data outside the Java runtime. This API enables Java programs to call native libraries and process native data without the brittleness and danger of JNI. The API invokes foreign functions, code outside the JVM, and safely accesses foreign memory, memory not managed by the JVM.
Note:
This is a preview feature. A preview feature is a feature whose design, specification, and implementation are complete, but is not permanent. A preview feature may exist in a different form or not at all in future Java SE releases. To compile and run code that contains preview features, you must specify additional command-line options. See Preview Language and VM Features.For background information about the Foreign Function and Memory API, see JEP 442.
The FFM API is contained in the package java.lang.foreign.
Topics
- On-Heap and Off-Heap Memory
- Memory Segments and Arenas
- Calling a C Library Function with the Foreign Function and Memory API
- Upcalls: Passing Java Code as a Function Pointer to a Foreign Function
- Foreign Functions That Return Pointers
- Memory Layouts and Structured Access
- Checking for Native Errors Using errno
- Slicing Allocators and Slicing Memory Segments
- Restricted Methods
- Calling Native Functions with jextract