Skip to content

Consolidate sysctl utilities into shared helpers and fix int-width sysctl misread (#3517) - #3518

Merged
dbwiddis merged 4 commits into
oshi:masterfrom
dbwiddis:refactor-sysctl-cli-consolidation
Jul 22, 2026
Merged

dbwiddis merged 4 commits into
oshi:masterfrom
dbwiddis:refactor-sysctl-cli-consolidation

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Consolidates the duplicated sysctl utility code into three shared helpers and fixes a latent bug the consolidation surfaced.

Before this change the sysctl logic was copied across eight classes: the command-line sysctl -n implementation existed in three places, and the JNA and FFM native bodies were near-identical per key-type (sysctlbyname(String) for macOS/FreeBSD, sysctl(int[]) for NetBSD/OpenBSD), differing only in which native INSTANCE/function was called.

Changes

  1. Command-line (oshi-common) — Move the NetBSD-specific command-line NetBsdSysctlUtil to a generic oshi.util.common.platform.unix.bsd.BsdSysctlUtil (usable by any BSD-family OS, including macOS) and repoint all command-line call sites: the 7 NetBSD common classes, and the "backup" String overloads of the JNA OpenBsdSysctlUtil and FFM OpenBsdSysctlUtilFFM (which duplicated it). Three copies → one.

  2. JNA (oshi-core) — Extract the shared buffer-sizing/error/decoding logic into oshi.jna.util.SysctlUtilJNA; each per-platform class supplies its native call as a lambda. Preserves per-method log levels and the macOS logWarning variants.

  3. FFM (oshi-core-ffm) — Mirror the extraction into oshi.ffm.util.SysctlFFM, using the existing callInArena* helpers.

  4. Bug fix (closes JNA sysctl(name, long) reads uninitialized bytes for int-width OIDs (FreeBSD hw.clockrate -> 6.2 EHz) #3517) — The shared long helper now honors the byte count the kernel reports via oldlenp: when the OID is a 4-byte int (e.g. FreeBSD hw.clockrate) it reads a ParseUtil.unsignedIntToLong widened int rather than getLong over a buffer whose high 4 bytes were never written. Previously new Memory() (unzeroed, unlike an FFM arena) left those bytes as malloc garbage, intermittently reporting an absurd CPU vendor frequency (e.g. 6.2 EHz). Applied to both JNA and FFM for symmetry. A CentralProcessorTest assertion that vendor and max frequency stay within an order of magnitude reproduces the bug and guards against regressions on every platform.

Also fixes a minor latent issue: the NetBSD/OpenBSD JNA classes logged the raw int[] MIB ([I@...) on failure; they now log Arrays.toString, matching FFM.

Testing

  • New BsdSysctlUtilTest covers the shared command-line class (success + failure paths of all overloads), gated to platforms that ship a sysctl command.
  • New CentralProcessorTest.testVendorFreqSanity() reproduces JNA sysctl(name, long) reads uninitialized bytes for int-width OIDs (FreeBSD hw.clockrate -> 6.2 EHz) #3517.
  • All existing tests pass, including the JNA/FFM NativeComparisonTest (-Paggregate-coverage).
  • Verified green on CI across Linux, macOS, Windows, FreeBSD, OpenBSD, NetBSD (with and without JNA), DragonFly BSD, OpenIndiana, and the native-free path.

Closes #3517.

Summary by CodeRabbit

  • Bug Fixes

    • Improved hardware and operating-system information detection across BSD platforms.
    • Fixed reading certain integer-width system values, including CPU frequency data.
    • Preserved fallback behavior when system information is unavailable.
  • Improvements

    • Standardized system information retrieval and error handling across native integrations.
    • Improved consistency of memory, disk, processor, filesystem, and hardware identifier reporting.
  • Tests

    • Added coverage for BSD system queries, fallback values, and CPU frequency sanity checks.

dbwiddis added 4 commits July 22, 2026 09:32
The command-line `sysctl -n` implementation was duplicated in three
places: oshi-common's NetBsdSysctlUtil, and the "Backup versions" blocks
of the JNA OpenBsdSysctlUtil and FFM OpenBsdSysctlUtilFFM.

Move the oshi-common NetBsdSysctlUtil to a generic
oshi.util.common.platform.unix.bsd.BsdSysctlUtil (usable by any
BSD-family OS incl. macOS) and delete the two OpenBSD duplicates. Repoint
all command-line String call sites (7 NetBSD, 5 OpenBSD JNA, 5 OpenBSD
FFM) to the shared class. The int[]/MIB and Memory/MemorySegment native
overloads remain in their platform-specific util classes.

Add BsdSysctlUtilTest exercising success and failure paths of all three
overloads, enabled on every platform that ships a sysctl command
(gated via a PlatformEnum helper), giving the shared class full coverage.
Remove the now-redundant command-line tests from OpenBsdSysctlUtilFFMTest.
The four JNA sysctl utility classes (mac SysctlUtil, FreeBSD BsdSysctlUtil,
NetBsd/OpenBsd SysctlUtil) each carried a near-identical copy of the
buffer-sizing, error-logging, and result-decoding logic; the only real
difference was the native call itself — sysctlbyname(String) on mac/FreeBSD
vs sysctl(int[]) on NetBSD/OpenBSD, both declared on the shared CLibrary
interface.

Introduce oshi.jna.util.SysctlUtilJNA which owns that shared logic. Each
per-platform class now supplies its native call as a SysctlCall lambda and
delegates. Log level (WARN vs ERROR) and the mac logWarning variants are
preserved via parameters.

Two correctness fixes folded into the shared long helper while extracting:
- Read int-width OIDs at their real size. Some OIDs exposed via the long
  API are kernel ints (e.g. FreeBSD hw.clockrate is a 4-byte int). The
  kernel writes only 4 bytes into the 8-byte buffer; getLong(0) then reads
  4 valid + 4 uninitialized bytes (new Memory() is not zeroed), yielding
  garbage like 6.2 EHz for the CPU vendor frequency. sysctl reports the
  bytes written via oldlenp, so read getInt (zero-extended, unsigned) when
  4 bytes were written and getLong otherwise. Latent pre-existing bug.
- Log the MIB as Arrays.toString(name) on NetBSD/OpenBSD instead of the raw
  int[] (default Object.toString, e.g. "[I@1a2b3c"), matching FFM.

Extraction plus these fixes changes only the JNA side, so the JNA/FFM
comparison tests (-Paggregate-coverage) validate it against the unchanged
FFM implementations.
Mirror the JNA extraction on the FFM side. The three FFM sysctl utility
classes (mac SysctlUtilFFM, FreeBSD BsdSysctlUtilFFM, OpenBSD
OpenBsdSysctlUtilFFM) each repeated the same arena management, buffer
sizing, and result decoding; the only difference was the native call —
sysctlbyname(String) on mac/FreeBSD vs sysctl(int[]) on OpenBSD.

Introduce oshi.ffm.util.SysctlFFM which owns that shared logic. Each
per-platform class keeps a small private method that allocates its
name/MIB segment, invokes its native function, and logs any errno, passed
to the helper as a SysctlOp lambda. The mac-only sysctl(int[],
MemorySegment) buffer variant (different return shape) is left in place.

The shared long helper reads int-width OIDs at their real size (getInt when
the kernel wrote 4 bytes, zero-extended), matching the JNA fix. FFM was not
observably affected (arena.allocate zero-fills, so an over-wide read was
already unsigned-correct), but honoring oldlenp keeps the two
implementations symmetric and robust.

Committed after the JNA extraction so the JNA/FFM comparison tests
(-Paggregate-coverage) exercise the FFM change against the
already-refactored JNA side.
Assert that the processor's vendor-advertised frequency and max frequency,
when both are known (> 0), are within an order of magnitude of each other.
Both describe the same CPU, so a large divergence indicates a corrupted
native read.

This directly reproduces the hw.clockrate int-as-long bug fixed earlier in
this branch: before the fix, FreeBSD reported a vendor frequency of ~6.2
EHz against a ~2.6 GHz max (~9 orders of magnitude apart), which this test
would have caught. Runs on every platform in CI via the live
CentralProcessorTest.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change consolidates BSD sysctl utilities, adds shared FFM and JNA result handlers, updates NetBSD and OpenBSD consumers, handles int-width values through long APIs, exports the common BSD package, and adds sysctl and processor-frequency tests.

Changes

BSD sysctl consolidation

Layer / File(s) Summary
Common BSD utility and NetBSD consumers
oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/*, oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/*, oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/*, oshi-common/src/test/java/oshi/util/common/platform/unix/bsd/*
Introduces and exports BsdSysctlUtil, updates NetBSD consumers to use it, and tests string, int, and long sysctl overloads on supported BSD platforms.
FFM sysctl helper and adapters
oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/*, oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/*, oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/*
Centralizes FFM sysctl allocation, decoding, logging, and int-width long handling, then routes macOS, FreeBSD, and OpenBSD implementations and consumers through the shared helper.
JNA sysctl helper and adapters
oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java, oshi-core/src/main/java/oshi/util/platform/*, oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/*, oshi-core/src/main/java/oshi/software/os/unix/openbsd/*, oshi-core/src/test/java/oshi/hardware/platform/shared/*
Adds shared JNA sysctl result handling with width-aware long decoding, refactors platform utilities to delegate to it, updates OpenBSD consumers to use the common BSD utility, and adds a processor-frequency sanity test.

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

Possibly related PRs

  • oshi/oshi#3310: Overlapping NetBSD sysctl utility refactoring.
  • oshi/oshi#3319: Introduces the FreeBSD FFM sysctl implementation refactored here.
  • oshi/oshi#3334: Introduces OpenBSD FFM sysctl bindings used by this refactor.

Poem

I’m a rabbit with sysctl schemes,
Sharing helpers across BSD dreams.
Four-byte values now widen right,
FFM and JNA shine bright.
Tests hop in, frequencies align!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.84% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main work: shared sysctl helper consolidation and the int-width sysctl bug fix.
Linked Issues check ✅ Passed The changes implement #3517 by widening long sysctl reads only after checking kernel-reported byte count, with JNA/FFM coverage and a regression test.
Out of Scope Changes check ✅ Passed The remaining refactors and helper consolidations support the sysctl fix and regression coverage, with no clearly unrelated code changes.
✨ 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.

@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.

🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java (1)

86-100: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider a direct unit test for the 4-byte widening branch.

A test using a stub SysctlCall that writes only 4 bytes into the 8-byte buffer (and sets oldlenp accordingly) would directly validate the #3517 fix without depending on platform-specific sysctl output.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java` around lines 86 -
100, Add a focused unit test for the sysctl method’s 4-byte widening branch,
using a stub SysctlCall that writes a 4-byte value to the buffer and sets the
provided size reference to INT_SIZE. Assert that sysctl returns the expected
unsigned widened value, without relying on platform-specific sysctl behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java`:
- Around line 86-100: Add a focused unit test for the sysctl method’s 4-byte
widening branch, using a stub SysctlCall that writes a 4-byte value to the
buffer and sets the provided size reference to INT_SIZE. Assert that sysctl
returns the expected unsigned widened value, without relying on
platform-specific sysctl behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4cc1b3df-9887-4528-bc36-70c7511d8e76

📥 Commits

Reviewing files that changed from the base of the PR and between 1d0803b and 8b5a707.

📒 Files selected for processing (34)
  • CHANGELOG.md
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdComputerSystem.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.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-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/package-info.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SysctlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/freebsd/BsdSysctlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java
  • oshi-core-ffm/src/test/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFMTest.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java
  • oshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.java
  • oshi-core/src/main/java/oshi/util/platform/unix/freebsd/BsdSysctlUtil.java
  • oshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.java
  • oshi-core/src/main/java/oshi/util/platform/unix/openbsd/OpenBsdSysctlUtil.java
  • oshi-core/src/test/java/oshi/hardware/platform/shared/CentralProcessorTest.java
💤 Files with no reviewable changes (1)
  • oshi-core-ffm/src/test/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFMTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
  • 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: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (4)
📚 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/openbsd/OpenBsdHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java
📚 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/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/package-info.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdComputerSystem.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdGlobalMemory.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.java
  • oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java
  • oshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java
  • oshi-core/src/main/java/oshi/util/platform/unix/openbsd/OpenBsdSysctlUtil.java
  • oshi-core/src/main/java/oshi/util/platform/unix/freebsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SysctlUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/freebsd/BsdSysctlUtilFFM.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/module-info.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/package-info.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdComputerSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdGlobalMemory.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/NetBsdFileSystem.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
📚 Learning: 2026-04-12T19:34:56.879Z
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:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
🔇 Additional comments (34)
oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java (1)

5-21: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdGlobalMemory.java (1)

17-17: LGTM!

Also applies to: 67-71

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

20-20: LGTM!

Also applies to: 154-164

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

22-22: LGTM!

Also applies to: 38-40

oshi-common/src/test/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtilTest.java (1)

1-78: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.java (1)

24-24: LGTM!

Also applies to: 36-41

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemFFM.java (1)

18-18: LGTM!

Also applies to: 62-78

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryFFM.java (1)

21-21: LGTM!

Also applies to: 50-55

oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java (1)

9-9: LGTM!

Also applies to: 20-20

oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java (1)

17-17: LGTM!

Also applies to: 28-34

oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java (1)

9-9: LGTM!

Also applies to: 20-20

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

1-9: LGTM!

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

61-61: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java (1)

14-14: LGTM!

Also applies to: 34-59, 71-71

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdComputerSystem.java (1)

17-17: LGTM!

Also applies to: 61-78

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java (1)

23-23: LGTM!

Also applies to: 52-52

oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java (2)

86-100: Correct fix for the reported width bug.

Reading only the kernel-reported byte count (size.longValue()) and explicitly zero-extending 4-byte results via ParseUtil.unsignedIntToLong correctly resolves the FreeBSD hw.clockrate-style bug from #3517, independent of whatever garbage bytes may exist in the unwritten portion of the malloc'd buffer.


64-75: LGTM!

Also applies to: 112-132, 144-179

oshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.java (1)

2-17: LGTM!

Also applies to: 25-28, 50-52, 63-65, 88-90, 101-103, 114-116

oshi-core/src/main/java/oshi/util/platform/unix/freebsd/BsdSysctlUtil.java (1)

2-17: LGTM!

Also applies to: 26-26, 38-40, 51-53, 64-66, 77-79, 90-92

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

7-33: LGTM!

Also applies to: 64-66, 77-79, 90-92, 103-105, 116-118

oshi-core/src/main/java/oshi/util/platform/unix/openbsd/OpenBsdSysctlUtil.java (1)

7-30: LGTM!

Based on learnings, this class lives in an implementation-detail subpackage rather than the root public API (oshi, oshi.hardware, oshi.software.os), so removing the legacy command-line-based overloads here is not a public API break.

Also applies to: 39-43, 52-56, 65-69, 78-82, 91-94

Source: Learnings

oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemJNA.java (1)

18-18: LGTM!

Also applies to: 62-78

oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryJNA.java (1)

20-20: LGTM!

Also applies to: 52-57

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

43-43: LGTM!

Also applies to: 113-115, 125-125, 157-157

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

61-62: LGTM!

CHANGELOG.md (1)

10-10: LGTM!

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

1-167: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SysctlUtilFFM.java (1)

11-11: LGTM!

Also applies to: 23-23, 58-59, 70-71, 94-95, 106-107, 118-118, 144-148

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/freebsd/BsdSysctlUtilFFM.java (1)

18-18: LGTM!

Also applies to: 44-44, 55-55, 66-66, 77-77, 87-98

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFM.java (1)

20-20: LGTM!

Also applies to: 46-47, 58-59, 70-71, 82-83, 93-105

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreFFM.java (1)

13-13: LGTM!

Also applies to: 32-32

oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreJNA.java (1)

13-13: LGTM!

Also applies to: 32-32

oshi-core/src/test/java/oshi/hardware/platform/shared/CentralProcessorTest.java (1)

15-15: LGTM!

Also applies to: 77-90

@dbwiddis
dbwiddis merged commit 5d304e0 into oshi:master Jul 22, 2026
13 of 14 checks passed
@dbwiddis
dbwiddis deleted the refactor-sysctl-cli-consolidation branch July 22, 2026 19:25
dbwiddis added a commit that referenced this pull request Jul 22, 2026
)

SolarisCentralProcessorJNA.queryProcessorId2() (the Kstat2 path) read
clock_MHz and passed it straight to ProcessorIdentifier as the vendor
frequency, omitting the * 1_000_000L conversion to Hz that both the
non-Kstat2 path in the same class and the FFM implementation apply. On a
SPARC system this reported a ~5067 Hz vendor frequency against a ~5.07 GHz
max.

Caught by the CentralProcessorTest.testVendorFreqSanity() assertion added
in #3518 (vendor and max frequency must be within an order of magnitude).
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 71 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.24%. Comparing base (1d0803b) to head (8b5a707).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ore/src/main/java/oshi/jna/util/SysctlUtilJNA.java 59.61% 17 Missing and 4 partials ⚠️
...hi/util/platform/unix/netbsd/NetBsdSysctlUtil.java 0.00% 15 Missing ⚠️
...n/platform/unix/netbsd/NetBsdCentralProcessor.java 0.00% 7 Missing ⚠️
.../util/platform/unix/openbsd/OpenBsdSysctlUtil.java 60.00% 6 Missing ⚠️
...mon/platform/unix/netbsd/NetBsdComputerSystem.java 0.00% 5 Missing ⚠️
...oftware/common/os/unix/netbsd/NetBsdOSProcess.java 0.00% 4 Missing ⚠️
...ore-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java 89.47% 2 Missing and 2 partials ⚠️
...ftware/common/os/unix/netbsd/NetBsdFileSystem.java 0.00% 3 Missing ⚠️
...e/common/os/unix/netbsd/NetBsdOperatingSystem.java 0.00% 3 Missing ⚠️
...ommon/platform/unix/netbsd/NetBsdGlobalMemory.java 0.00% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3518      +/-   ##
============================================
+ Coverage     78.16%   78.24%   +0.07%     
- Complexity       76     3720    +3644     
============================================
  Files           694      697       +3     
  Lines         24251    24104     -147     
  Branches       4029     3994      -35     
============================================
- Hits          18957    18861      -96     
+ Misses         3078     3046      -32     
+ Partials       2216     2197      -19     
Flag Coverage Δ
freebsd 31.11% <37.08%> (+0.26%) ⬆️
linux 35.04% <0.00%> (+0.21%) ⬆️
macos 35.99% <35.21%> (+0.25%) ⬆️
openbsd 30.31% <38.96%> (+0.23%) ⬆️
solaris 31.57% <0.00%> (+0.20%) ⬆️
windows 43.16% <0.00%> (+0.26%) ⬆️

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.

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.

JNA sysctl(name, long) reads uninitialized bytes for int-width OIDs (FreeBSD hw.clockrate -> 6.2 EHz)

1 participant