The OpenHFT Posix module is a zero-GC, low-latency Java façade over a portable subset of POSIX/Linux system calls, with provider fall-back to JNR, JNA or raw/reflective variants. Chronicle components rely on it for deterministic file-IO, memory-mapping and CPU-affinity operations that the JDK does not expose.
Audience: Internal, Stability: Stable
<dependency>
<groupId>net.openhft</groupId>
<artifactId>posix</artifactId>
<version>{project-version}</version>
</dependency>Simple usage:
PosixAPI posix = PosixAPI.posix();
long addr = posix.mmap(0, 4096,
MMapProt.PROT_READ_WRITE.value(),
MMapFlag.PRIVATE.value(),
fd, 0);
...
posix.munmap(addr, 4096);-
Determinism – no heap allocation on the hot path.
-
Portability – Linux/macOS/Windows support via provider auto-selection.
-
Fallback safety –
NoOpPosixAPIguarantees compilation in CI sandboxes. -
Traceability – every public constant links to POSIX-FN requirements.
| Provider | Native layer | Typical when… |
|---|---|---|
|
JNR-FFI |
Linux & x86_64/ARM, fastest syscalls |
|
JNR-FFI |
Windows equivalents (subset) |
|
JNA |
exotic/legacy platforms |
|
Reflection |
JVM ≥ 21 with |
|
— |
CI sandboxes / Graal native-image |
-Dchronicle.posix.provider= provider-name overrides the auto-choice.
| Area | Functions | Return model | Notes |
|---|---|---|---|
File-IO |
|
0 / FD / bytes |
|
Memory |
|
addr / 0 |
|
CPU-affinity |
|
0 |
portable bit-mask helpers |
Timing |
|
ns / µs |
falls back to |
# run unit tests + Checkstyle + spot-bugs
mvn -q verifyEnvironment variables:
-
POSIX_TEST_ALLOW_NATIVE– set to false in CI to forceNoOpPosixAPI. -
POSIX_SYSLOG_LEVEL– adjust logging noise during native provider load.
Why do I get PosixRuntimeException: EPERM on mlockall?
The process exceeded its RLIMIT_MEMLOCK.
On Linux:
ulimit -l unlimited # or edit /etc/security/limits.confNative provider fails to load on JDK 17+
Add JVM arg:
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED