Skip to content

Dedup BSD OSProcess open-file-limit, cwd, and bitness logic - #3465

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:bsd-osprocess-dedup
Jul 17, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:bsd-osprocess-dedup

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Part of the cross-OS consistency/dedup audit (OSProcess subsystem, BSD family).

The BSD OSProcess JNA and FFM twins duplicated a lot of non-native logic. This hoists the shared pieces without changing behavior:

  • BsdOSProcess: the getSoftOpenFileLimit/getHardOpenFileLimit skeleton (if current process → getrlimit, else → fallback) plus an elfBitness(String) helper, exposed via three overridable hooks (queryOwnProcessId, queryRlimitNofile, otherProcessOpenFileLimit). The hook defaults keep NetBSD — which overrides the limit methods directly — completely unaffected.
  • Per-platform bases (FreeBSD/OpenBSD/DragonFly): the byte-identical getCurrentWorkingDirectory/getOpenFiles delegations move here (4 twin copies → 1 base each). These stay per-platform because each delegates to a different procstat/fstat util with a different output format. OpenBSD (no procfs) overrides the non-current-process fallback to -1.
  • The 6 twins keep only their irreducible native bits: a queryRlimitNofile getrlimit hook, a one-line queryOwnProcessId, and the genuinely divergent argument/environment queries. FreeBSD and DragonFly bitness now reuse elfBitness.

Adds a portable BsdOSProcessTest (limit-routing skeleton + elfBitness parsing) and the os.unix.bsd opens line in module-info.test.

No CHANGELOG entry: pure dedup with identical observable behavior.

Local gate: spotless, checkstyle, forbiddenapis, javadoc, and a clean full-reactor build all pass; oshi-common tests including the new test pass. BSD native / JNA==FFM parity validated via the unix.yaml FreeBSD/OpenBSD/DragonFly VMs (dispatched manually, since unix.yaml does not trigger on pull requests).

Summary by CodeRabbit

  • Bug Fixes
    • Improved soft/hard open-file limit reporting across BSD platforms, including more accurate results for the current process versus other processes.
    • Improved current working directory and open-file count reporting on DragonFlyBSD, FreeBSD, and OpenBSD.
    • Improved 32-bit vs 64-bit architecture detection for BSD process queries.
  • Tests
    • Added BSD-focused unit coverage for open-file limits and architecture detection.
    • Updated existing procstat utility tests to match the current working-directory reading behavior.

Hoist the shared getrlimit-based open-file-limit skeleton and ELF-bitness
parsing into BsdOSProcess, and the byte-identical current-working-directory
and open-file delegations into the FreeBSD/OpenBSD/DragonFly bases. The JNA
and FFM twins now keep only their irreducible native bits: a queryRlimitNofile
getrlimit hook, a one-line queryOwnProcessId, and the genuinely divergent
argument/environment queries (FreeBSD/DragonFly bitness reuse elfBitness).

OpenBSD (no procfs) overrides the non-current-process limit fallback to -1.
NetBSD is unchanged: it fully overrides the limit methods, so the new
BsdOSProcess concrete defaults never affect it.

Adds a portable BsdOSProcessTest covering the limit-routing skeleton and
elfBitness parsing, plus the os.unix.bsd opens line in module-info.test.
@coderabbitai

coderabbitai Bot commented Jul 17, 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

Run ID: 0e4f8afa-ec84-4b5d-8dd4-ff31667c0b36

📥 Commits

Reviewing files that changed from the base of the PR and between 6f07093 and ae5e6d2.

📒 Files selected for processing (4)
  • oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtil.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.java
  • oshi-common/src/test/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtilTest.java
  • oshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.java
💤 Files with no reviewable changes (3)
  • oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtil.java
  • oshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.java
  • oshi-common/src/test/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtilTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.java
📚 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-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.java
🔇 Additional comments (1)
oshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.java (1)

14-14: LGTM!


📝 Walkthrough

Walkthrough

BSD process classes now share open-file limit routing and ELF bitness parsing. DragonFlyBSD, FreeBSD, and OpenBSD platform classes provide filesystem queries, while FFM and JNA backends implement native process-ID and RLIMIT_NOFILE hooks.

Changes

BSD process query consolidation

Layer / File(s) Summary
Shared BSD query contract and tests
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java, oshi-common/src/test/java/oshi/software/common/os/unix/bsd/BsdOSProcessTest.java, oshi-common/src/test/java/module-info.test
Shared soft/hard open-file limit routing, default native-query hooks, ELF bitness parsing, and deterministic tests are added.
Platform-specific file queries
oshi-common/src/main/java/oshi/software/common/os/unix/{dragonflybsd,freebsd,openbsd}/*OSProcess.java, oshi-common/src/main/java/oshi/util/common/platform/unix/{dragonflybsd,freebsd}/ProcstatUtil.java, oshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.java
DragonFlyBSD and FreeBSD use ProcstatUtil; OpenBSD uses FstatUtil and reports unavailable other-process limits. Obsolete CWD-map APIs and related tests are removed.
Native backend hooks
oshi-core*/src/main/java/oshi/software/os/unix/{dragonflybsd,freebsd,openbsd}/*OSProcess{FFM,JNA}.java
FFM and JNA implementations provide process-ID and RLIMIT_NOFILE hooks and delegate ELF parsing to the shared helper.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • oshi/oshi#3303: Earlier BSD open-file limit implementations that this refactor replaces.
  • oshi/oshi#3335: Related OpenBSD FFM RLIMIT_NOFILE hook implementation.
  • oshi/oshi#3370: Related shared BSD process abstraction and open-file limit logic.

Poem

Soft limits hop, hard limits shine,
BSD paths now align.
ELF bits flicker, doors swing free,
A rabbit cheers native harmony. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 accurately summarizes the main change: deduplicating BSD OSProcess open-file-limit, cwd, and bitness logic.
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 Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.87097% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.12%. Comparing base (6976275) to head (ae5e6d2).

Files with missing lines Patch % Lines
...oshi/software/common/os/unix/bsd/BsdOSProcess.java 78.57% 3 Missing ⚠️
...tware/common/os/unix/openbsd/OpenBsdOSProcess.java 66.66% 1 Missing ⚠️
.../software/os/unix/freebsd/FreeBsdOSProcessFFM.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3465      +/-   ##
============================================
- Coverage     75.14%   75.12%   -0.03%     
  Complexity       76       76              
============================================
  Files           587      587              
  Lines         21604    21576      -28     
  Branches       3611     3608       -3     
============================================
- Hits          16235    16209      -26     
+ Misses         3393     3390       -3     
- Partials       1976     1977       +1     
Flag Coverage Δ
freebsd 27.48% <61.29%> (+0.02%) ⬆️
linux 32.04% <35.48%> (+0.09%) ⬆️
macos 32.54% <35.48%> (+0.04%) ⬆️
openbsd 26.81% <58.06%> (+0.03%) ⬆️
solaris 29.24% <35.48%> (+0.10%) ⬆️
windows 40.94% <35.48%> (+0.02%) ⬆️

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.

getCwdMap (and FreeBSD's parseCwdMap helper it delegated to) had no
production caller — the OSProcess bases resolve the working directory
per process via getCwd, not via a bulk PID-to-cwd map. Drop the dead
methods and the tests that only exercised them.
@dbwiddis
dbwiddis merged commit 5d80950 into oshi:master Jul 17, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the bsd-osprocess-dedup branch July 17, 2026 17:26
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