Skip to content

Share the POSIX libc bindings across the UNIX FFM classes - #3565

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:posix-libc-functions
Aug 3, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:posix-libc-functions

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 2, 2026 •

Copy link
Copy Markdown
Member

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. Net −362/+134.

The name states the membership rule

Handles resolve with findOrThrow in a static initializer, so a symbol missing on one platform raises ExceptionInInitializerError there 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.

getloadavg is the counterexample, and it stays put

It 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:

long[] loadavg = queryCpuTotal().loadavg;

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 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.

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 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 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

  • Improvements
    • Unified common POSIX system operations across supported Unix platforms.
    • Improved consistency for process identification, host-name retrieval, and resource-limit handling.
    • Preserved platform-specific system functionality while reducing differences between Unix environments.
    • Increased reliability and maintainability of system information access across Linux, AIX, FreeBSD, OpenBSD, and Solaris.

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.
@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a27ee8a2-709e-4509-8a18-f11f1e436832

📥 Commits

Reviewing files that changed from the base of the PR and between ca4557e and aff292a.

📒 Files selected for processing (6)
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (11)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
📓 Path-based instructions (3)
**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/*.java: Do not use org.slf4j.event.**; use oshi.util.LogLevel instead.
Add the imports needed by code, and let Spotless own formatting and import ordering.
Verify native struct offsets, field widths, and sysctl/ioctl constants 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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
oshi-core-ffm/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-core-ffm/src/main/java/**/*.java: oshi-core-ffm must not reference com.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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.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 from oshi.annotation.concurrent, matching the modeled class when applicable.
Memoize constant or expensive, slowly changing system-call results with oshi.util.Memoizer, following surrounding patterns and using defaultExpiration() when values must refresh.
Place reusable per-OS acquisition and parsing helpers in oshi/driver/<os>/; keep parsing logic out of HAL classes where practical.
Prefer native calls for system information; on Linux prefer FileUtil for /proc and /sys, while on other platforms ExecutingCommand is 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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
🧠 Learnings (3)
📚 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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
📚 Learning: 2026-08-02T23:56:23.866Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3565
File: oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java:51-56
Timestamp: 2026-08-02T23:56:23.866Z
Learning: For Java FFM bindings in the oshi-core-ffm module, assume a 64-bit JVM and 64-bit operating system. Do not flag 32-bit native ABI or memory-layout compatibility concerns, consistent with the project's JDK 25 support policy, unless that policy changes.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
🔇 Additional comments (4)
oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java (2)

31-35: LGTM!


219-248: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java (1)

27-30: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.java (1)

25-27: LGTM!


📝 Walkthrough

Walkthrough

The PR adds a shared POSIX FFM libc binding class. Linux, AIX, FreeBSD, OpenBSD, and Solaris now inherit common getpid, gethostname, and resource-limit bindings.

Changes

POSIX libc consolidation

Layer / File(s) Summary
Shared POSIX bindings
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
Adds shared libc lookup, struct rlimit accessors, and wrappers for getpid, getrlimit, and gethostname.
Linux and AIX migration
oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
Both classes inherit the shared bindings and remove duplicate implementations. Platform-specific bindings remain.
BSD and Solaris migration
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
These classes inherit the shared bindings and remove duplicate process, hostname, and resource-limit declarations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • oshi/oshi#3322: Overlaps with the FreeBSD gethostname binding centralized by this PR.
  • oshi/oshi#3339: Modifies Solaris FFM libc bindings replaced by this shared implementation.
  • oshi/oshi#3469: Uses AIX libc and rlimit bindings centralized by this PR.

Poem

A rabbit finds one libc trail,
Shared bindings hop without fail.
getpid and limits now align,
Hostnames follow one design.
Across Unix fields, the burrow grows—
Fewer duplicates in tidy rows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the centralization of POSIX libc bindings across the UNIX FFM classes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.44%. Comparing base (e5cc7f7) to head (aff292a).

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     
Flag Coverage Δ
freebsd 32.83% <ø> (-0.01%) ⬇️
linux 36.82% <ø> (+0.02%) ⬆️
macos 37.75% <ø> (-0.03%) ⬇️
openbsd 31.94% <ø> (+<0.01%) ⬆️
solaris 33.35% <ø> (-0.01%) ⬇️
windows 44.67% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 value

Consider exposing LIBC to subclasses.

LIBC is private, so each subclass declares its own LINKER.defaultLookup() field and repeats the same explanatory comment. AixLibcFunctions, FreeBsdLibcFunctions, OpenBsdLibcFunctions, and SolarisLibcFunctions each keep a private LIBC, and LinuxLibcFunctions declares a local libc in its static initializer. Change the modifier to protected so 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 value

Add @ThreadSafe to PosixLibcFunctions.

This new public class under src/main/java must declare an oshi.annotation.concurrent annotation. Use @ThreadSafe for 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

📥 Commits

Reviewing files that changed from the base of the PR and between e5cc7f7 and ca4557e.

📒 Files selected for processing (6)
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/openbsd/OpenBsdLibcFunctions.java
  • oshi-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 use org.slf4j.event.**; use oshi.util.LogLevel instead.
Add the imports needed by code, and let Spotless own formatting and import ordering.
Verify native struct offsets, field widths, and sysctl/ioctl constants 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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-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-ffm must not reference com.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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-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 from oshi.annotation.concurrent, matching the modeled class when applicable.
Memoize constant or expensive, slowly changing system-call results with oshi.util.Memoizer, following surrounding patterns and using defaultExpiration() when values must refresh.
Place reusable per-OS acquisition and parsing helpers in oshi/driver/<os>/; keep parsing logic out of HAL classes where practical.
Prefer native calls for system information; on Linux prefer FileUtil for /proc and /sys, while on other platforms ExecutingCommand is 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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-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.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/linux/LinuxLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/aix/AixLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-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 & Availability

Run SolarisLibcFunctionsTest on 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 probe gethostname. Since this class now initializes POSIX, Solaris-specific, and getloadavg handles 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.
@dbwiddis
dbwiddis merged commit eb18af3 into oshi:master Aug 3, 2026
16 checks passed
@dbwiddis
dbwiddis deleted the posix-libc-functions branch August 3, 2026 00:20
dbwiddis added a commit that referenced this pull request Aug 3, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant