Skip to content

Add PerfCounterWildcardQueryFFM with PdhEnumObjectItems FFM binding; refactor LoadAverage - #3168

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:migrate-perfmon-drivers
Apr 18, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:migrate-perfmon-drivers

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 17, 2026 •

Copy link
Copy Markdown
Member

Wildcard Query Infrastructure

Adds FFM-based wildcard PDH counter query support, enabling enumeration of performance counter instances and querying per-instance values:

  • PdhFFM: Add PdhEnumObjectItemsW, PdhLookupPerfNameByIndexW, and PdhGetRawCounterValue FFM bindings; remove unused formatted counter bindings (PdhGetFormattedCounterValue, PdhGetFormattedCounterArray, PDH_FMT_COUNTERVALUE_* layouts)
  • PerfDataUtilFFM: Add enumInstances (two-call pattern with PDH_MORE_DATA retry), queryWildcardCounters, object name localization (required by PdhEnumObjectItemsW), and parseMultiSz for REG_MULTI_SZ parsing. Both wildcard and non-wildcard paths now use raw counters exclusively, matching JNA behavior
  • Advapi32UtilFFM: Add registryGetStringArray for REG_MULTI_SZ registry values (used for English→index counter name lookup)
  • WinNTFFM: Add REG_MULTI_SZ constant
  • PerfCounterWildcardQueryFFM: New class with PDH-first/WMI-fallback pattern and failed query caching, mirroring JNA's PerfCounterWildcardQuery

LoadAverage Refactoring

  • Extract abstract LoadAverage to oshi-common with daemon thread logic, exponential smoothing, startDaemon/stopDaemon/queryLoadAverage, and two abstract methods: queryNonIdleTicks() and queryQueueLength()
  • Create LoadAverageJNA singleton in oshi-core using JNA perfmon drivers
  • Create LoadAverageFFM singleton in oshi-core-java25 using FFM perfmon drivers
  • Add LoadAverageFFMTest mirroring existing JNA test structure

FFM Perfmon Drivers

  • ProcessInformationFFM: Add queryIdleProcessCounters() (wildcard query)
  • New non-wildcard drivers: MemoryInformationFFM, PagingFileFFM, ProcessorInformationFFM, SystemInformationFFM

Summary by CodeRabbit

  • Bug Fixes / Improvements

    • More reliable Windows perf-counter reads via raw-counter PDH path with PDH→WMI fallback and improved load-average reporting using platform-specific backends.
  • New Features

    • Wildcard enumeration for perf-counter instances.
    • New utilities for paging/memory and processor/system counters.
    • Support for reading multi-string (REG_MULTI_SZ) registry values.
  • Tests

    • Added Windows-only tests validating load-average behavior.
  • Chores

    • Updated CHANGELOG entry for 6.12.0 (in progress).

@coderabbitai

coderabbitai Bot commented Apr 17, 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: ea708857-d5c0-4475-8e0e-8a76de41f9b1

📥 Commits

Reviewing files that changed from the base of the PR and between f3b7173 and d9d852d.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinErrorFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.java
✅ Files skipped from review due to trivial changes (9)
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinErrorFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java
  • CHANGELOG.md
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.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). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-10T22:44:36.786Z
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:36.786Z
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-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
📚 Learning: 2026-04-12T19:34:59.050Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:59.050Z
Learning: The counterintuitive naming of `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` in OSHI (where a higher value means MORE performance and LESS efficiency, so P-cores get higher values than E-cores) is intentionally inherited from Microsoft's `PROCESSOR_RELATIONSHIP.EfficiencyClass` Win32 API: "A core with a higher value for the efficiency class has intrinsically greater performance and less efficiency." OSHI follows this same convention for cross-platform consistency. Do not flag P-cores being assigned higher efficiency values as a bug.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
📚 Learning: 2026-04-11T05:51:52.684Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:52.684Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.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/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.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/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
🔇 Additional comments (11)
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java (3)

50-60: PDH-first fallback flow looks good.

The failure cache is thread-safe, and the method cleanly falls back to WMI after an empty PDH result while avoiding repeated PDH attempts for the same object.


74-76: PDH wildcard delegation is consistent.

This keeps the wildcard query logic centralized in PerfDataUtilFFM, including its strict instance/value alignment behavior.


90-113: WMI fallback mapping preserves row alignment.

The implementation builds the instance list and each counter list in the same row iteration, keeping returned values aligned by index.

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java (1)

31-42: System counter wrappers look correct.

Both methods delegate to the expected FFM perf counter query path with the System perf object and matching raw WMI class.

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java (1)

31-43: Processor counter wrappers look correct.

Both methods consistently query the _Total processor instance through the FFM perf counter path.

oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java (6)

5-17: Common abstraction looks good.

The package move and abstract class shape cleanly separate shared load-average logic from JNA/FFM-specific perfmon queries.


20-25: Instance state is appropriate here.

The daemon thread and load-average array are now per-instance, while the immutable smoothing weights remain shared.


27-39: Hook surface is nicely scoped.

