java-ffm

Review Java 26 FFM bindings for ABI accuracy and arena lifetimes.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/bugabinga/pi-ext --skill java-ffm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: java-ffm
Source: https://github.com/bugabinga/pi-ext/tree/main/skills/java-ffm
Command: npx skills add https://github.com/bugabinga/pi-ext --skill java-ffm

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you write and review Java code that uses the Java 26 Foreign Function & Memory API (FFM) correctly and safely, so you avoid JVM crashes and subtle ABI/lifetime bugs when calling native C libraries or passing pointers and callbacks.

Core Features & Use Cases

  • Native calling and binding review: Verify C ABI/platform details, exact function signatures, library lookup choices, and error conventions before downcalls.
  • Correct off-heap memory modeling: Use arenas, memory segments, and explicit MemoryLayout/ValueLayout/FunctionDescriptor definitions to prevent wrong-size and out-of-bounds access.
  • Pointer and callback correctness: Distinguish returned pointers vs pointer out-parameters (e.g., T**), and ensure upcall stubs and arenas have lifetimes compatible with native usage.

Quick Start

Use the java-ffm skill while reviewing your Java FFM bindings and ask it to sanity-check your downcall descriptors, pointer handling, and arena lifetimes for the target native function.

Frequently Asked Questions about java-ffm

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call native C functions from Java using the Foreign Function & Memory API?

To call native C functions from Java using the Foreign Function & Memory API, define ABI-accurate FunctionDescriptors and use arenas for downcalls, ensuring safe native memory access and correct lifetime management.

What is the correct way to model C structs and arrays in Java FFM?

Modeling C structs and arrays in Java FFM requires explicit MemoryLayout and ValueLayout definitions, which prevents wrong-size and out-of-bounds access when exchanging native memory with Java.

How do I handle T* and T** pointer semantics in Java native memory access?

Handling T* and T** pointer semantics in Java native memory access involves distinguishing returned pointers from pointer out-parameters, ensuring arenas and upcall stubs have compatible lifetimes with native usage.

How do I create safe upcalls via function pointers in Java 26?

Creating safe upcalls via function pointers in Java 26 requires ensuring upcall stubs and their associated arenas have lifetimes compatible with the target native usage to prevent JVM crashes.

Why does my Java FFM downcall crash the JVM?

Java FFM downcalls crash the JVM due to subtle ABI bugs, wrong-size memory access, or mismatched arena lifetimes, requiring reference-backed safety checks and exact function signatures to prevent.

Can I use jextract to generate Java bindings for C libraries?

Using jextract to generate Java bindings for C libraries helps verify C ABI and platform details, but you still need explicit FunctionDescriptors and careful arena ownership for safe native access.