Native Interoperability with JDK 25 and the FFM API
summary
JDK 25 ships the finalized Foreign Function & Memory API so Java can allocate and manage native memory as memory segments and free it deterministically via deterministic arenas instead of relying on JNI or ByteBuffers. Live code shows struct-like MemoryLayout, varhandles for atomic and multi‑dimensional access, zero‑length null segments, and linking native functions to Java via method handles and functional interface glue. A demo uses jextract generates ONNX bindings to call ONNX Runtime and the examples (PID, strlen, small model inference) run successfully.
AI-written summary · about
chapters (19)
- 0:00JDK 25 and FFM API intro
- 1:22Legacy memory handling issues
- 9:28Memory segments in FFM API
- 11:53Arenas for memory lifecycle
- 15:50Memory layouts and value types
- 19:01Var handles for memory access
- 23:56Mapping memory to Java objects
- 27:28Record mappers for snapshots
- 31:22Byte buffers and arrays interop
- 32:25File memory mapping with FFM
- 33:29Shared arenas and thread safety
- 35:15Multi-dimensional arrays
- 38:04Advanced memory segment ops
- 40:30Linking Java to native functions
- 42:39Java interfaces for native calls
- 45:11Automating bindings with JExtract
- 46:14FFM API benefits summary
- 47:39Live demo: ONNX sentiment analysis
- 50:30Q&A
related talks
47mInterconnecting Java and Native Code with the FFM API
16mForeign Function and Memory API
01h 01mJava Enable Preview: Foreign Function and Memory Interface
49mWhen a Java Programmer Meets C
45mProject Panama - Foreign Function & Memory API
55mJava 19 Project Panama 4 Newbies
01h 01mNative Code, Off-Heap Data and Java
55mBare metal Java
