Skip to content

DragonFly BSD: add FFM port; refactor to mirror FreeBSD split - #3362

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:dragonfly-ffm
Jun 9, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:dragonfly-ffm

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #3346. Adds DragonFly BSD support to oshi-core-ffm, refactoring the existing JNA implementation along the way to match the abstract-base / JNA-subclass / FFM-subclass split used by FreeBSD/AIX.

With this PR, oshi-core-ffm covers the same set of platforms as oshi-core (JNA). The user-facing story is now simple: OSHI has JNA and FFM implementations; both cover all supported platforms; pick whichever fits your deployment.

What changed

Refactor (mirror FreeBSD pattern)

  • Move no-native DragonFly code to oshi-common: DragonFlyBsdOSThread and ProcstatUtil (with its test) are pure shell/file-parsing; they live next to the other Unix oshi-common classes.
  • Extract DragonFlyBsdOSProcess abstract base into oshi-common, holding the shared PsThreadColumns enum + PS_THREAD_COLUMNS constant used by both OSProcess and OSThread (same pattern as FreeBsdOSProcess).
  • Rename JNA classes with JNA suffix in oshi-core: DragonFlyBsd{OperatingSystem,OSProcess,CentralProcessor,HardwareAbstractionLayer}JNA. Matches FreeBSD/AIX.

New FFM implementations (oshi-core-ffm)

  • DragonFlyBsdLibcFunctions — adds only the DragonFly-specific lwp_gettid() downcall. Shared libc surface (getpid, sysctl, getrlimit, sysctlbyname) is reused from FreeBsdLibcFunctions.
  • DragonFlyBsdCentralProcessorFFM extends FreeBsdCentralProcessorFFM — inherits kern.cp_time system-tick logic from FreeBSD; overrides queryProcessorCpuLoadTicks to use DragonFly's kern.cputime sysctl (FreeBSD uses kern.cp_times).
  • DragonFlyBsdHardwareAbstractionLayerFFM — uses FreeBSD FFM implementations where behavior is identical (computer system, memory, sensors, power, disks, USB, sound, graphics, displays, network); overrides createProcessor for the DragonFly-specific CP; uses CupsPrinterFFM for printers.
  • DragonFlyBsdOperatingSystemFFM — full FFM implementation mirroring the JNA structure; uses FreeBsdLibcFunctions.getpid, DragonFlyBsdLibcFunctions.lwp_gettid, BsdSysctlUtilFFM for kern.boottime, and FreeBSD FFM file system / IP stats / network params.
  • DragonFlyBsdOSProcessFFM — full FFM implementation; uses FreeBsdLibcFunctions.getrlimit for file-descriptor limits and FreeBsdLibcFunctions.sysctl(int MIB) for bitness detection.

Wiring + docs

  • oshi.ffm.SystemInfo gains case DRAGONFLYBSD in createOperatingSystem and createHardware; DRAGONFLYBSD added to SUPPORTED_PLATFORMS.
  • oshi-common/module-info.java and oshi-core-ffm/module-info.java get the new package exports; oshi-core/module-info.java drops the moved-out oshi.util.platform.unix.dragonflybsd export.
  • module-info.test adds --add-opens entries for the new DragonFly packages in oshi-common.
  • ProcstatUtilTest switches from oshi.SystemInfo to ManagementFactory for its live-DragonFly PID (matches the FreeBSD/NetBSD test pattern, avoiding a oshi-common-to-oshi-core dependency).
  • Docs simplification — README selection-matrix, FAQ FFM platform list, oshi-core-ffm/module-info javadoc, and oshi-core/SystemInfo + oshi-core-ffm/SystemInfo javadoc all drop the "currently supports these specific OSes" lists, since FFM and JNA now cover the same platforms. The selection matrix in README just says "all supported platforms" for both columns.

Test plan

  • ./mvnw clean install from repo root passes (all 788 tests).
  • Spotless / Checkstyle / Forbidden APIs / Javadoc clean on oshi-common, oshi-core, oshi-core-ffm.
  • oshi-core SystemInfo references the new JNA-suffixed class names.
  • oshi-core-ffm SystemInfo now supports DragonFly; throws only for genuinely unsupported platforms.
  • PR CI matrix passes (Linux/macOS/Windows + FreeBSD/OpenBSD/OpenIndiana). DragonFly VM job runs only in unix.yaml push-to-master, so the FFM path is not exercised by PR CI today — same gap we've worked around for NetBSD.
  • Post-merge Unix CI validates the JNA-suffixed DragonFly classes still work on the actual DragonFly VM (the no-FFM portion).

Caveats / notes

  • The DragonFly FFM code path is untested in CI today (DragonFly's pkg install openjdk25 is still failing per FFM port: DragonFly BSD (extend FreeBSD bindings) #3346's blocker — no published binary on the vmactions DF VM image). When that clears, unix.yaml can be bumped to JDK 25 for DragonFly and FFM will be exercised. The FFM code is structured to closely mirror the FreeBSD FFM bindings, so confidence is high.
  • Behavior on JDK < 25 is unchanged: oshi.SystemInfo (JNA) instantiates the renamed DragonFlyBsd*JNA classes from oshi-core.

Summary by CodeRabbit

  • New Features

    • FFM backend now supports DragonFly BSD, adding DragonFly-specific OS and hardware coverage.
  • Documentation

    • Platform compatibility and implementation-selection docs updated to reflect FFM parity with the JNA implementation and standardized eligibility wording.
  • Tests

    • Test configuration and live tests updated to include DragonFly BSD package access and runtime PID acquisition for DragonFly-related tests.

Closes #3346. With this, oshi-core-ffm covers the same set of platforms
as oshi-core (JNA) — no platform exceptions in either docs or code.

- Move no-native DragonFly classes (OSThread, ProcstatUtil) to
  oshi-common.
- Extract DragonFlyBsdOSProcess abstract base into oshi-common, holding
  the shared PsThreadColumns enum + PS_THREAD_COLUMNS constant used by
  both OSProcess and OSThread. Mirrors the FreeBSD pattern.
- Rename the JNA implementations with JNA suffix
  (DragonFlyBsd{OperatingSystem,OSProcess,CentralProcessor,HardwareAbstractionLayer}JNA)
  for naming consistency with FreeBSD/AIX.
- Add the FFM port: DragonFlyBsdLibcFunctions (lwp_gettid only —
  everything else is reused from FreeBsdLibcFunctions),
  DragonFlyBsdCentralProcessorFFM (extends FreeBsdCentralProcessorFFM,
  overrides per-CPU tick query for DragonFly's kern.cputime sysctl),
  DragonFlyBsdHardwareAbstractionLayerFFM, DragonFlyBsdOperatingSystemFFM,
  DragonFlyBsdOSProcessFFM.
- Wire DRAGONFLYBSD into oshi.ffm.SystemInfo's SUPPORTED_PLATFORMS,
  createOperatingSystem, and createHardware.
- Update module-info.java in oshi-common and oshi-core-ffm to export
  the new packages; remove the now-empty oshi.util.platform.unix.
  dragonflybsd export from oshi-core. Add --add-opens entries for the
  new oshi-common test packages.
- Drop the redundant "(currently supported platforms …)" lists from
  README, FAQ, module-info, and SystemInfo javadocs. oshi-core-ffm now
  matches oshi-core platform coverage, so the docs just say "supports
  all OSHI-supported platforms."
- DragonFly ProcstatUtilTest uses ManagementFactory for its live PID
  (matches the FreeBSD/NetBSD test pattern), avoiding a oshi-common-to-
  oshi-core dependency on SystemInfo.

Tested with \`./mvnw clean install\` from root (all 788 tests pass).
@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR consolidates DragonFly BSD code into shared common packages, renames and re-wires JNA-specific DragonFly classes to use those commons, and adds a complete FFM implementation (libc downcalls, HAL, processor ticks, OS/process introspection) plus documentation and test updates.

Changes

DragonFly BSD Platform Unification

Layer / File(s) Summary
Shared abstractions and module structure
oshi-common/src/main/java/module-info.java, oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/*, oshi-common/src/test/java/module-info.test, oshi-common/src/test/java/oshi/util/common/platform/unix/dragonflybsd/*
New common packages oshi.software.common.os.unix.dragonflybsd and oshi.util.common.platform.unix.dragonflybsd. Adds DragonFlyBsdOSProcess abstract class with PsThreadColumns and PS_THREAD_COLUMNS; moves/updates DragonFlyBsdOSThread and ProcstatUtil package declarations and test module access.
JNA implementation refactoring
oshi-core/src/main/java/module-info.java, oshi-core/src/main/java/oshi/SystemInfo.java, oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsd*JNA.java, oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsd*JNA.java
Renames JNA classes to include JNA suffix, updates imports/wiring to use common abstractions, and routes DRAGONFLYBSD cases in SystemInfo to JNA variants. Removes the old module export for oshi.util.platform.unix.dragonflybsd.
FFM platform infrastructure
oshi-core-ffm/src/main/java/module-info.java, oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
FFM module docs updated to state platform support matches the JNA module; SUPPORTED_PLATFORMS gains DRAGONFLYBSD; createOperatingSystem()/createHardware() add DRAGONFLYBSD branches; oshi.ffm.platform.unix.dragonflybsd is exported.
FFM libc bindings
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/dragonflybsd/DragonFlyBsdLibcFunctions.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/dragonflybsd/package-info.java
New DragonFlyBsdLibcFunctions provides an FFM downcall wrapper for lwp_gettid() and related package documentation.
FFM hardware abstraction layer
oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdCentralProcessorFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java
DragonFlyBsdCentralProcessorFFM reads per-CPU tick counters from kern.cputime via FFM; DragonFlyBsdHardwareAbstractionLayerFFM instantiates the DragonFly-specific CPU and delegates other hardware categories to FreeBSD FFM helpers.
FFM OS and process implementation
oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java, oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
Adds DragonFlyBsdOperatingSystemFFM and DragonFlyBsdOSProcessFFM with sysctl-backed family/version/boot time, ps-based process/thread enumeration, /proc integration for cmdline/limits/start time, FFM getrlimit and ELF bitness detection, affinity parsing, and thread detail parsing using PsThreadColumns.
Documentation updates
CHANGELOG.md, FAQ.md, README.md
Changelog entry for DragonFly BSD FFM support added; FAQ/README updated to state FFM supports "the same platforms as" the JNA implementation and to standardize implementation-selection wording.

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant SystemInfo
  participant DragonFlyBsdOperatingSystemFFM
  participant DragonFlyBsdOSProcessFFM
  App->>SystemInfo: request OS/HAL for DRAGONFLYBSD
  SystemInfo->>DragonFlyBsdOperatingSystemFFM: createOperatingSystem()
  DragonFlyBsdOperatingSystemFFM->>DragonFlyBsdOSProcessFFM: enumerate/query processes (ps/sysctl/proc)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

  • oshi/oshi#3335: Similar SystemInfo/SUPPORTED_PLATFORMS wiring for adding a BSD platform to oshi-core-ffm.
  • oshi/oshi#3360: Similar FFM SystemInfo platform dispatch additions (NetBSD).
  • oshi/oshi#3330: Related FreeBSD/FFM support changes and platform wiring.

"🐰 I hopped through sysctl fields and ps lines,
lwp_gettid found by FFM's bright designs,
Threads and ticks and bitness anew,
DragonFly now flies — with a hop and a chew!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.06% 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
Title check ✅ Passed The title 'DragonFly BSD: add FFM port; refactor to mirror FreeBSD split' clearly and concisely summarizes the main changes: adding FFM support for DragonFly BSD and refactoring JNA implementations.
Linked Issues check ✅ Passed The PR successfully implements all coding objectives from issue #3346: DragonFly FFM HAL/OS mirroring JNA inheritance, lwp_gettid native binding, CPU tick override via kern.cputime, DRAGONFLYBSD platform parity, and documentation updates.
Out of Scope Changes check ✅ Passed All changes directly support the stated objective of adding DragonFly BSD FFM support and refactoring to mirror FreeBSD's architecture; no unrelated modifications are present.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@codecov

codecov Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.97%. Comparing base (23a158d) to head (a6329ac).

Files with missing lines Patch % Lines
...hi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java 0.00% 2 Missing ⚠️
oshi-core/src/main/java/oshi/SystemInfo.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3362      +/-   ##
============================================
- Coverage     74.99%   74.97%   -0.02%     
  Complexity       76       76              
============================================
  Files           552      552              
  Lines         22755    22757       +2     
  Branches       3759     3759              
============================================
- Hits          17064    17063       -1     
+ Misses         3586     3584       -2     
- Partials       2105     2110       +5     
Flag Coverage Δ
freebsd 25.75% <0.00%> (-0.02%) ⬇️
linux 29.12% <0.00%> (+<0.01%) ⬆️
macos 29.77% <0.00%> (-0.01%) ⬇️
openbsd 25.18% <0.00%> (+<0.01%) ⬆️
solaris 27.49% <0.00%> (+0.03%) ⬆️
windows 37.37% <0.00%> (-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: 3

🤖 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/dragonflybsd/ProcstatUtilTest.java`:
- Around line 89-92: The test currently falls back to -1 when parsing the JVM
pid; add a precondition assertion immediately after computing pid (from
ParseUtil.parseIntOrDefault(ManagementFactory.getRuntimeMXBean().getName().split("@",2)[0],
-1)) to fail fast if parsing failed—e.g., assertThat("Could not determine test
JVM pid", pid, is(greaterThanOrEqualTo(0))); then proceed to call
ProcstatUtil.getOpenFiles(pid); this ensures the test aborts with a clear
diagnostic instead of running with an invalid PID.

In
`@oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdCentralProcessorFFM.java`:
- Around line 43-50: The code in DragonFlyBsdCentralProcessorFFM that reads
per-CPU tick fields (the loop accessing ticks[cpu][TickType... ] using CP_USER,
CP_NICE, CP_SYS, CP_INTR, CP_IDLE offsets) assumes a non-zero cpu count and that
the ByteBuffer contains at least the expected bytes per-CPU; guard these reads
by validating cpus > 0 and that arraySize (or buf.remaining()) is >=
expectedBytesPerCpu * cpus (compute expectedBytesPerCpu from UINT64_SIZE and the
highest CP_* index used) before computing structSize and performing the loop,
and if the check fails, skip reading (or log/return) to avoid out-of-bounds
accesses.

In
`@oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java`:
- Around line 179-184: getCurrentThread() dereferences proc.getThreadDetails()
without checking if getCurrentProcess() returned null; before accessing proc,
add a null-check: call getCurrentProcess(), if it is null return a new
oshi.software.common.os.unix.dragonflybsd.DragonFlyBsdOSThread using a safe
fallback PID (e.g., 0) and the thread id from getThreadId(), otherwise proceed
to stream proc.getThreadDetails() as currently implemented (references:
getCurrentThread(), getCurrentProcess(), getThreadId(), OSProcess,
getThreadDetails(), DragonFlyBsdOSThread).
🪄 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: 59f93bd4-d099-4636-a59d-a0cd67334be3

📥 Commits

Reviewing files that changed from the base of the PR and between 23a158d and 4c77284.

📒 Files selected for processing (25)
  • CHANGELOG.md
  • FAQ.md
  • README.md
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/package-info.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtil.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/package-info.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtilTest.java
  • oshi-core-ffm/src/main/java/module-info.java
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/dragonflybsd/DragonFlyBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/dragonflybsd/package-info.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdCentralProcessorFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
  • oshi-core/src/main/java/module-info.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.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, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (3)
📚 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/dragonflybsd/DragonFlyBsdOSThread.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtil.java
📚 Learning: 2026-03-29T20:01:01.877Z
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:01.877Z
Learning: In this repo’s `module-info.java` files, keep exports aligned with which platform implementations are actually supported by the current FFM (Foreign Function & Memory) backend. Do not export FreeBSD, OpenBSD, or Solaris packages (e.g., `oshi.util.platform.unix.freebsd|openbsd|solaris`) in modules where the FFM implementation only supports Windows/macOS/Linux; this asymmetry vs older Java targets (e.g., the java11 module-info that exports all Unix packages) is intentional and should not be flagged as an omission unless the underlying support changes.

Applied to files:

  • oshi-core-ffm/src/main/java/module-info.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/DragonFlyBsdCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
🔇 Additional comments (22)
CHANGELOG.md (1)

7-7: LGTM!

FAQ.md (1)

103-103: LGTM!

README.md (1)

79-81: LGTM!

oshi-core-ffm/src/main/java/module-info.java (1)

4-5: LGTM!

Also applies to: 26-26

oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java (1)

19-19: LGTM!

Also applies to: 29-29, 63-64, 96-97, 118-119, 143-144

oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/dragonflybsd/DragonFlyBsdLibcFunctions.java (1)

1-41: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/dragonflybsd/package-info.java (1)

1-8: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java (1)

1-101: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)

1-448: LGTM!

oshi-common/src/main/java/module-info.java (1)

49-49: LGTM!

Also applies to: 58-58

oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (1)

1-30: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSThread.java (1)

5-5: LGTM!

Also applies to: 20-20, 116-131

oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/package-info.java (1)

1-9: LGTM!

oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtil.java (1)

5-5: LGTM!

oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/package-info.java (1)

8-8: LGTM!

oshi-common/src/test/java/module-info.test (1)

55-58: LGTM!

oshi-core/src/main/java/module-info.java (1)

5-5: LGTM!

oshi-core/src/main/java/oshi/SystemInfo.java (1)

17-17: LGTM!

Also applies to: 27-27, 61-63, 130-130, 165-165

oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdCentralProcessorJNA.java (1)

24-24: LGTM!

Also applies to: 26-26

oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java (1)

36-37: LGTM!

Also applies to: 39-39, 53-53

oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java (1)

38-39: LGTM!

Also applies to: 41-41, 45-45, 51-51, 53-53, 55-55, 86-86, 336-336

oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java (1)

30-30: LGTM!

Also applies to: 51-51, 53-53, 58-58, 147-148

Comment on lines +43 to +50
long structSize = arraySize / cpus;
for (int cpu = 0; cpu < cpus; cpu++) {
long base = structSize * cpu;
ticks[cpu][TickType.USER.getIndex()] = buf.get(JAVA_LONG, base + CP_USER * UINT64_SIZE);
ticks[cpu][TickType.NICE.getIndex()] = buf.get(JAVA_LONG, base + CP_NICE * UINT64_SIZE);
ticks[cpu][TickType.SYSTEM.getIndex()] = buf.get(JAVA_LONG, base + CP_SYS * UINT64_SIZE);
ticks[cpu][TickType.IRQ.getIndex()] = buf.get(JAVA_LONG, base + CP_INTR * UINT64_SIZE);
ticks[cpu][TickType.IDLE.getIndex()] = buf.get(JAVA_LONG, base + CP_IDLE * UINT64_SIZE);

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard kern.cputime layout before fixed-offset reads.

Line 43 and Lines 46-50 assume at least five uint64 tick fields per CPU. If cpus is 0 or the buffer is shorter than expected, this can throw at runtime while sampling ticks.

Suggested patch
     public long[][] queryProcessorCpuLoadTicks() {
         int cpus = getLogicalProcessorCount();
         long[][] ticks = new long[cpus][CentralProcessor.TickType.values().length];
+        if (cpus <= 0) {
+            return ticks;
+        }
         // DragonFly's kern.cputime returns a packed per-CPU array; the struct size per CPU is the total length
         // divided by CPU count (the trailing fields can vary by DragonFly version).
         MemorySegment buf = BsdSysctlUtilFFM.sysctl("kern.cputime");
         if (buf == null) {
             return ticks;
@@
         if (arraySize <= 0) {
             return ticks;
         }
         long structSize = arraySize / cpus;
+        long required = (CP_IDLE + 1L) * UINT64_SIZE;
+        if (structSize < required) {
+            return ticks;
+        }
         for (int cpu = 0; cpu < cpus; cpu++) {
             long base = structSize * cpu;
             ticks[cpu][TickType.USER.getIndex()] = buf.get(JAVA_LONG, base + CP_USER * UINT64_SIZE);
🤖 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/hardware/platform/unix/dragonflybsd/DragonFlyBsdCentralProcessorFFM.java`
around lines 43 - 50, The code in DragonFlyBsdCentralProcessorFFM that reads
per-CPU tick fields (the loop accessing ticks[cpu][TickType... ] using CP_USER,
CP_NICE, CP_SYS, CP_INTR, CP_IDLE offsets) assumes a non-zero cpu count and that
the ByteBuffer contains at least the expected bytes per-CPU; guard these reads
by validating cpus > 0 and that arraySize (or buf.remaining()) is >=
expectedBytesPerCpu * cpus (compute expectedBytesPerCpu from UINT64_SIZE and the
highest CP_* index used) before computing structSize and performing the loop,
and if the check fails, skip reading (or log/return) to avoid out-of-bounds
accesses.

Comment on lines +179 to +184
public OSThread getCurrentThread() {
OSProcess proc = getCurrentProcess();
final int tid = getThreadId();
return proc.getThreadDetails().stream().filter(t -> t.getThreadId() == tid).findFirst()
.orElse(new oshi.software.common.os.unix.dragonflybsd.DragonFlyBsdOSThread(proc.getProcessID(), tid));
}

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle null current process before dereferencing thread list.

Line 182 assumes getCurrentProcess() succeeded. If PID lookup/process fetch fails (e.g., fallback PID 0 path), this can NPE.

Suggested patch
     public OSThread getCurrentThread() {
         OSProcess proc = getCurrentProcess();
         final int tid = getThreadId();
+        if (proc == null) {
+            return new oshi.software.common.os.unix.dragonflybsd.DragonFlyBsdOSThread(getProcessId(), tid);
+        }
         return proc.getThreadDetails().stream().filter(t -> t.getThreadId() == tid).findFirst()
                 .orElse(new oshi.software.common.os.unix.dragonflybsd.DragonFlyBsdOSThread(proc.getProcessID(), tid));
     }
🤖 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/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java`
around lines 179 - 184, getCurrentThread() dereferences proc.getThreadDetails()
without checking if getCurrentProcess() returned null; before accessing proc,
add a null-check: call getCurrentProcess(), if it is null return a new
oshi.software.common.os.unix.dragonflybsd.DragonFlyBsdOSThread using a safe
fallback PID (e.g., 0) and the thread id from getThreadId(), otherwise proceed
to stream proc.getThreadDetails() as currently implemented (references:
getCurrentThread(), getCurrentProcess(), getThreadId(), OSProcess,
getThreadDetails(), DragonFlyBsdOSThread).

- ProcstatUtilTest: assert RuntimeMXBean-derived PID > 0 before using
  it, matching the FreeBSD ProcstatUtilTest precondition pattern.
- DragonFlyBsdCentralProcessorFFM: add a single structSize guard for
  the kern.cputime per-CPU layout. The dynamic structSize computation
  (unlike FreeBSD's static CPTIME_SIZE) makes an IOBE possible if the
  sysctl returns a short buffer — e.g. a stub sysctl on a non-DragonFly
  kernel. Skips the loop instead of crashing.
- CHANGELOG: match the one-liner format used for the AIX and NetBSD
  FFM ports and add the PR number.

Did not adopt CodeRabbit's getCurrentThread() null-check suggestion —
matches the no-null-check pattern used by every Unix OperatingSystem
implementation (JNA and FFM); if getCurrentProcess() could return null
it would be a longstanding cross-platform bug, not a DragonFly issue.
@dbwiddis
dbwiddis merged commit 91e3ea0 into oshi:master Jun 9, 2026
21 of 22 checks passed
@dbwiddis
dbwiddis deleted the dragonfly-ffm branch June 9, 2026 02:11
dbwiddis added a commit that referenced this pull request Jun 9, 2026
Matches the naming convention established by AIX (#3350), FreeBSD, and
extended to DragonFly today (#3362). The 8 oshi-core OpenBSD classes
(5 hardware, 3 software/os) get a JNA suffix to make the JNA-vs-FFM
split explicit in the file names. The 6 abstract bases in oshi-common
keep their unsuffixed names; the FFM classes in oshi-core-ffm already
have the FFM suffix.

- Rename:
  - OpenBsdComputerSystem.java → OpenBsdComputerSystemJNA.java
  - OpenBsdHardwareAbstractionLayer.java → OpenBsdHardwareAbstractionLayerJNA.java
  - OpenBsdCentralProcessor.java → OpenBsdCentralProcessorJNA.java
  - OpenBsdGlobalMemory.java → OpenBsdGlobalMemoryJNA.java
  - OpenBsdHWDiskStore.java → OpenBsdHWDiskStoreJNA.java
  - OpenBsdFileSystem.java → OpenBsdFileSystemJNA.java
  - OpenBsdOperatingSystem.java → OpenBsdOperatingSystemJNA.java
  - OpenBsdOSProcess.java → OpenBsdOSProcessJNA.java
- Three classes (OpenBsdGlobalMemory, OpenBsdFileSystem, OpenBsdOSProcess)
  previously used `extends oshi.<...>.<unqualified-same-name>` to
  disambiguate from the common base of the same name. With the suffix
  in place the FQN-extends becomes a regular `extends OpenBsdFoo` with
  a normal import — cleaner and matches every other platform.
- oshi-core SystemInfo updated for the two renamed entry points.
- OpenBsdSysctlUtil stays unsuffixed in oshi-core (matches the
  BsdSysctlUtil precedent — the FFM counterpart OpenBsdSysctlUtilFFM
  carries the suffix on the FFM side only).

Tested with `./mvnw clean install` from root (all tests pass).
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.

FFM port: DragonFly BSD (extend FreeBSD bindings)

1 participant