Repository navigation
FreeBSD Port: FFM concretes for the remaining HAL/OS surface - #3328
Conversation
FreeBsdFileSystemFFM mirrors FreeBsdFileSystemJNA — two trivial overrides for kern.openfiles / kern.maxfiles via BsdSysctlUtilFFM. Folds in three Sonar findings from PR #3322: * FreeBsdNetworkParamsFFM (S2184): widen HOST_NAME_MAX + 1 to long for the arena allocate call to match the gethostname argument on the next line, keeping both arithmetic paths in 64-bit math. * DisklabelTest x2 (S2153): drop the unnecessary .longValue() unboxing from assertThat(diskdata.getC()…) in the OpenBSD and NetBSD live smoke tests — Hamcrest's greaterThanOrEqualTo(0L) works on the Long directly, the unbox-then-rebox roundtrip is wasted work. The CPUMASK regex S5998 finding in FreeBsdCentralProcessorFFM (and its JNA sibling) was reviewed and marked false positive: the comma anchor between alternatives prevents catastrophic backtracking, and input is bounded kernel-controlled sysctl output. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Mirror of FreeBsdInternetProtocolStatsJNA. Reads net.inet.tcp.stats and net.inet.udp.stats via BsdSysctlUtilFFM.sysctl(name), returning the auto-arena MemorySegment, then memoizes the segment itself (instead of an intermediate BsdTcpstat / BsdUdpstat struct as the JNA sibling does — FFM lets us pull fields out at offset on demand, so the extra holder type isn't needed). Established-connection counts continue to come from the shared NetStat command-line driver. Field offsets and the ParseUtil.unsignedIntToLong widening match the JNA layout exactly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Mirror of FreeBsdPowerSourceJNA — three hw.acpi.battery.* sysctl reads (state/time/life) via BsdSysctlUtilFFM, then acpiconf -i 0 parsing for the richer device fields. Constructor signature and the heavy-but- straightforward command-output parsing are byte-identical to the JNA sibling. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Mirror of FreeBsdHWDiskStoreJNA. One native read (kern.disks via BsdSysctlUtilFFM); everything else is pure-Java parsing of iostat -Ix plus the GeomDiskList / GeomPartList drivers in oshi-common (hoisted in Phase 2). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The two classes are circularly dependent (OS constructs OSProcess, OSProcess holds the OS reference for the rlimit-of-self path), so they land together with all the libc bindings they share. * FreeBsdLibcFunctions gains: getpid, thr_self, sysctl (int-MIB form with errno capture), getrlimit + RLIMIT_LAYOUT (two longs, matching FreeBSD's struct rlimit) + RLIMIT_NOFILE = 8 (FreeBSD's value, not Linux's 7). rlimitCur/rlimitMax accessor helpers. * FreeBsdOSProcessFFM mirrors FreeBsdOSProcessJNA. Static ARGMAX read via BsdSysctlUtilFFM at class init; queryArguments / queryEnvironmentVariables / queryBitness via sysctl int-MIB (CTL_KERN=1, KERN_PROC=14, with KERN_PROC_ARGS=7 / KERN_PROC_ENV=35 / KERN_PROC_SV_NAME=9 leaves); getSoftOpenFileLimit / getHardOpenFileLimit via getrlimit(RLIMIT_NOFILE) for the calling process, falling back to /proc/<pid>/limits parsing for others (same as JNA). * FreeBsdOperatingSystemFFM mirrors FreeBsdOperatingSystemJNA. Wires the FFM siblings (FreeBsdFileSystemFFM, FreeBsdInternetProtocolStatsFFM, FreeBsdNetworkParamsFFM, FreeBsdOSProcessFFM); sessions go through WhoFFM.queryUtxent() (Phase 3); getProcessId / getThreadId use the new getpid / thr_self bindings; querySystemBootTime reads kern.boottime as a 16-byte struct via BsdSysctlUtilFFM.sysctl(name, segment), parsing the tv_sec long out of the result. * Hoists ProcstatUtil (oshi-core/oshi.util.platform.unix.freebsd) to oshi-common (oshi.util.common.platform.unix.freebsd) per the Phase 2 pattern, since both JNA OSProcess and the new FFM OSProcess need it and the original package is split (it also contains BsdSysctlUtil which is JNA-tied). FreeBsdOSProcessJNA import updated; the pure- parsing tests come along, and the live test now derives the current PID from ManagementFactory rather than oshi.SystemInfo (which lives in the JNA module and isn't visible from oshi-common). Module-info exports + add-opens updated to match. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Aggregate FFM HAL. Wires the FreeBsd*FFM concretes from Phases 4–5 (ComputerSystem, GlobalMemory, CentralProcessor, Sensors, PowerSource, HWDiskStore, Cups printer) and reuses the pure-Java BSD-shared classes (UnixDisplay, BsdNetworkIF, FreeBsdGraphicsCard / SoundCard / UsbDevice) that already live in oshi-common. Hoists BsdNetworkIF (oshi-core/oshi.hardware.platform.unix) to oshi-common (oshi.hardware.common.platform.unix), mirroring the Phase 2 treatment of FreeBsdGraphicsCard / SoundCard / UsbDevice etc. The class is pure-Java already (just ExecutingCommand + netstat parsing); it was just stranded in the JNA module because Phase 2 didn't touch the BSD network path. Both DragonFlyBsdHardwareAbstractionLayer and FreeBsdHardwareAbstractionLayerJNA pick up the new import path; no behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📜 Recent 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). (13)
📝 WalkthroughWalkthroughHoists FreeBSD utilities into oshi-common and exports the new FreeBSD package; adds FFM libc bindings; implements FFM-backed FreeBSD HAL, disk, power, filesystem, network/protocol stats, process/OS classes; and updates imports/tests. ChangesFreeBSD FFM Implementation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
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@@ Coverage Diff @@
## master #3328 +/- ##
============================================
- Coverage 75.00% 73.11% -1.90%
Complexity 76 76
============================================
Files 455 462 +7
Lines 17492 17925 +433
Branches 2872 2928 +56
============================================
- Hits 13120 13105 -15
- Misses 2780 3220 +440
- Partials 1592 1600 +8
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
🤖 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-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.java`:
- Around line 92-95: The test currently parses
ManagementFactory.getRuntimeMXBean().getName() into a PID via
ParseUtil.parseIntOrDefault and falls back to 0; change this to fail fast if
parsing doesn't produce a valid PID by using an impossible sentinel (e.g., -1)
and asserting the PID is positive before calling ProcstatUtil.getOpenFiles(pid).
Update ProcstatUtilTest to parse the PID with ParseUtil.parseIntOrDefault(...,
-1), add an assertion that the parsed pid > 0 (or fail the test with a clear
message referencing RuntimeMXBean#getName()), and only then call
ProcstatUtil.getOpenFiles(pid).
In
`@oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdPowerSourceFFM.java`:
- Around line 88-91: In FreeBsdPowerSourceFFM, the code reading
hw.acpi.battery.life uses "if (life > 0)" which leaves
psRemainingCapacityPercent at its default 1.0 when life == 0; change the
condition in the block that handles the sysctl result (the variable life from
BsdSysctlUtilFFM.sysctl and the assignment to psRemainingCapacityPercent) to use
">= 0" so a reported 0 value correctly sets psRemainingCapacityPercent = life /
100d (yielding 0.0) instead of leaving it at 1.0.
🪄 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
Run ID: 30f2c84b-e54a-450b-9b36-468d80b50150
📒 Files selected for processing (20)
oshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/package-info.javaoshi-common/src/test/java/module-info.testoshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.javaoshi-core-ffm/src/main/java/oshi/ffm/unix/freebsd/FreeBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHWDiskStoreFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdPowerSourceFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdInternetProtocolStatsFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.javaoshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.javaoshi-core/src/test/java/oshi/driver/unix/bsd/disk/DisklabelTest.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). (11)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (16)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3310
File: oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystem.java:164-166
Timestamp: 2026-05-31T04:49:16.646Z
Learning: In the oshi/oshi project, the NetBSD platform intentionally removes all JNA/native library dependencies (PR `#3310`). `NetBsdOperatingSystem.getThreadId()` uses `(int) Thread.currentThread().getId()` rather than `NetBsdLibc._lwp_self()` because the JNA native library is not bundled with the Maven dependency for the NetBSD platform. The mismatch between Java thread ids and kernel LWP ids is an accepted trade-off. Do not suggest reintroducing JNA-based calls (such as `NetBsdLibc._lwp_self()`) in NetBSD platform code.
📚 Learning: 2026-04-03T18:44:48.200Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:48.200Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.javaoshi-common/src/main/java/module-info.javaoshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/package-info.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdPowerSourceFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.javaoshi-common/src/main/java/module-info.javaoshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/package-info.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.javaoshi-common/src/test/java/module-info.testoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdPowerSourceFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
📚 Learning: 2026-04-03T18:43:51.290Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:99-100
Timestamp: 2026-04-03T18:43:51.290Z
Learning: In oshi/oshi PlatformEnum.java, the DragonFly BSD detection uses `osName.equalsIgnoreCase("dragonflybsd")` intentionally, mirroring the exact same check in JNA's `Platform.java` source. Java's `os.name` property on DragonFly BSD is "dragonflybsd" (no space), so `startsWith("DragonFly")` is NOT the correct pattern here. Do not suggest changing it to `startsWith`.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayer.javaoshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/package-info.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.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/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java
📚 Learning: 2026-05-31T04:49:16.646Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3310
File: oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystem.java:164-166
Timestamp: 2026-05-31T04:49:16.646Z
Learning: In the oshi/oshi project, the NetBSD platform intentionally removes all JNA/native library dependencies (PR `#3310`). `NetBsdOperatingSystem.getThreadId()` uses `(int) Thread.currentThread().getId()` rather than `NetBsdLibc._lwp_self()` because the JNA native library is not bundled with the Maven dependency for the NetBSD platform. The mismatch between Java thread ids and kernel LWP ids is an accepted trade-off. Do not suggest reintroducing JNA-based calls (such as `NetBsdLibc._lwp_self()`) in NetBSD platform code.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.javaoshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/package-info.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.javaoshi-core-ffm/src/main/java/oshi/ffm/unix/freebsd/FreeBsdLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
Applied to files:
oshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/package-info.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.javaoshi-common/src/test/java/module-info.test
📚 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/module-info.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/package-info.javaoshi-common/src/main/java/oshi/util/common/platform/unix/freebsd/ProcstatUtil.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.
Applied to files:
oshi-common/src/test/java/oshi/util/common/platform/unix/freebsd/ProcstatUtilTest.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java
📚 Learning: 2026-04-03T02:07:49.467Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:49.467Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.
Applied to files:
oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHWDiskStoreFFM.java
📚 Learning: 2026-04-17T23:43:35.860Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:35.860Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdInternetProtocolStatsFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/unix/freebsd/FreeBsdLibcFunctions.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.
Applied to files:
oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdPowerSourceFFM.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.
Applied to files:
oshi-core-ffm/src/main/java/oshi/ffm/unix/freebsd/FreeBsdLibcFunctions.java
📚 Learning: 2026-05-04T04:58:36.843Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3227
File: oshi-metrics/src/main/java/oshi/metrics/OshiMetrics.java:35-48
Timestamp: 2026-05-04T04:58:36.843Z
Learning: In `oshi-metrics/src/main/java/oshi/metrics/OshiMetrics.java`, the `private final OperatingSystem os` field is intentionally stored in the constructor even though it is not yet used. It is a placeholder for future OS-level metrics (e.g., process metrics) that will be added incrementally. Do not flag it as dead code.
Applied to files:
oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
🔇 Additional comments (17)
oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayer.java (1)
23-23: LGTM!oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerJNA.java (1)
23-23: LGTM!oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHardwareAbstractionLayer.java (1)
23-23: LGTM!oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java (1)
46-46: LGTM!oshi-core/src/test/java/oshi/driver/unix/bsd/disk/DisklabelTest.java (1)
175-175: LGTM!Also applies to: 194-194
oshi-core-ffm/src/main/java/oshi/ffm/unix/freebsd/FreeBsdLibcFunctions.java (2)
41-52: LGTM!
337-424: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHardwareAbstractionLayerFFM.java (1)
34-96: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHWDiskStoreFFM.java (1)
32-108: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdPowerSourceFFM.java (1)
30-55: LGTM!Also applies to: 56-148
oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemFFM.java (1)
15-27: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdInternetProtocolStatsFFM.java (1)
27-93: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java (2)
57-105: LGTM!Also applies to: 107-298, 300-354, 356-443, 445-463
428-430: ⚡ Quick winReconsider the
startTimetime-unit mismatch claim:startTime = now - this.upTimeis consistent becausegetUpTime()is treated as milliseconds across the codebase (e.g.,ProcessMetricsconverts it to seconds by dividing byMS_PER_SECOND), so subtracting fromSystem.currentTimeMillis()is correct.> Likely an incorrect or invalid review comment.oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java (2)
51-66: LGTM!Also applies to: 68-105, 107-162, 175-214, 216-246
164-173: ⚡ Quick winFix not needed:
thr_selferror check is correct
FreeBSDthr_self(2)returns0on success and-1on failure, so the existingthr_self(id) < 0check will correctly detect errors; removing/updating it as proposed isn’t required.> Likely an incorrect or invalid review comment.oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsFFM.java (1)
64-65: LGTM!
Both findings verified against current code; both still valid. 1. ProcstatUtilTest live-test PID parse defaulted to 0 on failure, which would silently pass 0 to ProcstatUtil.getOpenFiles and let the rest of the live assertions run against a meaningless PID. Switched the default to -1 and added an upfront assertThat(pid, is(greaterThan(0))) so a platform that doesn't follow RuntimeMXBean#getName()'s "pid@host" convention fails fast with a clear message instead of producing confusing downstream failures. 2. FreeBsdPowerSourceFFM/JNA: hw.acpi.battery.life uses -1 as the sysctl-failure sentinel and the kernel returns 0–100 for a real reading. The "life > 0" check left psRemainingCapacityPercent at its default 1.0 when life was a legitimate 0 (battery flat), reporting a discharged battery as fully charged. Both FFM and JNA copies switch to ">= 0" so genuine 0 readings drive the percent to 0.0; -1 still falls through and keeps the 1.0 default. Lockstep fix on the JNA sibling because Phase 6's NativeComparisonTest will compare the two implementations and any divergence would fail parity. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Upstream 8f3f018 removed the NetBSD GCC farm CI job but left two trailing blank lines at the end of unix.yaml that Spotless flags. The new upstream master is otherwise unchanged for the FreeBSD port, so this is just a one-line cleanup after the merge into freebsd-ffm. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* Phase 6 commit 1: wire FreeBSD into oshi.ffm.SystemInfo Adds PlatformEnum.FREEBSD to SUPPORTED_PLATFORMS, dispatches to FreeBsdOperatingSystemFFM / FreeBsdHardwareAbstractionLayerFFM (shipped in PRs #3322 and #3328), and updates the class-level Javadoc that previously listed only Windows/macOS/Linux. FreeBSD is dropped from the "use oshi.SystemInfo (JNA) instead" call-out since the FFM path now covers it; OpenBSD, Solaris, AIX still need the JNA entry point. This is the last load-bearing change of the FreeBSD FFM port — after this, oshi.ffm.SystemInfo.isAvailable() returns true on FreeBSD and the public API works end-to-end. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Phase 6 commit 2: enable FreeBSD across FFM tests Now that oshi.ffm.SystemInfo dispatches to FreeBSD (Phase 6 commit 1), all six FFM tests previously gated to {LINUX, MAC, WINDOWS} need FreeBSD added so they exercise the new wiring on the FreeBSD CI: * oshi-core-ffm: SystemInfoTest, GlobalMemoryFFMTest, VirtualMemoryFFMTest, OperatingSystemFFMTest, ForeignFunctionsTest * oshi-benchmark: NativeComparisonTest (the big JNA-vs-FFM HAL/OS parity test that retires the per-piece comparison tests we explicitly skipped during Phases 3–5) No assertion changes — the test bodies already cover the FreeBSD-relevant surface generically through the public OSHI API. Mac CI continues to see the same 39 successful / 53 skipped split. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Phase 6 commit 3: handle FreeBSD-specific NativeComparisonTest parity gaps Three failures surfaced when Phase 6 commit 2 enabled NativeComparisonTest on FreeBSD. None are real parity bugs; all are structural differences between FreeBSD's process/sensor model and the other platforms. * ComparisonAssertions.assertWithinRatio now treats both-NaN as equal. CPU temperature comes back NaN on the FreeBSD CI VM (no coretemp kld module loaded) from both JNA and FFM, which is correct parity, but NaN/NaN arithmetic made the ratio check fail. * assertStartTimeMatches helper added to NativeComparisonTest. On Linux/Mac/Windows OSProcess#getStartTime() exposes the kernel's exact start time and strict equality holds. On FreeBSD startTime is derived as (now - elapsedTime) where elapsedTime is the seconds-resolution `ps -o etimes` value; JNA and FFM each capture `now` at slightly different timestamps so the derived values drift by tens of milliseconds. Switched the two startTime assertions (currentProcess() and processListStructure()) to a 2000ms tolerance on FreeBSD; other platforms keep strict equality. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Phase 6 commit 4: more FreeBSD parity gaps surfaced by NativeComparisonTest Two more failures appeared once Phase 6 commit 3's startTime and NaN fixes cleared the way; both are real and fixed in this commit. 1. process.softOpenFileLimit — JNA returned 10328, FFM returned 175554 (real open-files limit). Pre-existing JNA-on-FreeBSD bug: Resource.RLIMIT_NOFILE in the JNA platform module is the Linux value 7, but on FreeBSD RLIMIT_NOFILE = 8 (7 is RLIMIT_NPROC). So FreeBsdOSProcessJNA was calling getrlimit on the wrong resource — returning the max-processes limit instead of open-files. Added an explicit `int RLIMIT_NOFILE = 8;` to FreeBsdLibc that shadows the inherited Linux constant so the existing call site picks up the correct value with no code change at the caller. FFM was already using 8 (added in Phase 5 commit 5). 2. fileStoreUpdateAttributes totalSpace — JNA and FFM call updateAttributes() back-to-back, but on a live filesystem total space can drift by a few blocks while the test is itself writing (the observed delta was exactly 3×4KB = 12 KB out of 208 GB). Relaxed the strict equality to assertWithinRatio with a 0.1% tolerance, the same pattern this file already uses for other drift-prone counters. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Phase 6 commit 5: remove temporary FreeBSD FFM CI workflow freebsd-ffm.yaml was the push-triggered FreeBSD VM job introduced in Phase 1 (PR #3316) so in-progress FFM work got FreeBSD coverage between PR submissions. With the port complete and the permanent testfreebsd job in pr.yaml + unix.yaml exercising every change, the temp workflow is no longer needed. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Follow-up to the five FreeBSD FFM port PRs (#3316, #3319, #3322, #3328, #3330) covering loose ends that don't fit any individual port commit. JaCoCo agent excludes: * Remove `**/unix/BsdNetworkIF*` and `**/unix/UnixBaseboard*`. Both classes were hoisted to oshi-common during the port (#3316 and #3328 respectively) and are now exercised on the permanent FreeBSD CI job through `NativeComparisonTest.networkInterfaces()` and `ComputerSystem.getBaseboard()`; the excludes were silently dropping that coverage from the `freebsd` codecov flag. * Add `**/FreeBsdPowerSource*` alongside the existing `**/{Mac,Windows,Linux}PowerSource*` entries. No battery on the FreeBSD CI VM, same hardware-conditional pattern. Documentation: * Update the supported-platforms statement in README.md, FAQ.md, PERFORMANCE.md, src/site/markdown/index.md, oshi-core-ffm module-info Javadoc, oshi-core SystemInfo Javadoc, and oshi-core package-info Javadoc from "Windows, macOS, and Linux" to "Windows, macOS, Linux, and FreeBSD". CHANGELOG.md gains a New Features bullet linking all five FreeBSD FFM port PRs. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Phase 5 of the FreeBSD FFM port (tracking #3315). Lands the six
remaining
FreeBsd*FFMconcretes (FileSystem, InternetProtocolStats,PowerSource, HWDiskStore, OperatingSystem, OSProcess) plus the
aggregate
FreeBsdHardwareAbstractionLayerFFMbookend, finishing theHAL/OS implementation. FFM
SystemInfostill reports FreeBSD asunsupported — wiring waits for Phase 6.
Per-commit walk
FreeBsdFileSystemFFM(trivial mirror,kern.openfiles+kern.maxfilesviaBsdSysctlUtilFFM). Foldsin three Sonar findings from PR FreeBSD Port: FFM concretes for Memory/Sensors/Network/CPU #3322's review cycle:
HOST_NAME_MAX + 1widened to long inFreeBsdNetworkParamsFFM(S2184), and two
.longValue()unboxes removed inDisklabelTest(S2153). A fourth Sonar finding (CPUMASK regex S5998 in
FreeBsdCentralProcessorFFM) was triaged as a false positive — thecomma anchor between alternatives prevents catastrophic
backtracking, and input is bounded kernel-controlled sysctl output.
FreeBsdInternetProtocolStatsFFM. Memoizesthe
net.inet.tcp.stats/net.inet.udp.statsraw buffers fromBsdSysctlUtilFFM.sysctl(name)directly instead of materializingan intermediate
BsdTcpstat/BsdUdpstatholder the way the JNAsibling does — FFM lets us pull each field out at offset on demand.
FreeBsdPowerSourceFFM. Threehw.acpi.battery.*sysctl reads +acpiconf -i 0parsing.FreeBsdHWDiskStoreFFM. One sysctl read(
kern.disks) +iostat -Ixparsing + the pure-JavaGeomDiskList/GeomPartListdrivers in oshi-common from Phase 2.FreeBsdOperatingSystemFFM+FreeBsdOSProcessFFM(they're circularly dependent, so they landtogether). Extends
FreeBsdLibcFunctionswith four new bindings:getpid,thr_self,sysctl(int-MIB form with errno capturefor
kern.proc.*queries), andgetrlimit+RLIMIT_LAYOUT(twolongs) +
RLIMIT_NOFILE = 8(the FreeBSD value, not Linux's 7).Hoists
ProcstatUtil(oshi-core/oshi.util.platform.unix.freebsd)to oshi-common (
oshi.util.common.platform.unix.freebsd) per thePhase 2 pattern; both modules now import it from the common path.
The live test now derives the PID from
ManagementFactoryratherthan
oshi.SystemInfoso it can live in oshi-common.FreeBsdHardwareAbstractionLayerFFMbookend. Wires the FFM concretes from Phases 4–5; pure-Java
BSD-shared classes (
UnixDisplay,BsdNetworkIF,FreeBsd*forgraphics/sound/USB) come from oshi-common. Hoists
BsdNetworkIF(oshi-core/
oshi.hardware.platform.unix) tooshi-common/
oshi.hardware.common.platform.unix, mirroring Phase2's treatment of the other pure-Java BSD hardware classes; the
three JNA HALs that consumed it (FreeBSD, OpenBSD, DragonFlyBSD)
pick up the new import path with no behavior change.
Intentionally deferred
SystemInfofactory wiring — Phase 6. Keeps thehalf-built state hidden until everything is in place.
NativeComparisonTeststays gated to{LINUX, MAC, WINDOWS}.testing pattern established in FreeBSD Port: FFM libc bindings + sysctl util + WhoFFM driver #3319 commit 3, Phase 6's
NativeComparisonTestHAL/OS traversal will cover all of thesetransitively through the public API once
SystemInfowiresFreeBSD in.
Test plan
./mvnw clean compileacross oshi-common, oshi-core,oshi-core-ffm on each commit
./mvnw test— 749 (common) + 121 (core) + 68 (core-ffm) testspass on Mac; FreeBSD-only tests skip as expected
./mvnw spotless:check checkstyle:checkclean on each modulecommit hit a flaky
testFileSystem"total space should notchange" race in oshi-core's JNA test suite — unrelated to FFM)
testfreebsdjob inpr.yamlwill exercisethe codebase under
flags: freebsdTracks #3315.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor
Bug Fixes
Tests