Skip to content

Add FileUtilFFM and split Auxv into common/JNA/FFM - #3135

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:auxv-ffm
Apr 10, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:auxv-ffm

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 10, 2026 •

Copy link
Copy Markdown
Member

Adds FFM equivalents for native buffer-reading utilities and splits the Linux auxiliary vector driver into common, JNA, and FFM components.

Native size constants

Adds three constants to ForeignFunctions, derived from FFM's Linker.nativeLinker().canonicalLayouts():

  • NATIVE_LONG_SIZE — size of C long
  • NATIVE_SIZE_T_SIZE — size of C size_t
  • NATIVE_POINTER_SIZE — size of a native pointer

These replace the use of JNA's Native.LONG_SIZE, Native.SIZE_T_SIZE, and Native.POINTER_SIZE in FFM code paths.

FileUtilFFM

New class oshi.ffm.util.FileUtilFFM in oshi-core-java25, mirroring the buffer-reading methods from FileUtilJNA:

  • readNativeLongFromBuffer — reads a C long from a ByteBuffer
  • readSizeTFromBuffer — reads a C size_t from a ByteBuffer
  • readPointerFromBuffer — reads a native pointer from a ByteBuffer

Auxv split

The Linux auxiliary vector driver (/proc/self/auxv) is split into three parts:

Module Class Contents
oshi-common oshi.util.driver.linux.proc.Auxv Constants only (AT_PAGESZ, AT_HWCAP, AT_CLKTCK)
oshi-core oshi.driver.linux.proc.AuxvJNA queryAuxv() using FileUtilJNA.readNativeLongFromBuffer
oshi-core-java25 oshi.driver.linux.proc.AuxvFFM queryAuxv() using FileUtilFFM.readNativeLongFromBuffer

Other changes

  • LinuxCentralProcessorFFM.queryHwcap() now delegates to AuxvFFM.queryAuxv() instead of inline parsing, removing the local AT_HWCAP constant and readNativeLong method
  • Fixed a wasteful double-call in LinuxOperatingSystem where Auxv.queryAuxv() was called twice in the static initializer (once for USER_HZ, once for PAGE_SIZE) — now reuses the map

Summary by CodeRabbit

  • New Features

    • Added Foreign Function & Memory (FFM) support to query Linux auxiliary vectors and read native-sized values.
  • Refactor

    • Split auxiliary-vector handling into separate JNA and FFM backends.
    • Introduced platform-native size constants and FFM-specific buffer helpers.
  • Tests

    • Added tests validating native-size detection and FFM buffer decoding.
  • Documentation

    • Minor changelog entry adjustments for the upcoming release.

@coderabbitai

coderabbitai Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aabe4f5c-b270-4ac5-ba08-384519258c96

📥 Commits

Reviewing files that changed from the base of the PR and between 8284dd4 and 0d8dac1.

📒 Files selected for processing (13)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java
  • oshi-core-java25/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/ffm/util/FileUtilFFMTest.java
  • oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java
✅ Files skipped from review due to trivial changes (7)
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/main/java/module-info.java
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core-java25/src/test/java/oshi/ffm/util/FileUtilFFMTest.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java
  • oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
🧰 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/linux/LinuxCentralProcessorJNA.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
📚 Learning: 2026-04-06T04:45:51.516Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java
🔇 Additional comments (3)
oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java (2)

21-24: JNA-specific class split is clean and consistent.

AuxvJNA naming plus the private constructor aligns well with the backend-specific refactor.


38-41: AT_NULL termination now correctly relies on shared constants.

Using Auxv.AT_NULL for both branch and loop termination keeps behavior aligned with the common auxv contract.

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java (1)

147-147: HWCAP lookup now correctly uses the JNA auxv driver.

Good delegation to AuxvJNA.queryAuxv() with shared Auxv.AT_HWCAP constant.


📝 Walkthrough

Walkthrough

Adds a shared Auxv constants class, FFM-based auxv parsing utilities (FileUtilFFM, AuxvFFM, ForeignFunctions size constants), renames JNA Auxv to AuxvJNA, updates consumers to use the new APIs, adjusts module exports, and adds tests for the FFM helpers.

Changes

Cohort / File(s) Summary
Shared Auxv constants
oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java
New final utility class exposing AT_NULL, AT_PAGESZ, AT_HWCAP, AT_CLKTCK.
FFM foreign-size constants
oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
Added NATIVE_LONG_SIZE, NATIVE_SIZE_T_SIZE, NATIVE_POINTER_SIZE derived from FFM ValueLayout/linker.
FFM ByteBuffer helpers
oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java
New utility with readNativeLongFromBuffer, readSizeTFromBuffer, readPointerFromBuffer adapting reads to native sizes.
FFM auxv reader
oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java
New queryAuxv() reading /proc/self/auxv into a ByteBuffer and decoding (key,value) pairs into a Map<Integer,Long>.
JNA renaming & consumers
oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java, oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java, oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
Renamed Auxv → AuxvJNA, removed duplicated constants (moved to shared Auxv), updated callers to use AuxvJNA.queryAuxv() and shared constants.
FFM consumer update
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
Replaced inline /proc/self/auxv parsing with AuxvFFM.queryAuxv().getOrDefault(Auxv.AT_HWCAP, 0L).
Module & test visibility
oshi-core-java25/src/main/java/module-info.java, oshi-core-java25/src/test/java/module-info.test
Exported oshi.ffm.util and added test --add-opens for the package.
Tests
oshi-core-java25/src/test/java/oshi/ffm/util/FileUtilFFMTest.java, oshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java
Added tests for FileUtilFFM native-size behavior and renamed/updated JNA auxv test.
Changelog
CHANGELOG.md
Added/adjusted entries for the release noting the related PR lines.

