Skip to content

Extract common Windows perfmon/registry driver code to oshi-common - #3172

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:extract-common-windows-drivers
Apr 18, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:extract-common-windows-drivers

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Extracts shared logic from the Windows performance counter, registry (HKEY_PERFORMANCE_DATA), and process/thread data driver classes into oshi-common, reducing duplication between the JNA (oshi-core) and FFM (oshi-core-java25) implementations.

Changes

New in oshi-common

  • PerfCounter — Extracted from PerfDataUtil.PerfCounter inner class. Contains _Base suffix handling, counter path building, BASE_SUFFIX constant, and isBase()/stripBaseSuffix() helper methods.
  • HkeyPerformanceDataUtil — Abstract base class with HKEY_PERFORMANCE_TEXT/COUNTER constants, buildCounterIndexMap() (parses alternating index/name pairs from registry), and getCounterIndices() (resolves enum counter names to indices).
  • ProcessPerformanceData — Static utility with buildProcessMapFromRegistry() and buildProcessMapFromPerfCounters() that take pre-fetched data as parameters.
  • ThreadPerformanceData — Same pattern for thread data.

Renamed/refactored in oshi-core

  • HkeyPerformanceDataUtil → HkeyPerformanceDataUtilJNA (extends common class)
  • ProcessPerformanceData → ProcessPerformanceDataJNA (thin wrapper delegating to common class)
  • ThreadPerformanceData → ThreadPerformanceDataJNA (thin wrapper delegating to common class)
  • PerfDataUtil — Removed inner PerfCounter class, now imports from oshi-common
  • Unified FILETIME conversion to ParseUtil.filetimeToUtcMs() (removing JNA WinBase.FILETIME.filetimeToDate dependency)

Updated in oshi-core-java25

  • HkeyPerformanceDataUtilFFM — Extends common class, removed duplicate getCounterIndices() and map-building logic
  • ProcessPerformanceDataFFM / ThreadPerformanceDataFFM — Thin wrappers delegating to common class
  • PerfDataUtilFFM — Uses PerfCounter.isBase()/stripBaseSuffix() helpers and shared constants instead of local duplicates

Result

Net reduction of ~76 lines while improving code sharing. The common logic for parsing performance data is now in one place, making future maintenance easier and ensuring consistency between JNA and FFM implementations.

Summary by CodeRabbit

  • Refactor
    • Consolidated Windows perfmon and registry logic into shared common modules and moved platform-specific builders to use them.
  • New Features
    • Added a standalone perf-counter abstraction with consistent path and base-counter handling.
    • Introduced JNA and FFM adapters and runtime flags to detect disabled Windows performance counters.
    • Exposed safer registry helper overloads for robust reads.
  • Tests / Changelog
    • Updated tests and changelog to reflect these changes.

@coderabbitai

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a standalone immutable PDH counter POJO and centralizes Windows Perflib/HKEY performance-data helpers into oshi-common; refactors FFM/JNA adapters to delegate registry/perfmon reads and counter-index parsing to the new common utilities and updates consumers to use the shared PerfCounter and JNA-backed adapters.

Changes

Cohort / File(s) Summary
PerfCounter POJO
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
New immutable public class encapsulating object/instance/counter, BASE_SUFFIX, base-counter detection/stripping, getCounterPath(), equals/hashCode.
Shared HKEY perf utilities
oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
New abstract utility with HKEY_PERFORMANCE_TEXT, COUNTER, buildCounterIndexMap(...), and getCounterIndices(...) for registry counter-name→index parsing and enum→index resolution.
Process/Thread builders moved & API changed
oshi-common/.../ProcessPerformanceData.java, oshi-common/.../ThreadPerformanceData.java
Moved to common package; builders now accept caller-supplied Triplet/Pair perf/registry data (return null when input null), changed FILETIME conversion to ParseUtil.filetimeToUtcMs(...), exposed PROCESS/THREAD constants.
FFM adapters refactored
oshi-core-java25/.../HkeyPerformanceDataUtilFFM.java, .../ProcessPerformanceDataFFM.java, .../ThreadPerformanceDataFFM.java
Now extend/defer to common utilities, remove duplicate parsing/assembly, use superclass helpers for counter-index lookup, add getCounterIndex(String).
JNA adapters added/updated
oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java, .../ProcessPerformanceDataJNA.java, .../ThreadPerformanceDataJNA.java
JNA util extends common HkeyPerformanceDataUtil; new JNA adapter classes conditionally read registry/perf data (feature-flagged) and delegate map construction to common builders.
PerfCounter usage updated
oshi-core/.../PerfCounterQuery.java, PerfCounterQueryHandler.java, PerfCounterWildcardQuery.java
Switched imports/usages to oshi.driver.common.windows.perfmon.PerfCounter and instantiate new PerfCounter(...); updated handler key/parameter types accordingly.
Removed nested PerfCounter
oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
Deleted nested PerfCounter and createCounter(...) factory; callers migrated to standalone PerfCounter.
FFM PerfDataUtil adjustments
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
Replaced local _Base handling with PerfCounter.isBase/stripBaseSuffix; use HkeyPerformanceDataUtilFFM.getCounterIndex for name→index lookup.
Consumers switched to JNA adapters
oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java, WindowsOSProcess.java, WindowsOSThread.java
Now call ProcessPerformanceDataJNA/ThreadPerformanceDataJNA for registry/perfmon retrieval and defensively handle nullable maps.
Perfmon disabled detector (FFM)
oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
New class computing PERF_OS_DISABLED, PERF_PROC_DISABLED, PERF_DISK_DISABLED from config or service registry "Disable Performance Counters".
Registry helper additions (FFM)
oshi-core-java25/.../Advapi32UtilFFM.java
Added registryGetValue(rootKey, keyPath, valueName) and registryValueExists(rootKey, keyPath, valueName) overloads that open/close keys and probe existence.
Tests & changelog
oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java, CHANGELOG.md
Tests updated to use JNA-backed builders; changelog entry added documenting extraction to oshi-common.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant JNAAdapter as "Process/Thread JNA Adapter"
    participant HkeyUtil as "HkeyPerformanceDataUtil"
    participant CommonBuilder as "Process/Thread Performance Builder"

    Caller->>JNAAdapter: buildMapFromRegistry(pids)
    JNAAdapter->>HkeyUtil: readPerfDataFromRegistry(objectName, counterEnum)
    HkeyUtil-->>JNAAdapter: Triplet(listMaps, perfTime, meta)
    JNAAdapter->>CommonBuilder: buildMapFromRegistry(pids, Triplet)
    CommonBuilder-->>Caller: Map<Integer, PerfCounterBlock>
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐇 I nudged off the trailing "_Base" with care,

Counters hopped tidy from here to there.
JNA and FFM share one comfy burrow,
Less duplicated code — what a cheerful furrow!
🥕 Hop, hop, async and fair.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.24% 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 accurately and concisely summarizes the main change: extraction of common Windows perfmon/registry driver code to oshi-common module.

✏️ 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 49.41860% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.61%. Comparing base (27a47b5) to head (e74f939).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...va/oshi/util/platform/windows/Advapi32UtilFFM.java 22.22% 19 Missing and 2 partials ⚠️
...shi/driver/common/windows/perfmon/PerfCounter.java 62.06% 6 Missing and 5 partials ⚠️
...mmon/windows/registry/HkeyPerformanceDataUtil.java 58.33% 6 Missing and 4 partials ⚠️
...shi/driver/windows/perfmon/PerfmonDisabledFFM.java 50.00% 7 Missing and 3 partials ⚠️
...ver/windows/registry/ThreadPerformanceDataJNA.java 30.00% 7 Missing ⚠️
...er/windows/registry/ProcessPerformanceDataJNA.java 44.44% 4 Missing and 1 partial ⚠️
...ava/oshi/software/os/windows/WindowsOSProcess.java 16.66% 5 Missing ⚠️
...hi/software/os/windows/WindowsOperatingSystem.java 16.66% 5 Missing ⚠️
...ommon/windows/registry/ProcessPerformanceData.java 50.00% 1 Missing and 1 partial ⚠️
...common/windows/registry/ThreadPerformanceData.java 33.33% 1 Missing and 1 partial ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3172      +/-   ##
==========================================
- Coverage   58.66%   58.61%   -0.06%     
==========================================
  Files         341      346       +5     
  Lines       17926    17859      -67     
  Branches     3166     3159       -7     
==========================================
- Hits        10517    10468      -49     
+ Misses       5853     5840      -13     
+ Partials     1556     1551       -5     
Flag Coverage Δ
linux 25.70% <0.00%> (-0.07%) ⬇️
macos 29.02% <0.00%> (+0.10%) ⬆️
windows 33.27% <49.41%> (-0.19%) ⬇️

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

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

Inline comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java`:
- Around line 27-37: The constructor PerfCounter(String objectName, String
instanceName, String counterName) incorrectly detects base counters by searching
for the first occurrence of BASE_SUFFIX anywhere in counterName; change this to
only treat BASE_SUFFIX as a suffix (use counterName.endsWith(BASE_SUFFIX) or
check index == counterName.length() - BASE_SUFFIX.length()) and when true set
this.counter to the name with the suffix removed and this.baseCounter = true
(matching isBase() and stripBaseSuffix() behavior); otherwise leave this.counter
as counterName and this.baseCounter = false so PDH paths are built correctly for
names that contain "_Base" in the middle.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java`:
- Around line 65-68: The public method
buildProcessMapFromPerfCounters(Collection<Integer> pids, String procName)
declares a procName parameter but never uses it (it calls
ProcessInformationFFM.queryProcessCounters()), breaking the API contract; remove
the unused String procName parameter and keep a single-argument
buildProcessMapFromPerfCounters(Collection<Integer> pids) that delegates to
ProcessPerformanceData.buildProcessMapFromPerfCounters(pids,
ProcessInformationFFM.queryProcessCounters()), and update any callers to invoke
the one-arg overload; alternatively, if filtering by procName is required,
implement filtering inside buildProcessMapFromPerfCounters using
ProcessInformationFFM.queryProcessCounters() result before delegating to
ProcessPerformanceData.buildProcessMapFromPerfCounters.

In
`@oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java`:
- Around line 57-69: The method
ProcessPerformanceDataJNA.buildProcessMapFromPerfCounters(Collection<Integer>
pids, String procName) currently ignores procName and calls
ProcessInformationJNA.queryProcessCounters() with no args; either (A) thread the
filter through by adding an overload on ProcessInformationJNA (e.g.,
queryProcessCounters(String procName) or queryProcessCounters(String procName,
Collection<Integer> pids)) and call that from this method so procName is applied
(follow the ThreadPerformanceDataJNA dispatch pattern), or (B) remove this 2-arg
overload and its Javadoc so there is only the single-arg variant that does not
claim to filter by name; update related Javadoc accordingly and ensure
ProcessPerformanceData.buildProcessMapFromPerfCounters callers are adjusted if
you remove the overload.
🪄 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: 0eed5d1b-bf31-4d63-b068-fca61a05f0fa

📥 Commits

Reviewing files that changed from the base of the PR and between 27a47b5 and aa4a35c.

