> Markdown version of [/videos/100338-native-speed-java-comfort-calling-rust-from-the-jvm-with-project-panama](https://www.wearedevelopers.com/videos/100338-native-speed-java-comfort-calling-rust-from-the-jvm-with-project-panama). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Native Speed, Java Comfort: Calling Rust from the JVM with Project Panama Ditch verbose JNI bindings forever. Project Panama transforms Java 22 into a seamless orchestrator for optimized Rust ecosystems, granting native speed without sacrificing JVM comfort. - **Speakers:** [Gonzalo Ortiz Jaureguizar](https://www.wearedevelopers.com/@gonzalo-ortiz-jaureguizar) - **Event:** World Congress 2026 Europe - **Published:** July 10, 2026 - **Duration:** 29:37 - **URL:** https://www.wearedevelopers.com/videos/100338-native-speed-java-comfort-calling-rust-from-the-jvm-with-project-panama ## Summary The JVM offers exceptional performance, but developers building data-intensive applications often need to leverage native C++ or Rust libraries for access to specialized ecosystems or precise low-level memory ergonomics. Historically, the Java Native Interface (JNI) placed a heavy burden on developers by requiring verbose, JVM-specific native glue code. With the introduction of Project Panama's Foreign Function & Memory (FFM) API in Java 22, the ecosystem gains a safe, elegant way to interact directly with standard C ABI libraries. Panama shifts the integration burden cleanly to the Java side, allowing external native Rust or C logic to remain blissfully agnostic of the calling virtual machine. Replacing Java's standard regex engine with Rust's highly optimized logic illustrates multiple core Panama integration patterns. Panama enables safe, deterministic off-heap memory management through `Arena` allocators, seamlessly empowering developers to manage stateful native objects—like a compiled regex struct—across multiple invocations without triggering excessive garbage-collection constraints or "fighting against the language." To circumvent manually calculating memory offsets when reading complex structs, engineers can chain Rust's `cbindgen` with the JDK's `jextract` tool to safely auto-generate Java bindings. Furthermore, Panama proves robust enough to pass downcode Java lambdas into native memory environments as directly executable callbacks. Despite these crucial advancements, developers shouldn't reflexively migrate logic under the strict assumption that Rust will fundamentally outperform the JVM; the Java just-in-time compiler and garbage collector are exceptionally fast "until it isn't." Instead, crossing boundaries should be strictly driven by ecosystem access. Because traversing the JVM-to-native gap inherently incurs context-switching execution costs, developers must utilize coarse-grained calls and leverage zero-copy data formats like Apache Arrow rather than constantly copying Java strings off-heap. Cross-boundary observability also has teething issues: strict JVM limits require developers to lean on tools like async-profiler over standard JFR instances, navigate disconnected logging streams, and utilize disparate debuggers. Nonetheless, Panama successfully positions Java to emulate Python's success as an easy-to-use orchestrator for highly efficient native code, enabling modern data ecosystems to natively execute complex operations with confidence. **Keywords:** project panama FFM API, calling rust from java, JNI legacy migrations, java off-heap memory arenas, jextract code generation, rust cbindgen workflows, c ABI interoperability, apache arrow zero-copy sharing, async-profiler native visibility, java native performance ergonomics, cross-runtime debugging, jvm memory boundaries ## Chapters 1. **Motivations for calling native code from Java** (02:04) — The primary reasons to bridge Java and native languages like Rust lie in ecosystems and ergonomics rather than just raw performance. 1. **Comparing JNI and Project Panama philosophies** (04:18) — JNI expects native libraries to be aware of the JVM, whereas Project Panama treats native libraries purely as uncoupled native code. 1. **Adding integers with JNI and Project Panama** (06:26) — A side-by-side comparison reveals JNI's complex native glue code against Panama's simpler native implementation but more verbose Java bindings. 1. **Processing regular expressions and passing string variables** (08:21) — Sending strings to native code requires copying UTF-8 bytes to off-heap memory so the garbage collector does not move them. 1. **Managing off-heap memory lifecycles with arenas** (11:34) — Project Panama introduces arenas to safely allocate and automatically deallocate off-heap memory blocks based on desired object lifecycles. 1. **Allocating and reusing native memory objects** (12:41) — Maintaining a persistent native handle inside an object allows reusing expensive structures like compiled regex engines without recompiling them. 1. **Returning complex structures from native code** (14:51) — Extracting multiple data points from native structs requires carefully reading and mapping raw bytes using memory slice utilities. 1. **Generating Java bindings with jextract and cbindgen** (16:58) — Tools like jextract automate the generation of tedious Panama boilerplate by reading C header files produced from Rust with cbindgen. 1. **Implementing callbacks from Rust back to Java** (18:44) — Project Panama requires registering Java methods as native-callable function pointers to allow external Rust dependencies to invoke Java logic. 1. **Performance costs of native boundary crossings** (21:31) — Crossing the barrier between Java and native code introduces latency, making batch processing or memory-sharing formats like Apache Arrow favorable. 1. **Profiling native execution calls with async-profiler** (24:40) — Native code boundaries demand specialized external profiling tools rather than standard diagnostic utilities to accurately trace execution stacks. 1. **Tooling challenges with debugging, logging, and IDEs** (25:27) — Integrating native code within Java applications complicates developer workflows by fragmenting debugging environments, logging systems, and memory metric tracking. ## Related Moments - [Exploring JVM crashes and future debugging trends](https://www.wearedevelopers.com/videos/846-debugging-unveiled-exploring-debugger-internals-and-hidden-gems) (from "Debugging Unveiled: Exploring Debugger Internals and Hidden Gems") - [Discussion on JIT memory parameters and cross-language benchmarking](https://www.wearedevelopers.com/videos/240-just-in-time-compilation-in-jvm) (from "Just-in-time Compilation in JVM") - [Evaluating performance tradeoffs between JVM and native images](https://www.wearedevelopers.com/videos/443-going-serverless-using-the-spring-framework-ecosystem) (from "Going serverless using the Spring Framework ecosystem") - [Comparing native GraalVM image throughput against traditional JVM instances](https://www.wearedevelopers.com/videos/1595-like-spring-but-faster-the-new-java-jedi) (from "Like Spring, but Faster: The new Java Jedi") - [Exploring the rising adoption and versatility of Rust](https://www.wearedevelopers.com/videos/1335-wearedevelopers-live-should-we-respect-llms-is-rust-taking-over-developers-as-content-creators-and-more) (from "WeAreDevelopers LIVE - Should We Respect LLMs? Is Rust Taking Over? Developers as Content Creators and more") - [Audience Q&A on developer advocacy and Java trends](https://www.wearedevelopers.com/videos/537-bootiful-spring-boot-3) (from "Bootiful Spring Boot 3") ## Related Articles - [Building AI Solutions with Rust and Docker](https://www.wearedevelopers.com/magazine/494-building-ai-solutions-with-rust-and-docker) - [4 reasons why you should learn Rust in 2021 – and maybe even have fun doing it](https://www.wearedevelopers.com/magazine/35-4-reasons-why-you-should-learn-rust-in-2021-and-maybe-even-have-fun-doing-it) - [Using Java 17 latest features in real world projects](https://www.wearedevelopers.com/magazine/121-using-java-17-latest-features-in-real-world-projects) - [Top in-demand programming languages to learn in 2021](https://www.wearedevelopers.com/magazine/30-top-in-demand-programming-languages-to-learn-in-2021) ## Related Jobs - [Principal Engineer - AI Search & Vector Infrastructure](https://www.wearedevelopers.com/jobs/ext/381484-principal-engineer-ai-search-vector-infrastructure) at **Redis** - [Platform Engineer - Mercury Runtime Platform](https://www.wearedevelopers.com/jobs/ext/293235-platform-engineer-mercury-runtime-platform) at **Raiffeisen Bank International AG** - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Principal Software Engineer, Identity](https://www.wearedevelopers.com/jobs/ext/1469181-principal-software-engineer-identity) at **GitHub** - [Principal Software Engineer, Database Infrastructure](https://www.wearedevelopers.com/jobs/ext/1465908-principal-software-engineer-database-infrastructure) at **GitHub** - [Senior Software Engineer, Client Apps Platform](https://www.wearedevelopers.com/jobs/ext/1773893-senior-software-engineer-client-apps-platform) at **GitHub**