Repository navigation
Extract common Windows perfmon/registry driver code to oshi-common - #3172
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds 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
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>
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify 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. Comment |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
📒 Files selected for processing (19)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-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.javaoshi-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.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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.readPerfDataFromRegistryandProcessInformationJNA.queryProcessCounters(per provided context snippets), and theprocessData == null → nullcontract is preserved. The FILETIME branch viaParseUtil.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
startTimeis consistently converted from a FILETIME viaParseUtil.filetimeToUtcMs(startTime, false)(ELAPSEDTIME is annotated as filetime in the value map), and registry-path upTime arithmetic is unchanged. Input types align withHkeyPerformanceDataUtilJNA.readPerfDataFromRegistry/ThreadInformationJNA.queryThreadCountersper provided snippets.oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java (1)
27-97: LGTM — clean swap to the sharedPerfCountertype.
PerfCounter.createCounter(object, instance, counter)has the same parameter order and return type as the removedPerfDataUtil.createCounter, and downstreamPerfCounterQueryHandlerstill consumescounter.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 honorsprocName/threadNumviaThreadInformationJNA.queryThreadCounters(procName, threadNum), so the observed behavior ofupdateAttributes()is unchanged.oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java (1)
29-173: LGTM — mechanical import/factory swap only.Per-instance
PerfCounterconstruction continues to feedpdhQueryHandler.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/ThreadPerformanceDataJNAare the new registry-reading wrappers; since the common classes no longer self-query, calling them from tests would returnnullinstead 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 providedParseUtilcontext.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
aa4a35c to
6b7affd
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (1)
388-402: Optional: reuse sharedbuildCounterIndexMapto avoid duplicated parsing.
lookupPerfIndexByEnglishNamere-parses the same registry array thatHkeyPerformanceDataUtil.buildCounterIndexMap(...)already centralizes (alternating index/name pairs). Since it's protected to the shared base, you could expose it (or a small helper) and domap.getOrDefault(name, 0). The current inline loop works and only runs on cache miss inLOCALIZE_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
finalwith 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 inProcessPerformanceData.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
📒 Files selected for processing (20)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-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.javaoshi-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 — sharedPerfCounterwiring 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: SamePerfmonDisabledparity concern asThreadPerformanceDataFFM.This FFM entry point does not consult
PerfmonDisabled.PERF_PROC_DISABLED, unlike the JNA counterpart. See the verification request onThreadPerformanceDataFFM.buildThreadMapFromPerfCounters— the same question applies here (whetherProcessInformationFFM.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 inheritedHKEY_PERFORMANCE_TEXT/COUNTERconstants, and delegation tobuildCounterIndexMap(...)andgetCounterIndices(objectName, counterEnum, COUNTER_INDEX_MAP)all line up with the shared contracts. The fallbackbuildCounterIndexMap(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
queryCountersandqueryWildcardCountersnow delegate_Basedetection/strip toPerfCounter.isBase/PerfCounter.stripBaseSuffix, keeping the existingsecondValue-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 thePerfmonDisabledshort-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 onPerfmonDisabled.PERF_PROC_DISABLEDbefore 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)yieldsctime/10_000 - EPOCH_DIFF, i.e. 100ns-since-1601 → ms-since-1970 UTC, which matches the previousWinBase.FILETIME.filetimeToDate(ctime).getTime()behavior. Thectime > nowheuristic (distinguishing raw FILETIME from already-converted ms) is preserved correctly in both branches.Also applies to: 103-106
6b7affd to
58f6c16
Compare
There was a problem hiding this comment.
🧹 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 oninstanceValues.
buildProcessMapFromRegistryexplicitly returnsnullwhen its pre-fetched input isnull(lines 43–45, and documented in the Javadoc). The siblingbuildProcessMapFromPerfCountersis now also a public API accepting caller-supplied data, but unconditionally dereferencesinstanceValues.getA()/getB()and will NPE if a caller passesnull(e.g., if a futurequeryProcessCounters()implementation signals failure withnullrather than an emptyPair). 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.
registryValueExistsandregistryGetValueeach callRegOpenKeyEx/RegCloseKeyindependently, so this path opens the same key twice at class init for each of the three services. BecauseregistryGetValuealready returnsnullwhen 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-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.javaoshi-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_HKEYPERFDATAgating (passingnullwhen disabled, which the commonbuildProcessMapFromRegistryhandles by returningnull), and the perf-counter path now correctly exposes only the single-arg variant, consistent with the resolution to the priorprocName-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
registryValueExistscorrectly treatsERROR_SUCCESS/ERROR_MORE_DATAas existence signals for a NULLlpDataprobe. SwallowingThrowableto returnnull/falseis 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 (unlikeregistryGetStringArrayabove, 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_DISABLEDshort-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 commonThreadPerformanceData.buildThreadMapFromRegistrypreserves the existing null-return semantics, and the Javadoc correction onpidsnow matches the shared contract (process IDs, not thread IDs). Caller atWindowsOperatingSystemFFMhandlesnullor empty by falling back to the registry path, so returningCollections.emptyMap()here is correct.oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.java (1)
15-15: SharedPerfCountermigration 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: CommonPerfCounterusage 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.registryis exported from theoshi-commonmodule (line 25 ofoshi-common/src/main/java/module-info.java), so JPMS builds inoshi-coreandoshi-core-java25will resolve the import correctly.oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (3)
43-44: Single-counter_Basehandling is cleanly centralized.Delegating suffix detection and stripping to common
PerfCounterkeeps the FFM path aligned with the shared perfmon model.Also applies to: 93-95
318-320: Wildcard_Basehandling preserves alignment behavior.The refactor only centralizes suffix stripping while keeping the per-property
isBasetracking and existing abort-on-add-failure flow intact. Based on learnings,queryWildcardCountersintentionally aborts when anyaddEnglishCountercall 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.
58f6c16 to
2a3d918
Compare
There was a problem hiding this comment.
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 classfinalto match@Immutable.All fields are already
final; making the classfinalprevents 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:lookupPerfIndexByEnglishNamere-reads registry + rebuilds index map on each call.Each invocation does a fresh
registryGetStringArrayand a fullbuildCounterIndexMap. This is effectively amortized becauselocalizeObjectNamecaches perperfObjectviaLOCALIZE_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-initializedConcurrentHashMapfield) 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-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.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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
buildCounterIndexMapand missing-counter early return ingetCounterIndicesare 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.filetimeToUtcMsunifies FILETIME conversion with the FFM path.COUNTER_INDEX_MAP.get(objectName)inreadPerfDataBufferis safe becausegetCounterIndiceshas already validatedobjectNamebefore this is reached.oshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.java (1)
23-60: LGTM!FFM counterpart of
PerfmonDisabledlooks correct: GlobalConfig override takes precedence, registry fallback correctly type-checks theDisable Performance CountersDWORD, 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
ThreadPerformanceDatais correct, and thePERF_PROC_DISABLEDshort-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.PerfCounterto the sharedoshi.driver.common.windows.perfmon.PerfCounterwithcreateCounter(...)— PDH flow unchanged.oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java (1)
88-105: LGTM —_Basehandling consolidated throughPerfCounter.Both single-counter and wildcard paths now use
PerfCounter.isBase(...)/PerfCounter.stripBaseSuffix(...), and the wildcard path correctly tracks per-propertyisBasestate in parallel withcounterHandles. 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 viaThreadInformationJNA) from the shared parsing logic inoshi.driver.common.windows.registry.ThreadPerformanceData. ThePerfmonDisabled.PERF_PROC_DISABLEDshort-circuit and theprocName/threadNumoverload selection look correct and mirror the pattern inProcessPerformanceDataJNA.One minor note for consideration:
buildThreadMapFromRegistrydoes not guard onPerfmonDisabledthe waybuildThreadMapFromPerfCountersdoes, but this mirrorsProcessPerformanceDataJNA(which uses aPERFDATAgate) — 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*JNAdelegates.Imports (lines 56, 60) and all six call sites (lines 304, 313, 330, 334, 338, 342) are updated consistently. The new
ProcessPerformanceDataJNA/ThreadPerformanceDataJNAmethods 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
PROCESSconstant 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
Pairshape 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
PROCESSconstant.Also applies to: 40-43
54-55: Perf-counter delegation looks correct.
ProcessInformationFFM.queryProcessCounters()returns the exactPair<List<String>, Map<ProcessPerformanceProperty, List<Long>>>shape expected by the common builder.
2a3d918 to
3c59044
Compare
There was a problem hiding this comment.
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
Arenavia try-with-resources, close the opened subkey infinally, and adopt null/false-on-failure semantics that match the consumer inPerfmonDisabledFFM.java(which usesinstanceofon the result). TheregistryValueExistsprobe correctly treatsERROR_MORE_DATAas 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 theRegCloseKeyreturn 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 singleget+ null-check.
containsKey(...)followed byget(...)does two lookups per key. UsingInteger idx = counterIndexMap.get(...);once and branching onidx == nullis slightly cleaner and avoids the redundancy (safe here because indices stored in the map are always> 0, perbuildCounterIndexMap). 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-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 previousWinBase.FILETIME.filetimeToDate(...).getTime()for a UTC FILETIME (both computeft/10_000 - EPOCH_DIFF).getCounterIndices(objectName, counterEnum, COUNTER_INDEX_MAP)preserves the "skip first enum constant" contract andnull-on-miss behavior.mapCounterIndicesFromRegistry()correctly funnels both success andWin32Exceptionpaths throughbuildCounterIndexMap(...), keeping the unmodifiable-map invariant.oshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java (2)
70-78: LGTM —getCounterIndexdefault is consistent with caller expectations.Returning
0for an unknown name is the correct sentinel here because the sole caller (PerfDataUtilFFM.localizeUsingPerfIndex) explicitly checksif (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 viabuildCounterIndexMap(null).Routing both success and exception paths through
buildCounterIndexMap(...)keeps the returnedCOUNTER_INDEX_MAPshape 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_Basehandling and registry-index plumbing is delegated appropriately.Suffix detection/stripping through
PerfCounter.isBase/PerfCounter.stripBaseSuffixmatches the previous inlineendsWith/substringlogic in both the single-counter and wildcard paths, and the per-counterisBase[p-1]alignment in the wildcard path is preserved. ThelookupPerfIndexByEnglishNamedelegation toHkeyPerformanceDataUtilFFM.getCounterIndexreplaces 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
nullon missing input and otherwise transform caller-supplied data, making them platform-agnostic and suitable for oshi-common. Thectime > nowheuristic andupTimefloor (< 1 → 1) preserve prior behavior, andParseUtil.filetimeToUtcMs(ctime, false)is semantically equivalent to the previousFILETIME.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 unconditionalfiletimeToUtcMs+ clamp-to-now-1for future start times preserves the pre-refactor behavior for perf-counter thread start times. The registry path's(perfTime100nSec - ELAPSEDTIME) / 10_000Luptime 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 forPERF_PROC_DISABLEDshort-circuit.The guard addresses the prior divergence and ensures both code paths respect
oshi.os.windows.perfmon.disabledidentically. Delegation toThreadPerformanceData.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
ThreadPerformanceDataFFMmodulo JNA/FFM type prefixes, with the samePERF_PROC_DISABLEDshort-circuit andUtil.isBlank(procName)dispatch. Centralizing the transform inThreadPerformanceDatakeeps 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.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.java (2)
74-96: Minor: ReplacecontainsKey+getwith 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-nullIntegers, a singleget(...)+ 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:abstractwithout abstract members or protected constructor.The class is declared
abstractyet exposes onlyprotected statichelpers 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 staticon a final utility class (with a private constructor) aligns with the rest ofoshi-commonutilities 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-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.javaoshi-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.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-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.javaoshi-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: The0sentinel forgetCounterIndexis correctly validated by all callers.The only caller in
PerfDataUtilFFM.localizeUsingPerfIndex()explicitly checksif (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.
3c59044 to
156f5cf
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java (2)
29-39: Constructor duplicatesstripBaseSuffix/isBaselogic.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.
createCounterjust 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 usenew 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-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.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-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
PerfCounterandcreateCounterfactory is consistent with the migration tooshi.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_000with the<1clamp, and the perf-counter path correctly treatsELAPSEDTIMEas a FILETIME viaParseUtil.filetimeToUtcMs(startTime, false)with the> nowclamp preserved. ThenameIndex++remains inside the PID-filter branch, matching the previous behavior, and thenullshort-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 > nowguard beforeParseUtil.filetimeToUtcMs(ctime, false)correctly preserves the original dual-interpretation ofELAPSEDTIME(already-epoch-ms for registry path vs. raw FILETIME). The registry-side_Totalexclusion is retained; the perf-counter path correctly relies on the caller'sWHERE NOT NAME LIKE '_Total'WHERE clause inProcessInformation(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=falseor the registry read fails,processDataisnulland the common transformer returnsnull, 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_DISABLEDflag viaProcessInformationJNA.queryProcessCounters()(which checksPerfmonDisabled.PERF_PROC_DISABLEDand returns an empty Pair), whereas the FFM implementation adds a check at the wrapper level inProcessPerformanceDataFFM.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.
buildCounterIndexMapis null-safe and returns an unmodifiable map even on empty input, andgetCounterIndicespreserves the existing "all-or-nothing" contract by returningnullwhen any required lookup is missing — matching the prior JNA behavior and keeping both downstream implementations consistent.Using
protected statichelpers on anabstractclass (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
HkeyPerformanceDataUtiland routingmapCounterIndicesFromRegistry/getCounterIndicesthrough the shared helpers preserves the existing semantics: the counter index map is unmodifiable, the exception path yields an empty (unmodifiable) map viabuildCounterIndexMap(null), andreadPerfDataFromRegistrystill bails out early when either object or per-enum index resolution fails.Also applies to: 275-286
70-78: The0sentinel for "not found" is already properly guarded at the only call site.The single caller of
getCounterIndexislookupPerfIndexByEnglishNameat line 387 inPerfDataUtilFFM.java, which is invoked fromlocalizeUsingPerfIndex(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 tolookupPerfNameByIndex. No action needed.oshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.java (3)
180-191: LGTM — parse-error handling correctly moved intoparseIntOrDefault.Dropping the explicit
NumberFormatExceptioncatch is correct becauseParseUtil.parseIntOrDefault(invoked inside the sharedbuildCounterIndexMap) already handles malformed entries by returning the default. ReturningbuildCounterIndexMap(null)onWin32Exceptionpreserves the previous "empty unmodifiable map" failure contract.
40-48: No action required. Verification found no lingering references to the oldHkeyPerformanceDataUtilclass name in the codebase. The class is located in adriversubpackage, 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 identicalfalseflag, 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 inParseUtilTest.javavalidates the conversion algorithm.
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
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 | 🟠 MajorPreserve 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-awareupdateAttributes(...), andqueryMatchingThreads(...)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: reusePerfCounter.getCounterPath()instead of the privatecounterPathhelper.Now that
PerfCounterlives inoshi-commonand 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 onPerfCounter).🤖 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/test/java/oshi/driver/windows/registry/RegistryDriversTest.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-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.javaoshi-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.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-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.javaoshi-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
nullwhen 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,
queryWildcardCountersintentionally 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
nullon 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
finallywhile preserving the documentednull-on-failure contract.
237-259: Existence probe handles the expected size-query return codes.Including
ERROR_SUCCESS,ERROR_MORE_DATA, andERROR_INSUFFICIENT_BUFFERkeeps 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
buildCounterIndexMapkeeps 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;
_Basesuffix handling is consistently suffix-only across the constructor,isBase, andstripBaseSuffix. 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 —_Basesuffix handling centralized correctly.Both
queryCountersandqueryWildcardCountersnow consistently route throughPerfCounter.isBase/PerfCounter.stripBaseSuffix, and the resulting base-flag is propagated toreadRawCounterValueto selectSecondValue. The wildcard path still aborts with an emptyPairon anyaddEnglishCounterfailure, 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
ThreadPerformanceDatabuilders, and short-circuits onPERF_PROC_DISABLEDbefore hitting PDH. TheUtil.isBlank(procName)dispatch correctly preserves bothqueryThreadCounters()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 > nowFILETIME heuristic, and useParseUtil.filetimeToUtcMs(ctime, false)which is equivalent to the previousWinBase.FILETIME.filetimeToDate(...).getTime()path (treating the raw 100-ns value as UTC)._Totalexclusion 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
ProcessPerformanceDatabuilders is clean, and thePerfmonDisabledFFM.PERF_PROC_DISABLEDshort-circuit before PDH querying matches the pattern used elsewhere (ThreadPerformanceDataFFM,ThreadPerformanceDataJNA). Previous feedback on the droppedprocNameoverload 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/ThreadPerformanceDataJNAis a clean lift; control flow inprocessMapToListis unchanged. Note thePERF_PROC_DISABLEDconsistency concern raised onProcessPerformanceDataJNA.buildProcessMapFromPerfCounterswill also benefit this call site once addressed.oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.java (1)
27-27: LGTM.The common
PerfCounterimport 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
PerfCounterwiring 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.
156f5cf to
ec37da5
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java (1)
274-280: PasspidstobuildProcessMapFromRegistryinstead ofnull.On Line 276,
nullis passed even though the single-PIDpidsset is already computed on Line 274 and correctly forwarded to both the perf-counter fallback (Line 279) andqueryProcessWtsMap(Line 284). The commonbuildProcessMapFromRegistry(pids, processData)uses that collection as a PID filter — passingnulldisables 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-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 ofPerfCounter.Removal of the nested
PerfCounterclass andcreateCounterfactory is consistent with the migration tooshi.driver.common.windows.perfmon.PerfCounter. Remaining PDH helper methods are unchanged and theImmutableimport cleanup is appropriate.oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java (1)
29-29: LGTM — switched to sharedPerfCounter.Import and constructor call correctly delegate to the new
oshi.driver.common.windows.perfmon.PerfCounter. Behavior ofqueryInstancesAndValuesFromPDH(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 < 1floor and the uint32/uint64STARTADDRESSdemotion).
91-135: PerfCounter path conversion preserves prior behavior.
ParseUtil.filetimeToUtcMs(startTime, false)with the subsequentstartTime > nowclamp matches the old semantics (raw filetime → ms-since-1970, no TZ adjustment), and null-guard oninstanceValuescorrectly aligns with the JNA/FFM callers passing throughqueryThreadCounters()results.One subtle note: the ParseUtil Javadoc (context snippet 4) describes
local=falseas “already UTC (WMI PerfRawData classes)”, butELAPSEDTIMEhere 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:buildCounterIndexMapparsing looks correct.The odd-length tolerance (
length > 1, step-2 fromi=1), theidx > 0filter viaparseIntOrDefault(..., 0), andputIfAbsent(first-wins on duplicate names, matching Perflib’s localized-English array semantics) are all sound. ReturningCollections.unmodifiableMapon the internal HashMap makes the public contract safe.Optional nit: if
counterText[i]is evernull, 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:getCounterIndicescorrectly skips enum[0] and fails closed.Iterating from
i=1(skipping the instance-name enum constant), returningnullon any missing lookup, and building anEnumMapkeyed 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
HkeyPerformanceDataUtiland routingreadPerfDataFromRegistrythroughgetCounterIndices(objectName, counterEnum, COUNTER_INDEX_MAP)removes the duplicate FFM/JNA implementations while preserving the static-init lookup cache. The newgetCounterIndex(String)with a0default is a reasonable public addition for callers that only need a single English-counter index.
275-286: Fallback tobuildCounterIndexMap(null)on failure is a nice touch.Returning the unmodifiable empty map produced by
buildCounterIndexMap(null)(instead of a freshCollections.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_DISABLEDshort-circuit brings the FFM path to parity withThreadPerformanceDataJNA.buildThreadMapFromPerfCounters, and delegation to the commonThreadPerformanceData.buildThreadMapFromPerfCounterskeeps the conversion logic single-sourced. Note that the guard’s correctness is coupled toPerfmonDisabledFFM'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
ThreadPerformanceDataAPI, the overload chain (pids→pids, null, -1) preserves call sites, andPerfmonDisabled.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 > nowheuristic 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-1970now, so the guard reliably distinguishes pre- vs. post-converted inputs without changing behavior relative to the previousWinBase.FILETIME.filetimeToDate(ctime).getTime()call.
84-122: Perf-counter builder: null-guard and unified FILETIME conversion look good.Returning
nullwheninstanceValues == nullcleanly matches the callers inProcessPerformanceDataJNA/ProcessPerformanceDataFFM(context snippets 2 and 3), and the switch toParseUtil.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 declarethrows Throwable. It wraps the entire method body in atry/catchblock that catchesThrowableand returnsnullon any error—including missing keys/values, access denied, or other failures. No exception escapes to the caller and noExceptionInInitializerErrorrisk exists.The suggestion to align with the JNA path by checking
registryValueExists()first is valid for consistency, but not critical since the current behavior (returningnullon 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, thePERFDATAgate is preserved for the registry path, and thePerfmonDisabledFFM.PERF_PROC_DISABLEDshort-circuit is now mirrored here (matchingThreadPerformanceDataFFM). The unusedprocNameoverload has also been removed, so the FFM surface is consistent with the common API.
ec37da5 to
f937bb3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
oshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.java (1)
29-34: Optional: avoid doubleendsWithscan in the constructor.
stripBaseSuffix(counterName)andisBase(counterName)each callendsWith(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: reusePerfCounter.getCounterPath()instead of a local duplicate.The private
counterPath(object, instance, counter)helper duplicatesPerfCounter.getCounterPath(). Since the class is now imported and already used forisBase/stripBaseSuffix, thequeryCounters/queryWildcardCounterssites could construct aPerfCounterand callgetCounterPath(), eliminating the local helper and the parallelisBase/counterName/path bookkeeping (thePerfCounteralready holds both the normalized name and theisBaseCounter()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 afinalutility class instead ofabstractwith only static members.
HkeyPerformanceDataUtilhas no instance state or abstract methods —buildCounterIndexMapandgetCounterIndicesare pure static helpers. Theabstractmodifier 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 toprotected statichelpers. Making the classfinalwithpublic statichelpers (matching thePerfCounterstyle 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-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.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-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.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-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.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-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.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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
registryGetStringArrayopen/close pattern, correctly swallow failures with a debug log on close-only errors, andregistryValueExistsnow treatsERROR_INSUFFICIENT_BUFFERas a hit alongsideERROR_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/instanceValuescleanly centralizes map construction, null-in → null-out is consistent across both builders, and the unconditionalParseUtil.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 > nowFILETIME conversion (vs. the unconditional conversion inThreadPerformanceData) 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,
getCounterIndicesnull-check at line 68 correctly gates all downstream COUNTER_INDEX_MAP usage (includingreadPerfDataBufferat line 157), and theParseUtil.filetimeToUtcMs(perfTime100nSec, false)replacement is equivalent to the removedFILETIME.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
procNameoverload and the missingPERF_PROC_DISABLEDshort-circuit are both resolved. The registry path correctly honorsPERFDATA(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
PerfmonDisabledsemantics faithfully: config wins when set, otherwise a registry REG_DWORD> 0is the sole trigger; any other value (null, non-Integer, non-positive) defaults to "not disabled". The zero-lengthMemorySegment.ofAddress(HKEY_LOCAL_MACHINE)handle is consistent with the existingAdvapi32UtilFFM.registryGetStringArray(rootKey, ...)pattern.oshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.java (1)
38-73: LGTM.Past concern about the missing
PerfmonDisabledguard on the FFM path is resolved viaPerfmonDisabledFFM.PERF_PROC_DISABLED, achieving parity withThreadPerformanceDataJNA. TheprocName/threadNumdispatch toThreadInformationFFM.queryThreadCountersis 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
ThreadPerformanceDataandHkeyPerformanceDataUtilJNA, with correctPERF_PROC_DISABLEDshort-circuit andUtil.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/ThreadPerformanceDataJNAis consistent, and the addedpcb == null/wts == nullguards 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
*JNAentry points (both memoized static helpers and the on-demand fallbacks inprocessMapToList), matching the changes inWindowsOSProcessand preserving the registry-first-then-perf-counters semantics.Also applies to: 304-304, 313-313, 329-343
| 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; | ||
| } |
There was a problem hiding this comment.
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.
f937bb3 to
cd0b96a
Compare
There was a problem hiding this comment.
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)andregistryValueExists(rootKey, keyPath, valueName)correctly wrap open/close in try/finally, log (rather than throw) on close failure, and use a catch-allThrowable→ null/false per the null-tolerant contract their caller (PerfmonDisabledFFM.isDisabled) relies on. The previous feedback on includingERROR_INSUFFICIENT_BUFFERinregistryValueExistsis already resolved at line 249.Optional nit: the open-key/close-key scaffolding here duplicates the pattern in
registryGetStringArrayandregistryGetKeys(rootKey, ...). If more of these accrue, consider a smallwithOpenKey(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)swallowsThrowableand returnsnull, so class loading can't fail here. TheisDisabledprecedence (config override → registry DWORD → default false) mirrors the JNA flag semantics consumed byProcessPerformanceDataFFM/ThreadPerformanceDataFFM(short-circuit when true).Minor:
Util.isBlankperoshi-common/.../Util.javaonly treats null/empty as blank (not whitespace-only), so a config value of" "would fall through toBoolean.parseBooleanand evaluate tofalserather than triggering the registry fallback. If you want to match a common "blank" intuition here you couldperfDisabled.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.
HkeyPerformanceDataUtilis declaredabstractbut exposes only static helpers and a protected no-arg constructor, with no abstract methods. Theextendsrelationship inHkeyPerformanceDataUtilFFMtherefore 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-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.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-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.javaoshi-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.javaoshi-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.javaoshi-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.PerfCounterkeeps 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 ongetCounterIndices.Enum iteration starting at 1 (skipping the instance/name sentinel), null-return semantics on any missing index, and the
EnumMapresult 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 handlenullas 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 == nullguard preserves the prior "disabled/failed" semantics that the JNA wrapper relied on (whenPERFDATAconfig is off).The
ctime > nowheuristic to detect unconverted FILETIME values (100-ns since 1601, ~10^17) vs. epoch millis (~10^13) is preserved, andParseUtil.filetimeToUtcMs(ctime, false)is semantically equivalent to the previousWinBase.FILETIME.filetimeToDate(ctime).getTime()— both yield UTC ms since 1970.
84-122: LGTM — perf-counter flow mirrors registry flow consistently.Accepting a caller-supplied
Pairkeeps 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/ThreadPerformanceDataJNAmatches the refactor direction: the JNA wrappers ownHKEY_PERFORMANCE_DATAacquisition andPERFDATAgating, while the common classes only build the map. The imports forProcessPerfCounterBlock/ThreadPerfCounterBlockfromoshi.driver.common.windows.registryalign with the moved types. Assertions on non-null/non-empty remain valid givenPERFDATAdefaults totrue.
cd0b96a to
6d57f70
Compare
There was a problem hiding this comment.
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 toHkeyPerformanceDataUtilFFM+ commonThreadPerformanceData, or by querying PerfMon viaThreadInformationFFM.📝 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
📒 Files selected for processing (22)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/perfmon/PerfCounter.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataJNA.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOSThread.javaoshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-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.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ThreadPerformanceData.javaoshi-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.javaoshi-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.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/util/platform/windows/Advapi32UtilFFM.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/HkeyPerformanceDataUtil.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ThreadPerformanceDataFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-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.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-core/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataJNA.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-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.javaoshi-core-java25/src/main/java/oshi/driver/windows/registry/ProcessPerformanceDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/PerfCounterQueryHandler.javaoshi-core-java25/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabledFFM.javaoshi-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.javaoshi-common/src/main/java/oshi/driver/common/windows/registry/ProcessPerformanceData.javaoshi-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 inregistryValueExists().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/enumIndexMapare 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
_Totalexclusion 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
nullpropagation, and the FILETIME conversion switch toParseUtil.filetimeToUtcMs(startTime, false)matches the unified conversion used elsewhere in this PR. Thenow - 1clamp 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_DISABLEDshort-circuit now matchesThreadPerformanceDataJNA, addressing the earlier parity concern. Delegation to the commonThreadPerformanceData.buildThreadMapFromPerfCountersis correct.
| 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); | ||
| } |
There was a problem hiding this comment.
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.
| 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
6d57f70 to
e74f939
Compare
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 fromPerfDataUtil.PerfCounterinner class. Contains_Basesuffix handling, counter path building,BASE_SUFFIXconstant, andisBase()/stripBaseSuffix()helper methods.HkeyPerformanceDataUtil— Abstract base class withHKEY_PERFORMANCE_TEXT/COUNTERconstants,buildCounterIndexMap()(parses alternating index/name pairs from registry), andgetCounterIndices()(resolves enum counter names to indices).ProcessPerformanceData— Static utility withbuildProcessMapFromRegistry()andbuildProcessMapFromPerfCounters()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 innerPerfCounterclass, now imports from oshi-commonParseUtil.filetimeToUtcMs()(removing JNAWinBase.FILETIME.filetimeToDatedependency)Updated in oshi-core-java25
HkeyPerformanceDataUtilFFM— Extends common class, removed duplicategetCounterIndices()and map-building logicProcessPerformanceDataFFM/ThreadPerformanceDataFFM— Thin wrappers delegating to common classPerfDataUtilFFM— UsesPerfCounter.isBase()/stripBaseSuffix()helpers and shared constants instead of local duplicatesResult
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