JEP-454 introduced the Foreign Function & Memory (FFM) API as a stable feature in JDK 22, offering a cleaner alternative to JNI for calling native code from Java. The article walks through three approaches: traditional JNI (requiring C headers, glue code, and manual compilation), manual Panama using MethodHandle and FunctionDescriptor, and automated binding generation via jextract. JMH benchmarks using the `pow` function from libm.so show that Panama's `invokeExact` and type-matching `invoke` paths achieve ~29.5 ns/op versus ~34.7 ns/op for JNI. Profiler analysis reveals the actual native call overhead is ~12.5 ns for Panama versus ~17.5 ns for JNI — roughly a 30% reduction. The performance gain is attributed to the JIT compiler's ability to optimize the `nep_invoker_blob` stub more aggressively than JNI's `native_wrapper`.
Sort: