Skip to content

Migrate LinuxCentralProcessor udev calls - #3120

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:udev-ffm
Apr 5, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:udev-ffm

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Continues the FFM migration of udev-dependent HAL components (following
#3117 which covered PowerSource, UsbDevice, HWDiskStore, NetworkIF, and
LogicalVolumeGroup). This PR migrates LinuxCentralProcessor.

Changes

oshi-core

  • LinuxCentralProcessor (de-finalized): The three udev-dependent
    methods are refactored into protected hooks with sysfs fallbacks:

    • readTopologyWithUdev() — delegates to readTopologyFromSysfs()
    • queryCurrentFreqFromUdev(long[]) — delegates to queryCurrentFreqFromSysfs(long[])
    • queryMaxFreqFromUdev() — delegates to queryMaxFreqFromSysfs()

    The corresponding JNA static helpers (readTopologyFromUdev,
    queryCurrentFreqFromUdev(UdevContext, long[]),
    queryMaxFreqFromUdev(UdevContext)) and sysfs fallbacks are retained
    as protected static methods for use by subclasses.
    queryMaxFreqFromCpuFreqPath is promoted from private to
    protected static to avoid duplication.

  • LinuxCentralProcessorJNA (new): final subclass overriding the
    three hooks with Udev.INSTANCE JNA calls, guarded by HAS_UDEV.

  • LinuxHardwareAbstractionLayer: createProcessor() now returns
    new LinuxCentralProcessorJNA().

oshi-core-java25

  • LinuxCentralProcessorFFM (new): public final subclass
    overriding the three hooks with UdevFunctions FFM calls inside
    Arena.ofConfined() try-with-resources, guarded by HAS_UDEV from
    LinuxOperatingSystemFFM. Falls back to sysfs on any Throwable.

  • LinuxHardwareAbstractionLayerFFM: createProcessor() now
    returns new LinuxCentralProcessorFFM().

Bug Fixes

  • Pre-existing OOB in queryCurrentFreqFromUdev(UdevContext, long[]):
    The max tracking update was outside the cpu-index bounds check,
    causing a potential ArrayIndexOutOfBoundsException if udev reported
    a CPU index beyond the logical processor count. Moved inside the guard.

  • Null guard on udev_new() in LinuxCentralProcessorJNA: All
    three overrides now check for a null return from
    Udev.INSTANCE.udev_new() before entering the try/finally block,
    preventing a NullPointerException if context allocation fails.

Summary by CodeRabbit

  • New Features
    • Enhanced CPU detection on Linux with an additional, safer method for topology and frequency queries and automatic fallbacks.
  • Refactor
    • Modularized processor detection to allow multiple implementations and improve compatibility across diverse Linux systems.
  • Bug Fixes / Improvements
    • More robust handling of fallback paths and clearer logging when preferred methods are unavailable.

- De-finalize LinuxCentralProcessor; extract three udev-dependent methods
  (readTopologyWithUdev, queryCurrentFreqFromUdev, queryMaxFreqFromUdev)
  as protected hooks with sysfs fallbacks in the base class
- Add LinuxCentralProcessorJNA (oshi-core) overriding the hooks with
  JNA Udev calls; LinuxHardwareAbstractionLayer now instantiates it
- Add LinuxCentralProcessorFFM (oshi-core-java25) overriding the hooks
  with FFM UdevFunctions calls; LinuxHardwareAbstractionLayerFFM now
  instantiates it
- Fix pre-existing OOB: move max-freq tracking inside cpu-index bounds
  check in queryCurrentFreqFromUdev(UdevContext, long[])
- Add null guard on udev_new() return in all three JNA overrides
- Promote queryMaxFreqFromCpuFreqPath to protected static; remove
  duplicate queryMaxFreqFromCpuFreqPathFFM from FFM subclass
@coderabbitai

coderabbitai Bot commented Apr 5, 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: 45b1acdf-9ec7-4310-adb4-8c46217cbf99

📥 Commits

