Skip to content

Restore optional JNA native access for NetBSD with command-line fallback - #3433

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:netbsd-jna-restore
Jul 7, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:netbsd-jna-restore

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 7, 2026 •

Copy link
Copy Markdown
Member

Resolves #3347.

Summary

NetBSD's JNA native support was removed in #3310 because JNA does not distribute a native binary for NetBSD — it is only available as the optional pkgsrc java-jna package, and OSHI does not require users to install dependencies. This PR restores the native path while keeping the command-line implementation as a runtime fallback, so NetBSD gets native performance when java-jna is present and continues to work without it.

How it works

  • Availability gate — NetBsdSysctlUtil.JNA_AVAILABLE (following the SolarisOperatingSystemJNA / HAS_KSTAT2 pattern) forces NetBsdLibc.INSTANCE at class load and catches UnsatisfiedLinkError. Detected once.
  • Native *JNA subclasses in oshi-core, each extending the command-line NetBsd* base in oshi-common and gating per method (if (!JNA_AVAILABLE) return super.x();):
    • NetBsdCentralProcessorJNA — kern.cp_time ticks (system + per-CPU) and getloadavg
    • NetBsdOperatingSystemJNA — getpid / _lwp_self for process/thread identity
    • NetBsdOSProcessJNA — getrlimit open-file limits and kern.proc_args for other processes' environment
    • NetBsdHardwareAbstractionLayerJNA — supplies the JNA processor
  • Wiring — the oshi-core (JNA) SystemInfo selects the *JNA classes; oshi-core-ffm is unchanged (keeps the native-free command-line classes). Common NetBsdOperatingSystem gains an overridable createProcess factory and NetBsdHardwareAbstractionLayer is de-finalized, mirroring the existing FreeBSD hooks.
  • Bug fix along the way — NetBsdLibc now defines RLIMIT_NOFILE = 8 (NetBSD's value from <sys/resource.h>). JNA's inherited Resource.RLIMIT_NOFILE is the Linux value 7, so the pre-Remove JNA native library requirement for NetBSD #3310 code would have queried the wrong resource.

Testing

unix.yaml now runs the NetBSD 10.1 VM on both paths:

  • Test JDK 21, NetBSD (no JNA) — no java-jna; exercises the command-line fallback (JNA_AVAILABLE == false)
  • Test JDK 21, NetBSD (JNA) — installs java-jna and points jna.boot.library.path at the pkgsrc libjnidispatch; exercises the native path (JNA_AVAILABLE == true)

Clean full-reactor build + spotless/checkstyle/forbiddenapis/javadoc pass locally. Runtime behavior on NetBSD is validated by the two CI jobs above (JNA native calls can't be exercised on the local macOS build).

Summary by CodeRabbit

  • New Features
    • Added optional JNA-backed NetBSD support for CPU and process details (including improved tick breakdown and system load average), activated only when the native library is present.
    • Enhanced NetBSD environment and open-file limit retrieval under JNA.
    • Expanded the NetBSD JNA package exposure in the public module surface.
  • Bug Fixes
    • Restored correct NetBSD file-descriptor limit behavior with automatic fallback when JNA native access isn’t available.
  • Chores
    • Updated CI to run NetBSD tests separately with and without JNA installed.

NetBSD's JNA native support was removed in #3310 because JNA does not distribute
a native binary for NetBSD (only the optional pkgsrc java-jna package), and OSHI
does not require installing dependencies. This restores the native path while
keeping the command-line implementation as a runtime fallback.

A JNA-availability gate (NetBsdSysctlUtil.JNA_AVAILABLE, following the Solaris
HAS_KSTAT2 pattern) forces NetBsdLibc.INSTANCE at class load and catches
UnsatisfiedLinkError. When JNA is available the new *JNA subclasses use native
sysctl (cp_time ticks, load average), getpid/_lwp_self for process/thread
identity, getrlimit for open-file limits, and kern.proc_args for other
processes' environment; otherwise each method delegates to the command-line
NetBsd* base classes in oshi-common.

The oshi-core JNA SystemInfo now selects the *JNA NetBSD classes; oshi-core-ffm
continues to use the native-free command-line classes. Common
NetBsdOperatingSystem gains an overridable createProcess factory and
NetBsdHardwareAbstractionLayer is de-finalized, mirroring the FreeBSD hooks.

NetBsdLibc gains RLIMIT_NOFILE = 8 (NetBSD's value); JNA's inherited
Resource.RLIMIT_NOFILE is the Linux value 7, so the pre-#3310 code would have
queried the wrong resource.

unix.yaml now runs the NetBSD VM both without java-jna (command-line path) and
with it (native path).
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a80a72e2-466e-47c9-840d-eca8bc5ccac7

📥 Commits

Reviewing files that changed from the base of the PR and between 3e25321 and 12c7a79.

📒 Files selected for processing (1)
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (12)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)

📝 Walkthrough

Walkthrough

Adds NetBSD JNA-backed implementations for sysctl access, OS process, operating system, and central processor, opens base classes for extension, routes NetBSD wiring to the new classes, exports the new package, and splits CI into JNA and non-JNA NetBSD jobs.

Changes

NetBSD JNA Support

Layer / File(s) Summary
Base class extension points
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java, oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
Removes final from NetBsdHardwareAbstractionLayer, widens NetBsdOSProcess.os to protected, and introduces an overridable createProcess hook in NetBsdOperatingSystem.
NetBSD sysctl JNA utility
oshi-core/src/main/java/oshi/jna/platform/unix/NetBsdLibc.java, oshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.java, oshi-core/src/main/java/oshi/util/platform/unix/netbsd/package-info.java
Adds NetBsdSysctlUtil with JNA_AVAILABLE detection and overloaded native sysctl calls for int/long/String/Structure/Memory results, plus a RLIMIT_NOFILE constant and utility package docs.
NetBsdOSProcessJNA implementation
oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java
Adds JNA-backed open-file-limit and environment-variable retrieval via getrlimit and kern.proc_args, falling back to the superclass when unavailable.
NetBsdOperatingSystemJNA and wiring
oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.java, oshi-core/src/main/java/oshi/SystemInfo.java, oshi-core/src/main/java/module-info.java, oshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.java
Adds JNA-backed process/thread ID retrieval and a createProcess override returning NetBsdOSProcessJNA, routes NetBSD OS creation through the JNA class, and exports the NetBSD utility package.
NetBsdCentralProcessorJNA and HAL
oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdCentralProcessorJNA.java, oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHardwareAbstractionLayerJNA.java, oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/package-info.java, oshi-core/src/main/java/oshi/SystemInfo.java
Adds JNA-backed CPU tick and load average queries via kern.cp_time sysctl and getloadavg, plus a HAL override returning the JNA processor and NetBSD hardware wiring in SystemInfo.
CI job split
.github/workflows/unix.yaml, CHANGELOG.md
Relabels the existing job as "NetBSD (no JNA)", adds a testnetbsdjna job installing java-jna and running tests with JNA enabled, and records the NetBSD JNA restoration in the changelog.

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

Sequence Diagram(s)

sequenceDiagram
  participant SystemInfo
  participant NetBsdOperatingSystemJNA
  participant NetBsdOSProcessJNA
  participant NetBsdSysctlUtil
  participant NetBsdLibc

  SystemInfo->>NetBsdOperatingSystemJNA: createOperatingSystem()
  NetBsdOperatingSystemJNA->>NetBsdOperatingSystemJNA: getProcessListFromPS()
  NetBsdOperatingSystemJNA->>NetBsdOSProcessJNA: createProcess(pid, psMap)
  NetBsdOSProcessJNA->>NetBsdSysctlUtil: sysctl(kern.proc_args, KERN_PROC_ENV)
  NetBsdSysctlUtil->>NetBsdLibc: native sysctl call
  NetBsdLibc-->>NetBsdSysctlUtil: buffer or error
  NetBsdSysctlUtil-->>NetBsdOSProcessJNA: Memory or null
  NetBsdOSProcessJNA-->>NetBsdOperatingSystemJNA: environment map
Loading

Possibly related issues

Possibly related PRs

  • oshi/oshi#3307: Both PRs touch NetBSD wiring in SystemInfo.java's NETBSD switch cases and module-info.java's package export.
  • oshi/oshi#3375: Introduces the overridable createProcess(int, Map<BsdPsKeyword,String>) factory pattern that this PR relies on for NetBSD.
  • oshi/oshi#3387: Refactors NetBsdCentralProcessor with sysctl/queryVmStats hooks that NetBsdCentralProcessorJNA in this PR subclasses.

Poem

A rabbit hops through pkgsrc lanes,
JNA gears turn, no fallback pains 🐇
sysctl whispers cp_time's beat,
loadavg hums a native feat.
NetBSD now runs swift and true—
two CI jobs, JNA and non-JNA too!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: restoring optional NetBSD JNA support with a command-line fallback.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.15%. Comparing base (c21538a) to head (12c7a79).

Files with missing lines Patch % Lines
oshi-core/src/main/java/oshi/SystemInfo.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3433      +/-   ##
============================================
- Coverage     75.19%   75.15%   -0.04%     
  Complexity       76       76              
============================================
  Files           580      580              
  Lines         21609    21609              
  Branches       3588     3588              
============================================
- Hits          16248    16240       -8     
- Misses         3331     3339       +8     
  Partials       2030     2030              
Flag Coverage Δ
freebsd 26.94% <0.00%> (-0.01%) ⬇️
linux 31.55% <0.00%> (-0.02%) ⬇️
macos 31.77% <0.00%> (-0.05%) ⬇️
openbsd 26.43% <0.00%> (+<0.01%) ⬆️
solaris 28.49% <0.00%> (+0.03%) ⬆️
windows 40.02% <0.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.

@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: 1

🧹 Nitpick comments (1)
.github/workflows/unix.yaml (1)

150-198: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider consolidating testnetbsd and testnetbsdjna via a matrix to reduce duplication.

The two jobs are identical except for the pkg_add java-jna line and the JAVA_TOOL_OPTIONS export. A single job parameterized with a matrix (e.g., an install/env variable pair) would avoid maintaining two near-duplicate step blocks going forward.

🤖 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 @.github/workflows/unix.yaml around lines 150 - 198, Consolidate the
duplicated NetBSD workflow jobs into a single matrix-based job. The only
differences between testnetbsd and testnetbsdjna are the java-jna package
install and the JAVA_TOOL_OPTIONS setting, so refactor the workflow to
parameterize those variations with matrix values. Keep the shared checkout,
vmactions/netbsd-vm setup, and test command in one job, and use the matrix to
control the optional JNA install and environment variable.
🤖 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-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java`:
- Around line 94-116: The environment parsing in
NetBsdOSProcessJNA.queryEnvironmentVariables advances the buffer offset using
Java string length, but the sysctl payload is native bytes and may use a
multibyte charset. Update the loop to advance by the actual byte length of each
NUL-terminated entry read from Memory, not envStr.length(), so parsing stays
aligned and subsequent environment entries are not corrupted; keep the fix
localized to the sysctl read loop and the offset update logic.

---

Nitpick comments:
In @.github/workflows/unix.yaml:
- Around line 150-198: Consolidate the duplicated NetBSD workflow jobs into a
single matrix-based job. The only differences between testnetbsd and
testnetbsdjna are the java-jna package install and the JAVA_TOOL_OPTIONS
setting, so refactor the workflow to parameterize those variations with matrix
values. Keep the shared checkout, vmactions/netbsd-vm setup, and test command in
one job, and use the matrix to control the optional JNA install and environment
variable.
🪄 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: 51300fbd-5c72-4b12-b770-0bea8163c589

📥 Commits

Reviewing files that changed from the base of the PR and between c21538a and 5ec54fe.

📒 Files selected for processing (15)
  • .github/workflows/unix.yaml
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.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/netbsd/NetBsdCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/package-info.java
  • oshi-core/src/main/java/oshi/jna/platform/unix/NetBsdLibc.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.java
  • oshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.java
  • oshi-core/src/main/java/oshi/util/platform/unix/netbsd/package-info.java
📜 Review details
⏰ Context from checks skipped due to timeout. (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-core/src/main/java/oshi/jna/platform/unix/NetBsdLibc.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/util/platform/unix/netbsd/package-info.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.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/netbsd/NetBsdHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/package-info.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdCentralProcessorJNA.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: For the NetBSD platform implementation in this project (under `oshi/software/os/unix/netbsd/`), do not recommend reintroducing JNA/native-library calls (e.g., `NetBsdLibc._lwp_self()`), because the NetBSD platform intentionally avoids bundling JNA with its Maven dependency. Instead, keep using Java thread identifiers (e.g., `(int) Thread.currentThread().getId()` in `NetBsdOperatingSystem.getThreadId()`), and treat any mismatch between Java thread IDs and kernel LWP IDs as an accepted trade-off.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java
📚 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/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
📚 Learning: 2026-05-31T05:53:04.246Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3311
File: .github/workflows/site.yaml:21-21
Timestamp: 2026-05-31T05:53:04.246Z
Learning: When a GitHub Actions workflow verifies that a pinned commit SHA matches a version tag, dereference annotated tags before comparing to a commit SHA. The API `GET /repos/{owner}/{repo}/git/refs/tags/{tag}` returns the tag *object* SHA for annotated tags (not the underlying commit SHA), so comparing it directly to a commit SHA will cause false mismatches. Instead: (1) fetch the tag object SHA via `GET /repos/{owner}/{repo}/git/refs/tags/{tag}`; (2) resolve that tag object to the underlying commit by calling `GET /repos/{owner}/{repo}/git/tags/{tag_object_sha}`; (3) compare the pinned commit SHA to the resolved commit at `.object.sha`.

Applied to files:

  • .github/workflows/unix.yaml
🔇 Additional comments (21)
.github/workflows/unix.yaml (2)

150-153: LGTM!


173-198: 🚀 Performance & Scalability

/usr/pkg/lib matches the pkgsrc java-jna install path, so this hardcoded JNA library path is fine.

			> Likely an incorrect or invalid review comment.
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.java (1)

35-35: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (1)

62-62: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java (1)

82-101: LGTM!

oshi-core/src/main/java/oshi/jna/platform/unix/NetBsdLibc.java (1)

62-68: LGTM!

oshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.java (3)

34-54: LGTM!


19-134: LGTM!


143-157: 🩺 Stability & Availability

Guard against zero-length sysctl results before allocating Memory. new Memory(0) throws, so a zero-sized response would bypass the method’s null-on-failure behavior.

oshi-core/src/main/java/oshi/util/platform/unix/netbsd/package-info.java (1)

1-9: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdCentralProcessorJNA.java (2)

1-106: LGTM!


60-78: 🎯 Functional Correctness

NetBSD supports per-CPU kern.cp_time MIBs The third MIB element is valid here, so this loop can query per-CPU ticks as intended.

			> Likely an incorrect or invalid review comment.
oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHardwareAbstractionLayerJNA.java (1)

1-23: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/package-info.java (1)

1-9: LGTM!

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

18-28: LGTM!

Also applies to: 133-133, 169-169

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

26-26: LGTM!

oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.java (3)

40-57: LGTM on ARGMAX static initializer.

Handles the JNA-unavailable case and logs on sysctl failure. No issues.


1-39: LGTM!

Also applies to: 84-93, 117-119


63-82: 🎯 Functional Correctness

Check the getrlimit failure path If NetBsdLibc.INSTANCE.getrlimit(...) returns an error code here, fall back to super before reading rlim_cur/rlim_max; otherwise a failed call can surface as a bogus zero limit.

oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.java (1)

1-45: LGTM!

getProcessId/getThreadId correctly gate the native calls behind NetBsdSysctlUtil.JNA_AVAILABLE with fallback to the command-line superclass, consistent with the PR's stated goal of restoring optional JNA support for NetBSD. createProcess correctly wires in NetBsdOSProcessJNA.

oshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.java (1)

1-9: LGTM!

The KERN_PROC_ENV sysctl payload is a NUL-delimited native byte buffer;
advancing the offset by String.length() misaligns on a multibyte charset.
Parse via ParseUtil.parseByteArrayToStrings on the raw bytes instead (the same
byte-based helper used by the command-line queryArguments).
@dbwiddis
dbwiddis merged commit f19cf50 into oshi:master Jul 7, 2026
18 of 19 checks passed
@dbwiddis
dbwiddis deleted the netbsd-jna-restore branch July 7, 2026 18:37
@dbwiddis dbwiddis mentioned this pull request Jul 7, 2026
dbwiddis added a commit that referenced this pull request Sep 20, 2026
* CI: test NetBSD on JDK 25, covering the FFM implementation

pr.yaml gains a NetBSD job alongside FreeBSD, OpenBSD and OpenIndiana, on the
same unix path gate: JDK 25 with pkgsrc java-jna installed, so both native
implementations run and the oshi.comparison tests compare like with like.

unix.yaml's NetBSD JNA job moves from JDK 21 to 25 and from jna-aggregate to
aggregate-coverage, so one job covers JNA, FFM and the comparison tests. Its
no-JNA counterpart stays on JDK 21: it exists to exercise the command-line
fallback where JNA_AVAILABLE is false, which needs no FFM.

The JDK 25 jobs upload under a plain `netbsd` flag, as the other platforms do,
retiring `netbsd-jna`. The no-JNA job keeps `netbsd-nojna` rather than sharing
that flag: carryforward is per flag, so a PR uploading `netbsd` suppresses the
carried-forward master value, and the fallback-only lines this master-only job
covers would read as uncovered on every PR.

pkgsrc has no binary openjdk25 package yet, so the JDK 25 jobs try pkg_add
first and fall back to a checksum-pinned mirror of the pkgsrc-wip bootstrap
JDK. Neither source available, or a checksum mismatch, fails the job rather
than quietly dropping FFM coverage. The mirror becomes dead code once
lang/openjdk25 ships.

* Add FFM native access for NetBSD

The FFM backend on NetBSD used the native-free oshi-common classes, so every
value came from running a command. Add FFM bindings for sysctl, getloadavg,
_lwp_self, getpid and getrlimit, mirroring the optional JNA path (#3433): CPU
ticks from kern.cp_time, the load average, process and thread IDs, the open-file
limits, other processes' environments via kern.proc_args, and the routing table
via NET_RT_DUMP.

Each native call is gated on NetBsdSysctlUtilFFM.FFM_AVAILABLE and falls back to
the command-line implementation when it is false. NetBSD's JDK builds for i386
and 32-bit ARM use the Zero VM, which may have no native linker; there, loading
the bindings throws, and the gate catches it once at class load.

To keep the two backends from diverging, the logic the JNA twin carried is
hoisted into oshi-common as hooks the backends fill in: queryCpTime and
queryLoadAverage on NetBsdCentralProcessor, and queryEnvironmentBytes on
NetBsdOSProcess, which also uses BsdOSProcess's existing queryRlimitNofile. The
JNA classes now override only those hooks.

NativeComparisonTest runs on NetBSD, through a PlatformEnum condition since
JUnit's OS enum has no constant for it. Two of its readings are taken again when
the kernel reports a process as a zombie mid-posix_spawn, and its priority
comparison is skipped as it already is on Solaris, NetBSD's pri column being the
dynamic lwp_eprio value.

oshi-core-ffm also gains the test logger configuration the other modules have:
the three BSD sysctl tests each look up a name or MIB that does not exist, to
prove the default is returned, and each logged a warning that reads like a
defect in a CI log.

Closes #3348

* Stop PERFORMANCE.md enumerating the FFM platforms

The list omitted NetBSD and DragonFly BSD. FAQ.md already states that the FFM
implementation covers the same platforms as JNA, so defer to that rather than
keeping a second list in step with it.
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.

NetBSD: restore JNA native calls with command-line fallback

1 participant