Skip to content

Push USER_HZ and PAGE_SIZE down into JNA/FFM OS subclasses - #3136

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:linux-os-split
Apr 10, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:linux-os-split

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 10, 2026 •

Copy link
Copy Markdown
Member

Separate the Auxv-dependent USER_HZ and PAGE_SIZE constants from the common LinuxOperatingSystem superclass into LinuxOperatingSystemJNA and LinuxOperatingSystemFFM, each using their respective AuxvJNA/AuxvFFM implementations. This removes the last JNA dependency from the common Linux OS superclass for these values.

Changes

LinuxOperatingSystem (common superclass)

  • Remove static USER_HZ/PAGE_SIZE fields and AuxvJNA dependency
  • Make getHz() and getPageSize() abstract instance methods
  • Make BOOTTIME private with a getBootTime() static getter
  • Pass this to LinuxOSThread constructor from getCurrentThread()

LinuxOperatingSystemJNA / LinuxOperatingSystemFFM

  • Add USER_HZ/PAGE_SIZE static fields via AuxvJNA/AuxvFFM
  • Expose hz() and pageSize() static methods for other JNA/FFM classes
  • Override instance getHz()/getPageSize()

LinuxOSProcess / LinuxOSThread (common)

  • Use getOs().getHz(), getOs().getPageSize(), LinuxOperatingSystem.getBootTime() instead of static calls
  • LinuxOSThread receives LinuxOperatingSystem in constructor

LinuxCentralProcessor / LinuxGlobalMemory (common)

  • LinuxCentralProcessor takes hz constructor parameter; JNA/FFM subclasses pass their respective hz() static value
  • LinuxGlobalMemory takes pageSize constructor parameter

LinuxHardwareAbstractionLayer

  • Make createMemory() and createProcessor() abstract
  • JNA/FFM HALs override, passing appropriate static values

Summary by CodeRabbit

  • Refactor
    • Linux clock-tick (USER_HZ) and page-size are now determined by platform-specific OS implementations and propagated through processor, memory, process, and thread components; memory/processor creation is delegated to platform-specific HAL implementations for more consistent, flexible behavior.
  • Documentation
    • Changelog updated to reflect these platform-specific improvements.

@coderabbitai

coderabbitai Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Refactors Linux platform initialisation to compute and expose USER_HZ and PAGE_SIZE in JNA/FFM OS subclasses, pass those values into HAL factories and into processor/memory constructors, and convert several base/static OS lookups to instance-based accessors used by processes/threads.

Changes

Cohort / File(s) Summary
FFM Linux: OS values & HAL
oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java, oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java, oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
Add cached USER_HZ/PAGE_SIZE (auxv + getconf fallbacks) with hz()/pageSize() accessors; add no-arg LinuxCentralProcessorFFM() calling super(LinuxOperatingSystemFFM.hz()); add createMemory() override returning new LinuxGlobalMemory(LinuxOperatingSystemFFM.pageSize()).
JNA Linux: OS values & HAL
oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java, oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java, oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
Add cached USER_HZ/PAGE_SIZE with hz()/pageSize() and override instance getters; add no-arg LinuxCentralProcessorJNA() calling super(LinuxOperatingSystemJNA.hz()); override createMemory() and createProcessor() to construct JNA-backed instances.
Core HAL & Components
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java, oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java, oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.java
Make createMemory() and createProcessor() abstract in base HAL; introduce hz field and protected LinuxCentralProcessor(long hz) constructor; change LinuxGlobalMemory to use injected pageSize instance field and add constructor.
OS/Process/Thread context updates
oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java, oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java, oshi-core/src/main/java/oshi/software/os/linux/LinuxOSThread.java
Convert static getHz()/getPageSize() into abstract instance methods; add static getBootTime(); pass LinuxOperatingSystem instance into LinuxOSThread and thread construction in processes; update attribute calculations to use the instance OS for hz/pageSize.
Changelog
CHANGELOG.md
Add changelog entry noting push of Linux USER_HZ and PAGE_SIZE into JNA/FFM OS subclasses and wiring through HAL, processor, memory, process, and thread classes.

Sequence Diagram(s)

sequenceDiagram
    participant OS as LinuxOperatingSystem (JNA / FFM)
    participant HAL as LinuxHardwareAbstractionLayer
    participant CPU as LinuxCentralProcessor
    participant MEM as LinuxGlobalMemory

    OS->>OS: Static init: query auxv / getconf\ncompute USER_HZ, PAGE_SIZE
    HAL->>OS: call hz(), pageSize()
    HAL->>MEM: new LinuxGlobalMemory(pageSize)
    MEM-->>HAL: GlobalMemory
    HAL->>CPU: new LinuxCentralProcessor(hz)
    CPU-->>HAL: CentralProcessor
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • rohan-coder02