Reviewing files that changed from the base of the PR and between bb024c6 and 32cf2cc.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
📜 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). (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
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 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.
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: 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.
📚 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 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/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.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: 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
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
📚 Learning: 2026-04-05T16:15:03.230Z
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:03.230Z
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/hardware/platform/linux/LinuxCentralProcessor.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/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-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
🔇 Additional comments (16)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java (5)

1-48: LGTM! Well-structured JNA udev implementation.

The readTopologyWithUdev() override correctly:

  • Guards HAS_UDEV before attempting udev operations
  • Adds null guard for udev_new() (addressing the bug fix mentioned in PR objectives)
  • Uses try-finally for proper resource cleanup
  • Falls back to readTopologyFromSysfs() when udev is unavailable

50-80: LGTM! Consistent null guards and fallback pattern.

Both frequency query overrides follow the same defensive pattern as readTopologyWithUdev(), with proper null guards on udev_new() and appropriate fallbacks to sysfs methods.


82-109: LGTM! Proper resource management and null handling.

The topology enumeration correctly:

  • Unrefs the enumerate handle in finally
  • Checks device != null before accessing properties
  • Unrefs the device in its own finally block
  • Delegates to the shared getLogicalProcessorFromSyspath() helper

Based on learnings, the absence of a null guard on udev.enumerateNew() is intentional and consistent with the established OSHI pattern.


111-140: LGTM! Bug fix correctly applied.

The OOB bug fix is properly implemented: the max frequency tracking (lines 125-127) is now inside the CPU-index bounds check, preventing out-of-bounds access when the parsed CPU index exceeds the array length.


142-156: LGTM! Clean delegation to shared helper.

The max frequency query correctly derives the cpufreq policy path from the first CPU syspath and delegates to the shared queryMaxFreqFromCpuFreqPath() helper.

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

51-51: LGTM! Class correctly de-finalized to abstract.

The class is now abstract, allowing JNA and FFM subclasses to provide their respective udev implementations while sharing the common sysfs fallback logic.


163-170: LGTM! Backend-agnostic topology initialization.

The call to readTopologyWithUdev() is now unconditional, correctly delegating the udev/sysfs decision to the subclass implementation. The fallback to readTopologyFromCpuinfo() is retained for cases where sysfs enumeration also fails.


195-200: LGTM! Well-documented abstract hook.

The abstract method signature and Javadoc clearly describe the contract for subclasses.


202-224: LGTM! Clean sysfs fallback implementation.

The sysfs-based topology reading correctly uses Files.find() to enumerate CPU directories and reads MODALIAS from the uevent file instead of querying udev.


226-262: LGTM! Correctly promoted to protected static.

The helper method is now accessible to subclasses, enabling code reuse between JNA and FFM implementations while maintaining the original logic.


403-460: LGTM! Consistent frequency query pattern.

The queryCurrentFreq() method correctly attempts the udev-based query first and falls back to /proc/cpuinfo parsing. The queryCurrentFreqFromSysfs() helper mirrors the JNA implementation with the OOB bug fix properly applied.


462-498: LGTM! Max frequency query with proper fallback chain.

The queryMaxFreq() correctly combines udev-based, lshw, and current frequency sources. The queryMaxFreqFromCpuFreqPath() helper is appropriately promoted to protected static for reuse by subclasses.

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

1-35: LGTM! Correct FFM imports and class structure.

The class correctly:

  • Imports HAS_UDEV from LinuxOperatingSystemFFM (not the JNA version)
  • Uses the FFM UdevFunctions for native calls
  • Declares its own logger for FFM-specific error messages

36-85: LGTM! Proper FFM memory and resource management.

The topology reader correctly:

  • Uses Arena.ofConfined() for scoped memory management
  • Checks MemorySegment.NULL.equals(udev) before proceeding
  • Maintains proper cleanup order (device → enumerate → udev) via nested try-finally
  • Falls back to sysfs on any Throwable, consistent with OSHI's FFM error-handling pattern

Based on learnings, the Throwable catch with fallback is the intentional pattern for FFM implementations.


87-137: LGTM! Consistent with JNA implementation.

The current frequency query mirrors the JNA version with proper:

  • Bounds checking before array access
  • Max tracking inside bounds check (OOB bug fix)
  • Fallback to queryCurrentFreqFromSysfs() on any error

139-172: LGTM! Clean max frequency implementation.

The max frequency query correctly derives the cpufreq path and delegates to the shared queryMaxFreqFromCpuFreqPath() helper, with proper fallback to queryMaxFreqFromSysfs() on any error.


📝 Walkthrough

Walkthrough

Introduces backend-specific LinuxCentralProcessor subclasses (JNA and FFM) and refactors the base class to expose protected hooks for udev-based topology and frequency queries, with automatic fallbacks to sysfs-based implementations.

Changes

Cohort / File(s) Summary
Base class refactor
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
Made LinuxCentralProcessor abstract; extracted udev/sysfs logic into protected hooks: readTopologyWithUdev(), queryCurrentFreqFromUdev(...), queryMaxFreqFromUdev(); added sysfs helper methods and adjusted visibility for reuse.
JNA backend
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
New final subclass implementing udev interactions with JNA; overrides the three protected hooks to enumerate udev cpu devices, parse topology/frequency, and unref native resources; falls back to sysfs on failures.
FFM backend
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
New final subclass implementing udev interactions via FFM (UdevFunctions); overrides the three protected hooks to use a confined Arena, enumerate cpu devices, parse topology/frequencies, and unmap/unref resources; falls back to sysfs on errors.
HAL factory updates
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java, oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
Updated factories to instantiate backend-specific processor implementations: JNA-backed in the base HAL and FFM-backed in the FFM HAL.
Changelog
CHANGELOG.md
Added entry referencing the udev migration PR (#3120).

Sequence Diagram

sequenceDiagram
    participant Client
    participant HAL as LinuxHardwareAbstractionLayer
    participant Proc as LinuxCentralProcessor (abstract)
    participant Backend as ProcessorBackend (JNA/FFM)
    participant Udev as udev (JNA or FFM)
    participant Sysfs

    Client->>HAL: createProcessor()
    HAL->>Backend: new LinuxCentralProcessorJNA/FFM()
    Client->>Backend: queryCurrentFreq()/queryMaxFreq()
    Backend->>Backend: query*FromUdev(...)
    Backend->>Udev: allocate/context & enumerate cpu devices
    alt udev succeeds
        Backend->>Backend: parse topology/freq from devices
        Backend-->>Client: return values (scaled where applicable)
        Backend->>Udev: unref/release
    else udev fails
        Backend->>Sysfs: call sysfs-based query helpers
        Backend-->>Client: return sysfs-derived values
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 I hopped through udev paths and code,

JNA and FFM each took a road,
When devices hide, sysfs will show,
Processors hum, frequencies flow,
A little rabbit cheers the mode! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.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 'Migrate LinuxCentralProcessor udev calls' accurately summarizes the main change: refactoring udev-dependent code from the base LinuxCentralProcessor class into subclass implementations (LinuxCentralProcessorJNA and LinuxCentralProcessorFFM).

✏️ 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 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.04%. Comparing base (9a00acd) to head (32cf2cc).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3120      +/-   ##
==========================================
+ Coverage   66.51%   68.04%   +1.53%     
==========================================
  Files          37       37              
  Lines        2025     2025              
  Branches      336      336              
==========================================
+ Hits         1347     1378      +31     
+ Misses        563      529      -34     
- Partials      115      118       +3     

☔ 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/hardware/platform/linux/LinuxCentralProcessor.java`:
- Around line 171-174: The call site currently checks the JNA flag
LinuxOperatingSystem.HAS_UDEV and chooses between readTopologyWithUdev() and
readTopologyFromSysfs(), which prevents the FFM backend
(LinuxCentralProcessorFFM.readTopologyWithUdev()) from deciding when to use
udev; remove the conditional and call readTopologyWithUdev() unconditionally so
the backend can internally fall back to sysfs as needed (leave
readTopologyFromSysfs() available for the backend to call). Use the existing
readTopologyWithUdev() symbol at this call site and eliminate the HAS_UDEV
branch so the backend implementation controls the udev/sysfs choice.
🪄 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: 768b79dd-1d6c-4dd0-89bb-c8b67a435e06

📥 Commits

Reviewing files that changed from the base of the PR and between 9a00acd and bb024c6.

📒 Files selected for processing (5)
  • 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/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/LinuxHardwareAbstractionLayer.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). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
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 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.
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: 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.
📚 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/LinuxHardwareAbstractionLayerFFM.java
  • 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/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.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/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.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 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/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.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: 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
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
🔇 Additional comments (7)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java (2)

57-57: The extracted hook/helper surface is well placed.

De-finalizing the base type and promoting the shared topology/max-frequency helpers keeps the proc/sysfs parsing centralized while leaving only the backend-specific native work to the JNA and FFM subclasses.

Also applies to: 203-301, 535-590


443-533: The current-frequency split looks good, including the bounds fix.

Routing queryCurrentFreq() through the protected hook keeps the fallback chain intact, and the max update now stays inside the CPU-index guard.

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

25-70: JNA context ownership looks correct.

Each override guards udev_new(), delegates to the shared helper, and unreferences the UdevContext in finally, which matches the injected-context lifecycle in LinuxCentralProcessor.

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

38-40: Factory wiring looks right.

This switches the default Linux HAL to the JNA-backed processor without changing the public CentralProcessor contract.

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

36-85: The FFM topology path mirrors the JNA lifecycle well.

The confined arena, explicit udev_*_unref() calls, and sysfs fallback keep the native lifetime bounded and aligned with the base hook contract.


87-172: The FFM frequency overrides preserve the shared fallback chain.

Both methods keep the udev-specific work localized while reusing the base sysfs helpers for the final fallback and cpufreq parsing.

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

24-27: This override completes the processor backend swap.

LinuxHardwareAbstractionLayerFFM will now instantiate LinuxCentralProcessorFFM instead of inheriting the JNA default from LinuxHardwareAbstractionLayer.

- Fix pre-existing OOB: move max-freq tracking inside cpu-index bounds
  check in queryCurrentFreqFromUdev
- Add null guard on udev_new() return in all three JNA overrides
- Make LinuxCentralProcessor abstract; make the three udev hook methods
  abstract (subclasses own the udev/sysfs decision)
- Remove HAS_UDEV branch from initProcessorCounts(); call
  readTopologyWithUdev() unconditionally so the backend controls the
  udev/sysfs choice
- Move all JNA udev helpers and imports out of LinuxCentralProcessor
  into LinuxCentralProcessorJNA; base class now has no JNA udev
  dependencies (only LinuxLibc remains, to be addressed later)
- Promote queryMaxFreqFromCpuFreqPath to protected static; remove
  duplicate queryMaxFreqFromCpuFreqPathFFM from LinuxCentralProcessorFFM
- Fix copyright year to 2026 on new files
- Add CHANGELOG entry for #3120
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