The abstract methods expose only the two platform-specific perfmon reads needed by the shared smoothing loop.


41-44: Thread-safe snapshot handling looks good.

The method keeps the internal array encapsulated and reads it under the same monitor used by the updater.


47-58: Lifecycle synchronization is sound.

The stop/start guard remains mutually exclusive on the same instance monitor. Based on learnings, the synchronized stopDaemon() / startDaemon() lifecycle pattern that interrupts, nulls, and checks loadAvgThread under the same monitor is intentionally safe and should not be flagged as a double-sampler race.


60-121: Daemon loop integration looks good.

The shared loop now delegates only the perfmon reads to subclasses while preserving the existing sampling cadence, synchronization, and interruption behavior.


📝 Walkthrough

Walkthrough

Moves LoadAverage to a common abstract instance-based class and adds JNA/FFM concrete implementations; replaces formatted PDH reads with raw reads; adds PDH wildcard enumeration with PDH→WMI fallback and failure cache; introduces multiple FFM perfmon wrappers and REG_MULTI_SZ registry support; updates tests and bindings.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added 6.12.0 (in progress) bullet for PR #3168 describing PerfCounterWildcardQueryFFM and LoadAverage refactor.
LoadAverage (abstraction & impls)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java, oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java, oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java
Converted LoadAverage from static utility to public abstract instance class with per-instance daemon and abstract query hooks; added thread-safe JNA and FFM singleton implementations.
PDH/FFM bindings
oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
Removed formatted-counter accessors/layouts; added raw-counter layout, PdhGetRawCounterValue, PdhLookupPerfNameByIndexW, PdhEnumObjectItemsW, and raw-status constants.
Perf data utilities & wildcard queries
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java, oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
Switched to raw PDH reads; added queryWildcardCounters(...), PDH instance enumeration, English→localized name lookup, multi-SZ parsing, and PDH→WMI fallback with a failed-PDH cache and dedicated PDH/WMI helpers.
FFM perfmon wrappers
oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/*
Added FFM-backed helpers: MemoryInformationFFM, PagingFileFFM, ProcessorInformationFFM, SystemInformationFFM; extended ProcessInformationFFM with queryIdleProcessCounters().
Registry & WinError constants
oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java, oshi-core-java25/src/main/java/oshi/ffm/windows/WinErrorFFM.java, oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
Added REG_MULTI_SZ and ERROR_MORE_DATA; implemented registryGetStringArray(...) with sizing retries and multi-sz parsing.
Consumers & tests
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java, oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.java, oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java, oshi-core-java25/src/test/java/module-info.test
Switched consumers/tests to instance-based LoadAverage (JNA/FFM), updated daemon lifecycle calls, added Windows FFM test and adjusted test module add-opens.
Minor docs/comments
oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
Javadoc updated to describe returned idle counters as "raw".

Sequence Diagram(s)

sequenceDiagram
    participant Client as PerfCounterWildcardQueryFFM
    participant Cache as FAILED_PDH_CACHE
    participant PDH as PerfDataUtilFFM (PDH)
    participant WMI as WmiQueryHandlerFFM

    Client->>Cache: is perfObject cached?
    alt cached (PDH known to fail)
        Client->>WMI: queryInstancesAndValuesFromWMI(...)
        WMI-->>Client: (instances, values)
    else not cached
        Client->>PDH: queryInstancesAndValuesFromPDH(...)
        PDH->>PDH: PdhEnumObjectItemsW -> build query -> PdhCollectQueryData
        PDH-->>Client: (instances, values)
        alt instances empty
            Client->>Cache: mark perfObject failed
            Client->>WMI: queryInstancesAndValuesFromWMI(...)
            WMI-->>Client: (instances, values)
        end
    end
    Client-->>Client: return (instances, values)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐇 I hopped from static fields to instance ground,

JNA and FFM summoned counters all around,
When PDH trips, WMI offers a hand,
Wildcards, raw reads, threads softly stand,
I twitch my nose — metrics found and sound!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.89% 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 clearly and specifically summarizes the primary changes: adding PerfCounterWildcardQueryFFM with PdhEnumObjectItems FFM binding and refactoring LoadAverage. The title directly aligns with the main objectives.

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.93536% with 108 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.12%. Comparing base (88c6095) to head (f3b7173).

Files with missing lines Patch % Lines
...va/oshi/util/platform/windows/PerfDataUtilFFM.java 61.31% 33 Missing and 20 partials ⚠️
.../platform/windows/PerfCounterWildcardQueryFFM.java 19.23% 19 Missing and 2 partials ⚠️
...va/oshi/util/platform/windows/Advapi32UtilFFM.java 56.09% 11 Missing and 7 partials ⚠️
...va/oshi/driver/windows/perfmon/LoadAverageFFM.java 77.27% 2 Missing and 3 partials ⚠️
...va/oshi/driver/windows/perfmon/LoadAverageJNA.java 77.27% 2 Missing and 3 partials ⚠️
...river/windows/perfmon/ProcessorInformationFFM.java 0.00% 2 Missing ⚠️
...i/driver/windows/perfmon/MemoryInformationFFM.java 0.00% 1 Missing ⚠️
...ava/oshi/driver/windows/perfmon/PagingFileFFM.java 0.00% 1 Missing ⚠️
...i/driver/windows/perfmon/SystemInformationFFM.java 50.00% 1 Missing ⚠️
...ware/platform/windows/WindowsCentralProcessor.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3168      +/-   ##
==========================================
+ Coverage   58.02%   58.12%   +0.09%     
==========================================
  Files         326      333       +7     
  Lines       17417    17652     +235     
  Branches     3072     3121      +49     
==========================================
+ Hits        10107    10261     +154     
- Misses       5820     5871      +51     
- Partials     1490     1520      +30     
Flag Coverage Δ
linux 26.19% <0.00%> (-0.24%) ⬇️
macos 29.36% <0.00%> (-0.41%) ⬇️
windows 32.37% <58.93%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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: 6

🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java (1)

37-47: Guard counter lists before indexing them.

If the wildcard query returns instances but a missing or shorter value list, this loop can throw and stop load-average sampling. Returning (0, 0) matches the existing “no data” fallback behavior.

Proposed defensive guard
         List<Long> proctimeTicks = valueMap.get(IdleProcessorTimeProperty.PERCENTPROCESSORTIME);
         List<Long> proctimeBase = valueMap.get(IdleProcessorTimeProperty.ELAPSEDTIME);
+        if (proctimeTicks == null || proctimeBase == null || proctimeTicks.size() < instances.size()
+                || proctimeBase.size() < instances.size()) {
+            return new Pair<>(0L, 0L);
+        }
         long nonIdleTicks = 0L;
         long nonIdleBase = 0L;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java`
around lines 37 - 47, The loop in LoadAverageJNA that iterates over instances
reads proctimeTicks.get(i) and proctimeBase.get(i) without ensuring those lists
are non-null and long enough; add defensive guards: check that valueMap contains
IdleProcessorTimeProperty.PERCENTPROCESSORTIME and ELAPSEDTIME and that
proctimeTicks and proctimeBase are non-null and have size > i before indexing
inside the for loop over instances; if either list is missing or too short, bail
out and return the existing “no data” fallback (0, 0) to avoid throwing an
IndexOutOfBoundsException.
🤖 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/driver/windows/perfmon/ProcessInformationFFM.java`:
- Around line 40-44: The JavaDoc on the method in ProcessInformationFFM that
"Returns cooked idle process performance counters" is incorrect—update the
summary and `@return` to state these are raw idle process counters (e.g., change
"cooked" to "raw" and reword to "Returns raw idle process performance counters"
and "@return Raw performance counters for idle process.") to accurately reflect
that the method returns raw values.

In `@oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`:
- Around line 54-57: PDH_RAW_COUNTER_LAYOUT is misaligned (extra padding after
CStatus) and treats TimeStamp incorrectly; remove the explicit
MemoryLayout.paddingLayout(4) after CStatus, represent the FILETIME TimeStamp as
the two DWORDs rather than a single aligned JAVA_LONG, and mark non‑standard
aligned wide fields as unaligned; specifically update PDH_RAW_COUNTER_LAYOUT so
CStatus remains JAVA_INT.withName("CStatus"), TimeStamp is two DWORDs (e.g., two
JAVA_INT_UNALIGNED fields or a single JAVA_LONG_UNALIGNED named "TimeStamp"),
FirstValue and SecondValue use
ValueLayout.JAVA_LONG_UNALIGNED.withName("FirstValue"/"SecondValue"), and
MultiCount uses JAVA_INT_UNALIGNED.withName("MultiCount") to match native
offsets 0x00,0x04,0x0C,0x14,0x1C.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java`:
- Around line 219-237: The call to RegQueryValueEx (in Advapi32UtilFFM.java)
treats ERROR_INSUFFICIENT_BUFFER as the only undersized-buffer return, but
RegQueryValueExW can return ERROR_MORE_DATA (234); add ERROR_MORE_DATA = 234 to
WinErrorFFM.java, import/use it in Advapi32UtilFFM.java, and change the second
RegQueryValueEx result handling to treat ERROR_MORE_DATA like
ERROR_INSUFFICIENT_BUFFER (i.e., retry with a resized buffer or fail
immediately) by checking for ERROR_MORE_DATA when deciding to reallocate or
throw, and use lpcbData to drive the correct new allocation size before the
retry.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`:
- Around line 146-149: readRawCounterValue currently returns FirstValue without
validating the PDH_RAW_COUNTER.CStatus field; update it to read the CStatus from
the allocated PDH_RAW_COUNTER_LAYOUT MemorySegment (using the RAW_CSTATUS
offset) after PdhGetRawCounterValue succeeds and only return FirstValue when
CStatus equals PDH_CSTATUS_VALID_DATA (0) or PDH_CSTATUS_NEW_DATA (1); if
CStatus is any other value, throw or propagate an exception (or return a
sentinel) to avoid returning stale/invalid data. Add the two constants
PDH_CSTATUS_VALID_DATA and PDH_CSTATUS_NEW_DATA in PdhFFM and reference them in
readRawCounterValue, and use the existing PDH_RAW_COUNTER_LAYOUT,
RAW_FIRST_VALUE_OFFSET and the corresponding RAW_CSTATUS offset to locate the
fields.

In
`@oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java`:
- Around line 27-33: The test currently starts the shared LoadAverageFFM daemon
with loadAvg.startDaemon() and may skip loadAvg.stopDaemon() if an assertion
fails; wrap the test body that calls startDaemon(), Util.sleep(...),
queryLoadAverage(...), and the assertions in a try block and call
loadAvg.stopDaemon() in a finally block so the LoadAverageFFM singleton is
always stopped; reference the LoadAverageFFM instance (loadAvg), its
startDaemon() and stopDaemon() methods and the queryLoadAverage(...) call when
making the change.

In `@oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.java`:
- Around line 27-33: The test starts a shared daemon via loadAvg.startDaemon()
but only calls loadAvg.stopDaemon() after assertions, so the daemon may remain
running if an assertion fails; wrap the work after startDaemon in a try/finally
(e.g., after calling loadAvg.startDaemon(), run Util.sleep(...) and
loadAvg.queryLoadAverage(...) and the assertions inside try { ... } finally {
loadAvg.stopDaemon(); }) to ensure loadAvg.stopDaemon() always executes;
reference the LoadAverageTest test harness and the loadAvg.startDaemon(),
loadAvg.queryLoadAverage(...), and loadAvg.stopDaemon() methods when making the
change.

---

Nitpick comments:
In `@oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java`:
- Around line 37-47: The loop in LoadAverageJNA that iterates over instances
reads proctimeTicks.get(i) and proctimeBase.get(i) without ensuring those lists
are non-null and long enough; add defensive guards: check that valueMap contains
IdleProcessorTimeProperty.PERCENTPROCESSORTIME and ELAPSEDTIME and that
proctimeTicks and proctimeBase are non-null and have size > i before indexing
inside the for loop over instances; if either list is missing or too short, bail
out and return the existing “no data” fallback (0, 0) to avoid throwing an
IndexOutOfBoundsException.
🪄 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: 5a0a4732-bfee-4266-a199-ccfebda04dd8

📥 Commits

Reviewing files that changed from the base of the PR and between 88c6095 and 8952e46.

📒 Files selected for processing (18)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.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). (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (8)
📚 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/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.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/test/java/module-info.test
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.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/oshi/util/platform/windows/Advapi32UtilFFM.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/test/java/module-info.test
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
📚 Learning: 2026-04-10T22:44:36.786Z
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:36.786Z
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/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
📚 Learning: 2026-04-12T19:34:59.050Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:59.050Z
Learning: The counterintuitive naming of `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` in OSHI (where a higher value means MORE performance and LESS efficiency, so P-cores get higher values than E-cores) is intentionally inherited from Microsoft's `PROCESSOR_RELATIONSHIP.EfficiencyClass` Win32 API: "A core with a higher value for the efficiency class has intrinsically greater performance and less efficiency." OSHI follows this same convention for cross-platform consistency. Do not flag P-cores being assigned higher efficiency values as a bug.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.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/windows/WindowsCentralProcessor.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
🔇 Additional comments (15)
CHANGELOG.md (1)

33-33: Looks good — changelog entry is clear and scoped appropriately.

This accurately captures the wildcard PDH/FFM addition and the LoadAverage refactor in the same style as surrounding entries.

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java (1)

16-32: LGTM — clean FFM perfmon utility wrapper.

The class is stateless, the private constructor/final utility pattern is appropriate, and queryPageSwaps() matches the PerfCounterQueryFFM.queryValues(...) contract shown in the related context.

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java (1)

30-33: LGTM — consistent FFM perf counter wrapper.

querySwapUsed() uses the shared PerfCounterQueryFFM.queryValues(...) contract correctly with the paging-file enum, PDH object, and WMI fallback class.

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

13-14: LGTM!

Opening the new Windows perfmon package for JUnit reflection matches the added LoadAverageFFMTest.

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java (2)

31-34: LGTM!

querySystemCounters() correctly reuses the common processor tick properties and total-processor raw counter selector.


41-44: LGTM!

The interrupts query mirrors the JNA-style wrapper shape and uses the expected InterruptsProperty enum.

oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java (1)

27-27: LGTM!

REG_MULTI_SZ belongs with the existing registry value type constants and enables explicit multi-string type checks.

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java (1)

73-76: LGTM!

The singleton-based delegation preserves the existing config-gated daemon startup and nelem validation behavior.

Also applies to: 317-321

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java (1)

45-48: LGTM!

The wildcard query uses the shared idle-process property enum and the expected IDPROCESS = 0 selector.

oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java (2)

22-29: LGTM!

The static-final singleton keeps daemon state centralized and avoids repeated LoadAverageJNA instances.


52-56: LGTM!

The queue-length lookup preserves a safe 0L fallback when the counter is unavailable.

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java (1)

31-42: LGTM.

The FFM wrapper mirrors the common perfmon property definitions and keeps both system counter queries consistently routed through PerfCounterQueryFFM.

oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java (1)

31-56: LGTM.

The FFM implementation cleanly supplies the two platform hooks required by the common LoadAverage base and keeps missing queue-length data safely defaulted to 0L.

oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java (1)

50-113: LGTM.

The PDH-first/WMI-fallback flow matches the wildcard enum contract, and the failed-query cache is thread-safe.

oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java (1)

27-122: LGTM.

The common base cleanly separates daemon/smoothing logic from the platform-specific perfmon queries while preserving the existing load-average lifecycle.

@dbwiddis
dbwiddis force-pushed the migrate-perfmon-drivers branch from 8952e46 to 3f7b8cb Compare April 17, 2026 23:31

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

♻️ Duplicate comments (1)
oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java (1)

229-238: ⚠️ Potential issue | 🟠 Major

Retry instead of parsing after an undersized-buffer result.

Line 236 still treats ERROR_MORE_DATA / ERROR_INSUFFICIENT_BUFFER as readable data. If the value grows between the size probe and the read, this can parse a truncated REG_MULTI_SZ. Only parse after ERROR_SUCCESS; otherwise resize from lpcbData and retry.

Proposed fix
-                int size = lpcbData.get(JAVA_INT, 0);
-                // Allocate extra for double-null terminator
-                MemorySegment data = arena.allocate(size + 4);
-                data.fill((byte) 0);
-                lpcbData.set(JAVA_INT, 0, size + 4);
-
-                rc = RegQueryValueEx(hKey, toWideString(arena, valueName), 0, lpType, data, lpcbData);
-                if (rc != ERROR_SUCCESS && rc != ERROR_INSUFFICIENT_BUFFER && rc != ERROR_MORE_DATA) {
+                int size = lpcbData.get(JAVA_INT, 0);
+                MemorySegment data;
+                do {
+                    // Allocate extra for double-null terminator
+                    data = arena.allocate(size + 4L);
+                    data.fill((byte) 0);
+                    lpcbData.set(JAVA_INT, 0, size + 4);
+
+                    rc = RegQueryValueEx(hKey, toWideString(arena, valueName), 0, lpType, data, lpcbData);
+                    if (rc == ERROR_INSUFFICIENT_BUFFER || rc == ERROR_MORE_DATA) {
+                        size = lpcbData.get(JAVA_INT, 0);
+                    }
+                } while (rc == ERROR_INSUFFICIENT_BUFFER || rc == ERROR_MORE_DATA);
+
+                if (rc != ERROR_SUCCESS) {
                     throw new Win32Exception(rc);
                 }
Microsoft RegQueryValueExW documentation ERROR_MORE_DATA buffer too small lpcbData required size
🤖 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/util/platform/windows/Advapi32UtilFFM.java`
around lines 229 - 238, The code currently treats ERROR_MORE_DATA /
ERROR_INSUFFICIENT_BUFFER as readable data after the RegQueryValueEx call;
change the logic in the RegQueryValueEx handling (around variables rc, lpcbData,
data and the RegQueryValueEx call) so that you only parse the buffer when rc ==
ERROR_SUCCESS, and on rc == ERROR_MORE_DATA or ERROR_INSUFFICIENT_BUFFER use the
updated size in lpcbData to reallocate data and retry the RegQueryValueEx call
(loop until ERROR_SUCCESS or a true error), then parse only on success; keep
throwing Win32Exception for other error codes.
🤖 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-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`:
- Around line 47-58: The stop/start race can create two sampler threads because
stopDaemon() sets loadAvgThread = null immediately after interrupting; change
the lifecycle so the worker clears the shared loadAvgThread reference when it
exits and stopDaemon() only nulls the field after confirming termination (use
Thread.join with a bounded timeout) to avoid races. Specifically: in
stopDaemon(), call interrupt() and then join(timeout) on the existing
loadAvgThread and only set loadAvgThread = null after join returns (or the
thread has otherwise terminated); in the Thread body started by startDaemon()
ensure the thread clears loadAvgThread upon normal exit (and respects
interruption while performing perfmon queries) and that startDaemon() still
checks loadAvgThread == null before creating a new thread. Ensure the shared
variable loadAvgThread is only cleared by the worker on exit or by stopDaemon
after join to prevent double samplers.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`:
- Around line 287-298: The loop that fills counterHandles aborts the entire
wildcard query on the first addEnglishCounter failure, which is too strict;
change PerfDataUtilFFM so that when addEnglishCounter(path) throws you skip that
specific counter add instead of returning an empty Pair — e.g., for each
props[p] catch exceptions, log them, insert a null sentinel (or simply do not
add to counterHandles[p-1] for that instance) and continue; ensure later code
that reads handles treats nulls as missing (0L reads) so a single transient
failure won’t close the whole query (align behavior with queryCounters and
prevent PerfCounterWildcardQueryFFM.queryInstancesAndValues from disabling PDH
for the whole perfObject).
- Around line 188-201: The retry loop currently overwrites PDH-returned buffer
sizes with the previous input sizes plus 1024, which discards the authoritative
required-size written by PdhEnumObjectItemsW; change the logic in the loop that
handles PDH_MORE_DATA so that after PdhEnumObjectItemsW returns PDH_MORE_DATA
you read the updated values from counterLen and instanceLen (these contain the
required TCHAR counts), allocate counterBuf and instanceBuf based on those
returned sizes (and optionally add a fixed headroom like +1024), and only then
retry the call; also add a small max-iteration cap (e.g., 5) around the do/while
to guarantee termination under pathological churn.

---

Duplicate comments:
In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java`:
- Around line 229-238: The code currently treats ERROR_MORE_DATA /
ERROR_INSUFFICIENT_BUFFER as readable data after the RegQueryValueEx call;
change the logic in the RegQueryValueEx handling (around variables rc, lpcbData,
data and the RegQueryValueEx call) so that you only parse the buffer when rc ==
ERROR_SUCCESS, and on rc == ERROR_MORE_DATA or ERROR_INSUFFICIENT_BUFFER use the
updated size in lpcbData to reallocate data and retry the RegQueryValueEx call
(loop until ERROR_SUCCESS or a true error), then parse only on success; keep
throwing Win32Exception for other error codes.
🪄 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: 981d9235-7b18-4368-a81e-a4c2e3d44783

📥 Commits

Reviewing files that changed from the base of the PR and between 8952e46 and 3f7b8cb.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinErrorFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.java
✅ Files skipped from review due to trivial changes (8)
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinErrorFFM.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.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). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (7)
📚 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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.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/util/platform/windows/Advapi32UtilFFM.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/util/platform/windows/Advapi32UtilFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
📚 Learning: 2026-04-11T05:51:52.684Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:52.684Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
📚 Learning: 2026-04-10T22:44:36.786Z
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:36.786Z
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/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
🔇 Additional comments (7)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java (1)

27-45: The abstract query hooks and synchronized snapshotting look good.

The common daemon now cleanly delegates platform-specific counter collection while keeping load-average state protected behind the existing monitor.

Also applies to: 62-105

oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java (1)

20-62: LGTM.

The JNA singleton cleanly preserves the existing perfmon flow, handles missing counter maps safely, and keeps queue-length fallback behavior consistent with the driver contract.

oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java (2)

50-61: Approve: PDH→WMI fallback with failed-query cache faithfully mirrors the JNA implementation.

Gate logic, one-shot LOG.info on disable, and idempotent cache add via ConcurrentHashMap.newKeySet() are correct. Note that FAILED_QUERY_CACHE is process-lifetime (never cleared) — that matches the JNA class's behavior, so intentional, but worth noting for long-running processes where perf counters are rebuilt externally (e.g., lodctr /r).


92-113: No null-safety issue: IWbemClassObjectFFM.getString() and getLong() never return null.

Both methods explicitly document they return "" and 0L respectively on missing/null property values. The implementation confirms this: every code path returns a non-null value. No coalescing is needed; lines 108 and 110 are safe as written.

			> Likely an incorrect or invalid review comment.
oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java (1)

46-82: Approve: raw-counter layout and new PDH bindings match the native ABI.

  • PDH_RAW_COUNTER_LAYOUT now matches the 32-byte native struct with correct offsets (CStatus@0, TimeStampLow@4, TimeStampHigh@8, FirstValue@12, SecondValue@20, MultiCount@28). JAVA_LONG_UNALIGNED/JAVA_INT_UNALIGNED correctly account for the 4-byte-aligned FirstValue/SecondValue positions.
  • PdhGetRawCounterValue, PdhLookupPerfNameByIndexW, and PdhEnumObjectItemsW signatures and arities match the Win32 PDH ABI.
  • PDH_CSTATUS_VALID_DATA/PDH_CSTATUS_NEW_DATA match MS documentation.

Previous struct-layout concern is correctly resolved.

oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (2)

146-158: Approve: raw-counter read now validates CStatus before consuming FirstValue.

Previous review concern about returning data without checking PDH_RAW_COUNTER.CStatus is fully addressed. The use of JAVA_LONG_UNALIGNED at RAW_FIRST_VALUE_OFFSET correctly matches the 4-byte-aligned field position in the 32-byte native struct. The IllegalStateException propagates up to the calling try { ... } catch (Throwable t) blocks in queryCounters/queryWildcardCounters, which correctly log and substitute default values — preserving per-counter fault tolerance.


335-390: Approve: English→localized object-name resolution via Perflib registry + PdhLookupPerfNameByIndexW.

The lookup strategy is correct: it reads HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009\Counter (always English regardless of system locale) to resolve the English name to its index, then uses PdhLookupPerfNameByIndexW to get the localized name that PdhEnumObjectItemsW expects. Two-call size probing on PdhLookupPerfNameByIndexW is handled correctly, and LOCALIZE_CACHE amortizes the registry read (the Counter multistring is large, so caching is important). Fallback to the English name on any failure degrades gracefully.

@dbwiddis
dbwiddis force-pushed the migrate-perfmon-drivers branch from 3f7b8cb to f3b7173 Compare April 17, 2026 23:57

@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 (3)
oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java (3)

225-227: Avoid raw RuntimeException; use a more specific type.

Throwing a bare RuntimeException for a type mismatch is a minor smell. IllegalStateException (or Win32Exception-style domain type) conveys intent better, even though the outer catch (Throwable) makes this functionally equivalent.

🤖 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/util/platform/windows/Advapi32UtilFFM.java`
around lines 225 - 227, Replace the raw RuntimeException thrown in
Advapi32UtilFFM when the registry type mismatches with a more specific exception
(e.g., IllegalStateException or a Win32-specific exception type); update the
throw that currently builds "Unexpected registry type " + lpType.get(JAVA_INT,
0) + ", expected REG_MULTI_SZ" to instead throw IllegalStateException (or a
Win32Exception) with the same message to convey intent more clearly.

261-263: RegCloseKey return value is silently discarded.

Other methods in this file (e.g., registryGetKeys at lines 144–147) treat a failed close as a fatal error. Here the return code is ignored. Since this is in a finally, throwing would mask the original exception, so silently ignoring is arguably the better choice — consider at least logging at debug level on non-success for consistency.

-            } finally {
-                RegCloseKey(hKey);
-            }
+            } finally {
+                int closeRc = RegCloseKey(hKey);
+                if (closeRc != ERROR_SUCCESS) {
+                    LOG.debug("RegCloseKey failed for {}\\{}: rc={}", keyPath, valueName, closeRc);
+                }
+            }
🤖 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/util/platform/windows/Advapi32UtilFFM.java`
around lines 261 - 263, The RegCloseKey(hKey) call in Advapi32UtilFFM's finally
block currently discards the return value; change it to capture the return code
and, if it indicates failure (non-success), emit a debug-level log message
(consistent with how registryGetKeys handles RegCloseKey failures) rather than
throwing, so the original exception isn’t masked—use the same logger/format used
elsewhere in this class for consistency.

247-258: Bound the multi-sz parse loop by the actual bytes returned, not buffer capacity.

data.byteSize() is the allocated buffer size (size + 4), not the bytes actually written by RegQueryValueEx. The explicit zero-fill at line 235 plus the empty-string break at line 252 keeps this safe today, but if the zero-fill is ever removed, or if readWideString is changed to scan past embedded nulls, the loop could read uninitialized tail bytes. Prefer bounding by the value returned in lpcbData for clarity and defensiveness.

♻️ Proposed refactor
-                    // Parse multi-sz: null-delimited wide strings, double-null terminated
-                    List<String> result = new ArrayList<>();
-                    long offset = 0;
-                    while (offset < data.byteSize()) {
+                    // Parse multi-sz: null-delimited wide strings, double-null terminated
+                    List<String> result = new ArrayList<>();
+                    long dataBytes = Integer.toUnsignedLong(lpcbData.get(JAVA_INT, 0));
+                    long offset = 0;
+                    while (offset < dataBytes) {
                         String s = readWideString(data.asSlice(offset));
                         if (s.isEmpty()) {
                             break;
                         }
                         result.add(s);
                         offset += ((long) s.length() + 1) * 2; // chars + null, 2 bytes each
                     }
🤖 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/util/platform/windows/Advapi32UtilFFM.java`
around lines 247 - 258, The multi-sz parsing loop in Advapi32UtilFFM currently
bounds by data.byteSize() (the allocated buffer) which can exceed the actual
bytes written; change the loop to use the actual byte count returned by
RegQueryValueEx (lpcbData) as the upper bound, ensure each slice/read of
readWideString is limited to the remaining bytes (e.g., asSlice(offset, lpcbData
- offset) or equivalent), and stop when offset >= lpcbData or when an empty
string is encountered; update uses of offset arithmetic to compare against
lpcbData (not data.byteSize()) so the loop never reads past the returned data.
🤖 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-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java`:
- Around line 225-227: Replace the raw RuntimeException thrown in
Advapi32UtilFFM when the registry type mismatches with a more specific exception
(e.g., IllegalStateException or a Win32-specific exception type); update the
throw that currently builds "Unexpected registry type " + lpType.get(JAVA_INT,
0) + ", expected REG_MULTI_SZ" to instead throw IllegalStateException (or a
Win32Exception) with the same message to convey intent more clearly.
- Around line 261-263: The RegCloseKey(hKey) call in Advapi32UtilFFM's finally
block currently discards the return value; change it to capture the return code
and, if it indicates failure (non-success), emit a debug-level log message
(consistent with how registryGetKeys handles RegCloseKey failures) rather than
throwing, so the original exception isn’t masked—use the same logger/format used
elsewhere in this class for consistency.
- Around line 247-258: The multi-sz parsing loop in Advapi32UtilFFM currently
bounds by data.byteSize() (the allocated buffer) which can exceed the actual
bytes written; change the loop to use the actual byte count returned by
RegQueryValueEx (lpcbData) as the upper bound, ensure each slice/read of
readWideString is limited to the remaining bytes (e.g., asSlice(offset, lpcbData
- offset) or equivalent), and stop when offset >= lpcbData or when an empty
string is encountered; update uses of offset arithmetic to compare against
lpcbData (not data.byteSize()) so the loop never reads past the returned data.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e7a5574b-ea89-404f-a5ce-267adacfd0fb

📥 Commits

Reviewing files that changed from the base of the PR and between 3f7b8cb and f3b7173.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinErrorFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.java
✅ Files skipped from review due to trivial changes (9)
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/MemoryInformationFFM.java
  • oshi-core-java25/src/test/java/oshi/driver/windows/perfmon/LoadAverageFFMTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/SystemInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinErrorFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/LoadAverageFFM.java
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/ProcessInformationJNA.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core/src/test/java/oshi/driver/windows/perfmon/LoadAverageTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PagingFileFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/ProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.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). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (14)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java
📚 Learning: 2026-04-12T19:34:59.050Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:59.050Z
Learning: The counterintuitive naming of `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` in OSHI (where a higher value means MORE performance and LESS efficiency, so P-cores get higher values than E-cores) is intentionally inherited from Microsoft's `PROCESSOR_RELATIONSHIP.EfficiencyClass` Win32 API: "A core with a higher value for the efficiency class has intrinsically greater performance and less efficiency." OSHI follows this same convention for cross-platform consistency. Do not flag P-cores being assigned higher efficiency values as a bug.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.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/windows/WindowsCentralProcessor.java
📚 Learning: 2026-04-10T22:44:36.786Z
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:36.786Z
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-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
📚 Learning: 2026-04-11T05:51:52.684Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:52.684Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.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/util/platform/windows/Advapi32UtilFFM.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/util/platform/windows/Advapi32UtilFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.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-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
🔇 Additional comments (7)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessor.java (1)

38-38: JNA load-average integration looks consistent.

The import, daemon startup, and query path now consistently use the LoadAverageJNA singleton while preserving the existing nelem validation.

Also applies to: 75-75, 321-321

oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java (1)

5-17: Common load-average abstraction looks sound.

The shared daemon/smoothing logic is cleanly separated from backend-specific perfmon queries, and the synchronized lifecycle/state access remains consistent. Based on learnings, the synchronized stopDaemon() / startDaemon() pattern here is intentional and should not be flagged as a race.

Also applies to: 20-22, 27-44, 47-122

oshi-core/src/main/java/oshi/driver/windows/perfmon/LoadAverageJNA.java (1)

22-62: JNA backend implementation looks good.

The singleton is safely initialized, and both perfmon hooks provide defensive fallbacks for missing counter data.

oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (4)

146-158: LGTM: raw counter reads now validate CStatus.

Using layout-derived offsets for CStatus and FirstValue avoids hard-coded struct offset drift and prevents invalid raw samples from leaking to callers. Based on learnings, PDH_RAW_COUNTER_LAYOUT must preserve native alignment so FirstValue is read from the aligned layout offset.


167-217: LGTM: instance enumeration handles PDH buffer churn safely.

The PDH_MORE_DATA path now reuses PDH-returned lengths, adds headroom, and caps retries, which is a good fit for changing process/thread instance lists.


289-298: LGTM: aborting on wildcard counter-add failure preserves alignment.

Returning an empty result here is safer than partially filling per-property lists because callers rely on strict index alignment between instances and every values list. Based on learnings, queryWildcardCounters intentionally aborts on addEnglishCounter failure to preserve the parallel-list contract.


337-392: LGTM: localized object lookup has safe fallbacks.

The English-index lookup and localized-name resolution fall back to the original object name on missing registry/API data, keeping PDH fallback behavior non-fatal.

refactor LoadAverage

Wildcard query infrastructure:
- Add PdhEnumObjectItemsW, PdhLookupPerfNameByIndexW, and
  PdhGetRawCounterValue FFM bindings to PdhFFM
- Add enumInstances (two-call pattern with PDH_MORE_DATA retry) and
  queryWildcardCounters to PerfDataUtilFFM
- Add object name localization (PdhEnumObjectItemsW requires localized
  names) with registry-based English-to-index lookup
- Add registryGetStringArray to Advapi32UtilFFM for REG_MULTI_SZ
- Create PerfCounterWildcardQueryFFM with PDH-first/WMI-fallback pattern
- Use raw counters exclusively (matching JNA), removing formatted
  counter bindings

LoadAverage refactoring:
- Extract abstract LoadAverage to oshi-common with daemon thread logic,
  exponential smoothing, and two abstract query methods
- Create LoadAverageJNA in oshi-core implementing queries via JNA
  drivers
- Create LoadAverageFFM in oshi-core-java25 implementing queries via FFM
  drivers
- Add LoadAverageFFMTest mirroring existing JNA test

FFM perfmon drivers:
- Add queryIdleProcessCounters() to ProcessInformationFFM (wildcard)
- Add MemoryInformationFFM, PagingFileFFM, ProcessorInformationFFM,
  SystemInformationFFM non-wildcard drivers
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