Repository navigation
Extract BSD OperatingSystem common bases (JNA/FFM) - #3375
Conversation
The FreeBSD, OpenBSD, and DragonFly OperatingSystem classes each duplicated their entire body between the JNA and FFM backends (the method signatures were identical; only the native calls and backend factory types differed). Following the Solaris #3367 template, extract an abstract per-platform base in oshi-common holding the ps-based process enumeration, process/thread counts, services, and system uptime/boot time. The JNA and FFM subclasses are reduced to the genuinely backend-specific bits: the OSProcess factory (a new createProcess hook), the FileSystem/NetworkParams/InternetProtocolStats factories, getpid/ thread-id, the sysctl version query, and who sessions. Per-platform notes: - FreeBSD/DragonFly read boot time from a native sysctl struct, so the base declares an abstract queryBootTime() hook (memoized); OpenBSD text-parses it, so its base implements queryBootTime() concretely. - OpenBSD's InternetProtocolStats and NetworkParams are common (non-native) classes, so they move into the base; FreeBSD/DragonFly keep their JNA/FFM factory overrides. DragonFly reuses FreeBSD's filesystem/IP/network impls and keeps its kernel-thread (pid <= 0) filter. NetBSD already has a single common OperatingSystem class and is unchanged. The JNA/FFM subclasses shrink from ~225-238 lines each to ~55-90.
📝 WalkthroughWalkthroughThis PR introduces three new abstract base classes in ChangesBSD Operating System Base Classes
JNA and FFM Platform Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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❌ Patch coverage is Additional details and impacted files
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.
🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java (1)
66-69: 💤 Low valueMinor inconsistency: JNA uses DragonFlyBsdLibc while FFM uses FreeBsdLibcFunctions for
getpid().The JNA backend calls
DragonFlyBsdLibc.INSTANCE.getpid()while the FFM backend callsFreeBsdLibcFunctions.getpid(). This works correctly sincegetpid()is a standard POSIX call, but consider aligning both backends to use the same library pattern for consistency (either both use DragonFlyBsd-specific or both use FreeBsd-shared).🤖 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/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java` around lines 66 - 69, The JNA backend in DragonFlyBsdOperatingSystemJNA.getProcessId() calls DragonFlyBsdLibc.INSTANCE.getpid(), which is inconsistent with the FFM backend that uses FreeBsdLibcFunctions.getpid(); change the call in getProcessId() to use FreeBsdLibcFunctions.getpid() so both backends use the same libc wrapper naming pattern (or alternatively update the FFM side to DragonFlyBsdLibc—pick one approach and make both use the same symbol).
🤖 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.
Nitpick comments:
In
`@oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java`:
- Around line 66-69: The JNA backend in
DragonFlyBsdOperatingSystemJNA.getProcessId() calls
DragonFlyBsdLibc.INSTANCE.getpid(), which is inconsistent with the FFM backend
that uses FreeBsdLibcFunctions.getpid(); change the call in getProcessId() to
use FreeBsdLibcFunctions.getpid() so both backends use the same libc wrapper
naming pattern (or alternatively update the FFM side to DragonFlyBsdLibc—pick
one approach and make both use the same symbol).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 82213aeb-0e3e-4daf-b042-3755ded597af
📒 Files selected for processing (9)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: JMH Benchmarks, ubuntu-latest
🧰 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/software/common/os/unix/openbsd/OpenBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOperatingSystem.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
🔇 Additional comments (30)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOperatingSystem.java (7)
41-46: LGTM!
48-59: LGTM!
61-104: LGTM!
133-141: LGTM!
143-168: LGTM!
170-185: LGTM!
116-122:getCurrentThread()relies ongetThreadId()from the class hierarchy
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOperatingSystem.javacallsgetThreadId()without declaring it locally; confirm the method is provided via theOperatingSystemAPI and/or an inherited superclass implementation so this compiles and is consistent with other platform implementations.oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java (4)
42-42: LGTM!Also applies to: 25-25
67-75: LGTM!
89-92: LGTM!
94-107: LGTM!oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java (3)
33-33: LGTM!Also applies to: 15-15
77-80: LGTM!
82-92: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOperatingSystem.java (3)
42-184: LGTM!
90-91: No module-boundary issue:FreeBsdOSProcess/FreeBsdOSThreadand the referenced constants are inoshi-common.
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.javadefinespublic static final String PS_COMMAND_ARGSandpublic static final List<BsdPsKeyword> PS_KEYWORDSused at lines 90–91 and 97–98.
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSThread.javaprovides the concreteFreeBsdOSThreadinstantiated at line 120.> Likely an incorrect or invalid review comment.
115-121: ResolvegetThreadId()inheritance concern ingetCurrentThread()
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOperatingSystem.javacallsgetThreadId()fromgetCurrentThread(), andgetThreadId()is implemented in the FreeBSD concrete subclasses (FreeBsdOperatingSystemJNA/FreeBsdOperatingSystemFFM) via@Override, so the call is satisfied by the class hierarchy.oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java (1)
38-107: LGTM!oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java (1)
32-97: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.java (7)
1-50: LGTM!
52-68: LGTM!
70-96: LGTM!
144-172: LGTM!
174-209: LGTM!
98-124: ConfirmOpenBsdOSProcessstatic fields are present inoshi-common.
oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.javadefinespublic static final String PS_COMMAND_ARGSandpublic static final List<BsdPsKeyword> PS_KEYWORDS, matching the references inOpenBsdOperatingSystem.
126-142: OpenBsdOSThread exists inoshi-commonand matches the expected OpenBSD package. It’s implemented atoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSThread.javaunderpackage oshi.software.common.os.unix.openbsd;, so the fallback instantiation inOpenBsdOperatingSystemis valid without an explicit import.oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java (2)
23-23: LGTM!Also applies to: 28-32
68-71: LGTM!oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java (2)
17-17: LGTM!Also applies to: 23-27
59-62: LGTM!
Summary
Completes the BSD
OperatingSystemdeduplication (after theOSProcess#3372 andOSThread#3374 work). The FreeBSD, OpenBSD, and DragonFlyOperatingSystemclasses each duplicated their entire body between the JNA and FFM backends — the method signatures were identical; only the native calls and backend factory types differed.Following the Solaris #3367 template, this extracts an abstract per-platform base in
oshi-commonholding the shared, non-native logic (ps-based process enumeration, process/thread counts, services, system uptime/boot time). The JNA and FFM subclasses are reduced to the genuinely backend-specific bits: theOSProcessfactory (a newcreateProcesshook), theFileSystem/NetworkParams/InternetProtocolStatsfactories,getpid/thread-id, the sysctl version query, andwhosessions.Per-platform notes:
queryBootTime()hook (memoized viagetSystemBootTime()); OpenBSD text-parses it, so its base implementsqueryBootTime()concretely.InternetProtocolStatsandNetworkParamsare common (non-native) classes, so they move into its base; FreeBSD/DragonFly keep their JNA/FFM factory overrides.pid <= 0) filter in the shared enumeration.OperatingSystemclass and is unchanged.The JNA/FFM subclasses shrink from ~225–238 lines each to ~55–90. Net −287 lines. Behavior is unchanged — the per-platform
pscommands and column lists are identical to before.Cross-platform commonality between the three new bases (e.g.
getProcessCount/getServices) remains; collapsing that into a sharedBsdOperatingSystemsuper-base is a possible follow-up but was kept out to keep this change a clean JNA↔FFM dedup mirroring the Solaris template.Testing
All five
unix.yamlVM jobs pass, exercising the refactored code on real FreeBSD, OpenBSD, DragonFly, and NetBSD systems (plus OpenIndiana). Local spotless / checkstyle / forbidden-APIs / javadoc and a clean full-reactor build also pass.Summary by CodeRabbit
Release Notes