{
  "id": 2539008,
  "title": "Sharing memory between processes with java.lang.foreign and jextract",
  "url": "https://urgent.news/2026/08/22/sharing-memory-between-processes-with-java-lang-foreign-and-jextract",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-22T08:23:30.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/mishmash-io/sharing-memory-between-processes-with-javalangforeign-and-jextract-ch0"
  },
  "original_language": "en",
  "account": "Java Foreign Function and Memory API (java.lang.foreign) is a tool that enables leveraging OS-specific optimizations for Java code, specifically when dealing with C/C++ preprocessor and its macros. However, writing and maintaining Java-side code can be challenging due to the complexity of these preprocessor directives. To simplify this process, jextract, a JDK tool, reads C/C++ header files and produces Java code that integrates with the original C/C++ structures seamlessly.\n\nThis article focuses on using jextract to implement a high-performance inter-process communication (IPC) mechanism called short-circuit read and write. Short-circuit I/O refers to a technique of using shared memory to bypass the normal data transfer overhead, thus providing zero-copy data locality. It is commonly employed in distributed systems, like Apache HDFS, where data locality is crucial for performance.\n\nTo implement short-circuiting in Java, the article demonstrates how to use jextract-generated code alongside OS-specific shared memory techniques. First, a shared memory object and its file descriptor are created, followed by allocating memory within the shared object. After mapping the shared memory into the process's address space, data is written and can be accessed concurrently by multiple processes. To share the memory segment with other processes, the file descriptor is passed through a Unix domain socket via a control message, allowing other processes to access the same memory directly without any network involvement, resulting in faster and more efficient data transfer.",
  "summary": "Java Foreign Function and Memory API ( java.lang.foreign ) is a powerful tool that you can use to take advantage of various OS-specific optimizations. Often though, due to high usage of the C/C++ preprocessor and its powerful macros it can be cumbersome to write and maintain the Java-side code. Help is available in the form of jextract - a JDK tool that reads C/C++ header files (*.h) and…",
  "key_points": [
    "java.lang.foreign simplifies OS-specific optimizations for Java code",
    "jextract generates Java code from C/C++ header files",
    "Short-circuit read/write uses shared memory for zero-copy data locality"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}