📒 Files selected for processing (19)
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.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/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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 (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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.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
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.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/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
🔇 Additional comments (10)
oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java (1)

23-119: LGTM — clean transformation of query-based logic into a pure builder.

Signatures line up with the Triplet/Pair shapes returned by HkeyPerformanceDataUtilJNA.readPerfDataFromRegistry and ProcessInformationJNA.queryProcessCounters (per provided context snippets), and the processData == null → null contract is preserved. The FILETIME branch via ParseUtil.filetimeToUtcMs(ctime, false) is consistent with the rest of the PR.

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

23-132: LGTM — consistent with the common refactor.

Thread startTime is consistently converted from a FILETIME via ParseUtil.filetimeToUtcMs(startTime, false) (ELAPSEDTIME is annotated as filetime in the value map), and registry-path upTime arithmetic is unchanged. Input types align with HkeyPerformanceDataUtilJNA.readPerfDataFromRegistry / ThreadInformationJNA.queryThreadCounters per provided snippets.

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

27-97: LGTM — clean swap to the shared PerfCounter type.

PerfCounter.createCounter(object, instance, counter) has the same parameter order and return type as the removed PerfDataUtil.createCounter, and downstream PerfCounterQueryHandler still consumes counter.getCounterPath() / counter.isBaseCounter().

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

22-106: LGTM — retargets to the JNA adapter without changing control flow.

ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters(pids, procName, tid) (per the provided snippet) still honors procName/threadNum via ThreadInformationJNA.queryThreadCounters(procName, threadNum), so the observed behavior of updateAttributes() is unchanged.

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

29-173: LGTM — mechanical import/factory swap only.

Per-instance PerfCounter construction continues to feed pdhQueryHandler.addCounterToQuery(counter) unchanged, and the abort-on-failure contract (preserves instance/value alignment) is preserved.

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

15-15: LGTM — import-only change.

PerfCounter's new API surface (getCounterPath(), isBaseCounter()) matches the prior nested type, so no logic change is needed here.

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

29-36: LGTM — tests correctly retargeted to the JNA entry points.

ProcessPerformanceDataJNA / ThreadPerformanceDataJNA are the new registry-reading wrappers; since the common classes no longer self-query, calling them from tests would return null instead of exercising the registry path.

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

67-90: Shared registry parsing integration looks good.

The refactor cleanly delegates index resolution and Perflib text parsing to the common base class, and ParseUtil.filetimeToUtcMs(perfTime100nSec, false) matches the UTC timestamp conversion expected by the provided ParseUtil context.

Also applies to: 107-123, 180-190

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

49-60: Good extraction of the shared counter-index helpers.

The builder is defensive for missing registry data, returns an immutable map, and the lookup helper preserves the expected all-required-counters contract for registry parsing.

Also applies to: 74-96

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

38-42: JNA adapter delegation looks clean.

This keeps native querying in the JNA layer while centralizing thread map construction in oshi-common; the disabled-PerfMon guard also preserves the expected empty-map fallback.

Also applies to: 64-72

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from aa4a35c to 6b7affd Compare April 18, 2026 16:53

@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/util/platform/windows/PerfDataUtilFFM.java (1)

388-402: Optional: reuse shared buildCounterIndexMap to avoid duplicated parsing.

lookupPerfIndexByEnglishName re-parses the same registry array that HkeyPerformanceDataUtil.buildCounterIndexMap(...) already centralizes (alternating index/name pairs). Since it's protected to the shared base, you could expose it (or a small helper) and do map.getOrDefault(name, 0). The current inline loop works and only runs on cache miss in LOCALIZE_CACHE, so this is a nice-to-have — deferring is fine.

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

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`
around lines 388 - 402, The method lookupPerfIndexByEnglishName currently
reparses the registry array; refactor it to reuse
HkeyPerformanceDataUtil.buildCounterIndexMap (or add a small accessor helper
that returns the Map<String,Integer>) and then do a map.getOrDefault(name, 0)
instead of iterating the counters array; update lookupPerfIndexByEnglishName to
call that shared helper (and reference LOCALIZE_CACHE usage where appropriate)
so parsing logic is centralized and the registry array is not processed twice.
oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java (1)

18-23: Minor: javadoc wording doesn't match the new design.

"Subclasses provide the platform-specific data source (JNA or FFM)" is misleading — this class is final with only static methods, and the JNA/FFM variants are separate classes that pass pre-fetched data in as parameters (composition, not inheritance). Same wording is mirrored in ProcessPerformanceData.java (lines 19-21). Consider rewording to something like "Callers (JNA/FFM variants) supply the platform-specific pre-fetched registry or perf-counter data."

🤖 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/ThreadPerformanceData.java`
around lines 18 - 23, Update the class Javadoc for ThreadPerformanceData (and
mirror the same change in ProcessPerformanceData) to reflect the new composition
design: replace "Subclasses provide the platform-specific data source (JNA or
FFM)" with wording that callers (JNA/FFM variants) supply pre-fetched registry
or perf-counter data as parameters, e.g. "Callers (JNA/FFM variants) supply the
platform-specific pre-fetched registry or performance-counter data." Ensure the
Javadoc keeps the existing description about building thread/process performance
data maps and retains the `@ThreadSafe` annotation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java`:
- Around line 62-68: ThreadPerformanceDataFFM.buildThreadMapFromPerfCounters
lacks the Perfmon-disabled short-circuit present in
ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters; add a guard that checks
the same disabled flag (PerfmonDisabled.PERF_PROC_DISABLED) and returns
Collections.emptyMap() when set, either by reimplementing the disable check
inside ThreadPerformanceDataFFM.buildThreadMapFromPerfCounters or by adding the
guard at a higher level (e.g., in WindowsOperatingSystemFFM) so both FFM and JNA
paths behave identically under the oshi.os.windows.perfmon.disabled
configuration.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java`:
- Around line 18-23: Update the class Javadoc for ThreadPerformanceData (and
mirror the same change in ProcessPerformanceData) to reflect the new composition
design: replace "Subclasses provide the platform-specific data source (JNA or
FFM)" with wording that callers (JNA/FFM variants) supply pre-fetched registry
or perf-counter data as parameters, e.g. "Callers (JNA/FFM variants) supply the
platform-specific pre-fetched registry or performance-counter data." Ensure the
Javadoc keeps the existing description about building thread/process performance
data maps and retains the `@ThreadSafe` annotation.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`:
- Around line 388-402: The method lookupPerfIndexByEnglishName currently
reparses the registry array; refactor it to reuse
HkeyPerformanceDataUtil.buildCounterIndexMap (or add a small accessor helper
that returns the Map<String,Integer>) and then do a map.getOrDefault(name, 0)
instead of iterating the counters array; update lookupPerfIndexByEnglishName to
call that shared helper (and reference LOCALIZE_CACHE usage where appropriate)
so parsing logic is centralized and the registry array is not processed twice.
🪄 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: d230c264-c03b-44f2-ab62-b320d7c50500

📥 Commits

Reviewing files that changed from the base of the PR and between aa4a35c and 6b7affd.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.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/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (4)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • 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/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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: Analyze (java)
  • 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)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
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: 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
📚 Learning: 2026-04-17T23: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/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.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/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.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/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.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/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.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/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.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/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.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
📚 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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.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
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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/ThreadPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
🔇 Additional comments (7)
oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java (1)

29-29: LGTM — shared PerfCounter wiring is consistent.

The import and factory usage align with the common implementation, and the construction call remains compatible with the previous counter creation flow.

Also applies to: 172-173

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

2-2: LGTM.

No concerns with this metadata update.

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

53-56: Same PerfmonDisabled parity concern as ThreadPerformanceDataFFM.

This FFM entry point does not consult PerfmonDisabled.PERF_PROC_DISABLED, unlike the JNA counterpart. See the verification request on ThreadPerformanceDataFFM.buildThreadMapFromPerfCounters — the same question applies here (whether ProcessInformationFFM.queryProcessCounters() honors the disable flag internally or this is an intentional FFM-module divergence).

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

44-87: LGTM — FFM delegation to shared base is correctly wired.

The extension of HkeyPerformanceDataUtil, use of inherited HKEY_PERFORMANCE_TEXT/COUNTER constants, and delegation to buildCounterIndexMap(...) and getCounterIndices(objectName, counterEnum, COUNTER_INDEX_MAP) all line up with the shared contracts. The fallback buildCounterIndexMap(null) at line 275 correctly yields an empty unmodifiable map.

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

94-97: LGTM — base-suffix handling centralized.

Both queryCounters and queryWildcardCounters now delegate _Base detection/strip to PerfCounter.isBase / PerfCounter.stripBaseSuffix, keeping the existing secondValue-selection semantics intact.

Also applies to: 319-322

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

1-73: LGTM — JNA adapter correctly preserves the PerfmonDisabled short-circuit.

The JNA entry points correctly (a) keep registry acquisition in the JNA module via HkeyPerformanceDataUtilJNA.readPerfDataFromRegistry, and (b) short-circuit the perf-counter path on PerfmonDisabled.PERF_PROC_DISABLED before delegating to the shared map builder.

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

54-57: LGTM — FILETIME conversion is equivalent to the prior JNA-based path.

ParseUtil.filetimeToUtcMs(ctime, false) yields ctime/10_000 - EPOCH_DIFF, i.e. 100ns-since-1601 → ms-since-1970 UTC, which matches the previous WinBase.FILETIME.filetimeToDate(ctime).getTime() behavior. The ctime > now heuristic (distinguishing raw FILETIME from already-converted ms) is preserved correctly in both branches.

Also applies to: 103-106

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from 6b7affd to 58f6c16 Compare April 18, 2026 17:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

84-89: Consider mirroring the registry method's null-safety on instanceValues.

buildProcessMapFromRegistry explicitly returns null when its pre-fetched input is null (lines 43–45, and documented in the Javadoc). The sibling buildProcessMapFromPerfCounters is now also a public API accepting caller-supplied data, but unconditionally dereferences instanceValues.getA()/getB() and will NPE if a caller passes null (e.g., if a future queryProcessCounters() implementation signals failure with null rather than an empty Pair). A small guard keeps the two entry points symmetric and hardens the contract against future caller variations.

🛡️ Proposed defensive guard
     public static Map<Integer, ProcessPerfCounterBlock> buildProcessMapFromPerfCounters(Collection<Integer> pids,
             Pair<List<String>, Map<ProcessPerformanceProperty, List<Long>>> instanceValues) {
+        if (instanceValues == null) {
+            return null;
+        }
         Map<Integer, ProcessPerfCounterBlock> processMap = new HashMap<>();
         long now = System.currentTimeMillis(); // 1970 epoch
         List<String> instances = instanceValues.getA();
         Map<ProcessPerformanceProperty, List<Long>> valueMap = instanceValues.getB();

And update the Javadoc return clause to match (e.g., "…performance counter information, or null if instanceValues is null.").

🤖 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/ProcessPerformanceData.java`
around lines 84 - 89, Add a null-check for the incoming Pair parameter in
buildProcessMapFromPerfCounters so it returns null immediately if instanceValues
is null (mirroring buildProcessMapFromRegistry behavior) to avoid NPEs when
calling instanceValues.getA()/getB(); also update the method Javadoc return
clause to say it may return null if instanceValues is null and keep references
to the instanceValues variable and the method name
buildProcessMapFromPerfCounters in the change so reviewers can locate it easily
(this keeps symmetry with buildProcessMapFromRegistry and handles potential null
returns from queryProcessCounters).
oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java (1)

44-57: Optional: drop the double registry open and tidy log separators.

registryValueExists and registryGetValue each call RegOpenKeyEx/RegCloseKey independently, so this path opens the same key twice at class init for each of the three services. Because registryGetValue already returns null when the value is missing, unsupported, or access fails, the existence probe is only needed to disambiguate "missing" from "existed but wrong type" for the warning. You can collapse this to a single lookup:

♻️ Proposed simplification
-            MemorySegment hklm = MemorySegment.ofAddress(WinRegFFM.HKEY_LOCAL_MACHINE);
-            if (Advapi32UtilFFM.registryValueExists(hklm, key, value)) {
-                Object disabled = Advapi32UtilFFM.registryGetValue(hklm, key, value);
-                if (disabled instanceof Integer) {
-                    if ((Integer) disabled > 0) {
-                        LOG.warn("{} counters are disabled and won't return data: {}\\\\{}\\\\{} > 0.", service,
-                                "HKEY_LOCAL_MACHINE", key, value);
-                        return true;
-                    }
-                } else {
-                    LOG.warn(
-                            "Invalid registry value type detected for {} counters. Should be REG_DWORD. Ignoring: {}\\\\{}\\\\{}.",
-                            service, "HKEY_LOCAL_MACHINE", key, value);
-                }
-            }
+            MemorySegment hklm = MemorySegment.ofAddress(WinRegFFM.HKEY_LOCAL_MACHINE);
+            if (Advapi32UtilFFM.registryValueExists(hklm, key, value)) {
+                Object disabled = Advapi32UtilFFM.registryGetValue(hklm, key, value);
+                if (disabled instanceof Integer) {
+                    if ((Integer) disabled > 0) {
+                        LOG.warn("{} counters are disabled and won't return data: HKEY_LOCAL_MACHINE\\{}\\{} > 0.",
+                                service, key, value);
+                        return true;
+                    }
+                } else {
+                    LOG.warn("Invalid registry value type detected for {} counters. Should be REG_DWORD. "
+                            + "Ignoring: HKEY_LOCAL_MACHINE\\{}\\{}.", service, key, value);
+                }
+            }

Note: the \\\\ sequences in the log format render as literal \\ (two backslashes) in output, which is unusual for a registry path. Single \ is more readable. Purely cosmetic.

