Java UIO 2 is the next-generation evolution of the Java UIO project, rebuilt from the ground up to leverage the Foreign Function & Memory API (FFM). By moving beyond traditional JNI, Java UIO 2 achieves unprecedented performance and hardware-level accuracy for Linux Userspace IO. Engineered for JDK 25, it provides a cutting-edge cross-platform solution for modern embedded systems.
While the original Java UIO set the standard for JNI-based IO, Java UIO 2 moves into the future with Project Panama. By utilizing FFM (refined in JDK 25), we eliminate the JNI "tax," allowing the JVM to optimize native calls with the same efficiency as standard Java code.
sudo apt install gitcd ~/git clone --depth 1 https://github.com/sgjava/javauio2.git
cd ~/javauio2/scripts./install-java.sh./setup-permissions.sh(only required on ARM)sudo rebootcd ~/javauio2mvn clean install-P arm64(profile for aarch64)-P arm32(profile for armhf, but no runtime linker yet)
In raw performance testing on the Pine A64 (Cortex-A53), the FFM implementation demonstrated a massive leap over established JNI methods:
| Operation | HawtJNI (Legacy) | Java UIO 2 (FFM) | Improvement |
|---|---|---|---|
| GPIO Writes | ~292k ops/sec | ~561k ops/sec | +91.5% |
| GPIO Reads | ~400k ops/sec | ~582k ops/sec | +45.5% |
Note: Benchmarks were performed on single-core execution. With FFM, the Java-to-Native bridge is no longer the bottleneck; the performance limit is now defined by the Linux Kernel's ioctl latency.
Unlike other libraries that "guess" the size of C structs or use hardcoded offsets, Java UIO 2 uses a unique Native Sizer during the build process:
- Cross-Architecture Probing: Uses cross-compilers and QEMU User Emulation to probe the exact memory layout of the target architecture (ARM64, ARM32, X86_64).
- Byte-Perfect Alignment: Ensures that the MemoryLayout used in Java is identical to the C struct compiled for the target, preventing SIGSEGV and alignment issues common in cross-platform development.
Java UIO 2 is engineered for a modern dev-ops workflow. You can compile native code and generate Java bindings for ARM64 and ARM32 directly from an X86_64 workstation.
- Integrated jextract automation.
- Automated native library bundling for multiple architectures.
- Seamless integration with Project Lombok for clean, boilerplate-free code.
Java UIO 2 prioritizes the modern Linux GPIO Character Device API over the deprecated sysfs interface. This provides:
- Better performance and reduced CPU overhead.
- Precise event timestamping.
- Atomic multi-line configuration.
Java UIO 2 provides a forward-looking strategy. While FFM is our primary focus for performance, we acknowledge the current state of 32-bit tooling.
| Architecture | JNI (Java UIO) | FFM (Java UIO 2) |
|---|---|---|
| ARM32 (v7) | β Supported | β³ Pending Linker |
| ARM64 (v8) | β Supported | β Recommended |
| X86_64 | β Supported | β Recommended |
Note: As of JDK 25, X86_32 is no longer supported. Java UIO 2 focuses on high-performance 64-bit paths while maintaining a path for ARM32.
This is the beginning of the FFM-native ecosystem for Java. The core infrastructure is stable, and the following modules are currently being ported:
- β Periphery Core: GPIO, I2C, SPI, LED, PWM, and Serial.
- β u8g2: High-performance port for monochrome displays.
- Real-time Sensors: Optimized drivers for I2C/SPI sensors using zero-copy FFM memory segments.
