Repository navigation
Share the POSIX libc bindings across the UNIX FFM classes - #3565
Conversation
Five of the six *LibcFunctions classes carried byte-identical bindings for getpid, getrlimit with its struct layout and both accessors, and gethostname. Verified identical rather than merely similarly named: the AIX and Solaris blocks diff clean against each other, and OpenBSD differs only by not binding gethostname. They now live in PosixLibcFunctions, which the five extend. Java statics are inherited by name, so all 22 call sites compile unchanged. The class is named for its membership rule rather than its members. Handles resolve with findOrThrow in a static initializer, so a symbol missing on one platform raises ExceptionInInitializerError there and takes the rest of the class with it. POSIX-mandated is what guarantees the symbol exists everywhere, which makes it the criterion for belonging rather than a matter of taste. getloadavg is the counterexample and stays per-platform. It looks like a peer of these and four of the six bind it, but it is a BSD extension rather than POSIX and AIX does not have it -- AIX reads load average from perfstat_cpu_total. Hoisting it would have broken AIX at class load, on a platform that never asks for it. A BsdLibcFunctions tier to hold it was considered and rejected: it would hold exactly one member, and the shareable set does not otherwise cluster by family, since AIX and Solaris are identical to the BSDs for everything in the POSIX tier. RLIMIT_NOFILE stays in each subclass: POSIX names it but does not fix its value, which is 7 on Linux and AIX, 8 on the BSDs and 5 on Solaris/illumos. Its per-platform javadoc already records that JNA's inherited Linux value would query the wrong resource. DragonFly BSD is untouched. It binds only lwp_gettid, so it has nothing to inherit and extending would bind three handles it never calls. Linux needed one extra step: it assigns its handles in a static block rather than per-field initializers, so the three assignments came out along with the declarations. The JNA side needs no equivalent. jna-platform's LibCAPI already declares gethostname, getrlimit and getloadavg, and OSHI's own CLibrary declares getpid, so the platform interfaces inherit them; the only thing duplicated there is the RLIMIT_NOFILE constant, which must be. The asymmetry is that JNA inherits its bindings while FFM hand-writes them.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (3)
📜 Recent review details⏰ Context from checks skipped due to timeout. (11)
🧰 Additional context used📓 Path-based instructions (3)**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (3)📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-07-30T00:35:22.638ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
🔇 Additional comments (4)
📝 WalkthroughWalkthroughThe PR adds a shared POSIX FFM libc binding class. Linux, AIX, FreeBSD, OpenBSD, and Solaris now inherit common ChangesPOSIX libc consolidation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3565 +/- ##
============================================
+ Coverage 79.41% 79.44% +0.02%
+ Complexity 4034 199 -3835
============================================
Files 707 707
Lines 24280 24280
Branches 4061 4061
============================================
+ Hits 19283 19289 +6
- Misses 2798 2801 +3
+ Partials 2199 2190 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java (2)
47-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider exposing
LIBCto subclasses.
LIBCisprivate, so each subclass declares its ownLINKER.defaultLookup()field and repeats the same explanatory comment.AixLibcFunctions,FreeBsdLibcFunctions,OpenBsdLibcFunctions, andSolarisLibcFunctionseach keep a privateLIBC, andLinuxLibcFunctionsdeclares a locallibcin its static initializer. Change the modifier toprotectedso subclasses reuse one lookup. This is optional and can follow in a later change.♻️ Proposed change
- private static final SymbolLookup LIBC = LINKER.defaultLookup(); + protected static final SymbolLookup LIBC = LINKER.defaultLookup();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java` around lines 47 - 49, Change the LIBC field in PosixLibcFunctions from private to protected so AixLibcFunctions, FreeBsdLibcFunctions, OpenBsdLibcFunctions, SolarisLibcFunctions, and LinuxLibcFunctions can reuse the shared LINKER.defaultLookup() instance and explanatory comment instead of declaring duplicate lookups.
38-45: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd
@ThreadSafetoPosixLibcFunctions.This new public class under
src/main/javamust declare anoshi.annotation.concurrentannotation. Use@ThreadSafefor this immutable handleholder utility class.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java` around lines 38 - 45, Annotate the public PosixLibcFunctions class with oshi.annotation.concurrent.ThreadSafe, adding the required import and placing the annotation directly on the class declaration.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.java`:
- Around line 23-29: Update the class Javadoc for OpenBsdLibcFunctions to remove
getrlimit from the list of additional bindings, leaving only getthrid as the
OpenBSD-specific binding.
In `@oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java`:
- Around line 51-56: Update RLIMIT_LAYOUT and its RLIMIT_CUR/RLIMIT_MAX
accessors to account for platform-specific rlim_t width, using a 32-bit layout
on 32-bit Linux/Android and the existing 64-bit layout elsewhere; alternatively,
explicitly exclude 32-bit Linux/Android from the FFM module’s supported
platforms and document that restriction.
---
Nitpick comments:
In `@oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java`:
- Around line 47-49: Change the LIBC field in PosixLibcFunctions from private to
protected so AixLibcFunctions, FreeBsdLibcFunctions, OpenBsdLibcFunctions,
SolarisLibcFunctions, and LinuxLibcFunctions can reuse the shared
LINKER.defaultLookup() instance and explanatory comment instead of declaring
duplicate lookups.
- Around line 38-45: Annotate the public PosixLibcFunctions class with
oshi.annotation.concurrent.ThreadSafe, adding the required import and placing
the annotation directly on the class declaration.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7f6bca32-5f87-4997-acea-4e6201456483
📒 Files selected for processing (6)
oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/*.java: Do not useorg.slf4j.event.**; useoshi.util.LogLevelinstead.
Add the imports needed by code, and let Spotless own formatting and import ordering.
Verify native struct offsets, field widths, andsysctl/ioctlconstants against the target operating system's real headers rather than inferring them from another OS.
Files:
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
oshi-core-ffm/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-core-ffm/src/main/java/**/*.java:oshi-core-ffmmust not referencecom.sun.jna.**.
Behavior changes in FFM implementation classes should also be applied equivalently to their corresponding JNA twins, unless the difference is intentionally specific to FFM or JNA.
Files:
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
**/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/src/main/java/**/*.java: Every public member must have Javadoc, and code and Javadoc—including{@link...}—must use imported simple class names rather than fully qualified names.
New classes should declare an appropriate concurrency annotation fromoshi.annotation.concurrent, matching the modeled class when applicable.
Memoize constant or expensive, slowly changing system-call results withoshi.util.Memoizer, following surrounding patterns and usingdefaultExpiration()when values must refresh.
Place reusable per-OS acquisition and parsing helpers inoshi/driver/<os>/; keep parsing logic out of HAL classes where practical.
Prefer native calls for system information; on Linux preferFileUtilfor/procand/sys, while on other platformsExecutingCommandis acceptable when native APIs do not expose the information.
Do not commit generated output,target/, or IDE files.
Files:
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
🧠 Learnings (2)
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.
Applied to files:
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
🔇 Additional comments (6)
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java (1)
22-37: LGTM!Also applies to: 58-107
oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java (1)
27-35: LGTM!oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java (1)
17-25: LGTM!oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java (1)
23-33: LGTM!oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java (2)
40-46: LGTM!
23-32: 🩺 Stability & AvailabilityRun
SolarisLibcFunctionsTeston a Solaris/illumos host before merging.The Solaris binding still uses
LINKER.defaultLookup(), matching the old lookup behavior, but the existing test suite does not probegethostname. Since this class now initializes POSIX, Solaris-specific, andgetloadavghandles once for all Solaris FFM callers, a missing symbol here can fail JVM initialization beyond hostname reads.
CodeRabbit review. Two of the three actionable findings applied; the
third skipped with reason.
The OpenBSD class javadoc still listed getrlimit among its own bindings
after the hoist. That was true of all five, not just OpenBSD: Linux
still claimed getpid, gethostname and getrlimit; AIX claimed hostname
and getrlimit; FreeBSD claimed getpid and getrlimit as pending work;
Solaris claimed getrlimit. Each now describes what it actually binds and
points at PosixLibcFunctions for the inherited POSIX three. Solaris also
says why RLIMIT_NOFILE stays declared locally.
LIBC becomes protected, so the four subclasses that extend
PosixLibcFunctions drop an identical private field that shadowed it, and
Linux drops the equivalent local in its static block. One lookup and one
explanation of why defaultLookup() is used instead of
libraryLookup("c"), rather than six.
Skipped: adding @threadsafe to PosixLibcFunctions. None of the six
sibling *LibcFunctions classes carries it, nor does the shared
ForeignFunctions parent, so annotating only the new class would make it
the odd one out. AGENTS.md asks new classes to match the annotation of
the class they are modeled on, and the model here has none. Worth doing
across the family, but as its own change rather than silently for one.
Also skipped: the 32-bit rlim_t layout. The FFM module requires JDK 25,
which removed the 32-bit x86 port, so every platform it runs on is
64-bit and rlim_t is 8 bytes.
OpenBSD had no getHostName() override, so it fell through to AbstractNetworkParams, which calls InetAddress.getLocalHost(). That resolves the name rather than just reading it, so on a host whose hostname is not resolvable -- routine in a container, or with no /etc/hosts entry -- it throws UnknownHostException, degrades to getLoopbackAddress() and reports "localhost" instead of the real name. It can also block on a DNS timeout. gethostname(2) is a plain syscall with neither failure mode. Every other platform already prefers the native call and keeps the JDK lookup as its fallback. OpenBSD now does the same, following the FreeBSD shape: OpenBsdNetworkParams becomes abstract with a queryHostName() hook and the prefer-native-fall-back-to-super override, and thin JNA and FFM subclasses supply the binding. getNetworkParams() moves from the shared OS base to the two backend subclasses, which is what lets the two differ. The FFM half only became possible with #3565: OpenBSD never bound gethostname itself, and inherits it from PosixLibcFunctions. NetBSD is deliberately left alone. Its OS class is concrete with no FFM subclass and there is no NetBsdLibcFunctions at all, because pkgsrc has no JDK 25 and its FFM backend takes the no-native route on purpose. Giving it a native host name would mean building that whole layer for one function; it stays on the JDK path, which cannot break when JDK 25 does arrive. Tracked on #3348. DragonFly BSD needs nothing: it returns FreeBsdNetworkParams{JNA,FFM} and already has the native call. OpenBSD is the best-covered of the three for this change. CI runs it on JDK 25 with aggregate coverage, so both backends exercise the new path on the next run -- unlike DragonFly, whose FFM code is untested on platform because its runner is JDK 21.
Five of the six
*LibcFunctionsclasses carried byte-identical bindings forgetpid,getrlimitwith its struct layout and both accessors, andgethostname. Verified identical rather than merely similarly named — the AIX and Solaris blocks diff clean against each other, and OpenBSD differs only by not bindinggethostname.They now live in
PosixLibcFunctions, which the five extend. Java statics are inherited by name, so all 22 call sites compile unchanged. Net −362/+134.The name states the membership rule
Handles resolve with
findOrThrowin a static initializer, so a symbol missing on one platform raisesExceptionInInitializerErrorthere and takes every other member of the class down with it. Being POSIX-mandated is what guarantees the symbol exists everywhere — that is the criterion for belonging, not a matter of taste, so the class is named for it.getloadavgis the counterexample, and it stays putIt looks like a peer of these and four of the six platforms bind it, but it is a BSD extension, not POSIX, and AIX does not have it — AIX reads load average from
perfstat_cpu_total:Hoisting it would have broken AIX at class load, on a platform that never asks for load average. Worth noting the comparison tests would not have caught that: they check values, and this fails before any value is produced, on a runner only cfarm exercises.
A
BsdLibcFunctionstier to hold it was considered and rejected — it would hold exactly one member, and the shareable set does not otherwise cluster by family, since AIX and Solaris are identical to the BSDs for everything in the POSIX tier.What deliberately stays per-platform
RLIMIT_NOFILE— POSIX names it but does not fix its value: 7 on Linux and AIX, 8 on the BSDs, 5 on Solaris/illumos. Each subclass keeps its own, with the existing javadoc recording that JNA's inherited Linux value would query the wrong resource.DragonFly BSD is untouched. It binds only
lwp_gettid, so it has nothing to inherit and extending would bind three handles it never calls.Linux needed one extra step: it assigns its handles in a
static {}block rather than per-field initializers, so the three assignments came out along with the declarations.The JNA side needs no equivalent
jna-platform's
LibCAPIalready declaresgethostname,getrlimitandgetloadavg, and OSHI's ownCLibrarydeclaresgetpid, so the platform interfaces inherit them. The only thing duplicated there is theRLIMIT_NOFILEconstant, which must be. The asymmetry is structural: JNA inherits its bindings, FFM hand-writes them — the same function costs one inherited declaration there and ~12 lines per platform here.Verification
Full gate green from clean: install, spotless, checkstyle, forbiddenapis, javadoc, 1509 tests / 0 failed.
Local testing only proves compilation and that nothing else broke — these classes cannot load on macOS. The real check is the FreeBSD, OpenBSD and OpenIndiana JNA==FFM comparison jobs plus cfarm AIX, which is where a wrong descriptor or a missing symbol would surface.
Summary by CodeRabbit