🤖 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/perfmon/PerfmonDisabledFFM.java`
around lines 44 - 57, Replace the double registry open
(Advapi32UtilFFM.registryValueExists followed by registryGetValue) with a single
call to Advapi32UtilFFM.registryGetValue(hklm, key, value), assign to Object
disabled, then: if disabled == null do nothing; else if disabled instanceof
Integer and ((Integer) disabled) > 0 log the warning and return true; else log
the invalid-type warning. Update the LOG.warn messages to use single backslashes
in the registry path string (e.g., "HKEY_LOCAL_MACHINE\\{key}\\{value}") and
keep references to service, key, and value as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java`:
- Around line 84-89: Add a null-check for the incoming Pair parameter in
buildProcessMapFromPerfCounters so it returns null immediately if instanceValues
is null (mirroring buildProcessMapFromRegistry behavior) to avoid NPEs when
calling instanceValues.getA()/getB(); also update the method Javadoc return
clause to say it may return null if instanceValues is null and keep references
to the instanceValues variable and the method name
buildProcessMapFromPerfCounters in the change so reviewers can locate it easily
(this keeps symmetry with buildProcessMapFromRegistry and handles potential null
returns from queryProcessCounters).

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java`:
- Around line 44-57: Replace the double registry open
(Advapi32UtilFFM.registryValueExists followed by registryGetValue) with a single
call to Advapi32UtilFFM.registryGetValue(hklm, key, value), assign to Object
disabled, then: if disabled == null do nothing; else if disabled instanceof
Integer and ((Integer) disabled) > 0 log the warning and return true; else log
the invalid-type warning. Update the LOG.warn messages to use single backslashes
in the registry path string (e.g., "HKEY_LOCAL_MACHINE\\{key}\\{value}") and
keep references to service, key, and value as before.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc12a4e8-e2dc-468d-8f0f-5b3e6ca69826

📥 Commits

Reviewing files that changed from the base of the PR and between 6b7affd and 58f6c16.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (4)
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
🚧 Files skipped from review as they are similar to previous changes (8)
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.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 11, windows-latest
  • 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 11, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (14)
📓 Common learnings
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.
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: 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: 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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
🔇 Additional comments (15)
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java (1)

23-56: LGTM — clean JNA delegate.

Preserves the OSHI_OS_WINDOWS_HKEYPERFDATA gating (passing null when disabled, which the common buildProcessMapFromRegistry handles by returning null), and the perf-counter path now correctly exposes only the single-arg variant, consistent with the resolution to the prior procName-dropped overload concern.

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

200-253: LGTM — new registry helpers behave as documented.

Both overloads safely open/close the key, and registryValueExists correctly treats ERROR_SUCCESS/ERROR_MORE_DATA as existence signals for a NULL lpData probe. Swallowing Throwable to return null/false is consistent with the boolean/optional-return contract used by other FFM utilities here.

One small nit: RegCloseKey's return value is intentionally ignored in these two new methods (unlike registryGetStringArray above, which logs at debug on close failure). Consider the same debug log for symmetry, but not blocking.

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

38-72: LGTM — guard parity achieved and delegation is clean.

The PERF_PROC_DISABLED short-circuit (lines 66–68) matches the JNA variant and is correctly applied to both the single-arg and three-arg overloads (since the former delegates to the latter). Registry-path delegation to the common ThreadPerformanceData.buildThreadMapFromRegistry preserves the existing null-return semantics, and the Javadoc correction on pids now matches the shared contract (process IDs, not thread IDs). Caller at WindowsOperatingSystemFFM handles null or empty by falling back to the registry path, so returning Collections.emptyMap() here is correct.

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

15-15: Shared PerfCounter migration looks good.

The handler’s key type now matches the common perfmon model used by the callers, with no control-flow changes in the handle lifecycle.

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

27-27: Common PerfCounter usage is consistent.

The new import and factory call line up with the shared PerfCounter.createCounter(...) API and preserve the existing PDH query flow.

Also applies to: 96-97

oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java (3)

49-60: Counter-index map parsing looks solid.

The alternating index/name loop handles null or incomplete registry data safely and returns an immutable result for shared consumers.


74-96: Common counter-index resolution matches the wildcard enum contract.

Skipping enum constant 0 and resolving the remaining counter names through the shared map keeps JNA and FFM behavior aligned.


5-26: Module export for new registry package is properly declared.

Verification confirms that oshi.driver.common.windows.registry is exported from the oshi-common module (line 25 of oshi-common/src/main/java/module-info.java), so JPMS builds in oshi-core and oshi-core-java25 will resolve the import correctly.

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

43-44: Single-counter _Base handling is cleanly centralized.

Delegating suffix detection and stripping to common PerfCounter keeps the FFM path aligned with the shared perfmon model.

Also applies to: 93-95


318-320: Wildcard _Base handling preserves alignment behavior.

The refactor only centralizes suffix stripping while keeping the per-property isBase tracking and existing abort-on-add-failure flow intact. Based on learnings, queryWildcardCounters intentionally aborts when any addEnglishCounter call fails to preserve strict instance/value-list alignment.


387-391: Registry index lookup now reuses the shared parser.

Using the common constants and buildCounterIndexMap(...) removes duplicated Perflib parsing while preserving the zero fallback for missing names.

oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java (4)

30-42: JNA utility inheritance cleanup looks good.

Extending the shared base and updating the logger/constructor keeps this class focused on the JNA-specific registry read path.

Also applies to: 48-48


67-72: Shared counter-index resolution is applied consistently.

The resolved object index and enum index map are used directly through the object scan and per-counter extraction path, avoiding duplicated lookup logic.

Also applies to: 90-90, 111-123


84-84: FILETIME conversion is clearer and equivalent.

Using ParseUtil.filetimeToUtcMs(perfTime100nSec, false) centralizes the Windows FILETIME-to-Unix-milliseconds conversion without applying a local timezone offset.


180-190: Registry counter map parsing delegation looks good.

The JNA path now shares the same Perflib text parsing and empty-map fallback as the common implementation.

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from 58f6c16 to 2a3d918 Compare April 18, 2026 17:48

@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-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java (1)

13-14: Optional: mark the class final to match @Immutable.

All fields are already final; making the class final prevents accidental subclassing that could break the immutability contract advertised by @Immutable.

♻️ Proposed change
 `@Immutable`
-public class PerfCounter {
+public final class PerfCounter {
🤖 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/perfmon/PerfCounter.java`
around lines 13 - 14, The class annotated with `@Immutable` (PerfCounter) should
be declared final to enforce immutability; update the class declaration for
PerfCounter to add the final modifier so it cannot be subclassed, leaving all
existing final fields and constructors unchanged.
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (1)

387-392: Minor: lookupPerfIndexByEnglishName re-reads registry + rebuilds index map on each call.

Each invocation does a fresh registryGetStringArray and a full buildCounterIndexMap. This is effectively amortized because localizeObjectName caches per perfObject via LOCALIZE_CACHE, but if this ever gets called from an uncached path, it becomes a hot spot. Consider memoizing the index map (e.g., a lazily-initialized ConcurrentHashMap field) so it’s computed at most once per process.

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

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`
around lines 387 - 392, lookupPerfIndexByEnglishName currently calls
Advapi32UtilFFM.registryGetStringArray and
HkeyPerformanceDataUtil.buildCounterIndexMap on every invocation; replace that
hot path with a lazily initialized, thread-safe cached index map (e.g., a static
ConcurrentHashMap or an unmodifiable Map initialized once) so the registry is
read and buildCounterIndexMap is executed only once per process; change
lookupPerfIndexByEnglishName to read from the cached map and fall back to 0 if
missing, and ensure cache initialization is safe for concurrent access and
consistent with existing LOCALIZE_CACHE usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java`:
- Around line 82-93: The Javadoc for stripBaseSuffix incorrectly states the
`@return` is a pair; update the Javadoc for the method stripBaseSuffix (and any
related comment text) to accurately describe that it returns only the stripped
counter name (a String) and whether it was a base counter is no longer returned;
adjust the method description line and the `@return` tag to say something like
"the counter name without the _Base suffix" and remove any mention of an isBase
flag, referencing BASE_SUFFIX and stripBaseSuffix to locate the code.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java`:
- Around line 13-14: The class annotated with `@Immutable` (PerfCounter) should be
declared final to enforce immutability; update the class declaration for
PerfCounter to add the final modifier so it cannot be subclassed, leaving all
existing final fields and constructors unchanged.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`:
- Around line 387-392: lookupPerfIndexByEnglishName currently calls
Advapi32UtilFFM.registryGetStringArray and
HkeyPerformanceDataUtil.buildCounterIndexMap on every invocation; replace that
hot path with a lazily initialized, thread-safe cached index map (e.g., a static
ConcurrentHashMap or an unmodifiable Map initialized once) so the registry is
read and buildCounterIndexMap is executed only once per process; change
lookupPerfIndexByEnglishName to read from the cached map and fall back to 0 if
missing, and ensure cache initialization is safe for concurrent access and
consistent with existing LOCALIZE_CACHE usage.
🪄 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: 774f365e-dbcb-47c5-b433-d325fecb00e8

📥 Commits

Reviewing files that changed from the base of the PR and between 58f6c16 and 2a3d918.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (5)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-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 (13)
📓 Common learnings
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: 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.
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: 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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.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-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.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-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.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-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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
📚 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/util/platform/windows/PerfDataUtilFFM.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-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
🔇 Additional comments (14)
oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java (1)

1-97: LGTM!

Shared base class cleanly consolidates buildCounterIndexMap and getCounterIndices. Null/short-array handling in buildCounterIndexMap and missing-counter early return in getCounterIndices are both correct.

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

40-190: LGTM!

Delegation to the common base is clean; switching to ParseUtil.filetimeToUtcMs unifies FILETIME conversion with the FFM path. COUNTER_INDEX_MAP.get(objectName) in readPerfDataBuffer is safe because getCounterIndices has already validated objectName before this is reached.

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

23-60: LGTM!

FFM counterpart of PerfmonDisabled looks correct: GlobalConfig override takes precedence, registry fallback correctly type-checks the Disable Performance Counters DWORD, and invalid types are warned and treated as enabled. Pattern parallels the JNA variant.

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

55-276: LGTM!

Extension of the shared base and delegation to getCounterIndices(..., COUNTER_INDEX_MAP) / buildCounterIndexMap(...) match the JNA refactor. Parsing logic for the registry perf data block is unchanged and still correct.

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

38-73: LGTM — PerfmonDisabledFFM guard in place.

Thin-wrapper delegation to the common ThreadPerformanceData is correct, and the PERF_PROC_DISABLED short-circuit brings the FFM path to parity with the JNA variant (addressing the earlier review note).

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

27-97: LGTM!

Mechanical migration from PerfDataUtil.PerfCounter to the shared oshi.driver.common.windows.perfmon.PerfCounter with createCounter(...) — PDH flow unchanged.

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

88-105: LGTM — _Base handling consolidated through PerfCounter.

Both single-counter and wildcard paths now use PerfCounter.isBase(...) / PerfCounter.stripBaseSuffix(...), and the wildcard path correctly tracks per-property isBase state in parallel with counterHandles. Behavior is preserved.

Also applies to: 316-322

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

26-73: LGTM — thin JNA wrapper delegating to common implementation.

The class cleanly separates JNA-specific data fetching (HKEY_PERFORMANCE_DATA via HkeyPerformanceDataUtilJNA, PerfMon via ThreadInformationJNA) from the shared parsing logic in oshi.driver.common.windows.registry.ThreadPerformanceData. The PerfmonDisabled.PERF_PROC_DISABLED short-circuit and the procName/threadNum overload selection look correct and mirror the pattern in ProcessPerformanceDataJNA.

One minor note for consideration: buildThreadMapFromRegistry does not guard on PerfmonDisabled the way buildThreadMapFromPerfCounters does, but this mirrors ProcessPerformanceDataJNA (which uses a PERFDATA gate) — if a similar registry-disable gate is intended for symmetry, worth a follow-up, otherwise fine as is.

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

56-60: LGTM — consistent re-routing to *JNA delegates.

Imports (lines 56, 60) and all six call sites (lines 304, 313, 330, 334, 338, 342) are updated consistently. The new ProcessPerformanceDataJNA / ThreadPerformanceDataJNA methods preserve signatures and return types, so the memoized suppliers and fallback paths behave identically. No behavioral change expected.

Also applies to: 298-343

oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java (3)

5-20: Common extraction looks good.

The package move, transformer-focused Javadoc, and shared PROCESS constant align with the JNA/FFM delegation model introduced by this PR.

Also applies to: 25-28


34-42: Registry transformer contract is clean.

Accepting pre-fetched registry data keeps acquisition out of the common layer, and the ParseUtil.filetimeToUtcMs(..., false) replacement preserves the previous UTC FILETIME conversion semantics.

Also applies to: 56-56


77-88: Perf-counter transformer preserves the aligned wildcard result contract.

The null guard and caller-supplied Pair shape fit the existing wildcard counter flow, where instance/value lists must remain parallel.

Also applies to: 108-108

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

14-14: Registry delegation is consistent.

The FFM-specific read remains in this wrapper, while shared block assembly is correctly delegated through the common PROCESS constant.

Also applies to: 40-43


54-55: Perf-counter delegation looks correct.

ProcessInformationFFM.queryProcessCounters() returns the exact Pair<List<String>, Map<ProcessPerformanceProperty, List<Long>>> shape expected by the common builder.

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from 2a3d918 to 3c59044 Compare April 18, 2026 18:30

@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/util/platform/windows/Advapi32UtilFFM.java (1)

200-253: LGTM — registry helper overloads are well-formed.

Both new overloads correctly scope Arena via try-with-resources, close the opened subkey in finally, and adopt null/false-on-failure semantics that match the consumer in PerfmonDisabledFFM.java (which uses instanceof on the result). The registryValueExists probe correctly treats ERROR_MORE_DATA as success, which is the expected return when querying an existing value with a NULL data buffer.

