Repository navigation
Restore optional JNA native access for NetBSD with command-line fallback - #3433
Conversation
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).
|
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 skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (12)
📝 WalkthroughWalkthroughAdds 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. ChangesNetBSD JNA Support
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
Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 #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
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: 1
🧹 Nitpick comments (1)
.github/workflows/unix.yaml (1)
150-198: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider consolidating
testnetbsdandtestnetbsdjnavia a matrix to reduce duplication.The two jobs are identical except for the
pkg_add java-jnaline and theJAVA_TOOL_OPTIONSexport. A single job parameterized with a matrix (e.g., aninstall/envvariable 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
📒 Files selected for processing (15)
.github/workflows/unix.yamloshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.javaoshi-core/src/main/java/module-info.javaoshi-core/src/main/java/oshi/SystemInfo.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdCentralProcessorJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/package-info.javaoshi-core/src/main/java/oshi/jna/platform/unix/NetBsdLibc.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.javaoshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/package-info.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.javaoshi-core/src/main/java/oshi/util/platform/unix/netbsd/package-info.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/SystemInfo.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/NetBsdCentralProcessorJNA.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/package-info.javaoshi-core/src/main/java/oshi/hardware/platform/unix/netbsd/package-info.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOSProcessJNA.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystemJNA.javaoshi-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.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.javaoshi-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/libmatches the pkgsrcjava-jnainstall 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 & AvailabilityGuard against zero-length
sysctlresults before allocatingMemory.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 CorrectnessNetBSD supports per-CPU
kern.cp_timeMIBs 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 CorrectnessCheck the
getrlimitfailure path IfNetBsdLibc.INSTANCE.getrlimit(...)returns an error code here, fall back tosuperbefore readingrlim_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/getThreadIdcorrectly gate the native calls behindNetBsdSysctlUtil.JNA_AVAILABLEwith fallback to the command-line superclass, consistent with the PR's stated goal of restoring optional JNA support for NetBSD.createProcesscorrectly wires inNetBsdOSProcessJNA.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).
* 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.
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-jnapackage, 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 whenjava-jnais present and continues to work without it.How it works
NetBsdSysctlUtil.JNA_AVAILABLE(following theSolarisOperatingSystemJNA/HAS_KSTAT2pattern) forcesNetBsdLibc.INSTANCEat class load and catchesUnsatisfiedLinkError. Detected once.*JNAsubclasses in oshi-core, each extending the command-lineNetBsd*base in oshi-common and gating per method (if (!JNA_AVAILABLE) return super.x();):NetBsdCentralProcessorJNA—kern.cp_timeticks (system + per-CPU) andgetloadavgNetBsdOperatingSystemJNA—getpid/_lwp_selffor process/thread identityNetBsdOSProcessJNA—getrlimitopen-file limits andkern.proc_argsfor other processes' environmentNetBsdHardwareAbstractionLayerJNA— supplies the JNA processorSystemInfoselects the*JNAclasses; oshi-core-ffm is unchanged (keeps the native-free command-line classes). CommonNetBsdOperatingSystemgains an overridablecreateProcessfactory andNetBsdHardwareAbstractionLayeris de-finalized, mirroring the existing FreeBSD hooks.NetBsdLibcnow definesRLIMIT_NOFILE = 8(NetBSD's value from<sys/resource.h>). JNA's inheritedResource.RLIMIT_NOFILEis the Linux value7, so the pre-Remove JNA native library requirement for NetBSD #3310 code would have queried the wrong resource.Testing
unix.yamlnow runs the NetBSD 10.1 VM on both paths:Test JDK 21, NetBSD (no JNA)— nojava-jna; exercises the command-line fallback (JNA_AVAILABLE == false)Test JDK 21, NetBSD (JNA)— installsjava-jnaand pointsjna.boot.library.pathat the pkgsrclibjnidispatch; 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