Skip to content

Add FFM registry drivers for HKEY_PERFORMANCE_DATA - #3171

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:ffm-registry-drivers
Apr 18, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:ffm-registry-drivers

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Parse HKEY_PERFORMANCE_DATA binary structs via FFM for process and thread performance data, bypassing the PDH abstraction layer for faster access.

Changes

oshi-common

  • Extract ProcessPerfCounterBlock and ThreadPerfCounterBlock POJOs from oshi-core inner classes into oshi.driver.common.windows.registry package, enabling FFM code to use them without depending on oshi-core (JNA)
  • Add exports oshi.driver.common.windows.registry to module-info

oshi-core-java25

  • WinPerfFFM: FFM struct layouts for PERF_DATA_BLOCK, PERF_OBJECT_TYPE, PERF_COUNTER_DEFINITION, PERF_INSTANCE_DEFINITION, PERF_COUNTER_BLOCK with pre-computed field offset constants
  • HkeyPerformanceDataUtilFFM: Core parser for HKEY_PERFORMANCE_DATA binary data using FFM RegQueryValueEx
  • ProcessPerformanceDataFFM and ThreadPerformanceDataFFM: Registry-based process/thread data drivers
  • WinRegFFM: Add HKEY_PERFORMANCE_DATA constant
  • WindowsOperatingSystemFFM: Switch from JNA to FFM registry data classes

oshi-core

  • Remove inner PerfCounterBlock classes from ProcessPerformanceData and ThreadPerformanceData, replaced by common POJOs
  • Update all consumers: WindowsOperatingSystem, WindowsOSProcess, WindowsOSProcessJNA, WindowsOSThread

oshi-benchmark

  • New RegistryComparisonTest: Validates JNA vs FFM registry parsing produces matching results (exact match on static fields, tolerance on dynamic/timing-sensitive fields)

Testing

  • All builds pass: mvn clean spotless:apply install checkstyle:check, forbiddenapis:check, javadoc:aggregate
  • Windows CI validates FFM struct parsing correctness via comparison tests

Summary by CodeRabbit

  • New Features

    • Added FFM-based registry drivers to read Windows process and thread performance counters.
  • Tests

    • Added comparison tests validating registry reads against PerfMon data on Windows.
  • Refactor

    • Moved shared process/thread performance data types into a common module and updated consumers.
  • Chores

    • Updated changelog for the upcoming release.

@coderabbitai

coderabbitai Bot commented Apr 18, 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: a6e97ebc-4ebd-4d29-9b1a-7d207b593be1

📥 Commits