One optional nit: unlike registryGetStringArray (line 318-321), these methods discard the RegCloseKey return code without logging. Fine to leave as-is given the "silent failure" contract, but a debug-level log on close failure would aid diagnostics without changing behavior.

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

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java`
around lines 200 - 253, Add a debug-level log if RegCloseKey returns a
non-success code in both registryGetValue(MemorySegment, String, String) and
registryValueExists(MemorySegment, String, String) without changing the existing
null/false-on-failure behavior; locate the finally blocks that call
RegCloseKey(hKey) and capture its return int, and if it != ERROR_SUCCESS call
the existing logger at debug level (or create a debug log call) including the
key handle and return code for diagnostics.
oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java (1)

74-96: Optional: consolidate double map lookups into a single get + null-check.

containsKey(...) followed by get(...) does two lookups per key. Using Integer idx = counterIndexMap.get(...); once and branching on idx == null is slightly cleaner and avoids the redundancy (safe here because indices stored in the map are always > 0, per buildCounterIndexMap). Nice-to-have; no behavior change.

♻️ Proposed refactor
-        if (!counterIndexMap.containsKey(objectName)) {
-            LOG.debug("Couldn't find counter index of {}.", objectName);
-            return null;
-        }
-        int counterIndex = counterIndexMap.get(objectName);
+        Integer objIdx = counterIndexMap.get(objectName);
+        if (objIdx == null) {
+            LOG.debug("Couldn't find counter index of {}.", objectName);
+            return null;
+        }
+        int counterIndex = objIdx;
         T[] enumConstants = counterEnum.getEnumConstants();
         EnumMap<T, Integer> indexMap = new EnumMap<>(counterEnum);
         // Start iterating at 1 because first Enum value defines the name/instance and
         // is not a counter name
         for (int i = 1; i < enumConstants.length; i++) {
             T key = enumConstants[i];
             String counterName = key.getCounter();
-            if (!counterIndexMap.containsKey(counterName)) {
-                LOG.debug("Couldn't find counter index of {}.", counterName);
-                return null;
-            }
-            indexMap.put(key, counterIndexMap.get(counterName));
+            Integer ctrIdx = counterIndexMap.get(counterName);
+            if (ctrIdx == null) {
+                LOG.debug("Couldn't find counter index of {}.", counterName);
+                return null;
+            }
+            indexMap.put(key, ctrIdx);
         }
🤖 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/HkeyPerformanceDataUtil.java`
around lines 74 - 96, The method getCounterIndices performs redundant map
lookups using containsKey(...) then get(...); replace those with a single
lookup: retrieve Integer counterIndex = counterIndexMap.get(objectName) and
return null if counterIndex == null, and inside the loop use Integer idx =
counterIndexMap.get(counterName) and check idx == null before putting into
indexMap; update variable names (e.g., counterIndex, idx) accordingly while
leaving enumConstants, indexMap, key.getCounter() and the returned new
Pair<>(counterIndex, indexMap) logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java`:
- Line 15: PerfCounter is used as a HashMap key in PerfCounterQueryHandler but
lacks value equality, causing fragile lookups and failing to distinguish
counters that differ only by baseCounter (e.g., "% Processor Time" vs "%
Processor Time_Base"); implement equals(Object) and hashCode() in the
PerfCounter class (oshi.driver.common.windows.perfmon.PerfCounter) to compare
all four fields (object, instance, counter, baseCounter), using Objects.equals
for null-safe comparisons in equals and Objects.hash(...) (or equivalent) to
compute hashCode so identical field values produce equal hashes and unequal
baseCounter values are distinct keys.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java`:
- Around line 74-96: The method getCounterIndices performs redundant map lookups
using containsKey(...) then get(...); replace those with a single lookup:
retrieve Integer counterIndex = counterIndexMap.get(objectName) and return null
if counterIndex == null, and inside the loop use Integer idx =
counterIndexMap.get(counterName) and check idx == null before putting into
indexMap; update variable names (e.g., counterIndex, idx) accordingly while
leaving enumConstants, indexMap, key.getCounter() and the returned new
Pair<>(counterIndex, indexMap) logic unchanged.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java`:
- Around line 200-253: Add a debug-level log if RegCloseKey returns a
non-success code in both registryGetValue(MemorySegment, String, String) and
registryValueExists(MemorySegment, String, String) without changing the existing
null/false-on-failure behavior; locate the finally blocks that call
RegCloseKey(hKey) and capture its return int, and if it != ERROR_SUCCESS call
the existing logger at debug level (or create a debug log call) including the
key handle and return code for diagnostics.
🪄 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: 528f8e97-190f-4d5d-b602-d58c5306f75d

📥 Commits

Reviewing files that changed from the base of the PR and between 2a3d918 and 3c59044.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (4)
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.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/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (14)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 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: 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.
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: 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/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.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/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
🔇 Additional comments (12)
oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java (1)

2-2: LGTM.

The copyright year range update is fine.

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

49-60: LGTM — robust null/short-array handling and defensive index parsing.

Null input, arrays of length ≤ 1, non-numeric index entries, and non-positive indices are all handled gracefully, and the returned map is made unmodifiable, which lets JNA/FFM subclasses treat the result as a safe read-only shared constant.

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

40-190: LGTM — clean delegation and correct FILETIME conversion.

  • ParseUtil.filetimeToUtcMs(perfTime100nSec, false) is semantically equivalent to the previous WinBase.FILETIME.filetimeToDate(...).getTime() for a UTC FILETIME (both compute ft/10_000 - EPOCH_DIFF).
  • getCounterIndices(objectName, counterEnum, COUNTER_INDEX_MAP) preserves the "skip first enum constant" contract and null-on-miss behavior.
  • mapCounterIndicesFromRegistry() correctly funnels both success and Win32Exception paths through buildCounterIndexMap(...), keeping the unmodifiable-map invariant.
oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java (2)

70-78: LGTM — getCounterIndex default is consistent with caller expectations.

Returning 0 for an unknown name is the correct sentinel here because the sole caller (PerfDataUtilFFM.localizeUsingPerfIndex) explicitly checks if (index == 0) and falls back to the English name. Worth keeping this contract documented on the method (already done).


275-286: LGTM — failure path preserves unmodifiable-map invariant via buildCounterIndexMap(null).

Routing both success and exception paths through buildCounterIndexMap(...) keeps the returned COUNTER_INDEX_MAP shape consistent (always unmodifiable) with the JNA variant.

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

90-103: LGTM — PerfCounter helpers cleanly replace inlined _Base handling and registry-index plumbing is delegated appropriately.

Suffix detection/stripping through PerfCounter.isBase / PerfCounter.stripBaseSuffix matches the previous inline endsWith/substring logic in both the single-counter and wildcard paths, and the per-counter isBase[p-1] alignment in the wildcard path is preserved. The lookupPerfIndexByEnglishName delegation to HkeyPerformanceDataUtilFFM.getCounterIndex replaces manual registry parsing with a centralized lookup.

Also applies to: 315-331, 386-388

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

41-74: LGTM — pure transformation utility with consistent null-in/null-out contract.

Both builders cleanly return null on missing input and otherwise transform caller-supplied data, making them platform-agnostic and suitable for oshi-common. The ctime > now heuristic and upTime floor (< 1 → 1) preserve prior behavior, and ParseUtil.filetimeToUtcMs(ctime, false) is semantically equivalent to the previous FILETIME.filetimeToDate(...).getTime() conversion for UTC FILETIMEs.

Also applies to: 84-122

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

41-81: LGTM — transformation-only API matches ProcessPerformanceData's pattern.

Null-in / null-out contract is consistent with ProcessPerformanceData. The unconditional filetimeToUtcMs + clamp-to-now-1 for future start times preserves the pre-refactor behavior for perf-counter thread start times. The registry path's (perfTime100nSec - ELAPSEDTIME) / 10_000L uptime math is also unchanged.

Also applies to: 91-135

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

64-73: LGTM — FFM now has parity with JNA for PERF_PROC_DISABLED short-circuit.

The guard addresses the prior divergence and ensures both code paths respect oshi.os.windows.perfmon.disabled identically. Delegation to ThreadPerformanceData.buildThreadMapFromPerfCounters(pids, instanceValues) keeps transformation logic centralized.

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

26-73: LGTM — mirrors the FFM variant closely, which is exactly what you want for cross-platform parity.

Structurally identical to ThreadPerformanceDataFFM modulo JNA/FFM type prefixes, with the same PERF_PROC_DISABLED short-circuit and Util.isBlank(procName) dispatch. Centralizing the transform in ThreadPerformanceData keeps JNA and FFM outputs bit-for-bit equivalent given the same underlying data.

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

29-29: LGTM — this now targets the JNA registry wrapper.

The test remains scoped to the concrete Windows registry driver while the shared parsing logic lives in common code.


36-36: LGTM — consistent with the process registry test.

This keeps the test exercising the JNA-specific entry point while delegating common map-building behavior underneath.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

74-96: Minor: Replace containsKey + get with a single lookup.

The counterIndexMap.containsKey(...) + counterIndexMap.get(...) pattern (lines 76-80 and 88-92) performs two hash lookups per entry. Since the map values are non-null Integers, a single get(...) + null check is cleaner and halves the lookups on the hot path (called once per counter per registry read).

♻️ Proposed refactor
-        if (!counterIndexMap.containsKey(objectName)) {
+        Integer counterIndex = counterIndexMap.get(objectName);
+        if (counterIndex == null) {
             LOG.debug("Couldn't find counter index of {}.", objectName);
             return null;
         }
-        int counterIndex = counterIndexMap.get(objectName);
         T[] enumConstants = counterEnum.getEnumConstants();
         EnumMap<T, Integer> indexMap = new EnumMap<>(counterEnum);
         // Start iterating at 1 because first Enum value defines the name/instance and
         // is not a counter name
         for (int i = 1; i < enumConstants.length; i++) {
             T key = enumConstants[i];
             String counterName = key.getCounter();
-            if (!counterIndexMap.containsKey(counterName)) {
+            Integer idx = counterIndexMap.get(counterName);
+            if (idx == null) {
                 LOG.debug("Couldn't find counter index of {}.", counterName);
                 return null;
             }
-            indexMap.put(key, counterIndexMap.get(counterName));
+            indexMap.put(key, idx);
         }
🤖 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/HkeyPerformanceDataUtil.java`
around lines 74 - 96, In getCounterIndices, avoid double hash lookups by
replacing the containsKey(...) + get(...) patterns on counterIndexMap: first for
the objectName lookup and then inside the loop for counterName; use a single
Integer lookup (e.g., Integer counterIndex = counterIndexMap.get(objectName))
and check for null before proceeding, and similarly get Integer idx =
counterIndexMap.get(counterName) and check for null before putting into
indexMap; keep all existing behavior and logging (LOG.debug) when a lookup
yields null and return null in those cases.

26-26: Consider: abstract without abstract members or protected constructor.

The class is declared abstract yet exposes only protected static helpers and has no abstract methods or state. Since it's effectively a utility namespace, subclasses (HkeyPerformanceDataUtilJNA/FFM) extend it solely to access the protected static methods. This works, but a couple of small tightenings are worth considering:

  • Add a protected (or package-private) no-arg constructor to document the intended subclass-only usage and prevent accidental instantiation paths from lint/tooling flags.
  • Alternatively, if you don't actually need the protected-static access pattern, making the methods public static on a final utility class (with a private constructor) aligns with the rest of oshi-common utilities and lets you drop the inheritance entirely.

Either direction is fine; the current hybrid is just mildly unidiomatic.

🤖 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/HkeyPerformanceDataUtil.java`
at line 26, The class HkeyPerformanceDataUtil is declared abstract but has no
abstract members and only protected static helpers; add a protected no-arg
constructor to document and enforce subclass-only usage and suppress accidental
instantiation or lint warnings (e.g., add "protected HkeyPerformanceDataUtil()
{}" to HkeyPerformanceDataUtil); keep existing protected static helper methods
and leave subclasses HkeyPerformanceDataUtilJNA/HkeyPerformanceDataUtilFFM
unchanged so they can continue to access those helpers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java`:
- Around line 53-55: The method buildProcessMapFromPerfCounters should
short-circuit when PerfmonDisabledFFM.PERF_PROC_DISABLED is set to avoid calling
ProcessInformationFFM.queryProcessCounters; update
buildProcessMapFromPerfCounters to first check
PerfmonDisabledFFM.PERF_PROC_DISABLED and return Collections.emptyMap() if true,
otherwise call ProcessInformationFFM.queryProcessCounters() and pass the result
into ProcessPerformanceData.buildProcessMapFromPerfCounters(pids, ...).

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java`:
- Around line 243-246: The registryValueExists() helper currently treats only
ERROR_SUCCESS and ERROR_MORE_DATA as indicating an existing value; update its
return condition to also consider ERROR_INSUFFICIENT_BUFFER as non-fatal. In the
method that calls RegQueryValueEx (using lpType and the allocated JAVA_INT),
change the boolean check to include ERROR_INSUFFICIENT_BUFFER alongside
ERROR_SUCCESS and ERROR_MORE_DATA so the method matches other size-probe paths
and doesn't return false negatives.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java`:
- Around line 74-96: In getCounterIndices, avoid double hash lookups by
replacing the containsKey(...) + get(...) patterns on counterIndexMap: first for
the objectName lookup and then inside the loop for counterName; use a single
Integer lookup (e.g., Integer counterIndex = counterIndexMap.get(objectName))
and check for null before proceeding, and similarly get Integer idx =
counterIndexMap.get(counterName) and check for null before putting into
indexMap; keep all existing behavior and logging (LOG.debug) when a lookup
yields null and return null in those cases.
- Line 26: The class HkeyPerformanceDataUtil is declared abstract but has no
abstract members and only protected static helpers; add a protected no-arg
constructor to document and enforce subclass-only usage and suppress accidental
instantiation or lint warnings (e.g., add "protected HkeyPerformanceDataUtil()
{}" to HkeyPerformanceDataUtil); keep existing protected static helper methods
and leave subclasses HkeyPerformanceDataUtilJNA/HkeyPerformanceDataUtilFFM
unchanged so they can continue to access those helpers.
🪄 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: 7b3d1308-972a-4fd9-9cff-fd75e8a0e495

📥 Commits

Reviewing files that changed from the base of the PR and between 2a3d918 and 3c59044.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (5)
  • 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/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • CHANGELOG.md
📜 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). (1)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (15)
📓 Common learnings
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.
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: 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: 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: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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.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
📚 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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.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
📚 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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.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
📚 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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.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
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

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

70-78: The 0 sentinel for getCounterIndex is correctly validated by all callers.

The only caller in PerfDataUtilFFM.localizeUsingPerfIndex() explicitly checks if (index == 0) before using the result (line 374), returning early with the original object if the lookup fails. The native PDH API is never called with a sentinel index. No changes needed.

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from 3c59044 to 156f5cf Compare April 18, 2026 18:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java (2)

29-39: Constructor duplicates stripBaseSuffix / isBase logic.

Minor DRY nit — the constructor can delegate to the static helpers to keep the suffix rule in one place:

♻️ Proposed refactor
     public PerfCounter(String objectName, String instanceName, String counterName) {
         this.object = objectName;
         this.instance = instanceName;
-        if (counterName.endsWith(BASE_SUFFIX)) {
-            this.counter = counterName.substring(0, counterName.length() - BASE_SUFFIX.length());
-            this.baseCounter = true;
-        } else {
-            this.counter = counterName;
-            this.baseCounter = false;
-        }
+        this.baseCounter = isBase(counterName);
+        this.counter = stripBaseSuffix(counterName);
     }
