Skip to content

Unify FileSystem file-descriptor methods behind common bases (JNA/FFM dedup) - #3445

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-filesystem-jna-ffm
Jul 10, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-filesystem-jna-ffm

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

First subsystem in the cross-OS consistency/dedup audit. No user-facing behavior change — pure structural consolidation.

What

Hoist the file-descriptor query methods (getOpenFileDescriptors/getMaxFileDescriptors/getMaxFileDescriptorsPerProcess) into common base classes so the JNA/FFM subclasses shrink to a single native hook — matching the pattern FreeBsdFileSystem already used (base implements the public methods, subclass provides one native call).

Platform Base change Subclass
macOS MacFileSystem gains the 3 FD methods + a querySysctl(String) hook JNA/FFM → one-line sysctl
OpenBSD OpenBsdFileSystem same treatment JNA/FFM → one-line sysctl
Windows new WindowsFileSystem base holds MAX_WINDOWS_HANDLES + FD methods behind a queryHandles() hook JNA/FFM extend it

Net −29 lines, and five platforms are now structurally uniform on the FreeBSD hook pattern.

Notes

  • MAX_WINDOWS_HANDLES: the FFM path had hardcoded the 64-bit value while JNA computed 32- vs 64-bit conditionally. The shared base uses the conditional form. This is not a behavioral fix — FFM only runs on 64-bit Windows (JDK 25+), where the values coincide — just backend consistency.
  • Deferred: the native getFileStores volume enumeration stays per-backend (Kernel32/WMI vs getfsstat are genuinely different native code, not mergeable without abstracting the whole native layer). Its JNA/FFM merge loop has a real drift (order handling + description enrichment differ), but hoisting it is coupled to the static WindowsOSFileStore.updateAttributes calls and needs a Windows-tested decision — split out to a follow-up.

Part of the subsystem-by-subsystem audit; more platforms/subsystems to follow.

Summary by CodeRabbit

  • New Features

    • Added file-descriptor usage and limit reporting for macOS, OpenBSD, and Windows.
    • Windows now reports open handles and shared system limits consistently across supported runtime options.
  • Improvements

    • Standardized file-descriptor reporting across native integration variants.
    • Added graceful fallback behavior when platform metrics are unavailable.

… dedup)

First subsystem in the cross-OS consistency audit. Hoist the file-descriptor
query methods to common base classes so the JNA/FFM subclasses shrink to a
single native hook, matching the pattern FreeBsdFileSystem already used:

- macOS: MacFileSystem base gains the three FD methods + a querySysctl(String)
  hook; MacFileSystemJNA/FFM drop to the one-line sysctl call.
- OpenBSD: same treatment on OpenBsdFileSystem.
- Windows: new WindowsFileSystem base holds MAX_WINDOWS_HANDLES + the FD methods
  behind a queryHandles() hook; JNA/FFM extend it.

No user-facing behavior change. The FFM Windows handle limit had hardcoded the
64-bit value while JNA computed it conditionally, but FFM runs only on 64-bit
Windows (JDK 25+) where the values coincide; the shared base uses the
conditional form to keep both backends consistent.

The native getFileStores volume enumeration stays per-backend (Kernel32/WMI vs
getfsstat are genuinely different native code); its JNA/FFM merge-loop drift is
deferred to a follow-up (coupled to the static WindowsOSFileStore
updateAttributes calls).
@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change centralizes file-descriptor reporting for macOS, OpenBSD, and Windows. Shared filesystem classes implement descriptor getters, while JNA and FFM subclasses provide native sysctl or handle-count queries.

Changes

File-descriptor reporting

Layer / File(s) Summary
macOS and OpenBSD descriptor contracts
oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java, oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdFileSystem.java
Base classes implement descriptor getters using abstract querySysctl hooks for platform-specific values.
Native sysctl implementations
oshi-core/src/main/java/oshi/software/os/mac/MacFileSystemJNA.java, oshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java, oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java, oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java
JNA and FFM subclasses delegate generic sysctl keys to their native utilities.
Shared Windows handle accounting
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsFileSystem.java
A new abstract base class computes Windows handle limits and derives open descriptors from native handle-count maps.
Windows native handle wiring
oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java, oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
Windows backends extend the shared base and provide ProcessInformationJNA or ProcessInformationFFM handle queries.

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

Possibly related PRs

  • oshi/oshi#3145: Modifies the shared macOS MacFileSystem class with additional filesystem members.

Poem

A bunny sees handles hop in line,
Sysctls query values fine.
JNA and FFM share the way,
Windows counts them night and day.
Centralized paths make data flow—
“Nip, nip!” says the rabbit, “off we go!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main refactor: consolidating file-descriptor methods into shared base classes across JNA/FFM implementations.
✨ 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 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.47%. Comparing base (4ff73e8) to head (fb0113c).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../software/common/os/windows/WindowsFileSystem.java 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3445      +/-   ##
============================================
- Coverage     74.52%   74.47%   -0.06%     
  Complexity       76       76              
============================================
  Files           580      581       +1     
  Lines         21945    21944       -1     
  Branches       3670     3669       -1     
============================================
- Hits          16355    16343      -12     
- Misses         3552     3564      +12     
+ Partials       2038     2037       -1     
Flag Coverage Δ
freebsd 26.85% <0.00%> (-0.01%) ⬇️
linux 31.37% <0.00%> (-0.02%) ⬇️
macos 31.76% <25.00%> (-0.04%) ⬇️
openbsd 26.34% <25.00%> (+<0.01%) ⬆️
solaris 28.37% <0.00%> (+0.01%) ⬆️
windows 39.73% <40.00%> (+0.01%) ⬆️

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.

@dbwiddis
dbwiddis merged commit b061c05 into oshi:master Jul 10, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the dedup-filesystem-jna-ffm branch July 10, 2026 22:29
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