Reviewing files that changed from the base of the PR and between 575c0f2 and bdb3119.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (7)
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-common/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • CHANGELOG.md
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.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). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
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`.
📚 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-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.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/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.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-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
🔇 Additional comments (1)
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java (1)

104-144: procName parameter is accepted but never applied as a filter.

buildProcessMapFromPerfCounters(pids, procName) declares procName with Javadoc "Filter by this process name." but the method body only filters by pids — procName is unused. This mirrors the same asymmetry previously flagged in ProcessPerformanceDataFFM: the thread counterpart (ThreadPerformanceData.buildThreadMapFromPerfCounters) branches on Util.isBlank(procName) to switch query methods, but the process path does not. Either wire procName through to ProcessInformationJNA.queryProcessCounters(...) or remove the parameter from both JNA and FFM signatures to keep them consistent.


📝 Walkthrough

Walkthrough

Adds FFM-based readers for HKEY_PERFORMANCE_DATA, extracts Process/Thread PerfCounterBlock POJOs into oshi-common and exports that package, updates JNA/FFM consumers to the shared types, and adds a JUnit comparison test validating registry vs perf-counter data paths.

Changes

Cohort / File(s) Summary
FFM struct & registry constants
oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java, oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
Added StructLayout definitions and byte-offset constants for PERF_* structures; added HKEY_PERFORMANCE_DATA constant.
FFM registry reader utility
oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
New thread-safe FFM utility to read/parse HKEY_PERFORMANCE_DATA buffers, resolve counters, and return per-instance counter maps with timestamps.
FFM process/thread drivers
oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java, oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
New FFM-based builders producing maps of process/thread PerfCounterBlock POJOs, handling ELAPSEDTIME/filetime normalization, scaling, and optional PID filtering.
Shared POJOs & module export
oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java, oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java, oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java, oshi-common/src/main/java/module-info.java
Added immutable Process/Thread PerfCounterBlock POJOs, package Javadoc, and exported oshi.driver.common.windows.registry from oshi-common.
JNA drivers updated to use shared POJOs
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java, oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
Removed nested PerfCounterBlock types; updated method signatures and construction to return/instantiate shared POJOs; widened some counter types to long.
OS/process/thread consumers updated
oshi-core/src/main/java/oshi/software/os/windows/...
WindowsOSProcess.java, WindowsOSProcessJNA.java, WindowsOSThread.java, WindowsOperatingSystem.java, WindowsOSProcessFFM.java, WindowsOperatingSystemFFM.java
Switched constructor/field/method signatures and internals to use ProcessPerfCounterBlock/ThreadPerfCounterBlock; adjusted FFM fallback call sites and types.
FFM public interface
oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
New public FFM interface with StructLayout definitions and offset constants used by FFM parsing.
Tests & benchmark comparison
oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java, oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
Added RegistryComparisonTest comparing JNA vs FFM maps (processes/threads) with overlap and numeric/timing assertions; updated existing registry test to use new POJOs.
Changelog
CHANGELOG.md
Added changelog entry noting FFM registry drivers and extraction of PerfCounterBlock POJOs into oshi-common.

Sequence Diagram(s)

sequenceDiagram
    participant Test as RegistryComparisonTest
    participant JNA as JNA Reader
    participant FFM as FFM Reader
    participant Util as HkeyPerformanceDataUtilFFM
    participant Reg as Windows Registry
    participant Parser as PERF_DATA_BLOCK Parser

    Test->>JNA: buildProcessMapFromRegistry(null)
    JNA->>Reg: Query perflib via JNA
    Reg-->>JNA: Binary perf data
    JNA->>JNA: Parse & build ProcessPerfCounterBlock map
    JNA-->>Test: Process map

    Test->>FFM: buildProcessMapFromRegistry(null)
    FFM->>Util: readPerfDataFromRegistry("Process", enum)
    Util->>Reg: Read HKEY_PERFORMANCE_DATA via FFM
    Reg-->>Util: MemorySegment buffer
    Util->>Parser: Walk PERF_DATA_BLOCK / objects / instances
    Parser-->>Util: Per-instance counter maps + timestamps
    Util-->>FFM: Triplet<List<Map>, perfTime100nSec, utcMillis>
    FFM->>FFM: Build ProcessPerfCounterBlock map
    FFM-->>Test: Process map

    Test->>Test: Compare maps (overlap, exact/static fields, cumulative ≥, memory ratio, timing)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Poem

🐇 I hopped through bytes and offsets wide,

Found PERF blocks where counters hide,
JNA met FFM at the registry door,
POJOs shared — no duplicates more,
A rabbit cheers — metrics verified! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add FFM registry drivers for HKEY_PERFORMANCE_DATA' directly and clearly describes the main change: adding Foreign Function & Memory (FFM) registry drivers for Windows HKEY_PERFORMANCE_DATA, which is the primary objective of this pull request.

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.32099% with 67 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.66%. Comparing base (8b2d49f) to head (575c0f2).

Files with missing lines Patch % Lines
...r/windows/registry/HkeyPerformanceDataUtilFFM.java 75.23% 17 Missing and 9 partials ⚠️
...er/windows/registry/ProcessPerformanceDataFFM.java 81.35% 3 Missing and 8 partials ⚠️
...ver/windows/registry/ThreadPerformanceDataFFM.java 85.29% 3 Missing and 7 partials ⚠️
...java/oshi/software/os/windows/WindowsOSThread.java 46.15% 7 Missing ⚠️
...software/os/windows/WindowsOperatingSystemFFM.java 64.28% 5 Missing ⚠️
...ava/oshi/software/os/windows/WindowsOSProcess.java 25.00% 2 Missing and 1 partial ⚠️
...river/windows/registry/ProcessPerformanceData.java 33.33% 2 Missing ⚠️
...driver/windows/registry/ThreadPerformanceData.java 50.00% 2 Missing ⚠️
...ommon/windows/registry/ThreadPerfCounterBlock.java 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3171      +/-   ##
==========================================
+ Coverage   58.29%   58.66%   +0.36%     
==========================================
  Files         336      341       +5     
  Lines       17693    17923     +230     
  Branches     3130     3165      +35     
==========================================
+ Hits        10314    10514     +200     
  Misses       5854     5854              
- Partials     1525     1555      +30     
Flag Coverage Δ
linux 25.79% <0.00%> (-0.23%) ⬇️
macos 28.91% <0.00%> (-0.27%) ⬇️
windows 33.43% <79.32%> (+0.61%) ⬆️

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

🧹 Nitpick comments (1)
oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java (1)

250-282: Consider adding RegCloseKey(HKEY_PERFORMANCE_DATA) to free cached buffers.

Per Microsoft documentation, calling RegCloseKey(HKEY_PERFORMANCE_DATA) after querying clears cached performance data and releases loaded performance DLLs. In long-running processes with frequent polling, skipping this can cause gradual memory accumulation. The current implementation (like the existing JNA version) does not call it, but since you're adding the parallel FFM path, this is an opportunity to address it here or in a follow-up for both implementations.

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

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java`
around lines 250 - 282, The readPerfDataBuffer method currently queries
HKEY_PERFORMANCE_DATA via RegQueryValueEx but never calls
RegCloseKey(HKEY_PERFORMANCE_DATA), which leaves Windows' cached performance
data and loaded DLLs resident; after finishing the registry query (both on
success after the ERROR_MORE_DATA loop and on any early error or exception) call
RegCloseKey(WinRegFFM.HKEY_PERFORMANCE_DATA) via the FFM binding (RegCloseKey)
and handle/log non-success return codes, ensuring the call is performed in every
exit path (normal return and in the catch block) so cached buffers are released.
🤖 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-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java`:
- Around line 117-131: The zero-value branch in assertWithinRatio incorrectly
treats the fractional ratio (e.g., 0.25) as an absolute byte limit, causing
valid transient zero reads to fail; change that branch to compare the nonZero
value against a small absolute byte tolerance instead (introduce a named
constant like ZERO_TOLERANCE_BYTES = 1024*1024 in the test class) and assert
nonZero <= ZERO_TOLERANCE_BYTES with the same descriptive message; keep all
other logic in assertWithinRatio unchanged.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java`:
- Around line 263-277: The retry loop in HkeyPerformanceDataUtilFFM that calls
RegQueryValueEx can exit with ret != ERROR_SUCCESS (e.g., ERROR_LOCK_FAILED) and
still return pPerfData; modify the method to validate ret after the resize loop
and handle non-success: if ret != ERROR_SUCCESS log an error including
objectName and ret, release or discard the allocated pPerfData (do not return
it) and return null; ensure the validation checks the final ret value from
RegQueryValueEx (the variable ret) before returning pPerfData.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java`:
- Around line 104-108: The procName parameter is accepted but unused; update
both ProcessPerformanceData.buildProcessMapFromPerfCounters and
ProcessPerformanceDataFFM.buildProcessMapFromPerfCounters to mirror the thread
implementations by branching on Util.isBlank(procName) and calling the
appropriate query method (e.g., ProcessInformation.queryProcessCounters() vs
ProcessInformation.queryProcessCounters(procName) and
ProcessInformationFFM.queryProcessCounters() vs
ProcessInformationFFM.queryProcessCounters(procName)); if the filtered overloads
don’t exist, add them to ProcessInformation / ProcessInformationFFM, and update
the Javadoc to reflect that procName filters results.

---

Nitpick comments:
In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java`:
- Around line 250-282: The readPerfDataBuffer method currently queries
HKEY_PERFORMANCE_DATA via RegQueryValueEx but never calls
RegCloseKey(HKEY_PERFORMANCE_DATA), which leaves Windows' cached performance
data and loaded DLLs resident; after finishing the registry query (both on
success after the ERROR_MORE_DATA loop and on any early error or exception) call
RegCloseKey(WinRegFFM.HKEY_PERFORMANCE_DATA) via the FFM binding (RegCloseKey)
and handle/log non-success return codes, ensuring the call is performed in every
exit path (normal return and in the catch block) so cached buffers are released.
🪄 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: 9ce385ee-3ef3-4077-91ef-747a76987f06