🤖 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/perfmon/PerfCounter.java`
around lines 29 - 39, The PerfCounter constructor duplicates the
suffix-detection logic; update the constructor to delegate to the existing
static helpers stripBaseSuffix and isBase instead of re-implementing the
behavior: use stripBaseSuffix(counterName) to set this.counter and use
isBase(counterName) to set this.baseCounter while keeping assignments for
this.object and this.instance unchanged so the single-source-of-truth for
BASE_SUFFIX handling resides in those helper methods.

133-135: Redundant static factory.

createCounter just calls the public constructor with the same parameter list, offering no additional value (no caching, no validation, no polymorphism). Consider removing it and having call sites use new PerfCounter(...) directly to keep the API minimal.

🤖 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/perfmon/PerfCounter.java`
around lines 133 - 135, Remove the redundant static factory method createCounter
in class PerfCounter; it simply delegates to the public constructor with
identical parameters and adds no behavior. Delete the createCounter(String
object, String instance, String counter) method and update all call sites to
construct instances directly with new PerfCounter(object, instance, counter).
Ensure there are no external callers relying on createCounter (search for
createCounter usages) and run tests to confirm compilation after replacing them.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java`:
- Around line 29-39: The PerfCounter constructor duplicates the suffix-detection
logic; update the constructor to delegate to the existing static helpers
stripBaseSuffix and isBase instead of re-implementing the behavior: use
stripBaseSuffix(counterName) to set this.counter and use isBase(counterName) to
set this.baseCounter while keeping assignments for this.object and this.instance
unchanged so the single-source-of-truth for BASE_SUFFIX handling resides in
those helper methods.
- Around line 133-135: Remove the redundant static factory method createCounter
in class PerfCounter; it simply delegates to the public constructor with
identical parameters and adds no behavior. Delete the createCounter(String
object, String instance, String counter) method and update all call sites to
construct instances directly with new PerfCounter(object, instance, counter).
Ensure there are no external callers relying on createCounter (search for
createCounter usages) and run tests to confirm compilation after replacing them.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fdd30ce2-0ff4-40db-92c3-ae27971f940f

📥 Commits

Reviewing files that changed from the base of the PR and between 3c59044 and 156f5cf.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (2)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (11)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
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: 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
📚 Learning: 2026-04-17T23: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/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.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/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

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

Applied to files:

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

2-2: LGTM.

Removal of the nested PerfCounter and createCounter factory is consistent with the migration to oshi.driver.common.windows.perfmon.PerfCounter. Copyright bump looks good.

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

41-135: LGTM — transformer refactor preserves original semantics.

The registry path still computes upTime = (perfTime100nSec - ELAPSEDTIME) / 10_000 with the <1 clamp, and the perf-counter path correctly treats ELAPSEDTIME as a FILETIME via ParseUtil.filetimeToUtcMs(startTime, false) with the > now clamp preserved. The nameIndex++ remains inside the PID-filter branch, matching the previous behavior, and the null short-circuits are consistent with callers (JNA/FFM wrappers) being responsible for pre-fetching.

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

41-122: LGTM — extraction preserves ELAPSEDTIME handling and filtering.

The ctime > now guard before ParseUtil.filetimeToUtcMs(ctime, false) correctly preserves the original dual-interpretation of ELAPSEDTIME (already-epoch-ms for registry path vs. raw FILETIME). The registry-side _Total exclusion is retained; the perf-counter path correctly relies on the caller's WHERE NOT NAME LIKE '_Total' WHERE clause in ProcessInformation(JNA|FFM).queryProcessCounters().

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

29-39: LGTM — tests correctly pivot to the JNA wrappers.

Routing the assertions through ProcessPerformanceDataJNA/ThreadPerformanceDataJNA (the single-arg overloads that internally read registry data and delegate to the common transformer) preserves the end-to-end non-empty-map guarantee this test exercises.

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

39-46: LGTM — registry delegation preserves null-on-failure contract.

When PERFDATA=false or the registry read fails, processData is null and the common transformer returns null, matching this method's javadoc ("or null otherwise") and the original behavior callers rely on for fallback to the perf-counter path.


55-61: JNA and FFM behavior for disabled PerfProc is aligned.

The JNA implementation handles the PERF_PROC_DISABLED flag via ProcessInformationJNA.queryProcessCounters() (which checks PerfmonDisabled.PERF_PROC_DISABLED and returns an empty Pair), whereas the FFM implementation adds a check at the wrapper level in ProcessPerformanceDataFFM.buildProcessMapFromPerfCounters(). Both paths return empty collections when the flag is set, so the backends remain aligned.

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

26-102: LGTM — clean extraction of shared Perflib registry logic.

The abstract base correctly centralizes the counter-name/index parsing and enum-resolution logic previously duplicated across JNA and FFM. buildCounterIndexMap is null-safe and returns an unmodifiable map even on empty input, and getCounterIndices preserves the existing "all-or-nothing" contract by returning null when any required lookup is missing — matching the prior JNA behavior and keeping both downstream implementations consistent.

Using protected static helpers on an abstract class (with subclasses having private constructors) is effectively a namespace-scoped inheritance pattern; it works, but since static methods aren't polymorphic you could equally have made this a final utility class with package-private helpers if you prefer a more conventional shape. Not worth changing.

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

44-97: LGTM — delegation to the shared base is correct and behavior-preserving.

Extending HkeyPerformanceDataUtil and routing mapCounterIndicesFromRegistry/getCounterIndices through the shared helpers preserves the existing semantics: the counter index map is unmodifiable, the exception path yields an empty (unmodifiable) map via buildCounterIndexMap(null), and readPerfDataFromRegistry still bails out early when either object or per-enum index resolution fails.

Also applies to: 275-286


70-78: The 0 sentinel for "not found" is already properly guarded at the only call site.

The single caller of getCounterIndex is lookupPerfIndexByEnglishName at line 387 in PerfDataUtilFFM.java, which is invoked from localizeUsingPerfIndex (line 373). That method correctly guards the return value: if (index == 0) at line 374, returning early with a fallback value before passing the index to lookupPerfNameByIndex. No action needed.

oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java (3)

180-191: LGTM — parse-error handling correctly moved into parseIntOrDefault.

Dropping the explicit NumberFormatException catch is correct because ParseUtil.parseIntOrDefault (invoked inside the shared buildCounterIndexMap) already handles malformed entries by returning the default. Returning buildCounterIndexMap(null) on Win32Exception preserves the previous "empty unmodifiable map" failure contract.


40-48: No action required. Verification found no lingering references to the old HkeyPerformanceDataUtil class name in the codebase. The class is located in a driver subpackage, which is implementation detail and not part of the public API; the rename is safe.


83-84: Confirmed: JNA and FFM timestamp conversions are equivalent.

Both implementations use ParseUtil.filetimeToUtcMs(perfTime100nSec, false) with the identical false flag, ensuring they produce the same UTC millisecond values. The conversion correctly transforms the PERF_DATA_BLOCK.PerfTime100nSec field (Windows 1601-epoch in 100-nanosecond increments) to Unix 1970-epoch milliseconds. The unit test in ParseUtilTest.java validates the conversion algorithm.

@dbwiddis

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java (1)

276-285: ⚠️ Potential issue | 🟠 Major

Preserve the existing invalid/empty fallback when JNA data is unavailable.

Both fallback paths can still leave the map null; Line 285 then bypasses the null-aware updateAttributes(...), and queryMatchingThreads(...) can return null to callers that expect a map.

Proposed fix
         if (USE_PROCSTATE_SUSPENDED) {
             this.tcb = queryMatchingThreads(pids);
         }
         Map<Integer, WtsInfo> wts = ProcessWtsData.queryProcessWtsMap(pids);
-        return updateAttributes(pcb.get(this.getProcessID()), wts.get(this.getProcessID()));
+        return updateAttributes(pcb == null ? null : pcb.get(this.getProcessID()), wts.get(this.getProcessID()));
@@
         if (threads == null) {
             threads = ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters(pids, this.getName(), -1);
         }
-        return threads;
+        return threads == null ? Collections.emptyMap() : threads;
     }

Also applies to: 365-370

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

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java`
around lines 276 - 285, The code currently dereferences pcb and wts directly
which skips the null-aware updateAttributes and can propagate unexpected non-map
values; change the final return to pass null when the maps are null so
updateAttributes receives nulls instead of throwing: call updateAttributes(pcb
== null ? null : pcb.get(this.getProcessID()), wts == null ? null :
wts.get(this.getProcessID())); do the same null-safe extraction for the second
occurrence around lines 365-370; keep existing assignments to pcb and tcb and
only guard the map lookups.
🧹 Nitpick comments (1)
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (1)

134-142: Optional: reuse PerfCounter.getCounterPath() instead of the private counterPath helper.

Now that PerfCounter lives in oshi-common and already formats \object(instance)\counter, this local helper duplicates that logic. Not a functional issue, just a small DRY opportunity (e.g., new PerfCounter(perfObject, instance, counterName).getCounterPath() or a new static builder on PerfCounter).

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

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`
around lines 134 - 142, The file defines a private helper counterPath that
duplicates existing logic in PerfCounter; replace calls to counterPath(...) with
PerfCounter's existing API (e.g., new PerfCounter(object, instance,
counter).getCounterPath() or a static builder if available) and remove the
private counterPath method to avoid duplication; update any imports/usages in
PerfDataUtilFFM to reference PerfCounter.getCounterPath() via the instantiated
PerfCounter to preserve identical formatting.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java`:
- Around line 53-56: The JNA implementation
ProcessPerformanceDataJNA.buildProcessMapFromPerfCounters is missing the same
early exit as other implementations; add a short-circuit at the start of that
method to check PerfmonDisabled.PERF_PROC_DISABLED and immediately return
Collections.emptyMap() when set (before calling
ProcessInformationJNA.queryProcessCounters()), mirroring the behavior in
ProcessPerformanceDataFFM.buildProcessMapFromPerfCounters and
ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters to avoid issuing PDH
queries when perfproc is disabled.

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java`:
- Around line 103-105: The call to
ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters can return null, causing
threads.get(getThreadId()) to NPE before updateAttributes can handle a null pcb;
guard the map by checking if the returned Map is null or does not
containKey(getThreadId()) and in that case call updateAttributes(procName, null)
(or otherwise mark the thread INVALID) instead of dereferencing
threads.get(...). Apply this check around the buildThreadMapFromPerfCounters
call in WindowsOSThread (use getThreadId() and updateAttributes(procName, ...)
to locate the code).

---

Outside diff comments:
In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java`:
- Around line 276-285: The code currently dereferences pcb and wts directly
which skips the null-aware updateAttributes and can propagate unexpected non-map
values; change the final return to pass null when the maps are null so
updateAttributes receives nulls instead of throwing: call updateAttributes(pcb
== null ? null : pcb.get(this.getProcessID()), wts == null ? null :
wts.get(this.getProcessID())); do the same null-safe extraction for the second
occurrence around lines 365-370; keep existing assignments to pcb and tcb and
only guard the map lookups.

---