Sequence Diagram(s)

sequenceDiagram
    participant CPU as LinuxCentralProcessorFFM
    participant AuxvFFM as AuxvFFM
    participant FileSys as /proc/self/auxv
    participant FileUtil as FileUtilFFM

    CPU->>AuxvFFM: queryAuxv()
    AuxvFFM->>FileSys: readAllBytes(ProcPath.AUXV)
    FileSys-->>AuxvFFM: ByteBuffer(native order)
    AuxvFFM->>FileUtil: readNativeLongFromBuffer(buff)  -- read key
    FileUtil-->>AuxvFFM: native long (key)
    AuxvFFM->>FileUtil: readNativeLongFromBuffer(buff)  -- read value
    FileUtil-->>AuxvFFM: native long (value)
    AuxvFFM->>AuxvFFM: store (key -> value) in Map
    AuxvFFM-->>CPU: return Map<Integer,Long>
    CPU->>CPU: getOrDefault(Auxv.AT_HWCAP, 0L)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • rohan-coder02

Poem

🐰 I hopped through bytes of native length,

reading keys with careful strength.
Auxv split into shared delight,
FFM and JNA both work right.
Cheers — a carrot for each byte! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add FileUtilFFM and split Auxv into common/JNA/FFM' accurately summarizes the main changes—introducing FileUtilFFM and restructuring Auxv into three components across different modules.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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.

@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 (2)
oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java (1)

35-40: Harden auxv parsing against partial/truncated buffers.

At Line 35-38, parsing assumes enough bytes are always available for key/value reads. Guarding on pair-size remaining bytes avoids BufferUnderflowException on malformed or short reads.

