0Pricing
Java Academy · Lesson

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

  1. Why FFM over JNI
  2. MemorySegment and Arena
  3. Downcall Handles
  4. Layouts and Structs
← Back to Java Academy