Nitpick comments:
In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`:
- Around line 134-142: The file defines a private helper counterPath that
duplicates existing logic in PerfCounter; replace calls to counterPath(...) with
PerfCounter's existing API (e.g., new PerfCounter(object, instance,
counter).getCounterPath() or a static builder if available) and remove the
private counterPath method to avoid duplication; update any imports/usages in
PerfDataUtilFFM to reference PerfCounter.getCounterPath() via the instantiated
PerfCounter to preserve identical formatting.
🪄 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: c8568ced-03ae-4617-aea4-786b38d14b7b

📥 Commits

Reviewing files that changed from the base of the PR and between 27a47b5 and 156f5cf.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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). (1)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (16)
📓 Common learnings
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: 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
📚 Learning: 2026-04-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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
🔇 Additional comments (26)
CHANGELOG.md (1)

36-36: LGTM!

The changelog entry accurately summarizes PR #3172, follows the established format convention, and is appropriately placed in the "Bug fixes / Improvements" section. The description clearly conveys the key changes: extracting common Windows perfmon/registry driver code to oshi-common to reduce duplication between JNA and FFM implementations.

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

2-2: LGTM.

The copyright update is straightforward; no concerns in this file’s visible changed segment.

oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java (3)

41-45: Null propagation is explicit and documented.

Both registry and perf-counter builders now clearly return null when caller-supplied data is unavailable, matching the updated method contracts.

Also applies to: 91-95


111-134: Aligned perf-counter extraction looks consistent.

The builder keeps one pass over the instance list and parallel property lists, which matches the wildcard-query alignment contract. Based on learnings, queryWildcardCounters intentionally aborts on counter-add failure to preserve strict parallel alignment between instances and per-property value lists.


117-121: Centralized FILETIME conversion looks good.

Using ParseUtil.filetimeToUtcMs(startTime, false) keeps the thread start-time conversion consistent with the rest of this PR.

oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java (2)

55-65: Good defensive parsing for Perflib counter text.

The helper safely handles missing registry data, malformed index entries, and exposes an immutable map to callers.


80-102: Counter-index resolution is cleanly centralized.

Returning null on missing object/counter indices preserves the existing fail-fast behavior while removing duplicate JNA/FFM lookup logic.

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

55-78: Good FFM/common split.

The subclass keeps FFM-specific registry access local while exposing a small lookup helper backed by the shared counter-index map.


97-102: Delegation to the common index helpers looks correct.

Both object/counter resolution and registry counter-text parsing now use the shared implementation, reducing divergence between JNA and FFM paths.

Also applies to: 279-285

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

208-227: Root-key registry value helper looks safe.

The method opens the key, delegates to the existing value reader, and closes the handle in finally while preserving the documented null-on-failure contract.


237-259: Existence probe handles the expected size-query return codes.

Including ERROR_SUCCESS, ERROR_MORE_DATA, and ERROR_INSUFFICIENT_BUFFER keeps this consistent with the other registry size-probe paths.

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

27-31: FFM perfmon-disable parity looks good.

The implementation mirrors the JNA behavior: config override first, then the service-specific registry flag, with invalid non-DWORD values ignored after warning.

Also applies to: 37-59

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

40-48: JNA path is cleanly aligned with the common helper.

The object/counter index lookup now shares the same implementation as FFM, and the timestamp conversion uses the centralized utility.

Also applies to: 67-84


180-190: Shared counter-index map construction looks good.

Delegating to buildCounterIndexMap keeps parsing behavior consistent across the JNA and FFM registry readers.

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

39-41: Registry delegation to common map-building looks correct.

The FFM wrapper now only fetches the platform-specific registry data and leaves object construction to the shared implementation.


66-72: PerfProc-disabled guard restores JNA/FFM parity.

Short-circuiting with Collections.emptyMap() before querying PerfMon matches the JNA wrapper’s behavior and avoids unnecessary counter access when PerfProc is disabled.

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

16-135: LGTM.

Immutable value object is well-scoped; _Base suffix handling is consistently suffix-only across the constructor, isBase, and stripBaseSuffix. Previous review feedback on suffix detection and stale Javadoc has been addressed.

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

92-99: LGTM — _Base suffix handling centralized correctly.

Both queryCounters and queryWildcardCounters now consistently route through PerfCounter.isBase / PerfCounter.stripBaseSuffix, and the resulting base-flag is propagated to readRawCounterValue to select SecondValue. The wildcard path still aborts with an empty Pair on any addEnglishCounter failure, preserving the instance/value alignment contract.

Also applies to: 317-320

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

38-73: LGTM.

Cleanly separates registry and perf-counter paths, delegates to the shared ThreadPerformanceData builders, and short-circuits on PERF_PROC_DISABLED before hitting PDH. The Util.isBlank(procName) dispatch correctly preserves both queryThreadCounters() overloads.

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

41-122: LGTM.

Shared builders correctly honour the null-input contract, preserve the ctime > now FILETIME heuristic, and use ParseUtil.filetimeToUtcMs(ctime, false) which is equivalent to the previous WinBase.FILETIME.filetimeToDate(...).getTime() path (treating the raw 100-ns value as UTC). _Total exclusion and pid filtering are unchanged.

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

29-38: LGTM.

Tests correctly target the new JNA-backed entrypoints; assertions and Windows-only gating are unchanged.

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

39-61: LGTM.

Delegation to the common ProcessPerformanceData builders is clean, and the PerfmonDisabledFFM.PERF_PROC_DISABLED short-circuit before PDH querying matches the pattern used elsewhere (ThreadPerformanceDataFFM, ThreadPerformanceDataJNA). Previous feedback on the dropped procName overload and the disabled-check is fully addressed here.

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

298-343: LGTM.

Switching the memoized suppliers and the non-memoized pid-filtered fallbacks to ProcessPerformanceDataJNA / ThreadPerformanceDataJNA is a clean lift; control flow in processMapToList is unchanged. Note the PERF_PROC_DISABLED consistency concern raised on ProcessPerformanceDataJNA.buildProcessMapFromPerfCounters will also benefit this call site once addressed.

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

27-27: LGTM.

The common PerfCounter import and factory call are wired consistently with the existing PDH query flow.

Also applies to: 96-97

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

29-29: LGTM.

The common PerfCounter wiring preserves the existing fail-fast wildcard behavior needed to keep instance and value lists aligned. Based on learnings, wildcard PDH queries intentionally abort when any counter registration fails to preserve strict parallel alignment.

Also applies to: 172-175

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

15-15: No issue — PerfCounter.isBaseCounter() is available in the common class (line 65), making the import switch safe.

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from 156f5cf to ec37da5 Compare April 18, 2026 19:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

274-280: Pass pids to buildProcessMapFromRegistry instead of null.

On Line 276, null is passed even though the single-PID pids set is already computed on Line 274 and correctly forwarded to both the perf-counter fallback (Line 279) and queryProcessWtsMap (Line 284). The common buildProcessMapFromRegistry(pids, processData) uses that collection as a PID filter — passing null disables the filter and materializes a map entry for every process on the system only to immediately discard all but one on Line 285. This is a (minor) efficiency regression versus the pre-refactor path and inconsistent with the rest of the method.

♻️ Proposed fix
-        Map<Integer, ProcessPerfCounterBlock> pcb = ProcessPerformanceDataJNA.buildProcessMapFromRegistry(null);
+        Map<Integer, ProcessPerfCounterBlock> pcb = ProcessPerformanceDataJNA.buildProcessMapFromRegistry(pids);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java`
around lines 274 - 280, The call to
ProcessPerformanceDataJNA.buildProcessMapFromRegistry currently passes null
which disables the PID filter; change the invocation in WindowsOSProcess (where
pids is defined as Set<Integer> pids =
Collections.singleton(this.getProcessID())) to pass pids instead of null so the
registry query is restricted to the single PID (modify the call to
ProcessPerformanceDataJNA.buildProcessMapFromRegistry(...) to use the pids
variable), keeping the existing fallback to
buildProcessMapFromPerfCounters(pids) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java`:
- Around line 274-280: The call to
ProcessPerformanceDataJNA.buildProcessMapFromRegistry currently passes null
which disables the PID filter; change the invocation in WindowsOSProcess (where
pids is defined as Set<Integer> pids =
Collections.singleton(this.getProcessID())) to pass pids instead of null so the
registry query is restricted to the single PID (modify the call to
ProcessPerformanceDataJNA.buildProcessMapFromRegistry(...) to use the pids
variable), keeping the existing fallback to
buildProcessMapFromPerfCounters(pids) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e21bf13d-da67-4db8-95ec-3714055658fb

📥 Commits

Reviewing files that changed from the base of the PR and between 156f5cf and ec37da5.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (2)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
🚧 Files skipped from review as they are similar to previous changes (8)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.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 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
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: 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
📚 Learning: 2026-04-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/util/platform/windows/PerfCounterWildcardQuery.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/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/util/platform/windows/PerfCounterWildcardQuery.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/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.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
🔇 Additional comments (15)
oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java (1)

1-176: LGTM — clean extraction of PerfCounter.

Removal of the nested PerfCounter class and createCounter factory is consistent with the migration to oshi.driver.common.windows.perfmon.PerfCounter. Remaining PDH helper methods are unchanged and the Immutable import cleanup is appropriate.

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

29-29: LGTM — switched to shared PerfCounter.

Import and constructor call correctly delegate to the new oshi.driver.common.windows.perfmon.PerfCounter. Behavior of queryInstancesAndValuesFromPDH (abort-on-add-failure to preserve list/map alignment, zero-timestamp guard) is preserved.

Also applies to: 172-173

oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java (2)

41-81: LGTM on the registry builder refactor.

Clean separation: caller supplies the pre-fetched triplet, this method stays purely a converter. Null-guard at line 43 matches the documented contract, and the rest of the loop preserves prior scaling/clamping behavior (including the upTime < 1 floor and the uint32/uint64 STARTADDRESS demotion).


91-135: PerfCounter path conversion preserves prior behavior.

ParseUtil.filetimeToUtcMs(startTime, false) with the subsequent startTime > now clamp matches the old semantics (raw filetime → ms-since-1970, no TZ adjustment), and null-guard on instanceValues correctly aligns with the JNA/FFM callers passing through queryThreadCounters() results.

One subtle note: the ParseUtil Javadoc (context snippet 4) describes local=false as “already UTC (WMI PerfRawData classes)”, but ELAPSEDTIME here comes from PDH. This is intentional — it matches the pre-refactor arithmetic — so no action needed, just flagging in case you want to reconcile the Javadoc semantics later.

oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java (2)

55-66: buildCounterIndexMap parsing looks correct.

The odd-length tolerance (length > 1, step-2 from i=1), the idx > 0 filter via parseIntOrDefault(..., 0), and putIfAbsent (first-wins on duplicate names, matching Perflib’s localized-English array semantics) are all sound. Returning Collections.unmodifiableMap on the internal HashMap makes the public contract safe.

Optional nit: if counterText[i] is ever null, it would be inserted as a null key. In practice the Perflib array never contains nulls, so this is defensive only — feel free to skip.


80-102: getCounterIndices correctly skips enum[0] and fails closed.

Iterating from i=1 (skipping the instance-name enum constant), returning null on any missing lookup, and building an EnumMap keyed by the enum class are all appropriate. Debug-level logs avoid spamming production.

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

55-97: Clean delegation to the new common base.

Extending HkeyPerformanceDataUtil and routing readPerfDataFromRegistry through getCounterIndices(objectName, counterEnum, COUNTER_INDEX_MAP) removes the duplicate FFM/JNA implementations while preserving the static-init lookup cache. The new getCounterIndex(String) with a 0 default is a reasonable public addition for callers that only need a single English-counter index.


275-286: Fallback to buildCounterIndexMap(null) on failure is a nice touch.

Returning the unmodifiable empty map produced by buildCounterIndexMap(null) (instead of a fresh Collections.emptyMap()) keeps the returned-map contract identical between success and failure paths. COUNTER_INDEX_MAP.get(...) / getOrDefault(..., 0) callers downstream therefore behave consistently.

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

64-73: Perfmon-disabled guard now added — resolves prior review.

The PerfmonDisabledFFM.PERF_PROC_DISABLED short-circuit brings the FFM path to parity with ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters, and delegation to the common ThreadPerformanceData.buildThreadMapFromPerfCounters keeps the conversion logic single-sourced. Note that the guard’s correctness is coupled to PerfmonDisabledFFM's registry read — see the separate comment on that file.

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

26-73: Straightforward JNA delegator — behavior-preserving split.

Signatures mirror the original ThreadPerformanceData API, the overload chain (pids → pids, null, -1) preserves call sites, and PerfmonDisabled.PERF_PROC_DISABLED / Util.isBlank(procName) gating match the pre-refactor logic. No concerns.

oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java (2)

41-74: Registry builder: ctime > now heuristic preserved correctly.

The conditional conversion if (ctime > now) ctime = ParseUtil.filetimeToUtcMs(ctime, false); is the right shape here — raw filetime values (100-ns since 1601) are far larger than any ms-since-1970 now, so the guard reliably distinguishes pre- vs. post-converted inputs without changing behavior relative to the previous WinBase.FILETIME.filetimeToDate(ctime).getTime() call.


84-122: Perf-counter builder: null-guard and unified FILETIME conversion look good.

Returning null when instanceValues == null cleanly matches the callers in ProcessPerformanceDataJNA/ProcessPerformanceDataFFM (context snippets 2 and 3), and the switch to ParseUtil.filetimeToUtcMs(ctime, false) keeps the arithmetic identical to the prior JNA path.

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

27-39: Tests correctly follow the new JNA entry points.

Switching to ProcessPerformanceDataJNA.buildProcessMapFromRegistry(null) / ThreadPerformanceDataJNA.buildThreadMapFromRegistry(null) tracks the refactor — the non-null/non-empty assertions remain valid because the JNA delegators now drive both the registry read and the map assembly.

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

37-60: The exception handling concern is incorrect; the 3-arg registryGetValue already catches all Throwables internally.

The 3-arg registryGetValue(rootKey, keyPath, valueName) overload does not declare throws Throwable. It wraps the entire method body in a try/catch block that catches Throwable and returns null on any error—including missing keys/values, access denied, or other failures. No exception escapes to the caller and no ExceptionInInitializerError risk exists.

The suggestion to align with the JNA path by checking registryValueExists() first is valid for consistency, but not critical since the current behavior (returning null on any error) is semantically equivalent.

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

39-61: Clean delegation to the common implementation — LGTM.

Both entry points correctly forward to oshi.driver.common.windows.registry.ProcessPerformanceData, the PERFDATA gate is preserved for the registry path, and the PerfmonDisabledFFM.PERF_PROC_DISABLED short-circuit is now mirrored here (matching ThreadPerformanceDataFFM). The unused procName overload has also been removed, so the FFM surface is consistent with the common API.

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from ec37da5 to f937bb3 Compare April 18, 2026 19:28

@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/perfmon/PerfCounter.java (1)

29-34: Optional: avoid double endsWith scan in the constructor.

stripBaseSuffix(counterName) and isBase(counterName) each call endsWith(BASE_SUFFIX). Not a hot path, but a single check would be slightly cleaner and also guards against a future divergence between the two helpers.

♻️ Proposed refactor
     public PerfCounter(String objectName, String instanceName, String counterName) {
         this.object = objectName;
         this.instance = instanceName;
-        this.counter = stripBaseSuffix(counterName);
-        this.baseCounter = isBase(counterName);
+        this.baseCounter = isBase(counterName);
+        this.counter = this.baseCounter
+                ? counterName.substring(0, counterName.length() - BASE_SUFFIX.length())
+                : counterName;
     }
🤖 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/perfmon/PerfCounter.java`
around lines 29 - 34, The constructor PerfCounter currently calls
stripBaseSuffix(counterName) and isBase(counterName) which each invoke
endsWith(BASE_SUFFIX); refactor the constructor to perform a single
endsWith(BASE_SUFFIX) check on counterName, set baseCounter from that boolean,
and then set counter to either counterName without the BASE_SUFFIX or the
original name (use the same strip logic inline or via a new private helper that
accepts the boolean) while keeping object and instance assignment unchanged;
reference symbols: PerfCounter(String objectName, String instanceName, String
counterName), stripBaseSuffix, isBase, BASE_SUFFIX, and fields
object/instance/counter/baseCounter.
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (1)

134-142: Optional: reuse PerfCounter.getCounterPath() instead of a local duplicate.

The private counterPath(object, instance, counter) helper duplicates PerfCounter.getCounterPath(). Since the class is now imported and already used for isBase/stripBaseSuffix, the queryCounters / queryWildcardCounters sites could construct a PerfCounter and call getCounterPath(), eliminating the local helper and the parallel isBase/counterName/path bookkeeping (the PerfCounter already holds both the normalized name and the isBaseCounter() flag).