📥 Commits

Reviewing files that changed from the base of the PR and between 8b2d49f and da41bd2.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.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). (5)
  • 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: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (13)
📓 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
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`.
📚 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-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.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-common/src/main/java/module-info.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.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-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.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/ffm/windows/WinRegFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.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/software/os/windows/WindowsOperatingSystem.java
📚 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/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.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-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.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/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
🔇 Additional comments (11)
oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java (1)

11-11: LGTM. HKEY_PERFORMANCE_DATA = 0x80000004L matches the Win32 predefined registry handle value.

oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java (1)

1-8: LGTM. Straightforward new package-info.

oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java (1)

13-118: LGTM. Straightforward extraction of the previously nested PerfCounterBlock into a shared immutable POJO; field set, constructor order, and getters match both existing call sites in ThreadPerformanceData (snippets show all 11 args populated in the same order).

CHANGELOG.md (1)

35-35: LGTM. Entry accurately summarizes the PR.

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

25-25: LGTM. New package export is consistent with the relocated POJOs being consumed by both oshi-core and oshi-core-java25.

oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java (1)

21-39: LGTM. Type switch to the shared POJOs is mechanical and matches the new return types of build{Process,Thread}MapFromRegistry.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java (1)

51-343: LGTM. Mechanical retyping to the new common POJOs; no behavioral change. All Supplier/Map generics, processMapToList locals, and static query return types are consistently updated.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java (1)

21-151: LGTM. Constructor, updateAttributes signatures, and the buildThreadMapFromPerfCounters map generic all correctly updated to ThreadPerfCounterBlock. Consistent with WindowsOSProcess.getThreadDetails() / queryMatchingThreads() call sites in the provided snippets.

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

57-60: Verify the struct layout against actual Windows header files with explicit pragma pack settings.

The proposed change correctly moves SystemTime to offset 36, but both current and proposed layouts place PerfTime at offset 56 when native documentation shows it at offset 52. Confirm whether winperf.h uses #pragma pack(4), #pragma pack(1), or default alignment, as this affects whether explicit padding is needed and where. The PDH learning indicates MSVC inserts implicit padding before LONGLONG fields, but native offsets suggest no gap between SystemTime and PerfTime—these need to be reconciled before applying the fix.

oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java (1)

96-96: This assertion is valid. Both ThreadPerformanceData (JNA) and ThreadPerformanceDataFFM use identical pointer normalization: they check the data type and either cast directly to (Long) for 64-bit values or apply Integer.toUnsignedLong((Integer) addr) for 32-bit integers. No divergence in normalization exists between the two paths, so exact equality comparison is appropriate.

oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java (1)

131-132: No issue found — FFM implementation matches JNA semantics.

The FFM registry path uses ParseUtil.filetimeToUtcMs(startTime, false), which is correct. JNA's registry path does not use filetimeToUtcMs at all; instead it uses FILETIME.filetimeToDate().getTime(), which performs the same UTC conversion without applying a timezone offset. Both approaches treat registry filetimes as already in UTC and do not apply TZ_OFFSET. The local=true flag in filetimeToUtcMs is used only for the PDH counter path (via PerfDataUtil), not the registry path. The FFM implementation is consistent with the JNA baseline.

			> Likely an incorrect or invalid review comment.

Comment on lines +104 to +108
public static Map<Integer, ProcessPerfCounterBlock> buildProcessMapFromPerfCounters(Collection<Integer> pids,
String procName) {
Map<Integer, ProcessPerfCounterBlock> processMap = new HashMap<>();
Pair<List<String>, Map<ProcessPerformanceProperty, List<Long>>> instanceValues = ProcessInformationFFM
.queryProcessCounters();

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check JNA baseline and available ProcessInformationFFM query methods.
rg -nP -C3 '\bqueryProcessCounters\s*\(' --type=java
rg -nP -C5 'buildProcessMapFromPerfCounters\s*\(' --type=java -g '!**/ProcessPerformanceDataFFM.java'

Repository: oshi/oshi

Length of output: 15963


🏁 Script executed:

#!/bin/bash
# Get full method implementation for JNA version
sed -n '104,150p' oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java

# Get full method implementation for FFM version  
sed -n '104,150p' oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java

# Check ThreadPerformanceData for comparison
rg -n 'buildThreadMapFromPerfCounters' oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java -A 2
rg -n 'buildThreadMapFromPerfCounters' oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java -A 2

Repository: oshi/oshi

Length of output: 5759


🏁 Script executed:

#!/bin/bash
# Get full ThreadPerformanceDataFFM implementation to see if it uses procName
sed -n '105,160p' oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java

# Also check ThreadPerformanceData (JNA) for comparison
sed -n '105,160p' oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java

Repository: oshi/oshi

Length of output: 6587


procName parameter is unused in both JNA and FFM versions; unlike ThreadPerformanceData.buildThreadMapFromPerfCounters(), which branches on procName to select query methods, the process counterpart does not.

The method accepts procName and Javadoc states "Filter by this process name", but neither ProcessPerformanceData (JNA) nor ProcessPerformanceDataFFM use it—both only filter by pids. This is inconsistent with the thread performance data methods (ThreadPerformanceData.buildThreadMapFromPerfCounters() and ThreadPerformanceDataFFM.buildThreadMapFromPerfCounters()), which correctly branch on Util.isBlank(procName) to call either unfiltered or filtered query methods.

Either wire procName through both implementations to match the thread pattern, or remove it from both signatures.

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

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java`
around lines 104 - 108, The procName parameter is accepted but unused; update
both ProcessPerformanceData.buildProcessMapFromPerfCounters and
ProcessPerformanceDataFFM.buildProcessMapFromPerfCounters to mirror the thread
implementations by branching on Util.isBlank(procName) and calling the
appropriate query method (e.g., ProcessInformation.queryProcessCounters() vs
ProcessInformation.queryProcessCounters(procName) and
ProcessInformationFFM.queryProcessCounters() vs
ProcessInformationFFM.queryProcessCounters(procName)); if the filtered overloads
don’t exist, add them to ProcessInformation / ProcessInformationFFM, and update
the Javadoc to reflect that procName filters results.

