Roray FFM Utils
Off-heap memory management and FFM utilities for high-performance Java
Foundation LayerJava 25+
Overview
Roray FFM Utils is the foundation layer of the MVP.Express stack. It provides high-level, type-safe abstractions over JDK’s Foreign Function & Memory (FFM) API, enabling efficient off-heap memory management without the complexity of raw pointer manipulation.
Key Features
Off-Heap Memory Management
- Arena-based allocation with automatic cleanup
- Reference counting for shared memory segments
- Type-safe memory layouts with compile-time validation
- Zero-copy slicing for efficient buffer management
Native Syscall Bindings
- Linux io_uring support for async I/O
- Direct socket operations bypassing Java’s networking stack
- Memory-mapped file I/O with proper resource management
FFM Integration
- Clean abstractions over MemorySegment and Arena
- Structured access using MemoryLayout
- Automatic native library loading and symbol lookup
Quick Example
// Allocate off-heap memory with automatic cleanup
try
Use Cases
- Custom allocators for performance-critical applications
- Memory-mapped data structures for persistent storage
- Native library integration without JNI
- Zero-copy I/O with direct buffer management
Performance Characteristics
| Operation | Allocation | Access Overhead |
|---|---|---|
| Arena allocation | ~10ns | 0 |
| Structured read | N/A | ~2ns |
| Structured write | N/A | ~2ns |
| Slice creation | ~5ns | 0 |
Requirements
- Java 25+ with
--enable-previewand--enable-native-access - Linux 5.1+ for io_uring features (optional)
Installation
Gradle (Kotlin DSL)
dependencies {
implementation("express.mvp:roray-ffm-utils:0.1.0")
}
// Enable preview features
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(listOf("--enable-preview"))
}
tasks.withType<JavaExec> {
jvmArgs("--enable-preview", "--enable-native-access=ALL-UNNAMED")
}
Maven
express.mvp
roray-ffm-utils
0.1.0