Non-blocking; it just avoids the centralized logic existing in two places.

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

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`
around lines 134 - 142, The private helper counterPath(object, instance,
counter) duplicates logic already in PerfCounter.getCounterPath(); remove this
local helper and update uses in queryCounters and queryWildcardCounters to
construct a PerfCounter (or reuse existing PerfCounter instances) and call
getCounterPath() instead, and stop maintaining parallel state such as
isBase/stripBaseSuffix/counterName there—use PerfCounter.isBaseCounter() and
PerfCounter's normalized name getters so all path/name/isBase bookkeeping comes
from PerfCounter.
oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java (1)

26-102: Consider a final utility class instead of abstract with only static members.

HkeyPerformanceDataUtil has no instance state or abstract methods — buildCounterIndexMap and getCounterIndices are pure static helpers. The abstract modifier only serves to prevent instantiation (which the protected no-op constructor would already accomplish), and the JNA/FFM subclasses extend it purely to gain unqualified access to protected static helpers. Making the class final with public static helpers (matching the PerfCounter style used elsewhere in this refactor) would be more idiomatic and avoid the "abstract class with only static members" smell. Entirely optional and can be deferred.

🤖 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/HkeyPerformanceDataUtil.java`
around lines 26 - 102, Change HkeyPerformanceDataUtil from an abstract class to
a final utility class: declare the class final, make the no-arg constructor
private to prevent instantiation, and change the helper methods
buildCounterIndexMap and getCounterIndices from protected static to public
static so callers (including former subclasses) can use them without
inheritance; update any callers that relied on subclassing to reference
HkeyPerformanceDataUtil.buildCounterIndexMap(...) and
HkeyPerformanceDataUtil.getCounterIndices(...).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java`:
- Around line 366-372: queryMatchingThreads calls this.getName(), which can be
null when invoked from updateAttributes before the process name is set; fix by
passing an explicit procName into queryMatchingThreads (derived from the current
ProcessCpu/ProcessBasicInfo object, e.g., pcb.getName()) or by reordering
updateAttributes so the pcb name is populated before calling
queryMatchingThreads; update the queryMatchingThreads signature/use sites to
accept and use a non-null procName (instead of this.getName()) and fall back to
existing behavior only when procName is blank.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java`:
- Around line 29-34: The constructor PerfCounter currently calls
stripBaseSuffix(counterName) and isBase(counterName) which each invoke
endsWith(BASE_SUFFIX); refactor the constructor to perform a single
endsWith(BASE_SUFFIX) check on counterName, set baseCounter from that boolean,
and then set counter to either counterName without the BASE_SUFFIX or the
original name (use the same strip logic inline or via a new private helper that
accepts the boolean) while keeping object and instance assignment unchanged;
reference symbols: PerfCounter(String objectName, String instanceName, String
counterName), stripBaseSuffix, isBase, BASE_SUFFIX, and fields
object/instance/counter/baseCounter.

In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java`:
- Around line 26-102: Change HkeyPerformanceDataUtil from an abstract class to a
final utility class: declare the class final, make the no-arg constructor
private to prevent instantiation, and change the helper methods
buildCounterIndexMap and getCounterIndices from protected static to public
static so callers (including former subclasses) can use them without
inheritance; update any callers that relied on subclassing to reference
HkeyPerformanceDataUtil.buildCounterIndexMap(...) and
HkeyPerformanceDataUtil.getCounterIndices(...).

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`:
- Around line 134-142: The private helper counterPath(object, instance, counter)
duplicates logic already in PerfCounter.getCounterPath(); remove this local
helper and update uses in queryCounters and queryWildcardCounters to construct a
PerfCounter (or reuse existing PerfCounter instances) and call getCounterPath()
instead, and stop maintaining parallel state such as
isBase/stripBaseSuffix/counterName there—use PerfCounter.isBaseCounter() and
PerfCounter's normalized name getters so all path/name/isBase bookkeeping comes
from PerfCounter.
🪄 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: be68617a-807b-424e-8a30-0547d05714a2

📥 Commits

Reviewing files that changed from the base of the PR and between ec37da5 and f937bb3.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (5)
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (14)
📓 Common learnings
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: 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
📚 Learning: 2026-04-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-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-common/src/main/java/oshi/driver/common/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/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

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

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
🔇 Additional comments (10)
oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java (1)

200-259: LGTM.

Both overloads mirror the existing registryGetStringArray open/close pattern, correctly swallow failures with a debug log on close-only errors, and registryValueExists now treats ERROR_INSUFFICIENT_BUFFER as a hit alongside ERROR_SUCCESS/ERROR_MORE_DATA.

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

41-135: LGTM.

Signature refactor to accept pre-fetched threadData/instanceValues cleanly centralizes map construction, null-in → null-out is consistent across both builders, and the unconditional ParseUtil.filetimeToUtcMs(startTime, false) matches the PDH counter always returning a 1601-epoch FILETIME.

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

41-122: LGTM.

Conditional ctime > now FILETIME conversion (vs. the unconditional conversion in ThreadPerformanceData) correctly preserves the original semantics where process ELAPSEDTIME may arrive pre-converted on the registry path. Null-in → null-out contract is consistent with the thread variant.

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

40-191: LGTM.

The delegation to the shared base class is clean, getCounterIndices null-check at line 68 correctly gates all downstream COUNTER_INDEX_MAP usage (including readPerfDataBuffer at line 157), and the ParseUtil.filetimeToUtcMs(perfTime100nSec, false) replacement is equivalent to the removed FILETIME.filetimeToDate(...).getTime() for 1601-epoch 100ns input.

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

25-61: LGTM.

The prior concerns about the dropped procName overload and the missing PERF_PROC_DISABLED short-circuit are both resolved. The registry path correctly honors PERFDATA (null triplet → common delegate returns null) and the PDH path now mirrors the FFM/thread-JNA early-exit pattern.

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

23-60: LGTM.

Mirrors the JNA PerfmonDisabled semantics faithfully: config wins when set, otherwise a registry REG_DWORD > 0 is the sole trigger; any other value (null, non-Integer, non-positive) defaults to "not disabled". The zero-length MemorySegment.ofAddress(HKEY_LOCAL_MACHINE) handle is consistent with the existing Advapi32UtilFFM.registryGetStringArray(rootKey, ...) pattern.

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

38-73: LGTM.

Past concern about the missing PerfmonDisabled guard on the FFM path is resolved via PerfmonDisabledFFM.PERF_PROC_DISABLED, achieving parity with ThreadPerformanceDataJNA. The procName/threadNum dispatch to ThreadInformationFFM.queryThreadCounters is preserved and correct.

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

26-73: LGTM — clean delegator.

The class is a straightforward thin adapter over ThreadPerformanceData and HkeyPerformanceDataUtilJNA, with correct PERF_PROC_DISABLED short-circuit and Util.isBlank(procName) branching matching the prior JNA behavior.

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

25-28: LGTM — delegation and null-tolerance look correct.

Mechanical swap to ProcessPerformanceDataJNA/ThreadPerformanceDataJNA is consistent, and the added pcb == null/wts == null guards at 285-286 are an appropriate defensive improvement given the delegate contracts.

Also applies to: 276-286, 367-369

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

56-60: LGTM — consistent JNA delegation.

All call sites have been uniformly updated to the *JNA entry points (both memoized static helpers and the on-demand fallbacks in processMapToList), matching the changes in WindowsOSProcess and preserving the registry-first-then-perf-counters semantics.

Also applies to: 304-304, 313-313, 329-343

Comment on lines 366 to 372
protected Map<Integer, ThreadPerfCounterBlock> queryMatchingThreads(Set<Integer> pids) {
Map<Integer, ThreadPerfCounterBlock> threads = ThreadPerformanceData.buildThreadMapFromRegistry(pids);
Map<Integer, ThreadPerfCounterBlock> threads = ThreadPerformanceDataJNA.buildThreadMapFromRegistry(pids);
if (threads == null) {
threads = ThreadPerformanceData.buildThreadMapFromPerfCounters(pids, this.getName(), -1);
threads = ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters(pids, this.getName(), -1);
}
return threads;
}

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

Minor: this.getName() may be stale/null on first call.

queryMatchingThreads is invoked from updateAttributes() at line 282 before this.name is populated at lines 285-286, so this.getName() can be null on the initial pass. Util.isBlank(null) inside the delegate safely falls back to the unfiltered queryThreadCounters(), so behavior is correct — but if you intended to actually filter by process name on the perf-counter fallback, consider deriving procName from pcb.getName() or reordering so updateAttributes(pcb, wts) runs before queryMatchingThreads.

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

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java`
around lines 366 - 372, queryMatchingThreads calls this.getName(), which can be
null when invoked from updateAttributes before the process name is set; fix by
passing an explicit procName into queryMatchingThreads (derived from the current
ProcessCpu/ProcessBasicInfo object, e.g., pcb.getName()) or by reordering
updateAttributes so the pcb name is populated before calling
queryMatchingThreads; update the queryMatchingThreads signature/use sites to
accept and use a non-null procName (instead of this.getName()) and fall back to
existing behavior only when procName is blank.

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from f937bb3 to cd0b96a Compare April 18, 2026 19:39

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

200-259: LGTM on the new overloads.

Both registryGetValue(rootKey, keyPath, valueName) and registryValueExists(rootKey, keyPath, valueName) correctly wrap open/close in try/finally, log (rather than throw) on close failure, and use a catch-all Throwable → null/false per the null-tolerant contract their caller (PerfmonDisabledFFM.isDisabled) relies on. The previous feedback on including ERROR_INSUFFICIENT_BUFFER in registryValueExists is already resolved at line 249.

Optional nit: the open-key/close-key scaffolding here duplicates the pattern in registryGetStringArray and registryGetKeys(rootKey, ...). If more of these accrue, consider a small withOpenKey(rootKey, keyPath, Function<MemorySegment, T>) helper. No action needed now.

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

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java`
around lines 200 - 259, The open-key/close-key pattern in
registryGetValue(rootKey, keyPath, valueName) and registryValueExists(rootKey,
keyPath, valueName) is duplicated elsewhere (see registryGetStringArray and
registryGetKeys); refactor by introducing a small helper method (e.g.,
withOpenKey or runWithOpenKey) that takes (MemorySegment rootKey, String
keyPath, Function<MemorySegment, T> action) to encapsulate RegOpenKeyEx,
RegCloseKey and the try/finally handling, then rewrite registryGetValue,
registryValueExists, registryGetStringArray and registryGetKeys to call this
helper passing the lambda that performs the RegQuery/RegEnum work so open/close
logging and error handling are centralized.
oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java (1)

27-60: LGTM — behavior matches the JNA counterpart.

Static-init registry reads are safe because Advapi32UtilFFM.registryGetValue(root, path, name) swallows Throwable and returns null, so class loading can't fail here. The isDisabled precedence (config override → registry DWORD → default false) mirrors the JNA flag semantics consumed by ProcessPerformanceDataFFM / ThreadPerformanceDataFFM (short-circuit when true).

Minor: Util.isBlank per oshi-common/.../Util.java only treats null/empty as blank (not whitespace-only), so a config value of " " would fall through to Boolean.parseBoolean and evaluate to false rather than triggering the registry fallback. If you want to match a common "blank" intuition here you could perfDisabled.trim() before the check, but this matches existing OSHI behavior elsewhere so it's fine to leave as-is.

🤖 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/perfmon/PerfmonDisabledFFM.java`
around lines 27 - 60, Trim the retrieved config value before blank-checking and
parsing in PerfmonDisabledFFM.isDisabled: assign perfDisabled =
GlobalConfig.get(config); then compute a trimmed variable (e.g., String perf =
perfDisabled == null ? null : perfDisabled.trim()), use Util.isBlank(perf) for
the registry fallback, and use Boolean.parseBoolean(perf) for the boolean parse
so whitespace-only config values behave as blank; update references to
perfDisabled in isDisabled accordingly.
oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java (1)

26-34: Abstract class with no abstract members.

HkeyPerformanceDataUtil is declared abstract but exposes only static helpers and a protected no-arg constructor, with no abstract methods. The extends relationship in HkeyPerformanceDataUtilFFM therefore doesn't actually enforce any contract — the subclasses could equally well be standalone utilities calling these statics. Consider either:

  • Adding an abstract method that captures the platform-specific native read (e.g. protected abstract String[] readPerflibCounterText()), so the base class genuinely owns the template-method flow, or
  • Making this a final utility class with a private constructor and letting the JNA/FFM adapters simply reference the statics (current JNA variant already does this per the AI summary).

Purely a design-clarity suggestion; behavior is fine as-is.

🤖 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/HkeyPerformanceDataUtil.java`
around lines 26 - 34, HkeyPerformanceDataUtil is declared abstract but has no
abstract members; either make it a true utility class or turn it into a template
base: Option A (preferred simple change): convert HkeyPerformanceDataUtil to a
final utility class by removing the abstract modifier, replace the protected
no-arg constructor with a private no-arg constructor, and keep the static helper
methods as-is; then update HkeyPerformanceDataUtilFFM to call the static helpers
directly. Option B (if you want a template method): add a protected abstract
String[] readPerflibCounterText() to HkeyPerformanceDataUtil, implement that
method in HkeyPerformanceDataUtilFFM (and any other subclass) so the base class
can own any shared template flow, and retain the protected constructor; choose
one approach and apply consistently across HkeyPerformanceDataUtil and
HkeyPerformanceDataUtilFFM.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java`:
- Around line 46-66: Update the Javadoc on buildCounterIndexMap to accurately
describe the counterText array format and the index/name ordering: state that
the array is pairs of "<index>", "<name>" (e.g. "2","System","4","Memory",...)
where even positions (0,2,4,...) hold numeric index strings and odd positions
(1,3,5,...) hold the corresponding counter names; reference the counterText
parameter so readers see this matches the parsing in buildCounterIndexMap which
reads idx = counterText[i-1] and name = counterText[i].

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java`:
- Around line 26-34: HkeyPerformanceDataUtil is declared abstract but has no
abstract members; either make it a true utility class or turn it into a template
base: Option A (preferred simple change): convert HkeyPerformanceDataUtil to a
final utility class by removing the abstract modifier, replace the protected
no-arg constructor with a private no-arg constructor, and keep the static helper
methods as-is; then update HkeyPerformanceDataUtilFFM to call the static helpers
directly. Option B (if you want a template method): add a protected abstract
String[] readPerflibCounterText() to HkeyPerformanceDataUtil, implement that
method in HkeyPerformanceDataUtilFFM (and any other subclass) so the base class
can own any shared template flow, and retain the protected constructor; choose
one approach and apply consistently across HkeyPerformanceDataUtil and
HkeyPerformanceDataUtilFFM.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java`:
- Around line 27-60: Trim the retrieved config value before blank-checking and
parsing in PerfmonDisabledFFM.isDisabled: assign perfDisabled =
GlobalConfig.get(config); then compute a trimmed variable (e.g., String perf =
perfDisabled == null ? null : perfDisabled.trim()), use Util.isBlank(perf) for
the registry fallback, and use Boolean.parseBoolean(perf) for the boolean parse
so whitespace-only config values behave as blank; update references to
perfDisabled in isDisabled accordingly.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java`:
- Around line 200-259: The open-key/close-key pattern in
registryGetValue(rootKey, keyPath, valueName) and registryValueExists(rootKey,
keyPath, valueName) is duplicated elsewhere (see registryGetStringArray and
registryGetKeys); refactor by introducing a small helper method (e.g.,
withOpenKey or runWithOpenKey) that takes (MemorySegment rootKey, String
keyPath, Function<MemorySegment, T> action) to encapsulate RegOpenKeyEx,
RegCloseKey and the try/finally handling, then rewrite registryGetValue,
registryValueExists, registryGetStringArray and registryGetKeys to call this
helper passing the lambda that performs the RegQuery/RegEnum work so open/close
logging and error handling are centralized.
🪄 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: d2966332-f28d-4014-922b-2f81867e4538