Poem

🐰
I tunneled through static ground and found,
Hz and pages safe and sound.
Constructors snug, HALs assemble tight,
Processors wake and memory alight.
Hop, compile — a patch delight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.51% 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 PR title accurately and concisely describes the main architectural change: moving USER_HZ and PAGE_SIZE constants from the common superclass down into JNA/FFM-specific subclasses.

✏️ 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.

@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 (6d0f975) to head (95d6ede).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3136      +/-   ##
============================================
+ 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.

@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

🤖 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/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java`:
- Around line 51-57: The static init currently calls AuxvJNA.queryAuxv() outside
the JNA guard and can throw NoClassDefFoundError; to fix, set safe defaults
USER_HZ = 100L and PAGE_SIZE = 4096L before the try, then move the
AuxvJNA.queryAuxv() call and the logic that reads
auxv.getOrDefault(Auxv.AT_CLKTCK, …) and auxv.getOrDefault(Auxv.AT_PAGESZ, …)
into the existing try block that catches NoClassDefFoundError (and other
exceptions), and only overwrite USER_HZ and PAGE_SIZE with values parsed via
AuxvJNA.queryAuxv() or fall back to
ParseUtil.parseLongOrDefault(ExecutingCommand.getFirstAnswer(...)) when the
lookup succeeds; ensure any thrown NoClassDefFoundError is caught so class
initialization can't fail.
🪄 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: 9e0a66b9-8a9f-4f70-b435-43af02c0ba49

📥 Commits

Reviewing files that changed from the base of the PR and between 6d0f975 and e391b1f.

📒 Files selected for processing (12)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSThread.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.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 11, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (8)
📚 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
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
📚 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/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.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/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.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
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.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/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.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/hardware/platform/linux/LinuxGlobalMemory.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSThread.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.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
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.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/software/os/linux/LinuxOperatingSystemJNA.java
🔇 Additional comments (16)
oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java (1)

44-80: Nice FFM-local auxv split.

This keeps the common Linux OS layer backend-agnostic while preserving a safe auxv -> getconf -> constant fallback chain.

oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java (1)

140-166: The new JNA accessors line up well with the injected call sites.

Exposing both static helpers and instance overrides keeps the hardware factories and the process/thread paths consistent.

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

38-40: Clean constructor wiring.

Passing LinuxOperatingSystemJNA.hz() into the superclass removes the old static OS dependency from the common processor code cleanly.

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

41-43: FFM constructor hookup looks good.

This matches the new superclass contract and keeps the Hz source backend-specific.

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

26-29: Good factory split for memory creation.

Injecting the FFM page size here keeps LinuxGlobalMemory free of backend lookups.

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

27-55: Nice move to injected page size.

Storing pageSize per instance makes the memory implementation independent of whichever Linux backend created it.

oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java (2)

261-264: Passing the OS instance into LinuxOSThread is the right seam.

It makes the thread path consume the same backend-specific timing values as the parent process path.


391-417: Good cleanup of the process math.

Using getOs().getHz() and getOs().getPageSize() here removes the last shared static dependency without changing the conversion logic.

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

54-58: The Hz injection is applied consistently.

Capturing hz once in the constructor and reusing it in both tick-conversion paths keeps the common processor logic clean and predictable.

Also applies to: 401-402, 527-528

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

26-34: Backend-specific factory wiring looks correct.

These overrides inject the JNA-derived page size and processor implementation at the HAL boundary, which keeps the shared Linux HAL decoupled from backend-specific Auxv sources.

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

34-37: Good decoupling in the shared HAL base class.

Making these factories abstract cleanly removes the last backend-specific assumptions from the common Linux HAL and leaves JNA/FFM selection to the concrete subclasses.

oshi-core/src/main/java/oshi/software/os/linux/LinuxOSThread.java (2)

34-50: Constructor-level OS injection fits this split well.

Holding the owning LinuxOperatingSystem instance here keeps backend-specific timing constants available to thread math without reintroducing static JNA coupling.


133-149: The jiffies-to-time conversions remain consistent after the refactor.

Using LinuxOperatingSystem.getBootTime() together with os.getHz() preserves the existing calculation flow while sourcing USER_HZ from the active backend.

oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java (3)

71-79: Encapsulating boot time behind an accessor cleans up the shared class.

This keeps the cached boot-time source centralized in the common Linux OS layer while letting other shared classes consume it without direct field coupling.

Also applies to: 532-539


207-208: Passing this into LinuxOSThread is the right follow-through.

That keeps thread calculations tied to the concrete OS instance that owns the backend-specific getHz() implementation.


523-530: Abstract getHz() / getPageSize() is a clean final step in the split.

The common Linux OS no longer needs to know which native backend supplied Auxv-derived values.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Line 10: Change the changelog entry for PR `#3136` to describe the Linux
USER_HZ/PAGE_SIZE refactor and the move to JNA/FFM OS subclasses and wiring
updates instead of "Create oshi-common module; move JNA-free common code".
Update the sentence to mention the Linux USER_HZ and PAGE_SIZE refactor into JNA
and FFM OS subclasses, and note related wiring and integration updates that were
made as part of this PR so the release note accurately reflects the PR scope.