Proposed refactor
+import oshi.ffm.ForeignFunctions;
+import oshi.util.driver.linux.proc.Auxv;
...
-        int key;
-        do {
-            key = (int) FileUtilFFM.readNativeLongFromBuffer(buff);
-            if (key > 0) {
-                auxvMap.put(key, FileUtilFFM.readNativeLongFromBuffer(buff));
-            }
-        } while (key > 0);
+        while (buff.remaining() >= 2 * ForeignFunctions.NATIVE_LONG_SIZE) {
+            int key = (int) FileUtilFFM.readNativeLongFromBuffer(buff);
+            long value = FileUtilFFM.readNativeLongFromBuffer(buff);
+            if (key == Auxv.AT_NULL) {
+                break;
+            }
+            if (key > 0) {
+                auxvMap.put(key, value);
+            }
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java` around
lines 35 - 40, The auxv parsing loop in AuxvFFM reads key/value pairs without
checking remaining bytes and can throw BufferUnderflowException on truncated
buffers; before calling FileUtilFFM.readNativeLongFromBuffer for the key (and
before reading the value), check buff.remaining() is at least the native long
size (or two times that for the full pair) and break or return if not enough
data, so auxvMap is only populated from complete key/value pairs and partial
reads are safely ignored.
oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java (1)

17-23: Consider adding AT_NULL to document auxv terminator semantics.

Parsers in oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java and oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java currently rely on implicit key > 0 termination. A shared AT_NULL = 0 constant would make this explicit and reduce magic-number coupling.

Proposed refactor
 public final class Auxv {
+    /** end of vector */
+    public static final int AT_NULL = 0;
+
     /** system page size */
     public static final int AT_PAGESZ = 6;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java` around lines
17 - 23, Add a public constant AT_NULL = 0 to Auxv (alongside AT_PAGESZ,
AT_HWCAP, AT_CLKTCK) and update the parsing code in AuxvJNA and AuxvFFM to use
Auxv.AT_NULL as the explicit terminator instead of relying on a magic "key > 0"
check; ensure any loop or condition that currently tests for key > 0 is changed
to compare against AT_NULL so the termination semantics are explicit and
consistent across implementations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java`:
- Around line 39-53: The 32-bit branches of readSizeTFromBuffer and
readPointerFromBuffer return signed ints that sign-extend to negative longs;
update both 4-byte paths to convert to unsigned long using
Integer.toUnsignedLong. Specifically, in readSizeTFromBuffer use
Integer.toUnsignedLong(FileUtil.readIntFromBuffer(buff)) when
ForeignFunctions.NATIVE_SIZE_T_SIZE == 4, and in readPointerFromBuffer return
Integer.toUnsignedLong(buff.getInt()) when ForeignFunctions.NATIVE_POINTER_SIZE
== 4; leave the 8-byte (long) branches unchanged.

---

Nitpick comments:
In `@oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java`:
- Around line 17-23: Add a public constant AT_NULL = 0 to Auxv (alongside
AT_PAGESZ, AT_HWCAP, AT_CLKTCK) and update the parsing code in AuxvJNA and
AuxvFFM to use Auxv.AT_NULL as the explicit terminator instead of relying on a
magic "key > 0" check; ensure any loop or condition that currently tests for key
> 0 is changed to compare against AT_NULL so the termination semantics are
explicit and consistent across implementations.

In `@oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java`:
- Around line 35-40: The auxv parsing loop in AuxvFFM reads key/value pairs
without checking remaining bytes and can throw BufferUnderflowException on
truncated buffers; before calling FileUtilFFM.readNativeLongFromBuffer for the
key (and before reading the value), check buff.remaining() is at least the
native long size (or two times that for the full pair) and break or return if
not enough data, so auxvMap is only populated from complete key/value pairs and
partial reads are safely ignored.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 50c2e2a3-ef97-4e31-a5b6-e512a8fda075

📥 Commits

Reviewing files that changed from the base of the PR and between 7567b79 and 8284dd4.

📒 Files selected for processing (12)
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java
  • oshi-core-java25/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/ffm/util/FileUtilFFMTest.java
  • oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.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). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (10)
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java
📚 Learning: 2026-04-06T04:45:51.516Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java
  • oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.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-java25/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/linux/LinuxCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
📚 Learning: 2026-04-05T05:40:43.357Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:43.357Z
Learning: In OSHI’s Linux FFM implementations (e.g., LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the corresponding JNA udev code, do not require/flag a missing null check around `udev_enumerate_new()`/`enumerateNew()`. Per libudev semantics, `udev_enumerate_new()` returns NULL only if udev itself is broken (e.g., OOM). Since `udev_new()` is already guarded and is the successful prerequisite for enumeration, treating `udev_enumerate_new()` as non-null is consistent with the established pattern; adding a redundant null guard would be inconsistent.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:18.791Z
Learning: When reviewing OSHI Linux FFM/JNA code that uses libudev, do not flag a missing null check on `udev_enumerate_new()` if `udev_new()` has already been guarded. Per libudev semantics, `udev_enumerate_new()` returns NULL only when the udev context itself is broken (e.g., OOM), so a successful `udev_new()` implies `udev_enumerate_new()` should succeed as well. Therefore, lack of a redundant null guard on `udev_enumerate_new()` is acceptable in this pattern.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java
🔇 Additional comments (2)
oshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java (1)

23-26: Looks good — test now correctly targets the JNA path.

AuxvJNA.queryAuxv() plus shared Auxv constants keeps this aligned with the new split design.

oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java (1)

17-23: Class split/rename is clean and consistent.

Javadoc and type naming clearly identify this as the JNA implementation.

@codecov

codecov Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.82%. Comparing base (7567b79) to head (0d8dac1).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3135      +/-   ##
============================================
+ Coverage     61.14%   61.82%   +0.68%     
  Complexity       12       12              
============================================
  Files            39       39              
  Lines          2329     2329              
  Branches        407      407              
============================================
+ Hits           1424     1440      +16     
+ Misses          786      770      -16     
  Partials        119      119              

☔ View full report in Codecov by Sentry.
📢 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.

Add native size constants (NATIVE_LONG_SIZE, NATIVE_SIZE_T_SIZE,
NATIVE_POINTER_SIZE) to ForeignFunctions, derived from FFM canonical
layouts.

Create FileUtilFFM in oshi-core-java25 mirroring the buffer-reading
methods from FileUtilJNA (readNativeLongFromBuffer, readSizeTFromBuffer,
readPointerFromBuffer) using FFM-derived sizes instead of JNA's
Native.LONG_SIZE etc. Use Integer.toUnsignedLong for 32-bit size_t and
pointer reads to avoid sign extension of unsigned types.

Split Auxv into three parts:
- oshi-common: Auxv constants (AT_NULL, AT_PAGESZ, AT_HWCAP, AT_CLKTCK)
- oshi-core: AuxvJNA (queryAuxv using FileUtilJNA)
- oshi-core-java25: AuxvFFM (queryAuxv using FileUtilFFM)

Update LinuxCentralProcessorFFM to use AuxvFFM instead of inline
auxv parsing, removing the local AT_HWCAP constant and readNativeLong
method.

Fix double Auxv.queryAuxv() call in LinuxOperatingSystem static
initializer by reusing the map for both USER_HZ and PAGE_SIZE.

Use Auxv.AT_NULL as explicit loop terminator in both AuxvJNA and
AuxvFFM instead of magic 'key > 0' check.
@dbwiddis
dbwiddis merged commit 6d0f975 into oshi:master Apr 10, 2026
14 of 15 checks passed
@dbwiddis
dbwiddis deleted the auxv-ffm branch April 10, 2026 18:08
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.

1 participant