📥 Commits

Reviewing files that changed from the base of the PR and between f937bb3 and cd0b96a.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (3)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
🚧 Files skipped from review as they are similar to previous changes (11)
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (14)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.
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/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.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/util/platform/windows/Advapi32UtilFFM.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.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/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/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-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.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-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
🔇 Additional comments (8)
oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java (1)

2-2: LGTM.

The copyright year update is consistent with the PR timestamp and does not introduce any functional risk.

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

2-2: LGTM.

The copyright year update is straightforward and safe.


15-15: LGTM.

Switching to the shared oshi.driver.common.windows.perfmon.PerfCounter keeps this handler aligned with the common perfmon abstraction introduced by the PR.

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

80-102: LGTM on getCounterIndices.

Enum iteration starting at 1 (skipping the instance/name sentinel), null-return semantics on any missing index, and the EnumMap result all match the prior JNA behavior and align with the contract the FFM/JNA adapters rely on. Debug-level logging on misses is appropriate since callers handle null as a recoverable "counters unavailable" signal.

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

5-5: LGTM — the common-thread-data extraction looks consistent.

The platform-specific data fetch stays in the JNA/FFM wrappers, the shared builders clearly document their null-input behavior, and the UTC FILETIME conversion via ParseUtil.filetimeToUtcMs(..., false) preserves the intended start-time handling.

Also applies to: 14-14, 19-20, 25-28, 34-42, 84-94, 118-118

oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java (2)

41-74: LGTM — clean extraction of map-builder logic.

The refactor correctly separates platform-specific data acquisition from the shared map-building logic. The processData == null guard preserves the prior "disabled/failed" semantics that the JNA wrapper relied on (when PERFDATA config is off).

The ctime > now heuristic to detect unconverted FILETIME values (100-ns since 1601, ~10^17) vs. epoch millis (~10^13) is preserved, and ParseUtil.filetimeToUtcMs(ctime, false) is semantically equivalent to the previous WinBase.FILETIME.filetimeToDate(ctime).getTime() — both yield UTC ms since 1970.


84-122: LGTM — perf-counter flow mirrors registry flow consistently.

Accepting a caller-supplied Pair keeps this method free of JNA/FFM query internals and allows each wrapper to handle its own counter acquisition. Null-guard, filtering, and uptime clamping match the registry flow for behavioral consistency.

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

21-39: LGTM — test correctly delegates to new JNA wrappers.

Switching to ProcessPerformanceDataJNA / ThreadPerformanceDataJNA matches the refactor direction: the JNA wrappers own HKEY_PERFORMANCE_DATA acquisition and PERFDATA gating, while the common classes only build the map. The imports for ProcessPerfCounterBlock / ThreadPerfCounterBlock from oshi.driver.common.windows.registry align with the moved types. Assertions on non-null/non-empty remain valid given PERFDATA defaults to true.

@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from cd0b96a to 6d57f70 Compare April 18, 2026 20:00

@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 (1)
oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java (1)

22-24: Stale class-level Javadoc.

After the refactor, this class no longer reads from HKEY_PERFORMANCE_DATA directly (that’s delegated to HkeyPerformanceDataUtilFFM) and no longer has any WMI fallback. Consider updating the Javadoc to reflect that it now builds thread maps by delegating to HkeyPerformanceDataUtilFFM + common ThreadPerformanceData, or by querying PerfMon via ThreadInformationFFM.

📝 Proposed doc tweak
-/**
- * Utility to read thread data from HKEY_PERFORMANCE_DATA information with backup from Performance Counters or WMI
- */
+/**
+ * Utility to read thread data from HKEY_PERFORMANCE_DATA information with backup from Performance Counters.
+ * Delegates map construction to {`@link` oshi.driver.common.windows.registry.ThreadPerformanceData}.
+ */
🤖 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 22 - 24, The class Javadoc for ThreadPerformanceDataFFM is stale:
it still claims to read from HKEY_PERFORMANCE_DATA and use a WMI fallback even
though the implementation now delegates HKEY reads to HkeyPerformanceDataUtilFFM
and builds thread maps via shared ThreadPerformanceData or by querying PerfMon
through ThreadInformationFFM; update the class-level Javadoc to accurately
describe the current behavior (delegates HKEY reads to
HkeyPerformanceDataUtilFFM, no WMI fallback, constructs thread maps using
ThreadPerformanceData and/or ThreadInformationFFM) and remove references to
direct HKEY_PERFORMANCE_DATA access and WMI fallback so the comment matches the
code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java`:
- Around line 106-109: In ProcessPerformanceData where you convert PDH FILETIME
values (ctime = elapsedTimeList.get(inst)) using ParseUtil.filetimeToUtcMs(...),
change the conversion to use the PDH/local FILETIME variant by passing
local=true (i.e., call ParseUtil.filetimeToUtcMs(ctime, true)) so PDH results
from queryProcessCounters()/ProcessInformation* are interpreted as local time
and creation time/uptime aren’t skewed on non-UTC systems.

---

Nitpick comments:
In
`@oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java`:
- Around line 22-24: The class Javadoc for ThreadPerformanceDataFFM is stale: it
still claims to read from HKEY_PERFORMANCE_DATA and use a WMI fallback even
though the implementation now delegates HKEY reads to HkeyPerformanceDataUtilFFM
and builds thread maps via shared ThreadPerformanceData or by querying PerfMon
through ThreadInformationFFM; update the class-level Javadoc to accurately
describe the current behavior (delegates HKEY reads to
HkeyPerformanceDataUtilFFM, no WMI fallback, constructs thread maps using
ThreadPerformanceData and/or ThreadInformationFFM) and remove references to
direct HKEY_PERFORMANCE_DATA access and WMI fallback so the comment matches the
code.
🪄 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: a69c255a-ffe8-4625-9729-455c9976ec18

📥 Commits

Reviewing files that changed from the base of the PR and between cd0b96a and 6d57f70.

📒 Files selected for processing (22)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.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/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.java
✅ Files skipped from review due to trivial changes (5)
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java
  • oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.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/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.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 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (16)
📓 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`.
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.
📚 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/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.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/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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/util/platform/windows/PerfDataUtil.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.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/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.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/driver/windows/registry/ProcessPerformanceDataJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.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/HkeyPerformanceDataUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.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-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java
🔇 Additional comments (10)
oshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.java (1)

208-226: Looks good.

The new root-key/path overloads correctly scope the opened key, close it in finally, and treat size-probe return codes consistently in registryValueExists().

Also applies to: 237-258

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

27-31: Looks good.

The FFM disabled-counter gate mirrors the expected config-first, registry-fallback flow and keeps invalid registry value types non-fatal.

Also applies to: 37-59

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

57-68: Looks good.

The shared parsing and index-resolution helpers preserve the previous fail-fast lookup behavior while centralizing the JNA/FFM duplicate logic.

Also applies to: 82-104

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

67-84: Looks good.

The JNA adapter now delegates shared index parsing/resolution cleanly, and the returned objectIndex/enumIndexMap are used consistently in the registry parse loop.

Also applies to: 90-123, 180-190

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

41-73: Registry map delegation looks good.

The null-on-missing-data contract is preserved, and the shared builder keeps the PID filtering and _Total exclusion in one place.

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

39-45: Looks good.

The JNA wrapper is now a thin platform-specific data fetcher, and the PerfProc-disabled short-circuit avoids issuing PDH process queries when they are known to be disabled.

Also applies to: 55-60

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

29-36: Looks good.

The tests now target the JNA-backed registry drivers, which matches the production refactor while preserving the existing non-empty map assertions.

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

39-45: Looks good.

The FFM wrapper now mirrors the JNA delegation shape and correctly short-circuits PerfProc-disabled systems before querying process counters.

Also applies to: 55-60

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

5-135: LGTM — clean extraction of shared thread-perf map-building logic.

The two entry points now accept pre-fetched data with consistent null propagation, and the FILETIME conversion switch to ParseUtil.filetimeToUtcMs(startTime, false) matches the unified conversion used elsewhere in this PR. The now - 1 clamp for future start times is preserved, and the unsigned start-address handling in the registry path (lines 72-73) is unchanged.

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

64-73: PerfmonDisabled guard parity with JNA — looks good.

The PerfmonDisabledFFM.PERF_PROC_DISABLED short-circuit now matches ThreadPerformanceDataJNA, addressing the earlier parity concern. Delegation to the common ThreadPerformanceData.buildThreadMapFromPerfCounters is correct.

Comment on lines 106 to 109
long ctime = elapsedTimeList.get(inst);
// if creation time value is less than current millis, it's in 1970 epoch,
// otherwise it's 1601 epoch and we must convert
if (ctime > now) {
ctime = WinBase.FILETIME.filetimeToDate((int) (ctime >> 32), (int) (ctime & 0xffffffffL)).getTime();
ctime = ParseUtil.filetimeToUtcMs(ctime, false);
}

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

Use the PDH/local FILETIME conversion here.

This path consumes ProcessInformation*.queryProcessCounters() PDH results, and ParseUtil.filetimeToUtcMs documents local=true for PDH counter FILETIME values. Passing false can skew process creation time and uptime on non-UTC systems.

🐛 Proposed fix
                 long ctime = elapsedTimeList.get(inst);
                 if (ctime > now) {
-                    ctime = ParseUtil.filetimeToUtcMs(ctime, false);
+                    ctime = ParseUtil.filetimeToUtcMs(ctime, true);
                 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
long ctime = elapsedTimeList.get(inst);
// if creation time value is less than current millis, it's in 1970 epoch,
// otherwise it's 1601 epoch and we must convert
if (ctime > now) {
ctime = WinBase.FILETIME.filetimeToDate((int) (ctime >> 32), (int) (ctime & 0xffffffffL)).getTime();
ctime = ParseUtil.filetimeToUtcMs(ctime, false);
}
long ctime = elapsedTimeList.get(inst);
if (ctime > now) {
ctime = ParseUtil.filetimeToUtcMs(ctime, true);
}
🤖 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/ProcessPerformanceData.java`
around lines 106 - 109, In ProcessPerformanceData where you convert PDH FILETIME
values (ctime = elapsedTimeList.get(inst)) using ParseUtil.filetimeToUtcMs(...),
change the conversion to use the PDH/local FILETIME variant by passing
local=true (i.e., call ParseUtil.filetimeToUtcMs(ctime, true)) so PDH results
from queryProcessCounters()/ProcessInformation* are interpreted as local time
and creation time/uptime aren’t skewed on non-UTC systems.

- Extract PerfCounter POJO from PerfDataUtil inner class to
  oshi.driver.common.windows.perfmon.PerfCounter with BASE_SUFFIX
  constant and isBase()/stripBaseSuffix() helper methods
- Extract HkeyPerformanceDataUtil abstract base class with shared
  getCounterIndices() logic, buildCounterIndexMap() parsing, and
  HKEY_PERFORMANCE_TEXT/COUNTER constants
- Extract ProcessPerformanceData and ThreadPerformanceData common
  logic (buildProcessMapFromRegistry, buildProcessMapFromPerfCounters,
  buildThreadMapFromRegistry, buildThreadMapFromPerfCounters) to
  oshi-common utility classes
- Rename JNA implementations to *JNA suffix (HkeyPerformanceDataUtilJNA,
  ProcessPerformanceDataJNA, ThreadPerformanceDataJNA)
- Unify FILETIME conversion to ParseUtil.filetimeToUtcMs() across both
  JNA and FFM code paths
- Update PerfDataUtilFFM to use PerfCounter helpers and shared constants
  instead of local duplicates
- Update all callers in WindowsOSProcess, WindowsOperatingSystem,
  WindowsOSThread, and test classes
@dbwiddis
dbwiddis force-pushed the extract-common-windows-drivers branch from 6d57f70 to e74f939 Compare April 18, 2026 20:10
@dbwiddis
dbwiddis merged commit 7536db8 into oshi:master Apr 18, 2026
16 of 17 checks passed
@dbwiddis
dbwiddis deleted the extract-common-windows-drivers branch April 18, 2026 20:56
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