In
`@oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java`:
- Around line 46-53: The static initializer in LinuxOperatingSystemFFM should
seed USER_HZ and PAGE_SIZE with safe defaults first (using
ParseUtil.parseLongOrDefault(ExecutingCommand.getFirstAnswer("getconf CLK_TCK"),
100L) and ParseUtil.parseLongOrDefault(ExecutingCommand.getFirstAnswer("getconf
PAGE_SIZE"), 4096L)), then attempt AuxvFFM.queryAuxv() inside a try/catch and
only overwrite those defaults if the returned Map from AuxvFFM.queryAuxv() is
non-null and contains positive values for Auxv.AT_CLKTCK and Auxv.AT_PAGESZ;
ensure any exception from AuxvFFM.queryAuxv() is caught so class initialization
cannot fail and USER_HZ/PAGE_SIZE remain the safe defaults.
🪄 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: 8f87a9c3-1433-46cf-a4ff-1e267d293878

📥 Commits

Reviewing files that changed from the base of the PR and between e391b1f and 15b65ce.

📒 Files selected for processing (13)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSThread.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.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). (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (10)
📚 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/LinuxGlobalMemory.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSThread.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
📚 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/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.java
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
📚 Learning: 2026-04-08T17:30:11.929Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3127
File: CHANGELOG.md:3-3
Timestamp: 2026-04-08T17:30:11.929Z
Learning: In the oshi/oshi repository's `CHANGELOG.md`, the standard layout uses `#` (h1) for release version headers and `#####` (h5) for subsection headers such as "New Features" and "Bug fixes / Improvements". This intentional heading level skip is the project's established convention and should not be flagged as a markdownlint MD001 violation.

Applied to files:

  • CHANGELOG.md
📚 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:

  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.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-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.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/software/os/linux/LinuxOperatingSystemFFM.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/software/os/linux/LinuxOperatingSystemJNA.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.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/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
🔇 Additional comments (1)
oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java (1)

51-64: Good defensive fallback ordering.

Initializing userHz/pageSz before AuxvJNA.queryAuxv() and assigning the finals after the try keeps class loading recoverable when auxv/JNA resolution fails, while still preferring auxv/getconf when available.

Also applies to: 98-99

Comment thread CHANGELOG.md Resolved
Separate the Auxv-dependent USER_HZ and PAGE_SIZE constants from the
common LinuxOperatingSystem superclass into LinuxOperatingSystemJNA
and LinuxOperatingSystemFFM, each using their respective AuxvJNA/AuxvFFM
implementations. This removes the last JNA dependency from the common
Linux OS superclass for these values.

## Changes

### LinuxOperatingSystem (common superclass)
- Remove static `USER_HZ`/`PAGE_SIZE` fields and `AuxvJNA` dependency
- Make `getHz()` and `getPageSize()` abstract instance methods
- Make `BOOTTIME` private with a `getBootTime()` static getter
- Pass `this` to `LinuxOSThread` constructor from `getCurrentThread()`

### LinuxOperatingSystemJNA / LinuxOperatingSystemFFM
- Add `USER_HZ`/`PAGE_SIZE` static fields via `AuxvJNA`/`AuxvFFM`
- Expose `hz()` and `pageSize()` static methods for other JNA/FFM classes
- Override instance `getHz()`/`getPageSize()`

### LinuxOSProcess / LinuxOSThread (common)
- Use `getOs().getHz()`, `getOs().getPageSize()`, `LinuxOperatingSystem.getBootTime()`
  instead of static calls
- `LinuxOSThread` receives `LinuxOperatingSystem` in constructor

### LinuxCentralProcessor / LinuxGlobalMemory (common)
- `LinuxCentralProcessor` takes `hz` constructor parameter; JNA/FFM
  subclasses pass their respective `hz()` static value
- `LinuxGlobalMemory` takes `pageSize` constructor parameter

### LinuxHardwareAbstractionLayer
- Make `createMemory()` and `createProcessor()` abstract
- JNA/FFM HALs override, passing appropriate static values

@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/software/os/linux/LinuxOSProcess.java (1)

391-392: Optional cleanup: cache hz and pageSize once per update pass.

No correctness issue, but local caching would simplify the math paths and avoid repeated virtual calls.

Refactor sketch
+        long hz = getOs().getHz();
+        long pageSize = getOs().getPageSize();
-        this.startTime = (LinuxOperatingSystem.getBootTime() * getOs().getHz()
-                + statArray[ProcPidStat.START_TIME.ordinal()]) * 1000L / getOs().getHz();
+        this.startTime = (LinuxOperatingSystem.getBootTime() * hz + statArray[ProcPidStat.START_TIME.ordinal()])
+                * 1000L / hz;
...
-            long pageSize = getOs().getPageSize();
             this.residentSetSize = resident * pageSize;
             this.privateResidentMemory = (resident - shared) * pageSize;
         } else {
-            this.residentSetSize = statArray[ProcPidStat.RSS.ordinal()] * getOs().getPageSize();
+            this.residentSetSize = statArray[ProcPidStat.RSS.ordinal()] * pageSize;
             this.privateResidentMemory = this.residentSetSize;
         }
-        this.kernelTime = statArray[ProcPidStat.KERNEL_TIME.ordinal()] * 1000L / getOs().getHz();
-        this.userTime = statArray[ProcPidStat.USER_TIME.ordinal()] * 1000L / getOs().getHz();
+        this.kernelTime = statArray[ProcPidStat.KERNEL_TIME.ordinal()] * 1000L / hz;
+        this.userTime = statArray[ProcPidStat.USER_TIME.ordinal()] * 1000L / hz;

Also applies to: 409-409, 413-413, 416-417

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java` around
lines 391 - 392, Cache getOs().getHz() and getOs().getPageSize() once at the
start of the update pass in LinuxOSProcess.update/constructor (or the method
that contains the startTime calculation) and replace repeated calls in
expressions like the startTime assignment (this.startTime =
(LinuxOperatingSystem.getBootTime() * getOs().getHz() +
statArray[ProcPidStat.START_TIME.ordinal()]) * 1000L / getOs().getHz()) and the
other referenced lines with the local hz and pageSize variables; ensure you use
these cached hz/pageSize variables wherever getOs().getHz() or
getOs().getPageSize() are currently invoked during that single update to avoid
repeated virtual calls.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java`:
- Around line 391-392: Cache getOs().getHz() and getOs().getPageSize() once at
the start of the update pass in LinuxOSProcess.update/constructor (or the method
that contains the startTime calculation) and replace repeated calls in
expressions like the startTime assignment (this.startTime =
(LinuxOperatingSystem.getBootTime() * getOs().getHz() +
statArray[ProcPidStat.START_TIME.ordinal()]) * 1000L / getOs().getHz()) and the
other referenced lines with the local hz and pageSize variables; ensure you use
these cached hz/pageSize variables wherever getOs().getHz() or
getOs().getPageSize() are currently invoked during that single update to avoid
repeated virtual calls.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d61ccf89-6734-4a43-bf6a-3cd649d9b72b

📥 Commits

Reviewing files that changed from the base of the PR and between 15b65ce and 95d6ede.

📒 Files selected for processing (13)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSThread.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (8)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSThread.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.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). (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:32.055Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.
📚 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/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
📚 Learning: 2026-04-10T22:44:32.055Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:32.055Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.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-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/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.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
📚 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/LinuxGlobalMemory.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java
🔇 Additional comments (5)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGlobalMemory.java (2)

27-36: Good constructor-based page-size injection.

This cleanly removes static OS coupling from LinuxGlobalMemory while preserving thread-safe immutability.


53-55: Getter update is correct.

Returning the injected pageSize aligns with the JNA/FFM-specific initialization path.

oshi-core/src/main/java/oshi/software/os/linux/LinuxOSProcess.java (1)

263-264: Looks correct: constructor call now matches OS-thread coupling.

Passing getOs() into LinuxOSThread is consistent with the updated constructor contract and keeps behavior intact.

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

54-58: Good constructor-based hz injection.

This is a clean decoupling from OS static access and keeps the conversion factor immutable per instance.

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

26-43: Constructor wiring is correct for FFM path.

super(LinuxOperatingSystemFFM.hz()) cleanly satisfies the new LinuxCentralProcessor(long hz) contract and keeps JNA/FFM behavior aligned.

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