Downcall Handles
Call native functions.
Calling Native Functions
A downcall is a call from Java down into native code. FFM represents each native function as a MethodHandle built from a Linker.
This lesson walks through finding, describing, and invoking a C function.
The Native Linker
Linker.nativeLinker() returns the linker for the running platform. It knows the C calling convention and can produce handles to native functions.
import java.lang.foreign.Linker;
public class Main {
public static void main(String[] args) {
Linker linker = Linker.nativeLinker();
System.out.println("Got native linker: " + linker);
}
}All lessons in this course
- Why FFM over JNI
- MemorySegment and Arena
- Downcall Handles
- Layouts and Structs