- Presented by: Per-Åke Minborg at JavaOne 2025, presenting Function and Memory Access in Pure Java and introducing JEP 454.
- JEP 454 Background: Evolved from JEP 393 (Foreign-Memory Access API) and JEP 389 (Foreign Linker API), designed to replace Java Native Interface (JNI) with problems like native-first model, high maintenance and deployment cost, and cumbersome data passing.
- JNI Workflow Example: Defining a native Java method with
native
modifier, generating C header file withjavac -h
, and writing the main C application. But it has issues like supporting only primitive types and Java objects, no deterministic memory free, limited addressing space, and inflexible addressing options. - Frameworks to Solve Problems: Java Native Access, Java Native Runtime, and JavaCPP but didn't gain traction. Minborg emphasized a more direct, pure Java paradigm.
Foreign Memory API:
- Accessed via
[MemorySegment](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/foreign/MemorySegment.html)
interface with size, lifetime, and thread confinement controls. [Arena](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/foreign/Arena.html)
interface for native memory segment lifecycle control (Global, Auto, Confined, Shared).[ValueLayout](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/foreign/ValueLayout.html)
interface models basic data types with carrier type, endianness, and alignment.- Examples showed memory allocation and writing with different arena types and value layouts, but manual offset computation was needed.
[MemoryLayout](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/foreign/MemoryLayout.html)
helps describe memory segment contents.
- Accessed via
- Foreign Function API: Introduced
[jextract](https://github.com/openjdk/jextract/blob/master/README.md)
, a tool to generate Java bindings from native library headers. Example called a native quick sort function. - Conclusion: FFM API provides safe and efficient native memory access, general and direct native function access with 100% Java, and the foundation of Project Panama interoperability with tools like
jextract
.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。