@dbwiddis
dbwiddis force-pushed the ffm-registry-drivers branch from da41bd2 to c6284eb Compare April 18, 2026 05:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java (1)

85-170: Precomputed counter-index map from getCounterIndices is discarded — re-resolved per instance × counter inside the loop.

getCounterIndices(...) at Line 89 returns a Pair<Integer, EnumMap<T, Integer>> whose second element is an already-validated enum→counter-index map, but the caller uses the Pair only for its null check. Then Line 170 re-resolves COUNTER_INDEX_MAP.get(key.getCounter()) for every (instance, counter) pair, which for e.g. Process/Thread with hundreds of instances and ~10 counters is a lot of redundant lookups. Using the precomputed EnumMap is both faster and avoids a second independent validation path.

♻️ Proposed refactor
-        Pair<Integer, EnumMap<T, Integer>> indices = getCounterIndices(objectName, counterEnum);
-        if (indices == null) {
+        Pair<Integer, EnumMap<T, Integer>> indices = getCounterIndices(objectName, counterEnum);
+        if (indices == null) {
             return null;
         }
+        int objectIndex = indices.getA();
+        EnumMap<T, Integer> keyToCounterIndex = indices.getB();

Then replace Line 127:

-            if (objectNameTitleIndex == COUNTER_INDEX_MAP.get(objectName).intValue()) {
+            if (objectNameTitleIndex == objectIndex) {

And replace Line 170:

-                        int keyIndex = COUNTER_INDEX_MAP.get(key.getCounter());
+                        int keyIndex = keyToCounterIndex.get(key);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java`
around lines 85 - 170, The readPerfDataFromRegistry method currently discards
the EnumMap returned by getCounterIndices and repeatedly calls the global
COUNTER_INDEX_MAP.get(...) inside the per-instance/per-counter loop; change the
method to extract the Pair<Integer, EnumMap<T,Integer>> result (use the Pair's
second element) into a local EnumMap<String,Integer> (or EnumMap<T,Integer>)
immediately after getCounterIndices, and then replace the per-counter lookup
COUNTER_INDEX_MAP.get(key.getCounter()) with a lookup in that local EnumMap
(using the enum key or its counter id as appropriate) so the validated,
precomputed mapping from getCounterIndices is reused for counterOffsets and
sizes throughout readPerfDataFromRegistry.
oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java (1)

131-147: Stale comment doesn't match the code.

Lines 144-145 claim "if creation time value is less than current millis, it's in 1970 epoch, otherwise it's 1601 epoch and we must convert", but the code at Line 132 unconditionally converts via ParseUtil.filetimeToUtcMs(startTime, false) and then only clamps startTime > now. The comment was copy-pasted from the Process variant (where it matches the if (ctime > now) branch) but doesn't apply here. Suggest deleting or rewording.

🧹 Proposed tidy
-
-                // if creation time value is less than current millis, it's in 1970 epoch,
-                // otherwise it's 1601 epoch and we must convert
                 threadMap.put(tid, new ThreadPerfCounterBlock(name, tid, pid, startTime, user, kernel, priority,
                         threadState, threadWaitReason, startAddr, contextSwitches));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java`
around lines 131 - 147, The inline comment about epoch conversion is stale and
misleading: update or remove it near the startTime handling in
ThreadPerformanceDataFFM where startTime is set via
ParseUtil.filetimeToUtcMs(startTime, false) and then clamped against now; ensure
any remaining comment accurately reflects that startTime is always converted to
UTC ms by ParseUtil.filetimeToUtcMs before being clamped and passed into the
ThreadPerfCounterBlock stored in threadMap (i.e., delete the copy-pasted “1970
vs 1601 epoch” wording or replace it with a brief note that ParseUtil handles
conversion and the subsequent clamp prevents future timestamps).
🤖 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-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java`:
- Around line 45-47: The assertion in RegistryComparisonTest.java currently uses
isGreaterThan(minSize * 9 / 10) which rejects exactly 90% when minSize is
divisible by 10; update the check for commonPids to require at least 90% by
computing the ceiling threshold (e.g., required = (minSize * 90 + 99) / 100 or
use a math ceil equivalent) and replace isGreaterThan(...) with
isGreaterThanOrEqualTo(required); apply the same change to the other two similar
assertions referenced around lines 88-90 (use the same ceiling calculation and
isGreaterThanOrEqualTo on commonPids compared to the computed required value).

---

Nitpick comments:
In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java`:
- Around line 85-170: The readPerfDataFromRegistry method currently discards the
EnumMap returned by getCounterIndices and repeatedly calls the global
COUNTER_INDEX_MAP.get(...) inside the per-instance/per-counter loop; change the
method to extract the Pair<Integer, EnumMap<T,Integer>> result (use the Pair's
second element) into a local EnumMap<String,Integer> (or EnumMap<T,Integer>)
immediately after getCounterIndices, and then replace the per-counter lookup
COUNTER_INDEX_MAP.get(key.getCounter()) with a lookup in that local EnumMap
(using the enum key or its counter id as appropriate) so the validated,
precomputed mapping from getCounterIndices is reused for counterOffsets and
sizes throughout readPerfDataFromRegistry.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java`:
- Around line 131-147: The inline comment about epoch conversion is stale and
misleading: update or remove it near the startTime handling in
ThreadPerformanceDataFFM where startTime is set via
ParseUtil.filetimeToUtcMs(startTime, false) and then clamped against now; ensure
any remaining comment accurately reflects that startTime is always converted to
UTC ms by ParseUtil.filetimeToUtcMs before being clamped and passed into the
ThreadPerfCounterBlock stored in threadMap (i.e., delete the copy-pasted “1970
vs 1601 epoch” wording or replace it with a brief note that ParseUtil handles
conversion and the subsequent clamp prevents future timestamps).
🪄 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: e1b53279-34ce-4bba-bb53-c9e88ebbed0b

📥 Commits

Reviewing files that changed from the base of the PR and between da41bd2 and c6284eb.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (6)
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-common/src/main/java/module-info.java
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.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, windows-latest
  • 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: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (12)
📓 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
📚 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/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.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-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.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/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
🔇 Additional comments (8)
oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java (1)

263-281: Final ret validation after resize loop is already present.

The post-loop check at Lines 277-280 now handles non-ERROR_SUCCESS exit from the resize loop. The earlier concern is addressed.

oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java (1)

96-108: procName parameter still accepted but unused.

The two-arg overload at Line 104 and the Javadoc at Line 100 imply filtering by process name, but procName is never passed to ProcessInformationFFM.queryProcessCounters() nor used for post-filtering. Behavior is identical to the single-arg overload. Either wire it through to a filtered queryProcessCounters(procName) overload (matching the thread-side pattern in ThreadPerformanceDataFFM.buildThreadMapFromPerfCounters) or drop the parameter and the JNA counterpart's parameter.

oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java (1)

17-155: LGTM — mechanical type refactor to shared POJO.

Constructor argument ordering on lines 81-82 and 154-155 matches the ThreadPerfCounterBlock constructor signature from oshi-common (name, threadID, owningProcessID, startTime, userTime, kernelTime, priority, threadState, threadWaitReason, startAddress, contextSwitches).

oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java (1)

21-39: LGTM.

Test-side type declarations match the new shared POJO types from oshi.driver.common.windows.registry. Assertions remain semantically unchanged.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java (1)

23-366: LGTM — signature/type migration to shared POJOs.

updateAttributes(pcb, wts) still guards pcb == null before dereference; thread-state override via THREADWAITREASON == 5 behavior is preserved.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java (1)

51-343: LGTM.

Supplier memoization, fallback chain (registry → perfcounters), and processMapToList(...) flow are unchanged in behavior; only the block value types were migrated to the shared POJOs.

oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java (1)

41-90: LGTM.

Constructor and updateAttributes(...) signatures now align with the shared POJOs and propagate correctly through super(...).

oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java (1)

39-83: LGTM — registry-path logic matches the JNA reference.

Field extraction, uptime flooring to 1, 100-nsec → ms scaling, and the addr instanceof Long ? … : Integer.toUnsignedLong(...) pointer-width handling all mirror ThreadPerformanceData.buildThreadMapFromRegistry(...).

@dbwiddis
dbwiddis force-pushed the ffm-registry-drivers branch from c6284eb to 575c0f2 Compare April 18, 2026 05:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java (2)

12-13: Consider making the class final.

@Immutable is advisory; declaring ProcessPerfCounterBlock final prevents subclasses from breaking immutability and matches the intent of the annotation.

♻️ Proposed fix
 `@Immutable`
-public class ProcessPerfCounterBlock {
+public final class ProcessPerfCounterBlock {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java`
around lines 12 - 13, The class marked `@Immutable`, ProcessPerfCounterBlock,
should be declared final to prevent subclassing from breaking immutability;
update the class declaration to add the final modifier on public class
ProcessPerfCounterBlock (ensure no subclasses rely on extending it and adjust
any tests/usages accordingly) so the intent of the annotation is enforced by the
type system.

23-23: pageFaults field type is inconsistent with its getter and narrows native DWORDs.

The field is int but getPageFaults() returns long; the counter is sourced from a native DWORD (4-byte unsigned) via (Integer) …PAGEFAULTSPERSEC in ProcessPerformanceData.buildProcessMapFromRegistry and pageFaultsList.get(inst).intValue() in buildProcessMapFromPerfCounters. Once the raw counter exceeds Integer.MAX_VALUE (~2.1B) — reachable on long-running, memory-intensive processes — the value silently wraps to a negative int and is sign-extended to a large negative long, which also risks flaking the new assertThat(p.getPageFaults()).isGreaterThanOrEqualTo(r.getPageFaults()) check in RegistryComparisonTest.

Storing as long end-to-end avoids the lossy narrowing without changing the public getter contract.

♻️ Proposed fix
-    private final int pageFaults;
+    private final long pageFaults;

-    public ProcessPerfCounterBlock(String name, int parentProcessID, int priority, long privateWorkingSetSize,
-            long workingSetSize, long startTime, long upTime, long bytesRead, long bytesWritten, int pageFaults) {
+    public ProcessPerfCounterBlock(String name, int parentProcessID, int priority, long privateWorkingSetSize,
+            long workingSetSize, long startTime, long upTime, long bytesRead, long bytesWritten, long pageFaults) {

Corresponding call sites in ProcessPerformanceData.java can drop the int narrowing and pass the value as long (use Integer.toUnsignedLong(...) for the registry path since the raw value is an unsigned DWORD).

Also applies to: 102-107

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

In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java`
at line 23, The pageFaults field in ProcessPerfCounterBlock is declared as int
but getPageFaults() returns long and native DWORD counters can exceed
Integer.MAX_VALUE; change the pageFaults field to long and update any
constructors/assignments in ProcessPerfCounterBlock to accept a long, then
update call sites in ProcessPerformanceData.buildProcessMapFromRegistry to pass
Integer.toUnsignedLong((Integer) …PAGEFAULTSPERSEC) instead of narrowing to int
and in buildProcessMapFromPerfCounters to stop using
pageFaultsList.get(inst).intValue() (pass the value as a long), ensuring all
types flow as long end-to-end to avoid signed narrowing/wraparound while keeping
the public getter unchanged.
oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java (1)

302-317: catch (NumberFormatException) is unreachable.

ParseUtil.parseIntOrDefault(...) already handles invalid numeric text internally by returning the default (0 here), so no NumberFormatException can propagate out of the try block. If the intent is to guard against unexpected shapes (e.g. an odd-length counterText or a null array), handle that explicitly instead; otherwise this catch is dead code.

♻️ Proposed fix
-    private static Map<String, Integer> mapCounterIndicesFromRegistry() {
-        HashMap<String, Integer> indexMap = new HashMap<>();
-        try {
-            String[] counterText = Advapi32UtilFFM.registryGetStringArray(
-                    MemorySegment.ofAddress(WinRegFFM.HKEY_LOCAL_MACHINE), HKEY_PERFORMANCE_TEXT, COUNTER);
-            for (int i = 1; i < counterText.length; i += 2) {
-                int idx = ParseUtil.parseIntOrDefault(counterText[i - 1], 0);
-                if (idx > 0) {
-                    indexMap.putIfAbsent(counterText[i], idx);
-                }
-            }
-        } catch (NumberFormatException nfe) {
-            // Unexpected to ever get this, but handling it anyway
-            LOG.error("Unable to parse English counter names in registry Perflib 009.");
-        }
-        return Collections.unmodifiableMap(indexMap);
-    }
+    private static Map<String, Integer> mapCounterIndicesFromRegistry() {
+        HashMap<String, Integer> indexMap = new HashMap<>();
+        String[] counterText = Advapi32UtilFFM.registryGetStringArray(
+                MemorySegment.ofAddress(WinRegFFM.HKEY_LOCAL_MACHINE), HKEY_PERFORMANCE_TEXT, COUNTER);
+        for (int i = 1; i < counterText.length; i += 2) {
+            int idx = ParseUtil.parseIntOrDefault(counterText[i - 1], 0);
+            if (idx > 0) {
+                indexMap.putIfAbsent(counterText[i], idx);
+            }
+        }
+        return Collections.unmodifiableMap(indexMap);
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java`
around lines 302 - 317, The catch(NumberFormatException) in
mapCounterIndicesFromRegistry is dead since ParseUtil.parseIntOrDefault won't
throw; remove that catch and instead explicitly validate the registry result:
after calling Advapi32UtilFFM.registryGetStringArray (counterText) check for
null and ensure counterText.length > 1, then iterate only up to
counterText.length - 1 (so you never read past the end) and keep the existing
ParseUtil.parseIntOrDefault usage and indexMap.putIfAbsent logic; preserve
returning Collections.unmodifiableMap(indexMap).
🤖 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-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java`:
- Around line 60-63: The assertions fail when native cumulative counters wrap
because ProcessPerfCounterBlock.pageFaults and
ThreadPerfCounterBlock.contextSwitches are stored as int and only widened in
getters; change those POJO fields to long, update their getters
(getPageFaults(), getContextSwitches()) to return long, and adjust any
constructors/assignment sites that set those fields to use long values so the
stored value never loses precision; after this change the existing >= assertions
in RegistryComparisonTest (and the similar checks at lines 103-106) will be
stable without test changes.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java`:
- Around line 12-13: The class marked `@Immutable`, ProcessPerfCounterBlock,
should be declared final to prevent subclassing from breaking immutability;
update the class declaration to add the final modifier on public class
ProcessPerfCounterBlock (ensure no subclasses rely on extending it and adjust
any tests/usages accordingly) so the intent of the annotation is enforced by the
type system.
- Line 23: The pageFaults field in ProcessPerfCounterBlock is declared as int
but getPageFaults() returns long and native DWORD counters can exceed
Integer.MAX_VALUE; change the pageFaults field to long and update any
constructors/assignments in ProcessPerfCounterBlock to accept a long, then
update call sites in ProcessPerformanceData.buildProcessMapFromRegistry to pass
Integer.toUnsignedLong((Integer) …PAGEFAULTSPERSEC) instead of narrowing to int
and in buildProcessMapFromPerfCounters to stop using
pageFaultsList.get(inst).intValue() (pass the value as a long), ensuring all
types flow as long end-to-end to avoid signed narrowing/wraparound while keeping
the public getter unchanged.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java`:
- Around line 302-317: The catch(NumberFormatException) in
mapCounterIndicesFromRegistry is dead since ParseUtil.parseIntOrDefault won't
throw; remove that catch and instead explicitly validate the registry result:
after calling Advapi32UtilFFM.registryGetStringArray (counterText) check for
null and ensure counterText.length > 1, then iterate only up to
counterText.length - 1 (so you never read past the end) and keep the existing
ParseUtil.parseIntOrDefault usage and indexMap.putIfAbsent logic; preserve
returning Collections.unmodifiableMap(indexMap).
🪄 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: c8653283-dd7d-40be-a94e-f0206e373ccb

📥 Commits

Reviewing files that changed from the base of the PR and between c6284eb and 575c0f2.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (7)
  • oshi-common/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinRegFFM.java
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/package-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerfCounterBlock.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinPerfFFM.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, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (11)
📓 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
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`.
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.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/software/os/windows/WindowsOSProcess.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/registry/ProcessPerfCounterBlock.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.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/registry/ProcessPerfCounterBlock.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.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/registry/HkeyPerformanceDataUtilFFM.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/registry/HkeyPerformanceDataUtilFFM.java
🔇 Additional comments (6)
oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceData.java (1)

17-17: LGTM — mechanical swap to shared ThreadPerfCounterBlock POJO.

Return-type changes and the two new ThreadPerfCounterBlock(...) call sites match the 11-arg constructor order, Javadoc @return tags were updated, and the removed inner class is no longer referenced.

Also applies to: 42-85, 95-159

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java (1)

23-24: LGTM — consumer updated to the shared POJO types.

Constructor, field, and method signatures correctly thread Map<Integer, ProcessPerfCounterBlock> / Map<Integer, ThreadPerfCounterBlock> through, and getThreadDetails() / updateAttributes(pcb, wts) read the expected getters from the new POJOs.

Also applies to: 61-89, 262-286, 296-336, 365-371

oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceData.java (1)

16-16: LGTM — builders now return the shared ProcessPerfCounterBlock map.

Both buildProcessMapFromRegistry and buildProcessMapFromPerfCounters constructor calls match the new 10-arg POJO signature (name, parentProcessID, priority, privateWorkingSetSize, workingSetSize, startTime, upTime, bytesRead, bytesWritten, pageFaults). The pre-existing conversion logic for the 1601 vs 1970 epoch is preserved.

Also applies to: 41-83, 92-94, 104-144

oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java (1)

27-135: LGTM — tolerances and overlap thresholds look sound.

Zero-branch in assertWithinRatio now compares against an absolute byte tolerance; 90% overlap uses the correct ceiling formula; thread startTime bound is justified by the documented 1/64s tick resolution plus rounding. With the pageFaults/contextSwitches widening handled at the POJO level, the cumulative >= checks should be stable.

oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java (2)

252-288: LGTM — synchronized buffer growth with proper ret validation.

Serializing HKEY_PERFORMANCE_DATA access via synchronized matches Windows guidance, the post-loop ret != ERROR_SUCCESS check (addressed earlier) closes the garbage-buffer hole, and Arena.ofAuto() is appropriate here because the returned MemorySegment's lifetime is managed via GC reachability from the caller.


85-208: LGTM — PERF_DATA_BLOCK walk is correct and fail-safe.

Object iteration correctly advances by TotalByteLength, counter definitions by ByteLength, and instance blocks by perfCounterBlockOffset + PERF_COUNTER_BLOCK_ByteLength. Unknown counter sizes or missing enum indices fall through to return null, which is the documented contract for partial failure.

Comment on lines +60 to +63
assertThat(p.getBytesRead()).as("process[%d].bytesRead", pid).isGreaterThanOrEqualTo(r.getBytesRead());
assertThat(p.getBytesWritten()).as("process[%d].bytesWritten", pid)
.isGreaterThanOrEqualTo(r.getBytesWritten());
assertThat(p.getPageFaults()).as("process[%d].pageFaults", pid).isGreaterThanOrEqualTo(r.getPageFaults());

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.

⚠️ Potential issue | 🟡 Minor

Cumulative-counter >= assertions are coupled to the signed-int wrap of pageFaults / contextSwitches.

getPageFaults() in ProcessPerfCounterBlock and getContextSwitches() in ThreadPerfCounterBlock both widen an int field to long in their getters. On a process/thread where the raw native counter crosses Integer.MAX_VALUE, one side can observe the wrapped (negative) value while the other sees a different wrap point, making the isGreaterThanOrEqualTo(r.getPageFaults()) / isGreaterThanOrEqualTo(r.getContextSwitches()) checks flaky on long-running machines. The root fix is to store these counters as long in the POJOs (see comment on ProcessPerfCounterBlock.pageFaults); once that is done, these assertions become robust with no test-side change required.

Also applies to: 103-106

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

In `@oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java`
around lines 60 - 63, The assertions fail when native cumulative counters wrap
because ProcessPerfCounterBlock.pageFaults and
ThreadPerfCounterBlock.contextSwitches are stored as int and only widened in
getters; change those POJO fields to long, update their getters
(getPageFaults(), getContextSwitches()) to return long, and adjust any
constructors/assignment sites that set those fields to use long values so the
stored value never loses precision; after this change the existing >= assertions
in RegistryComparisonTest (and the similar checks at lines 103-106) will be
stable without test changes.

Parse HKEY_PERFORMANCE_DATA binary structs via FFM for process and
thread performance data, bypassing the PDH abstraction layer.

New in oshi-common:
- ProcessPerfCounterBlock and ThreadPerfCounterBlock POJOs extracted
  from oshi-core inner classes to avoid FFM->JNA dependency

New in oshi-core-java25:
- WinPerfFFM: FFM struct layouts for PERF_DATA_BLOCK, PERF_OBJECT_TYPE,
  PERF_COUNTER_DEFINITION, PERF_INSTANCE_DEFINITION, PERF_COUNTER_BLOCK
- HkeyPerformanceDataUtilFFM: Core HKEY_PERFORMANCE_DATA binary parser
- ProcessPerformanceDataFFM and ThreadPerformanceDataFFM: Registry-based
  process/thread data drivers
- WinRegFFM: Added HKEY_PERFORMANCE_DATA constant

Updated oshi-core and oshi-benchmark to use common POJOs.

New RegistryComparisonTest in oshi-benchmark validates JNA vs FFM
registry parsing produces matching results.
@dbwiddis
dbwiddis force-pushed the ffm-registry-drivers branch from 575c0f2 to bdb3119 Compare April 18, 2026 06:10
@dbwiddis
dbwiddis merged commit 27a47b5 into oshi:master Apr 18, 2026
13 of 15 checks passed
@dbwiddis
dbwiddis deleted the ffm-registry-drivers branch April 18, 2026 13:55
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