Skip to content

Migrate all remaining Windows hardware classes to FFM three-tier pattern - #3176

Merged
dbwiddis merged 7 commits into
oshi:masterfrom
dbwiddis:migrate-windows-hal
Apr 20, 2026
Merged

dbwiddis merged 7 commits into
oshi:masterfrom
dbwiddis:migrate-windows-hal

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Completes the FFM migration of the entire Windows HardwareAbstractionLayer by migrating all remaining hardware classes to the common/JNA/FFM three-tier pattern. After this PR, every Windows hardware component has a pure-FFM implementation in oshi-core-java25.

Changes

New FFM implementations (oshi-core-java25)

  • WindowsCentralProcessorFFM — processor topology, CPU ticks, frequencies, load average, feature flags
  • WindowsHWDiskStoreFFM — disk enumeration, partition mapping, I/O statistics
  • WindowsGraphicsCardFFM — GPU enumeration via registry + DXGI adapter matching
  • WindowsGpuStatsFFM — GPU metrics via NVML, ADL, perfmon, and IOReport
  • WindowsDisplayFFM — display EDID via SetupAPI/Cfgmgr32
  • WindowsUsbDeviceFFM — USB device tree via Cfgmgr32
  • WindowsGlobalMemoryFFM — physical/virtual memory via Psapi + perfmon
  • WindowsVirtualMemoryFFM — swap/paging statistics
  • WindowsSensorsFFM — temperature, fan, voltage via WMI + LibreHardwareMonitor
  • WindowsSoundCardFFM — sound card enumeration via WMI
  • WindowsNetworkIfFFM — network interface stats via IPHlpAPI
  • WindowsLogicalVolumeGroupFFM — LVM enumeration via WMI + command line

New FFM drivers/bindings

  • LogicalProcessorInformationFFM — parses GetLogicalProcessorInformationEx binary structures (cores, packages, NUMA nodes, caches, efficiency classes, multi-group support)
  • DeviceTreeFFM — device tree traversal via Cfgmgr32 FFM bindings
  • Cfgmgr32FFM — Configuration Manager FFM bindings (CM_Get_Child, CM_Get_Sibling, CM_Get_DevNode_Registry_Property, CM_Get_Device_ID)
  • DxgiFFM — DXGI adapter enumeration via COM/FFM
  • AdlUtilFFM — AMD Display Library (ADL) Overdrive N metrics
  • Kernel32FFM additions — GetNativeSystemInfo, GetSystemTimes, IsProcessorFeaturePresent, GetLogicalProcessorInformationEx, CallNtPowerInformation
  • SetupApiFFM additions — SetupDiEnumDeviceInfo, SetupDiOpenDevRegKey
  • IPHlpAPIFFM fixes — corrected MIB_IF_ROW2 field offsets

Common superclasses extracted to oshi-common

  • WindowsCentralProcessor — shared tick processing, NUMA node mapping, processor identifier parsing, utility counter logic
  • WindowsHWDiskStore — shared disk/partition enumeration and WMI-to-disk mapping logic
  • WindowsGlobalMemory — shared memory calculation logic
  • DxgiUtil / DxgiAdapterInfo — shared DXGI adapter matching and VRAM parsing (moved from oshi-core)

JNA class renames (oshi-core)

All Windows hardware classes renamed with JNA suffix to distinguish from FFM counterparts:

  • WindowsCentralProcessor → WindowsCentralProcessorJNA
  • WindowsHWDiskStore → WindowsHWDiskStoreJNA
  • WindowsGraphicsCard → WindowsGraphicsCardJNA
  • WindowsDisplay → WindowsDisplayJNA
  • WindowsUsbDevice → WindowsUsbDeviceJNA
  • WindowsGlobalMemory → WindowsGlobalMemoryJNA
  • WindowsGpuStats → WindowsGpuStatsJNA
  • WindowsSensors → WindowsSensorsJNA
  • WindowsSoundCard → WindowsSoundCardJNA
  • WindowsNetworkIF → WindowsNetworkIfJNA
  • WindowsLogicalVolumeGroup → WindowsLogicalVolumeGroupJNA
  • WindowsHardwareAbstractionLayer → WindowsHardwareAbstractionLayerJNA

Stats

  • 48 files changed, ~4989 insertions, ~928 deletions
  • 6 commits covering 5 logical batches of work

Testing

  • All existing tests pass (unit + integration)
  • FFM implementations validated against JNA via the existing comparison test suite
  • Builds clean with spotless, checkstyle, forbiddenapis, and javadoc checks

Summary by CodeRabbit

  • Refactor
    • Windows hardware stack reorganized and unified to provide consistent JNA and FFM backends for Windows device and telemetry queries.
  • New Features
    • Broader, more reliable Windows telemetry and device enumeration: improved GPU detection/stats, CPU topology/load, memory/virtual memory, disks/partitions, displays, network interfaces, USB and sound devices, and sensors.
  • Documentation
    • Changelog updated for the upcoming release.

Create FFM implementations for WindowsSensors, WindowsGpuStats,
WindowsGlobalMemory, WindowsVirtualMemory, WindowsLogicalVolumeGroup,
WindowsSoundCard, and WindowsNetworkIF.

- Rename JNA classes to *JNA suffix
- Extract shared memory type parsing to common superclass
  WindowsGlobalMemory in oshi.hardware.common.platform.windows
- Add PERFORMANCE_INFORMATION layout to PsapiFFM
- Add GetIfEntry2 binding and MIB_IF_ROW2 offsets to IPHlpAPIFFM
- Wire up FFM HAL with all new implementations
- WindowsGpuStatsFFM skips ADL (no FFM impl yet), uses NVML/LHM/PDH
- Move DxgiAdapterInfo POJO to oshi-common (oshi.driver.common.windows.gpu)
- Extract shared logic to DxgiUtil (findMatch, normalizeName, registryValueToVram, PCI bus parsing)
- Create DxgiFFM: FFM COM vtable binding to dxgi.dll for adapter enumeration
- Create AdlUtilFFM: FFM binding to AMD Display Library (atiadlxx.dll)
- Create WindowsGraphicsCardFFM: full FFM port using DxgiFFM, Advapi32UtilFFM, LhmSensorFFM
- Update WindowsGpuStatsFFM: add ADL support for temperature, power, clocks, fan
- Rename WindowsGraphicsCard -> WindowsGraphicsCardJNA
- Update DxgiUtilJNA to delegate pure-logic methods to common DxgiUtil
- Create Cfgmgr32FFM: FFM binding to CfgMgr32.dll for device tree traversal
- Create DeviceTreeFFM: FFM equivalent of DeviceTree driver
- Create WindowsDisplayFFM: uses SetupApiFFM + Advapi32FFM for EDID registry reads
- Create WindowsUsbDeviceFFM: uses DeviceTreeFFM for USB device enumeration
- Add SetupDiEnumDeviceInfo and SetupDiOpenDevRegKey to SetupApiFFM
- Rename WindowsDisplay -> WindowsDisplayJNA
- Rename WindowsUsbDevice -> WindowsUsbDeviceJNA
- Update WindowsHardwareAbstractionLayerFFM with getDisplays/getUsbDevices overrides
- Extract common superclass WindowsHWDiskStore to oshi-common with shared
  fields, updateAttributes(), PDH result processing, WMI regex matching,
  and partition list assembly logic
- Rename WindowsHWDiskStore to WindowsHWDiskStoreJNA in oshi-core
- Create WindowsHWDiskStoreFFM in oshi-core-java25 using Kernel32FFM,
  PhysicalDiskFFM, and WMI FFM drivers
- Update WindowsHardwareAbstractionLayerFFM with getDiskStores() override
- Create WindowsCentralProcessor common superclass in oshi-common with
  shared non-native logic (parseIdentifier, lazilyCalculateMultiplier,
  buildNumaNodeProcMap, processTickData, config constants)
- Rename WindowsCentralProcessor to WindowsCentralProcessorJNA
- Rename WindowsHardwareAbstractionLayer to WindowsHardwareAbstractionLayerJNA
- Create WindowsCentralProcessorFFM using Advapi32FFM, Kernel32FFM,
  VersionHelpersFFM, ProcessorInformationFFM, LoadAverageFFM
- Create LogicalProcessorInformationFFM driver parsing
  GetLogicalProcessorInformationEx binary structures via FFM
- Add Kernel32FFM methods: GetNativeSystemInfo, GetSystemTimes,
  IsProcessorFeaturePresent, GetLogicalProcessorInformationEx,
  CallNtPowerInformation
- Update WindowsHardwareAbstractionLayerFFM to extend
  AbstractHardwareAbstractionLayer directly with createProcessor override
@coderabbitai

coderabbitai Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Centralizes Windows GPU types/utilities into a shared package, adds many FFM bindings and FFM-backed Windows implementations, introduces shared Windows base classes (CPU/memory/disk), refactors JNA implementations to extend those bases, updates module exports/imports, and adjusts tests/imports.

Changes

Cohort / File(s) Summary
Changelog & Module Export
CHANGELOG.md, oshi-common/src/main/java/module-info.java
Added a changelog bullet for PR #3176 and exported package oshi.driver.common.windows.gpu.
Shared GPU Package
oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiAdapterInfo.java, .../DxgiUtil.java, .../package-info.java
Moved DxgiAdapterInfo to shared package; added DxgiUtil with adapter-matching, VRAM parsing, name normalization, LUID/PCI parsing helpers; added package javadoc.
Shared Windows Base Classes
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java, .../WindowsGlobalMemory.java, .../WindowsHWDiskStore.java
Added abstract Windows base classes centralizing NUMA/utility/tick processing, memory type/SMBIOS mapping, and disk-store counters/partition helpers.
FFM Native Bindings
oshi-core-java25/src/main/java/oshi/ffm/windows/{Cfgmgr32FFM,DxgiFFM,IPHlpAPIFFM,Kernel32FFM,PsapiFFM,SetupApiFFM}.java
Added/extended FFM downcalls and safe wrappers for Cfgmgr32, DXGI, IPHlpAPI, Kernel32, Psapi, SetupAPI (device tree, adapter enumeration, NICs, topology, perf/registry access).
FFM Windows Implementations
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/*FFM.java
Added many FFM-backed hardware implementations (CentralProcessorFFM, GlobalMemoryFFM, HWDiskStoreFFM, VirtualMemoryFFM, GpuStatsFFM, GraphicsCardFFM, DisplayFFM, NetworkIfFFM, LogicalVolumeGroupFFM, SensorsFFM, SoundCardFFM, UsbDeviceFFM).
GPU / ADL Utilities & Topology
oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java, .../LogicalProcessorInformationFFM.java, .../DeviceTreeFFM.java
Added ADL FFM helper, logical-processor topology parser, and device-tree enumerator for Windows.
JNA Refactor & JNA Implementations
oshi-core/src/main/java/oshi/hardware/platform/windows/*JNA.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
Renamed many JNA classes with JNA suffix; refactored JNA implementations to extend new common Windows base classes; added JNA-backed disk-store implementation.
HAL Routing & SystemInfo
oshi-core-java25/.../WindowsHardwareAbstractionLayerFFM.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java, oshi-core/src/main/java/oshi/SystemInfo.java
Added FFM HAL class overrides and updated JNA HAL class; SystemInfo now selects the JNA HAL on Windows.
Imports, Delegation & Tests
oshi-core/src/main/java/oshi/jna/platform/windows/Dxgi.java, .../gpu/DxgiUtilJNA.java, .../test/*DxgiUtilTest.java, .../test/WindowsGraphicsCardTest.java
Updated imports to shared DxgiAdapterInfo; delegated JNA-side Dxgi util calls to shared DxgiUtil; updated tests to reference renamed classes/helpers.

Sequence Diagram(s)

sequenceDiagram
    participant App as SystemInfo
    participant HAL as WindowsHardwareAbstractionLayerJNA/FFM
    participant Impl as WindowsGraphicsCardJNA/FFM
    participant DXGI as DxgiFFM / Dxgi (JNA)
    participant Registry as SetupApiFFM / Cfgmgr32FFM
    participant Util as DxgiUtil

    App->>HAL: createHardware() / getGraphicsCards()
    HAL->>Impl: getGraphicsCards()
    Impl->>DXGI: queryAdapters()
    DXGI-->>Impl: List<DxgiAdapterInfo>
    Impl->>Registry: enumerate adapter registry entries
    Registry-->>Impl: registry/device info
    Impl->>Util: findMatch(adapters, registry values)
    Util-->>Impl: matched adapter (VRAM, LUID, PCI id)
    Impl-->>HAL: List<GraphicsCard>
    HAL-->>App: GraphicsCard list
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

Suggested reviewers

  • mprins

Poem

A tiny GUID in native land,
types and helpers join the band.
FFM, JNA, and Dxgi spin,
shared bases help the work begin.
🎉🖥️🔧

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Migrate all remaining Windows hardware classes to FFM three-tier pattern' is specific, concise, and directly describes the main change: completing the migration of Windows hardware components to the FFM three-tier architecture pattern.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.58889% with 1076 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.34%. Comparing base (d0ea166) to head (e5653a2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java 14.28% 180 Missing ⚠️
.../hardware/platform/windows/WindowsGpuStatsFFM.java 27.69% 115 Missing and 26 partials ⚠️
...i/hardware/platform/windows/WindowsSensorsFFM.java 26.16% 108 Missing and 19 partials ⚠️
...dware/platform/windows/WindowsGraphicsCardFFM.java 34.66% 81 Missing and 17 partials ⚠️
...e/platform/windows/WindowsCentralProcessorFFM.java 54.71% 71 Missing and 25 partials ⚠️
...platform/windows/WindowsLogicalVolumeGroupFFM.java 15.58% 62 Missing and 3 partials ⚠️
...e/common/platform/windows/WindowsGlobalMemory.java 3.27% 58 Missing and 1 partial ⚠️
...mmon/platform/windows/WindowsCentralProcessor.java 45.26% 39 Missing and 13 partials ⚠️
...hardware/platform/windows/WindowsUsbDeviceFFM.java 21.15% 39 Missing and 2 partials ⚠️
...c/main/java/oshi/driver/windows/DeviceTreeFFM.java 39.65% 32 Missing and 3 partials ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3176      +/-   ##
==========================================
- Coverage   58.45%   57.34%   -1.12%     
==========================================
  Files         395      414      +19     
  Lines       18295    19919    +1624     
  Branches     3205     3496     +291     
==========================================
+ Hits        10694    11422     +728     
- Misses       6006     6770     +764     
- Partials     1595     1727     +132     
Flag Coverage Δ
linux 23.10% <1.31%> (-2.16%) ⬇️
macos 26.04% <1.31%> (-2.31%) ⬇️
windows 34.68% <47.58%> (+0.94%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 8

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/hardware/platform/windows/WindowsVirtualMemory.java (1)

33-54: ⚠️ Potential issue | 🟡 Minor

Naming convention inconsistency within oshi-core JNA classes.

WindowsVirtualMemory lacks the JNA suffix despite its sibling WindowsGlobalMemoryJNA having one. Both are JNA implementations in oshi-core. The FFM counterpart WindowsVirtualMemoryFFM exists in oshi-core-java25, so the dual-implementation structure is in place. Confirm this naming asymmetry is intentional; if not, consider renaming to WindowsVirtualMemoryJNA for consistency with the global memory class.

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

In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.java`
around lines 33 - 54, Rename the class WindowsVirtualMemory to
WindowsVirtualMemoryJNA and update its constructor signature (currently
WindowsVirtualMemory(WindowsGlobalMemoryJNA windowsGlobalMemory)) and any
internal references (e.g., the private final WindowsGlobalMemoryJNA global field
and any usages of WindowsVirtualMemory in this module) to match the new name;
ensure the memoized supplier fields (used, totalVmaxVused, swapInOut) and the
logger LOG remain unchanged, and update any external references or imports
elsewhere in the codebase that reference WindowsVirtualMemory so they point to
WindowsVirtualMemoryJNA to keep naming consistent with WindowsGlobalMemoryJNA
and the existing WindowsVirtualMemoryFFM counterpart.
🧹 Nitpick comments (11)
oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java (1)

186-196: Benign race on lazy enumeration.

adaptersEnumerated is a plain volatile boolean, so two concurrent first-callers can both pass the check and both call enumerateAdapters before either sets BUS_TO_INDEX. The result is equivalent (idempotent work), but if you want to avoid the duplicate native calls you can guard with synchronized or a CAS on an AtomicBoolean. Optional.

🤖 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/gpu/AdlUtilFFM.java` around lines
186 - 196, The lazy enumeration in ensureAdaptersEnumerated can race because
adaptersEnumerated is a plain volatile; to prevent duplicate native calls, guard
the critical section so only one thread performs enumerateAdapters and sets
BUS_TO_INDEX: wrap the body of ensureAdaptersEnumerated (the check, call to
enumerateAdapters, BUS_TO_INDEX.set(result), and adaptersEnumerated=true) in a
synchronization or use an AtomicBoolean CAS (e.g., compareAndSet false->true) to
ensure only one caller proceeds to call enumerateAdapters while others return;
keep references to ensureAdaptersEnumerated, adaptersEnumerated, BUS_TO_INDEX,
and enumerateAdapters when making the change.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java (1)

47-49: Optional: restore the cache-field comments from the JNA version.

The JNA counterpart has helpful comments explaining the sentinel semantics of cachedNvmlDevice (null = unresolved, empty = unavailable), cachedAdlIndex (Integer.MIN_VALUE = unresolved), and prevUtilTicks. Copying those comments over would keep the two implementations easy to diff.

🤖 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/hardware/platform/windows/WindowsGpuStatsFFM.java`
around lines 47 - 49, Add the explanatory sentinel comments from the JNA
implementation above the three cache fields: for cachedNvmlDevice note that null
means "unresolved" and empty string means "unavailable", for cachedAdlIndex note
that Integer.MIN_VALUE is used as the "unresolved" sentinel, and for
prevUtilTicks indicate it holds previous GPU tick counters (null when not yet
initialized). Place these comments immediately above the declarations of
cachedNvmlDevice, cachedAdlIndex, and prevUtilTicks so the semantics match the
JNA version and make future diffs clear.
oshi-core-java25/src/main/java/oshi/ffm/windows/SetupApiFFM.java (1)

155-162: Struct size is hardcoded for 64-bit.

SP_DEVINFO_DATA_SIZE = 32 and DEVINST_OFFSET = 20 assume an 8-byte Reserved (ULONG_PTR on x64). On 32-bit this struct is 28 bytes with DEVINST_OFFSET = 20 still correct, but cbSize would need to be 28 to be accepted by SetupAPI. Since this file already uses is64Bit() elsewhere (line 129) for the detail buffer's cbSize, consider doing the same here if 32-bit support is in scope — otherwise a brief comment noting the x64 assumption would help future readers.

🤖 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/ffm/windows/SetupApiFFM.java` around
lines 155 - 162, SP_DEVINFO_DATA_SIZE is hardcoded to 32 (and
SP_DEVINFO_DATA_DEVINST_OFFSET set to 20) which assumes an x64 ULONG_PTR; update
this to handle 32-bit platforms by computing cbSize based on is64Bit() (use 32
when is64Bit() true, 28 otherwise) and keep DEVINST offset at 20, or if 32-bit
support is not desired add a brief comment above
SP_DEVINFO_DATA_SIZE/SP_DEVINFO_DATA_DEVINST_OFFSET stating the constants are
x64-only; reference SP_DEVINFO_DATA_SIZE, SP_DEVINFO_DATA_DEVINST_OFFSET and
is64Bit() to locate and implement the change.
oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java (2)

97-113: Silent catch hides CM_Get_Child/Sibling failures.

This catch (Throwable t) block drops the exception without any log — if the tree traversal ever starts failing (e.g. a CfgMgr32 signature mismatch or a transient error), there's no breadcrumb. A LOG.debug("CM_Get_Child/Sibling failed for node {}", node, t); here would be cheap and very useful when diagnosing why a device's children are missing. Would also need a logger added to the class.

🤖 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/DeviceTreeFFM.java` around
lines 97 - 113, Replace the silent catch in DeviceTreeFFM's traversal (around
the CM_Get_Child/CM_Get_Sibling calls) with a debug log that records the node
and the throwable; add a logger instance to the DeviceTreeFFM class (e.g.,
private static final Logger LOG) and change the catch(Throwable t) block to call
LOG.debug("CM_Get_Child/Sibling failed for node {}", node, t) so failures are
visible while preserving the skip behavior.

64-114: Consider a visited-set to avoid redundant BFS.

SetupDiEnumDeviceInfo returns every matching device at the interface-class level. If a device and one of its ancestors both match (e.g. a USB hub and its child both advertise the same interface GUID), the inner BFS will process the same node from multiple entry points — re-reading device ID/name/mfg and re-walking its children. The writes are idempotent, but parentMap.put(child, node) will be overwritten if a node is reached from two different parents (benign for a true tree, wrong if the enumeration yields two candidate parents for the same child).

A Set<Integer> visited guarded at the top of the BFS loop (e.g., if (!visited.add(node)) continue;) would eliminate the duplicate work and make parent assignment deterministic.

🤖 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/DeviceTreeFFM.java` around
lines 64 - 114, The inner BFS can revisit nodes when multiple interface-level
roots overlap; introduce a Set<Integer> visited (e.g., HashSet) and check it at
the start of the BFS loop that processes deviceTree (where node =
deviceTree.poll()): if (!visited.add(node)) continue; also only assign parentMap
for a child/sibling when that child was newly added (i.e., only put
parentMap.put(child, node) when visited.add(child) returns true or you check
contains before putting) so parent assignment is deterministic; update
references in the block that calls Cfgmgr32FFM.CM_Get_Child / CM_Get_Sibling,
and ensure deviceIdMap/nameMap/mfgMap are not reprocessed for already-visited
nodes.
oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java (1)

110-143: LGTM — minor nit on debug logging.

Buffer sizing, the buf.fill((byte) 0) pre-clear (critical for reuse across calls so readWideString sees the right terminator), and the pulLength in bytes all look right. Optional nit: the catch (Throwable t) blocks log the node/property but drop t itself — consider passing t as the last argument so SLF4J records the stack trace when debug is enabled.

🪵 Optional diff
-        } catch (Throwable t) {
-            LOG.debug("CM_Get_Device_ID failed for node {}", dnDevInst);
-        }
+        } catch (Throwable t) {
+            LOG.debug("CM_Get_Device_ID failed for node {}", dnDevInst, t);
+        }
-        } catch (Throwable t) {
-            LOG.debug("CM_Get_DevNode_Registry_Property failed for node {} property {}", dnDevInst, ulProperty);
-        }
+        } catch (Throwable t) {
+            LOG.debug("CM_Get_DevNode_Registry_Property failed for node {} property {}", dnDevInst, ulProperty, t);
+        }
🤖 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/ffm/windows/Cfgmgr32FFM.java` around
lines 110 - 143, The debug catch blocks in getDeviceId and getDevNodeProperty
currently log only contextual info and drop the caught Throwable; update both
catch handlers to pass the Throwable as the last argument to LOG.debug so SLF4J
records the stack trace (e.g., LOG.debug("CM_Get_Device_ID failed for node {}",
dnDevInst, t) and LOG.debug("CM_Get_DevNode_Registry_Property failed for node {}
property {}", dnDevInst, ulProperty, t)); make this change in the catch clauses
of getDeviceId and getDevNodeProperty.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSensorsFFM.java (1)

136-164: Optional: cache reflective Methods and compute getValue once per sensor.

This method resolves Class.forName(...) and getMethod("getValue") on every call, and the stream filters+maps both call getValue.invoke(sensor) on each element (so the reflective call happens twice per valid sensor). Since getLhmSensors already loads classes reflectively, consider caching the Sensor class/methods in a static holder and computing the value once per element via .mapToInt(...) with the filter folded in (e.g., -1 sentinel + .filter(v -> v > 0)). Not critical — reflection is cheap relative to WMI — just nicer on hot paths.

🤖 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/hardware/platform/windows/WindowsSensorsFFM.java`
around lines 136 - 164, getFansFromLHM currently calls Class.forName(...) and
sensorClass.getMethod("getValue") each invocation and invokes getValue twice per
sensor in the stream; cache the reflective Sensor class and Method (use
JLIBREHARDWAREMONITOR_PACKAGE and sensorClass/getValueMethod) in a static holder
and change the stream to invoke getValue only once per sensor (compute double
value once, use a sentinel or fold the filter into the mapping to discard
non-positive values), keeping existing exception handling/logging via LOG and
REFLECT_EXCEPTION_MSG when invoke fails; ensure getLhmSensors usage remains the
same and fall back to returning new int[0] on errors.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsUsbDeviceFFM.java (1)

59-67: Sort the top-level USB controller list before returning it.

Line 60 iterates a Set, so the public tree order can be nondeterministic even though child lists are sorted.

Proposed fix
         for (Integer controllerDevice : controllerDevices.getA()) {
             WindowsUsbDeviceFFM deviceAndChildren = queryDeviceAndChildren(controllerDevice, parentMap, nameMap,
                     deviceIdMap, mfgMap, "0000", "0000", "");
             if (deviceAndChildren != null) {
                 usbDevices.add(deviceAndChildren);
             }
         }
+        sort(usbDevices);
         return usbDevices;
🤖 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/hardware/platform/windows/WindowsUsbDeviceFFM.java`
around lines 59 - 67, The top-level controller iteration over
controllerDevices.getA() is non-deterministic because it iterates a Set; convert
that Set to a List and sort it before iterating so the returned usbDevices order
is stable. In the method that builds usbDevices (use the
controllerDevices.getA(), usbDevices, queryDeviceAndChildren, and
WindowsUsbDeviceFFM identifiers), create a sorted list of controller IDs (e.g.,
sort by the human-readable name from nameMap.getOrDefault(controllerId, "") or
by the integer ID if names are absent) and then loop over that sorted list to
call queryDeviceAndChildren and add results to usbDevices before returning.
oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiAdapterInfo.java (1)

5-5: LGTM — package move to oshi.driver.common.windows.gpu is clean.

Immutable value class shape is unchanged; the module-info export for this new package is noted in the summary. A small nit: the per-getter Javadocs that were removed might still be worth keeping for public getters like getVendorId()/getLuidLowPart() since the constructor Javadoc is the only remaining documentation — but this is strictly a nice-to-have and easy to revisit later.

🤖 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/gpu/DxgiAdapterInfo.java`
at line 5, Restore concise Javadoc comments on the public getters to preserve
API documentation: add brief per-getter Javadocs to methods such as
getVendorId(), getLuidLowPart(), getVendorName(), getDescription(), etc.,
describing the returned value (e.g., vendor ID, LUID low part, human-readable
vendor name, adapter description) while keeping the existing constructor
Javadoc; locate these methods in DxgiAdapterInfo and add one-line Javadoc blocks
above each public getter matching the style of the class constructor docs.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java (1)

63-102: Per-iteration allocations accumulate in the confined Arena.

pType, lpcbData, dummyBuf, and edidBuf are all allocated inside the for loop but share the outer confined Arena, so their memory is retained until getDisplays() returns. For typical display counts this is negligible, but it's straightforward to bound with a per-iteration arena — or to hoist the fixed-size scratch allocations (pType, lpcbData, and a reusable size-probe buffer) outside the loop and only allocate edidBuf inside.

♻️ One possible refactor
-                for (int i = 0;; i++) {
+                MemorySegment pType = arena.allocate(JAVA_INT);
+                MemorySegment lpcbData = arena.allocate(JAVA_INT);
+                MemorySegment dummyBuf = arena.allocate(1);
+                for (int i = 0;; i++) {
                     devInfoData.fill((byte) 0);
                     ...
-                        MemorySegment pType = arena.allocate(JAVA_INT);
-                        MemorySegment lpcbData = arena.allocate(JAVA_INT);
-                        MemorySegment dummyBuf = arena.allocate(1);
                         lpcbData.set(JAVA_INT, 0, 1);
🤖 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/hardware/platform/windows/WindowsDisplayFFM.java`
around lines 63 - 102, The confined Arena used in the getDisplays() loop causes
per-iteration allocations (pType, lpcbData, dummyBuf, edidBuf) to be retained
until the outer Arena is closed; fix by either creating and closing a
short-lived per-iteration Arena inside the for loop (allocate pType, lpcbData,
dummyBuf, and edidBuf from it and close it in finally) or hoist the fixed-size
scratch allocations (pType, lpcbData, dummyBuf) outside the loop and only
allocate edidBuf inside the loop so only EDID buffers are transient; update the
loop around SetupDiEnumDeviceInfo / RegQueryValueEx and ensure RegCloseKey still
runs in the finally block.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java (1)

149-152: Keep updateAttributes() failure handling silent.

This refresh path should signal failure via false; error logging here can get noisy for callers polling network stats.

♻️ Proposed cleanup
             ifRow.set(ValueLayout.JAVA_INT, IPHlpAPIFFM.OFFSET_INTERFACE_INDEX, queryNetworkInterface().getIndex());
             if (0 != IPHlpAPIFFM.GetIfEntry2(ifRow)) {
-                LOG.error("Failed to retrieve data for interface {}, {}", queryNetworkInterface().getIndex(),
-                        getName());
                 return false;
             }
@@
         } catch (Throwable t) {
-            LOG.error("Failed to retrieve data for interface {}, {}: {}", queryNetworkInterface().getIndex(), getName(),
-                    t.getMessage());
             return false;
         }

Based on learnings, OSHI FFM/API updateAttributes() implementations should catch Throwable and return false without logging.

Also applies to: 172-175

🤖 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/hardware/platform/windows/WindowsNetworkIfFFM.java`
around lines 149 - 152, In WindowsNetworkIfFFM.updateAttributes() remove the
noisy LOG.error on failing IPHlpAPIFFM.GetIfEntry2 and instead silently return
false; specifically, where you check "if (0 != IPHlpAPIFFM.GetIfEntry2(ifRow))"
(and the similar block around the later GetIfEntry2 at 172-175), drop the
processLogger/LOG call and just return false. Also wrap the body of
updateAttributes() in a broad try/catch(Throwable) that suppresses logging and
returns false on any error, preserving use of queryNetworkInterface().getIndex()
and getName() only for decision flow, not for error output.
🤖 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/hardware/common/platform/windows/WindowsCentralProcessor.java`:
- Around line 204-245: The loop currently uses the destination logical CPU index
(variable cpu) to read perfmon counter lists (systemList, userList, irqList,
softIrqList, idleList, baseList, initBase, processorUtilityBase,
initProcessorUtilityBase, processorUtility, initProcessorUtility, initUserList,
initSystemList), which mixes values when NUMA/processor-group instance order
differs; change the loop to use the instance position (e.g., an index variable i
over instances) to read from these parallel lists (use list.get(i)) and only use
getNumaNodeProcToLogicalProcMap().getOrDefault(instance, 0) /
ParseUtil.parseIntOrDefault(instance, 0) to compute the destination cpu for
storing into ticks[cpu]; keep the cpu>=ncpu guard and the subsequent adjustments
(IRQ subtraction, scaling, and USE_CPU_UTILITY calculations) but replace all
list.get(cpu) accesses with list.get(i) so counters align with the corresponding
instance.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java`:
- Around line 47-90: The partitionList field is never initialized so
getPartitions() can return null and cause NPE in updateAttributes(); initialize
partitionList to an empty list in the WindowsHWDiskStore constructor (or inline
at declaration) so getPartitions() always returns a non-null List, and ensure
setPartitionList(...) still replaces it when subclasses populate partitions;
update references to partitionList/getPartitions and leave updateAttributes()
unchanged.

In
`@oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java`:
- Around line 175-187: The parseNumaNode method currently only reads a single
GROUP_AFFINITY; instead read the GroupCount WORD from the NUMA_NODE_RELATIONSHIP
(at dataOffset + 24), then loop for i in [0, GroupCount) and for each affinity
compute affinityOffset = dataOffset + 26 + i*16, read the GROUP_AFFINITY Mask
(JAVA_LONG at affinityOffset) and Group (unsigned short at affinityOffset + 8),
and add one long[] { nodeNumber, group, mask } per affinity; update
parseNumaNode to handle GroupCount==0 gracefully and to iterate all
GROUP_AFFINITY entries rather than the single fixed one.

In `@oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java`:
- Around line 24-31: The comment above PERFORMANCE_INFORMATION_LAYOUT
incorrectly states "9 SIZE_T" while the layout defines 10 JAVA_LONG fields
(CommitTotal, CommitLimit, CommitPeak, PhysicalTotal, PhysicalAvailable,
SystemCache, KernelTotal, KernelPaged, KernelNonpaged, PageSize); update the
comment to read "10 SIZE_T" (or otherwise match the declared fields) so it
accurately describes the PERFORMANCE_INFORMATION struct represented by
PERFORMANCE_INFORMATION_LAYOUT.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java`:
- Around line 75-92: After the second Advapi32FFM.RegQueryValueEx call (the one
that fills edidBuf) add a debug log when rc != ERROR_SUCCESS so EDID failures
are not silently dropped; specifically, after the second RegQueryValueEx return
you should mirror the existing catch (Throwable) logging style used elsewhere in
WindowsDisplayFFM: log at debug (or the same logger used) including rc, the
edidName and any contextual key identifier so developers can see why the monitor
was skipped, then skip adding the display only if non-success.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java`:
- Around line 111-129: The two error-return paths in WindowsGlobalMemoryFFM
(inside the block that calls PsapiFFM.GetPerformanceInfo and its catch)
incorrectly return a fallback page size of 4098L; update both Triplet<> returns
to use the correct 4096L fallback page size so memAvailable/memTotal
calculations use the standard 4KB page size when GetPerformanceInfo fails.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java`:
- Around line 160-166: The code currently reads only unicast counters and maps
OutDiscards to collisions; update WindowsNetworkIfFFM to also read the
non-unicast counters (use the IPHlpAPIFFM offsets for non-unicast/NUcast receive
and transmit, e.g., OFFSET_IN_NON_UNICAST_PKTS / OFFSET_OUT_NON_UNICAST_PKTS or
the API's IN_MULTICAST/IN_BROADCAST combined offsets) and compute packetsRecv =
unicastRecv + nonUnicastRecv and packetsSent = unicastSent + nonUnicastSent; map
outDrops to the OutDiscards value (this.inDrops / this.outDrops), and stop
assigning OutDiscards to collisions—set collisions to 0 (or leave as not
tracked) since Windows no longer provides collision counts; update the
assignments for packetsRecv, packetsSent, outErrors/outDrops and collisions in
WindowsNetworkIfFFM accordingly.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java`:
- Around line 53-60: getSwapUsed() currently multiplies the percent value
returned by querySwapUsed() (stored in used) by page size, yielding
percent*pageSize instead of bytes; change getSwapUsed() to compute bytes by
applying the percentage to getSwapTotal() (i.e., return
Math.round(getSwapTotal() * (used.get() / 100.0))). Use the existing
getSwapTotal(), keep global.getPageSize(), used, and totalVmaxVused references,
and ensure proper conversion to long (rounding) to avoid precision loss.

---

Outside diff comments:
In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.java`:
- Around line 33-54: Rename the class WindowsVirtualMemory to
WindowsVirtualMemoryJNA and update its constructor signature (currently
WindowsVirtualMemory(WindowsGlobalMemoryJNA windowsGlobalMemory)) and any
internal references (e.g., the private final WindowsGlobalMemoryJNA global field
and any usages of WindowsVirtualMemory in this module) to match the new name;
ensure the memoized supplier fields (used, totalVmaxVused, swapInOut) and the
logger LOG remain unchanged, and update any external references or imports
elsewhere in the codebase that reference WindowsVirtualMemory so they point to
WindowsVirtualMemoryJNA to keep naming consistent with WindowsGlobalMemoryJNA
and the existing WindowsVirtualMemoryFFM counterpart.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiAdapterInfo.java`:
- Line 5: Restore concise Javadoc comments on the public getters to preserve API
documentation: add brief per-getter Javadocs to methods such as getVendorId(),
getLuidLowPart(), getVendorName(), getDescription(), etc., describing the
returned value (e.g., vendor ID, LUID low part, human-readable vendor name,
adapter description) while keeping the existing constructor Javadoc; locate
these methods in DxgiAdapterInfo and add one-line Javadoc blocks above each
public getter matching the style of the class constructor docs.

In `@oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java`:
- Around line 97-113: Replace the silent catch in DeviceTreeFFM's traversal
(around the CM_Get_Child/CM_Get_Sibling calls) with a debug log that records the
node and the throwable; add a logger instance to the DeviceTreeFFM class (e.g.,
private static final Logger LOG) and change the catch(Throwable t) block to call
LOG.debug("CM_Get_Child/Sibling failed for node {}", node, t) so failures are
visible while preserving the skip behavior.
- Around line 64-114: The inner BFS can revisit nodes when multiple
interface-level roots overlap; introduce a Set<Integer> visited (e.g., HashSet)
and check it at the start of the BFS loop that processes deviceTree (where node
= deviceTree.poll()): if (!visited.add(node)) continue; also only assign
parentMap for a child/sibling when that child was newly added (i.e., only put
parentMap.put(child, node) when visited.add(child) returns true or you check
contains before putting) so parent assignment is deterministic; update
references in the block that calls Cfgmgr32FFM.CM_Get_Child / CM_Get_Sibling,
and ensure deviceIdMap/nameMap/mfgMap are not reprocessed for already-visited
nodes.

In `@oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java`:
- Around line 110-143: The debug catch blocks in getDeviceId and
getDevNodeProperty currently log only contextual info and drop the caught
Throwable; update both catch handlers to pass the Throwable as the last argument
to LOG.debug so SLF4J records the stack trace (e.g., LOG.debug("CM_Get_Device_ID
failed for node {}", dnDevInst, t) and
LOG.debug("CM_Get_DevNode_Registry_Property failed for node {} property {}",
dnDevInst, ulProperty, t)); make this change in the catch clauses of getDeviceId
and getDevNodeProperty.

In `@oshi-core-java25/src/main/java/oshi/ffm/windows/SetupApiFFM.java`:
- Around line 155-162: SP_DEVINFO_DATA_SIZE is hardcoded to 32 (and
SP_DEVINFO_DATA_DEVINST_OFFSET set to 20) which assumes an x64 ULONG_PTR; update
this to handle 32-bit platforms by computing cbSize based on is64Bit() (use 32
when is64Bit() true, 28 otherwise) and keep DEVINST offset at 20, or if 32-bit
support is not desired add a brief comment above
SP_DEVINFO_DATA_SIZE/SP_DEVINFO_DATA_DEVINST_OFFSET stating the constants are
x64-only; reference SP_DEVINFO_DATA_SIZE, SP_DEVINFO_DATA_DEVINST_OFFSET and
is64Bit() to locate and implement the change.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java`:
- Around line 63-102: The confined Arena used in the getDisplays() loop causes
per-iteration allocations (pType, lpcbData, dummyBuf, edidBuf) to be retained
until the outer Arena is closed; fix by either creating and closing a
short-lived per-iteration Arena inside the for loop (allocate pType, lpcbData,
dummyBuf, and edidBuf from it and close it in finally) or hoist the fixed-size
scratch allocations (pType, lpcbData, dummyBuf) outside the loop and only
allocate edidBuf inside the loop so only EDID buffers are transient; update the
loop around SetupDiEnumDeviceInfo / RegQueryValueEx and ensure RegCloseKey still
runs in the finally block.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java`:
- Around line 47-49: Add the explanatory sentinel comments from the JNA
implementation above the three cache fields: for cachedNvmlDevice note that null
means "unresolved" and empty string means "unavailable", for cachedAdlIndex note
that Integer.MIN_VALUE is used as the "unresolved" sentinel, and for
prevUtilTicks indicate it holds previous GPU tick counters (null when not yet
initialized). Place these comments immediately above the declarations of
cachedNvmlDevice, cachedAdlIndex, and prevUtilTicks so the semantics match the
JNA version and make future diffs clear.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java`:
- Around line 149-152: In WindowsNetworkIfFFM.updateAttributes() remove the
noisy LOG.error on failing IPHlpAPIFFM.GetIfEntry2 and instead silently return
false; specifically, where you check "if (0 != IPHlpAPIFFM.GetIfEntry2(ifRow))"
(and the similar block around the later GetIfEntry2 at 172-175), drop the
processLogger/LOG call and just return false. Also wrap the body of
updateAttributes() in a broad try/catch(Throwable) that suppresses logging and
returns false on any error, preserving use of queryNetworkInterface().getIndex()
and getName() only for decision flow, not for error output.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSensorsFFM.java`:
- Around line 136-164: getFansFromLHM currently calls Class.forName(...) and
sensorClass.getMethod("getValue") each invocation and invokes getValue twice per
sensor in the stream; cache the reflective Sensor class and Method (use
JLIBREHARDWAREMONITOR_PACKAGE and sensorClass/getValueMethod) in a static holder
and change the stream to invoke getValue only once per sensor (compute double
value once, use a sentinel or fold the filter into the mapping to discard
non-positive values), keeping existing exception handling/logging via LOG and
REFLECT_EXCEPTION_MSG when invoke fails; ensure getLhmSensors usage remains the
same and fall back to returning new int[0] on errors.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsUsbDeviceFFM.java`:
- Around line 59-67: The top-level controller iteration over
controllerDevices.getA() is non-deterministic because it iterates a Set; convert
that Set to a List and sort it before iterating so the returned usbDevices order
is stable. In the method that builds usbDevices (use the
controllerDevices.getA(), usbDevices, queryDeviceAndChildren, and
WindowsUsbDeviceFFM identifiers), create a sorted list of controller IDs (e.g.,
sort by the human-readable name from nameMap.getOrDefault(controllerId, "") or
by the integer ID if names are absent) and then loop over that sorted list to
call queryDeviceAndChildren and add results to usbDevices before returning.

In `@oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java`:
- Around line 186-196: The lazy enumeration in ensureAdaptersEnumerated can race
because adaptersEnumerated is a plain volatile; to prevent duplicate native
calls, guard the critical section so only one thread performs enumerateAdapters
and sets BUS_TO_INDEX: wrap the body of ensureAdaptersEnumerated (the check,
call to enumerateAdapters, BUS_TO_INDEX.set(result), and
adaptersEnumerated=true) in a synchronization or use an AtomicBoolean CAS (e.g.,
compareAndSet false->true) to ensure only one caller proceeds to call
enumerateAdapters while others return; keep references to
ensureAdaptersEnumerated, adaptersEnumerated, BUS_TO_INDEX, and
enumerateAdapters when making the change.
🪄 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: 4ec5ec8b-a84b-4e97-a060-1a0b502884d1

📥 Commits

Reviewing files that changed from the base of the PR and between d0ea166 and 751946d.

📒 Files selected for processing (49)
  • CHANGELOG.md
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiAdapterInfo.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/package-info.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/DxgiFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/IPHlpAPIFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/SetupApiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSensorsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsUsbDeviceFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsDisplayJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsSensorsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDeviceJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemory.java
  • oshi-core/src/main/java/oshi/jna/platform/windows/Dxgi.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsGraphicsCardTest.java
  • oshi-core/src/test/java/oshi/util/gpu/DxgiUtilTest.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (1)

124-125: Nit: redundant substring end index.

The trailing getName().length() argument is the default; this can be simplified for readability.

Optional cleanup
-        } else if (getName().startsWith(PHYSICALDRIVE_PREFIX)) {
-            index = getName().substring(PHYSICALDRIVE_PREFIX.length(), getName().length());
+        } else if (getName().startsWith(PHYSICALDRIVE_PREFIX)) {
+            index = getName().substring(PHYSICALDRIVE_PREFIX.length());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java`
around lines 124 - 125, The substring call in WindowsHWDiskStore's branch using
getName().startsWith(PHYSICALDRIVE_PREFIX) is verbose: replace
getName().substring(PHYSICALDRIVE_PREFIX.length(), getName().length()) with the
simpler getName().substring(PHYSICALDRIVE_PREFIX.length()) to remove the
redundant end index; update the code in the same else-if block where getName()
and PHYSICALDRIVE_PREFIX are used (within class WindowsHWDiskStore) and run
tests/compile to ensure no behavior change.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java (1)

25-28: Stale Javadoc — migration is now complete.

Per the PR description, this PR finishes the FFM migration so every Windows hardware component has a pure-FFM implementation. The phrase "overriding methods as FFM implementations become available" reads like work-in-progress; consider updating it to reflect the now-complete coverage.

Suggested wording
-/**
- * FFM-based hardware abstraction layer for Windows. Extends {`@link` AbstractHardwareAbstractionLayer}, overriding
- * methods as FFM implementations become available.
- */
+/**
+ * FFM-based hardware abstraction layer for Windows. Provides pure-FFM implementations for all Windows hardware
+ * components.
+ */
🤖 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/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java`
around lines 25 - 28, Update the class Javadoc on
WindowsHardwareAbstractionLayerFFM to remove the "overriding methods as FFM
implementations become available" WIP wording and reflect that the FFM migration
is complete; specifically edit the comment above class
WindowsHardwareAbstractionLayerFFM to state that it is a complete FFM-based
hardware abstraction layer for Windows (extending
AbstractHardwareAbstractionLayer) and that all Windows hardware components now
have pure-FFM implementations.
🤖 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/hardware/common/platform/windows/WindowsHWDiskStore.java`:
- Around line 124-125: The substring call in WindowsHWDiskStore's branch using
getName().startsWith(PHYSICALDRIVE_PREFIX) is verbose: replace
getName().substring(PHYSICALDRIVE_PREFIX.length(), getName().length()) with the
simpler getName().substring(PHYSICALDRIVE_PREFIX.length()) to remove the
redundant end index; update the code in the same else-if block where getName()
and PHYSICALDRIVE_PREFIX are used (within class WindowsHWDiskStore) and run
tests/compile to ensure no behavior change.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java`:
- Around line 25-28: Update the class Javadoc on
WindowsHardwareAbstractionLayerFFM to remove the "overriding methods as FFM
implementations become available" WIP wording and reflect that the FFM migration
is complete; specifically edit the comment above class
WindowsHardwareAbstractionLayerFFM to state that it is a complete FFM-based
hardware abstraction layer for Windows (extending
AbstractHardwareAbstractionLayer) and that all Windows hardware components now
have pure-FFM implementations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6a5db919-f03f-4559-aa7f-fd873aaca4ee

📥 Commits

Reviewing files that changed from the base of the PR and between 751946d and 1389a3a.

📒 Files selected for processing (9)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.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, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
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.
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
📚 Learning: 2026-04-20T03:07:04.034Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3176
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java:53-60
Timestamp: 2026-04-20T03:07:04.034Z
Learning: In OSHI's Windows FFM paging file implementation (`oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java`), the `querySwapUsed()` method uses the Windows PDH raw counter for "% Usage" on the paging file. Despite its name, this raw counter returns page counts: `FirstValue` is the number of pages currently used and `SecondValue` is the total number of pages in the swap file. The formatted counter performs the division and multiplies by 100% to yield a true percentage. Therefore, computing swap used bytes as `pageSize * used.get()` (pages × page size) is correct — do not treat the return value as a percentage.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.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-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.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/hardware/common/platform/windows/WindowsHWDiskStore.java
🔇 Additional comments (8)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java (1)

33-54: Rename and retyping look consistent.

Class, logger, memoized supplier references, and constructor parameter type are all updated coherently to WindowsVirtualMemoryJNA / WindowsGlobalMemoryJNA. Matches the instantiation in WindowsGlobalMemoryJNA.createVirtualMemory() (line 69). Behavior is unchanged.

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java (2)

28-44: Superclass hoist and rename LGTM.

Extending the new common WindowsGlobalMemory while retaining access to the hoisted memoryType/smBiosMemoryType helpers (still used at lines 82 and 96) is clean. Logger and memoized readPerfInfo reference both track the rename.


111-111: Page size fallback fix (4098 → 4096) is correct.

4096 bytes is the actual default Windows page size; 4098 was a typo. Good catch.

oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java (2)

7-13: LGTM — imports are scoped to the new FFM layout.

The added layout imports are all used by PERFORMANCE_INFORMATION_LAYOUT, with no concerns.


24-31: LGTM — the PERFORMANCE_INFORMATION layout matches the 64-bit native shape.

The comment now matches the declared 10 SIZE_T fields, and the explicit padding keeps the 64-bit alignment/size consistent. Based on learnings, native FFM layouts need explicit padding where MSVC inserts alignment before 64-bit fields.

oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (2)

47-47: partitionList initialization addresses prior NPE concern.

Initializing to Collections.emptyList() ensures getPartitions() and updateAttributes() are NPE-safe before subclasses call setPartitionList(...). Resolves the previous review comment.


193-218: Asymmetric backslash handling between the two map* helpers — please confirm intentional.

mapDriveToPartition (Line 197) normalizes \\\\ → \\ on the antecedent key, but mapPartitionToLogicalDrive (Lines 215-216) does not apply the same normalization to either the antecedent or dependent. This matches the historical JNA behavior (the antecedent here is a Disk #N, Partition #N`` style string and the dependent is a logical-drive ID like C: with no escaped backslashes), so the asymmetry is likely correct — just flagging it to make sure that's the intent now that this is shared code reused by both FFM and JNA tiers, rather than each path having its own copy where the difference was implicitly understood.

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

30-95: LGTM — overrides mirror the JNA tier consistently.

All factory methods and enumeration overrides line up cleanly with WindowsHardwareAbstractionLayerJNA, just routed to the *FFM counterparts. Marking the class final is also a nice touch given there's no expected subclass.

@dbwiddis
dbwiddis force-pushed the migrate-windows-hal branch from 1389a3a to d67edd2 Compare April 20, 2026 03:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java (1)

115-123: Optional: tidy up the fully-qualified java.lang.foreign references.

Since MemorySegment is already imported, consider also importing java.lang.foreign.ValueLayout and java.lang.foreign.MemoryLayout (or exposing typed accessors/VarHandles from PsapiFFM) to remove the repeated fully-qualified names and make the struct-field reads a bit easier on the eyes. 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/hardware/platform/windows/WindowsGlobalMemoryFFM.java`
around lines 115 - 123, The code in WindowsGlobalMemoryFFM uses fully-qualified
java.lang.foreign types when reading perfInfo (e.g.,
perfInfo.get(java.lang.foreign.ValueLayout.JAVA_LONG,
java.lang.foreign.MemoryLayout.PathElement...)); tidy this by adding imports for
java.lang.foreign.ValueLayout and java.lang.foreign.MemoryLayout (or create
typed accessors/VarHandles in PsapiFFM) and update the reads for pageSize,
physAvail, and physTotal to use the shorter names (ValueLayout.JAVA_LONG and
MemoryLayout.PathElement...) and/or the new PsapiFFM accessors to improve
readability.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java (1)

82-94: Non-ERROR_MORE_DATA results from the sizing call are silently discarded.

The sizing RegQueryValueEx is only acted on when rc == ERROR_MORE_DATA. Any other return code (including ERROR_SUCCESS on a zero/one-byte value, or e.g. ERROR_FILE_NOT_FOUND when a device has no EDID key) is dropped without a log line, which makes this branch a bit harder to diagnose than the post-resize path you just added logging for. In practice EDID blocks are always ≥128 bytes so ERROR_SUCCESS here is essentially impossible, but a one-liner at debug for rc != ERROR_MORE_DATA would make the two RegQueryValueEx paths symmetric. Entirely optional.

🤖 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/hardware/platform/windows/WindowsDisplayFFM.java`
around lines 82 - 94, The sizing RegQueryValueEx call only handles rc ==
ERROR_MORE_DATA and silently ignores any other return codes; add a symmetric
debug log for the sizing path so non-ERROR_MORE_DATA outcomes are recorded.
After the first Advapi32FFM.RegQueryValueEx(key, edidName, 0, pType, dummyBuf,
lpcbData) call, if rc != ERROR_MORE_DATA, emit a LOG.debug including the monitor
index i and the rc value (same style as the later error log) to make
RegQueryValueEx failures visible; keep the rest of the flow that allocates
edidBuf and constructs new WindowsDisplayFFM(edid) 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-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java`:
- Around line 82-94: The sizing RegQueryValueEx call only handles rc ==
ERROR_MORE_DATA and silently ignores any other return codes; add a symmetric
debug log for the sizing path so non-ERROR_MORE_DATA outcomes are recorded.
After the first Advapi32FFM.RegQueryValueEx(key, edidName, 0, pType, dummyBuf,
lpcbData) call, if rc != ERROR_MORE_DATA, emit a LOG.debug including the monitor
index i and the rc value (same style as the later error log) to make
RegQueryValueEx failures visible; keep the rest of the flow that allocates
edidBuf and constructs new WindowsDisplayFFM(edid) unchanged.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java`:
- Around line 115-123: The code in WindowsGlobalMemoryFFM uses fully-qualified
java.lang.foreign types when reading perfInfo (e.g.,
perfInfo.get(java.lang.foreign.ValueLayout.JAVA_LONG,
java.lang.foreign.MemoryLayout.PathElement...)); tidy this by adding imports for
java.lang.foreign.ValueLayout and java.lang.foreign.MemoryLayout (or create
typed accessors/VarHandles in PsapiFFM) and update the reads for pageSize,
physAvail, and physTotal to use the shorter names (ValueLayout.JAVA_LONG and
MemoryLayout.PathElement...) and/or the new PsapiFFM accessors to improve
readability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8b24b328-5f2f-48fa-a9ba-a3d7e947d481

📥 Commits

Reviewing files that changed from the base of the PR and between 1389a3a and d67edd2.

📒 Files selected for processing (9)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.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 (15)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
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.
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.
📚 Learning: 2026-04-20T03:07:04.034Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3176
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java:53-60
Timestamp: 2026-04-20T03:07:04.034Z
Learning: In OSHI's Windows FFM paging file implementation (`oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java`), the `querySwapUsed()` method uses the Windows PDH raw counter for "% Usage" on the paging file. Despite its name, this raw counter returns page counts: `FirstValue` is the number of pages currently used and `SecondValue` is the total number of pages in the swap file. The formatted counter performs the division and multiplies by 100% to yield a true percentage. Therefore, computing swap used bytes as `pageSize * used.get()` (pages × page size) is correct — do not treat the return value as a percentage.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.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/hardware/platform/windows/WindowsGlobalMemoryFFM.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/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.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-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.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/hardware/platform/windows/WindowsDisplayFFM.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.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/hardware/common/platform/windows/WindowsHWDiskStore.java
🔇 Additional comments (2)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (1)

47-47: Prior NPE concern resolved.

partitionList is now initialized to Collections.emptyList(), so getPartitions() and updateAttributes() are safe before any setPartitionList(...) call. Extraction of the shared base class looks clean.

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

70-74: No action needed. The SetupApiFFM.SetupDiOpenDevRegKey wrapper (lines 203–204) already normalizes the invalid-handle sentinel to null before returning, so the null check at line 72 in WindowsDisplayFFM.java is correct.

			> Likely an incorrect or invalid review comment.

@dbwiddis
dbwiddis force-pushed the migrate-windows-hal branch from d67edd2 to d0e6154 Compare April 20, 2026 03:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (1)

130-131: Optional: document non-null contract for queryReadWriteStats.

updateAttributes() dereferences stats.getReadMap() unconditionally, so the abstract method's Javadoc at Line 139–145 should state that implementations must return a non-null DiskStats (or the base should guard against null). Not a current defect since both existing subclasses comply, but worth locking in for future implementors.

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

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java`
around lines 130 - 131, The code dereferences stats.getReadMap() in
updateAttributes() after calling queryReadWriteStats(index) without null checks;
add a clear non-null contract by updating the Javadoc of the abstract method
queryReadWriteStats(...) in WindowsHWDiskStore (or its declaring class) to state
it must never return null and that DiskStats.getReadMap()/getWriteMap() will be
non-null, referencing DiskStats, queryReadWriteStats, updateAttributes and
getReadMap so future implementors comply; alternatively (or additionally) add a
defensive null-check in updateAttributes() to handle a null DiskStats safely if
you prefer runtime safety over just documentation.
🤖 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/hardware/common/platform/windows/WindowsCentralProcessor.java`:
- Around line 92-105: In buildNumaNodeProcMap, the current logic resets procNum
on node change which breaks interleaved NUMA ordering; replace the single
procNum with a per-node counter (e.g., a Map<Integer,Integer>
nextProcIndexByNode) and for each LogicalProcessor in logProcs get node,
read-and-increment that node's counter to produce the per-node procNum, then put
the key into numaNodeProcToLogicalProcMap and increment lp; this preserves
correct per-NUMA numbering for numaNodeProcToLogicalProcMap regardless of
ordering.
- Around line 204-209: The loop in WindowsCentralProcessor that sets "cpu"
currently maps missing NUMA-instance keys and unparsable names to 0, which can
overwrite CPU0 ticks; change the logic in the loop (the block using
getNumaNodeProcToLogicalProcMap() and ParseUtil.parseIntOrDefault) to detect
missing mappings or parse failures and skip those instances instead of assigning
0—e.g., check containsKey(instance) before using the map (or use a sentinel like
-1 as the ParseUtil default) and continue when the resolved cpu is invalid
(negative or >= ncpu); update the code paths around variable "cpu", the calls to
getNumaNodeProcToLogicalProcMap() and ParseUtil.parseIntOrDefault, and the
existing cpu >= ncpu guard accordingly.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java`:
- Around line 130-131: The code dereferences stats.getReadMap() in
updateAttributes() after calling queryReadWriteStats(index) without null checks;
add a clear non-null contract by updating the Javadoc of the abstract method
queryReadWriteStats(...) in WindowsHWDiskStore (or its declaring class) to state
it must never return null and that DiskStats.getReadMap()/getWriteMap() will be
non-null, referencing DiskStats, queryReadWriteStats, updateAttributes and
getReadMap so future implementors comply; alternatively (or additionally) add a
defensive null-check in updateAttributes() to handle a null DiskStats safely if
you prefer runtime safety over just documentation.
🪄 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: 7ed8e3ec-7b4c-418e-8dd5-59673983b7a2

📥 Commits

Reviewing files that changed from the base of the PR and between d67edd2 and d0e6154.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (17)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
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.
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
📚 Learning: 2026-04-20T03:07:04.034Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3176
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java:53-60
Timestamp: 2026-04-20T03:07:04.034Z
Learning: In OSHI's Windows FFM paging file implementation (`oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java`), the `querySwapUsed()` method uses the Windows PDH raw counter for "% Usage" on the paging file. Despite its name, this raw counter returns page counts: `FirstValue` is the number of pages currently used and `SecondValue` is the total number of pages in the swap file. The formatted counter performs the division and multiplies by 100% to yield a true percentage. Therefore, computing swap used bytes as `pageSize * used.get()` (pages × page size) is correct — do not treat the return value as a percentage.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.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/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
🔇 Additional comments (4)
oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java (1)

24-31: LGTM.

Layout matches the native PERFORMANCE_INFORMATION (104 bytes total on 64-bit: cb + 4B padding + 10×SIZE_T + 3×DWORD + 4B trailing padding), and the comment is now accurate after the prior fix. Field name annotations let consumers resolve offsets via groupElement(...) safely.

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

109-130: LGTM.

readPerfInfo() correctly sizes the PERFORMANCE_INFORMATION struct from the layout, resolves PageSize/PhysicalAvailable/PhysicalTotal via groupElement, and falls back to the standard 4096-byte page size on error. Memoization with defaultExpiration() makes this resilient to transient failures.

oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (1)

30-137: LGTM — clean extraction of the shared Windows disk-store logic.

partitionList is now safely initialized to Collections.emptyList(), and updateAttributes() correctly handles the three index-resolution paths (partition major, PHYSICALDRIVE name prefix, or give up with a warning). setDiskStats(...) consistently uses getOrDefault(..., 0L), so a partial DiskStats will not throw. The sealed helpers (DiskStats, PartitionMaps) keep the JNA/FFM subclasses symmetric.

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

30-95: LGTM — full FFM wiring for the Windows HAL.

All four required abstract factories from AbstractHardwareAbstractionLayer (createComputerSystem, createProcessor, createMemory, createSensors) are implemented, and every collection accessor delegates to the corresponding *FFM static helper. With this in place, oshi-core-java25 now has a full pure-FFM Windows hardware stack as intended by the PR.

@dbwiddis
dbwiddis force-pushed the migrate-windows-hal branch from d0e6154 to 3e09664 Compare April 20, 2026 03:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java (2)

39-41: Thread-safety of initialUtilityCounters / utilityBaseMultiplier — worth a quick sanity check.

The class is @ThreadSafe and lazilyCalculateMultiplier is synchronized, but getInitialUtilityCounters() / setInitialUtilityCounters() are plain accessors on non-volatile fields, and utilityBaseMultiplier is also read from the synchronized path but written once. Since AbstractCentralProcessor.processorCpuLoadTicks is memoized with a TTL, concurrent threads can re-enter the tick query path when the memo expires, so there's at least a visibility concern across threads.

In practice the values are populated once at construction by initProcessorCounts() and refreshed only inside the synchronized multiplier path, so it's probably benign — but if you want to harden this, either marking the fields volatile or making the accessors synchronized on this would make the thread-safety story clean. Flagging for awareness rather than as a blocker.

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

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java`
around lines 39 - 41, initialUtilityCounters and utilityBaseMultiplier have
potential visibility issues across threads; make their updates and reads
thread-safe by either declaring both fields volatile or synchronizing their
accessors. Specifically, update the field declarations for
initialUtilityCounters and utilityBaseMultiplier to be volatile, or
alternatively make getInitialUtilityCounters and setInitialUtilityCounters
synchronized (or synchronize their callers), so values set by
initProcessorCounts and in lazilyCalculateMultiplier are reliably visible to
threads re-entering AbstractCentralProcessor.processorCpuLoadTicks.

184-199: Consider guarding against perfmon list-size mismatches.

Welcome-wagon note for anyone reading this later: the guard here rejects empty instances and null lists, but doesn't check that systemList/userList/irqList/softIrqList/idleList (and the utility-mode lists) all have at least instances.size() entries. Under normal PDH/WMI operation they will, but if a provider ever returns a short list, list.get(i) on lines 214–229 will throw IndexOutOfBoundsException and propagate out of the memoized supplier.

Cheap defensive option: bail out (return the zero-filled ticks) when any required list is shorter than instances.size(). Totally optional — just a nice-to-have for resilience.

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

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java`
around lines 184 - 199, The method processTickData currently checks for
null/empty lists but not that each list has at least instances.size() entries,
which can cause IndexOutOfBoundsException when iterating; add size checks at the
top of processTickData to verify systemList, userList, irqList, softIrqList,
idleList all have size >= instances.size(), and when USE_CPU_UTILITY is true
also verify baseList, systemUtility, processorUtility, processorUtilityBase,
initSystemList, initUserList, initBase, initSystemUtility, initProcessorUtility,
initProcessorUtilityBase each have size >= instances.size(); if any required
list is shorter, return the zero-filled ticks array immediately.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java (1)

30-95: Clean three-tier migration — LGTM.

All four abstract factory methods from AbstractHardwareAbstractionLayer (createComputerSystem, createProcessor, createMemory, createSensors) are implemented, and every collection accessor delegates cleanly to a corresponding Windows*FFM class. Marking the class final is a nice touch for this leaf-level implementation.

One minor observation: createProcessor/createMemory/createSensors widen visibility from protected (in the parent) to public (Line 33, 43, 48). This is consistent with the existing createComputerSystem on Line 38 so it's presumably intentional, but worth a quick sanity check — if these factories are not meant to be part of the API surface, keeping them protected would be more conservative.

🤖 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/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java`
around lines 30 - 95, The three factory methods createProcessor, createMemory,
and createSensors in WindowsHardwareAbstractionLayerFFM widen visibility to
public relative to their protected declarations in
AbstractHardwareAbstractionLayer; change their modifiers back to protected
(i.e., update the method signatures of createProcessor(), createMemory(), and
createSensors() in WindowsHardwareAbstractionLayerFFM) so they no longer expand
the API surface, leaving createComputerSystem() as-is if it is intentionally
public.
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (2)

248-253: Nit: simplification opportunity.

The empty-string guard isn't strictly necessary — "".split("\\s")[0] returns "" — but it does avoid the array allocation on the empty path. Purely stylistic; feel free to leave 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/hardware/common/platform/windows/WindowsHWDiskStore.java`
around lines 248 - 253, The method getIndexFromName currently checks for empty
string before splitting; simplify it by removing the empty-string guard and
directly returning the first token from the split (i.e., in getIndexFromName use
s.split("\\s")[0] or s.split("\\s", 2)[0] to avoid extra allocations), keeping
the method name getIndexFromName to locate the change.

155-185: Minor: consider logging when counter lists are missing.

When any of the six per-counter lists is null (Line 168-171), populateDiskStats silently returns an empty DiskStats, which will make updateAttributes() return false with no diagnostic trail. A debug/trace log here would help future troubleshooting without changing behavior. Non-blocking.

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

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java`
around lines 155 - 185, In populateDiskStats, add a debug/trace log when the
early-return condition triggers (instances.isEmpty() || any of
readList/readByteList/writeList/writeByteList/queueLengthList/diskTimeList is
null) so callers can diagnose why DiskStats is empty; log should include the
provided index and which counter lists are missing (or that instances is empty)
and use the class's existing logger (e.g., WindowsHWDiskStore logger) at
debug/trace level without changing the method's behavior or return value.
🤖 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/hardware/common/platform/windows/WindowsCentralProcessor.java`:
- Around line 43-58: The Javadoc for the private static method
isWindows8OrGreater incorrectly states "Subclasses must implement this…" which
is misleading; update the comment above isWindows8OrGreater in
WindowsCentralProcessor.java to accurately describe that this method performs a
local system-property based check for Windows 8+ and is fully implemented (e.g.,
"Checks whether the OS version is Windows 8 or greater using system property
'os.version'"). Ensure the `@return` tag remains correct and remove any wording
about subclasses or implementation obligations.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java`:
- Around line 39-41: initialUtilityCounters and utilityBaseMultiplier have
potential visibility issues across threads; make their updates and reads
thread-safe by either declaring both fields volatile or synchronizing their
accessors. Specifically, update the field declarations for
initialUtilityCounters and utilityBaseMultiplier to be volatile, or
alternatively make getInitialUtilityCounters and setInitialUtilityCounters
synchronized (or synchronize their callers), so values set by
initProcessorCounts and in lazilyCalculateMultiplier are reliably visible to
threads re-entering AbstractCentralProcessor.processorCpuLoadTicks.
- Around line 184-199: The method processTickData currently checks for
null/empty lists but not that each list has at least instances.size() entries,
which can cause IndexOutOfBoundsException when iterating; add size checks at the
top of processTickData to verify systemList, userList, irqList, softIrqList,
idleList all have size >= instances.size(), and when USE_CPU_UTILITY is true
also verify baseList, systemUtility, processorUtility, processorUtilityBase,
initSystemList, initUserList, initBase, initSystemUtility, initProcessorUtility,
initProcessorUtilityBase each have size >= instances.size(); if any required
list is shorter, return the zero-filled ticks array immediately.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java`:
- Around line 248-253: The method getIndexFromName currently checks for empty
string before splitting; simplify it by removing the empty-string guard and
directly returning the first token from the split (i.e., in getIndexFromName use
s.split("\\s")[0] or s.split("\\s", 2)[0] to avoid extra allocations), keeping
the method name getIndexFromName to locate the change.
- Around line 155-185: In populateDiskStats, add a debug/trace log when the
early-return condition triggers (instances.isEmpty() || any of
readList/readByteList/writeList/writeByteList/queueLengthList/diskTimeList is
null) so callers can diagnose why DiskStats is empty; log should include the
provided index and which counter lists are missing (or that instances is empty)
and use the class's existing logger (e.g., WindowsHWDiskStore logger) at
debug/trace level without changing the method's behavior or return value.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java`:
- Around line 30-95: The three factory methods createProcessor, createMemory,
and createSensors in WindowsHardwareAbstractionLayerFFM widen visibility to
public relative to their protected declarations in
AbstractHardwareAbstractionLayer; change their modifiers back to protected
(i.e., update the method signatures of createProcessor(), createMemory(), and
createSensors() in WindowsHardwareAbstractionLayerFFM) so they no longer expand
the API surface, leaving createComputerSystem() as-is if it is intentionally
public.
🪄 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: 7e1546c0-fd17-4393-a840-61e971704642

📥 Commits

Reviewing files that changed from the base of the PR and between d0e6154 and 3e09664.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.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, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (16)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
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.
📚 Learning: 2026-04-20T03:07:04.034Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3176
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java:53-60
Timestamp: 2026-04-20T03:07:04.034Z
Learning: In OSHI's Windows FFM paging file implementation (`oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java`), the `querySwapUsed()` method uses the Windows PDH raw counter for "% Usage" on the paging file. Despite its name, this raw counter returns page counts: `FirstValue` is the number of pages currently used and `SecondValue` is the total number of pages in the swap file. The formatted counter performs the division and multiplies by 100% to yield a true percentage. Therefore, computing swap used bytes as `pageSize * used.get()` (pages × page size) is correct — do not treat the return value as a percentage.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.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/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.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-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
🔇 Additional comments (6)
oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java (1)

24-31: LGTM — layout matches PERFORMANCE_INFORMATION.

Struct math checks out at 104 bytes (4 cb + 4 pad + 10×8 SIZE_T + 3×4 DWORD + 4 trailing pad), satisfying 8-byte alignment, and the corrected comment now accurately describes the field count. Consumers in WindowsGlobalMemoryFFM and WindowsVirtualMemoryFFM resolve field offsets by name, so they're insulated from any future reshuffling.

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

28-44: Looks consistent with the shared Windows memory base.

The inheritance move, logger/memoized method reference updates, WindowsVirtualMemoryJNA factory, and 4096L fallback all line up cleanly with the three-tier migration.

Also applies to: 68-69, 107-112

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

33-45: Rename plumbing looks clean.

The class, logger, constructor, injected global-memory type, and static memoized method references consistently use the JNA-specific implementation. The swap-used calculation also remains correct as page-count × page-size.

Based on learnings, Windows paging file % Usage raw counter returns page counts, so multiplying by page size is correct.

Also applies to: 47-59

oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (3)

40-47: Good catch on the prior NPE fix.

Initializing partitionList to Collections.emptyList() correctly guards updateAttributes() (Line 121-122) before subclasses populate partitions. Prior feedback fully addressed.


118-137: updateAttributes() logic looks correct.

Deriving the index from either the first partition's major number or the PHYSICALDRIVE name prefix is a sensible fallback ordering, and the containsKey guard before setDiskStats avoids zeroing out previous values when a query returns no matching counter row. Behavior matches the prior JNA implementation.


194-219: No changes needed — the asymmetry is inherited and consistent across both JNA and FFM.

Both WindowsHWDiskStoreJNA and WindowsHWDiskStoreFFM extend the common WindowsHWDiskStore class and inherit these methods as-is. The asymmetry you spotted (normalization in mapDriveToPartition but not in mapPartitionToLogicalDrive) is not a divergence in the FFM implementation — it's the established pattern in the shared base class used by both approaches. The different treatment appears intentional: physical drive identifiers (which include escaped backslashes) are normalized, while partition identifiers follow a different escaping convention. This is consistent across all implementations.

@dbwiddis

Copy link
Copy Markdown
Member Author

@CodeRabbit full review

@coderabbitai

coderabbitai Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 7

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

98-113: Optional: log the swallowed exception at debug.

Per the FFM-wrapper convention, CM_Get_Child / CM_Get_Sibling return error codes rather than throwing in practice, so this catch is defensive. A LOG.debug("CM_Get_Child/Sibling threw for node {}", node, t) would make the rare case debuggable without changing behavior. Feel free to ignore if you prefer the silent fallback.

🤖 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/DeviceTreeFFM.java` around
lines 98 - 113, Add a debug log in the catch block that currently swallows
exceptions for CM_Get_Child/CM_Get_Sibling so the rare thrown case is
observable; inside the catch for Throwable t in the loop that calls
Cfgmgr32FFM.CM_Get_Child(childSeg, node, 0) and
Cfgmgr32FFM.CM_Get_Sibling(siblingSeg, child, 0) call
LOG.debug("CM_Get_Child/Sibling threw for node {}", node, t) (or equivalent
SLF4J-style formatting) while keeping the current behavior of skipping the
node's children and not propagating the exception; update imports if necessary
to reference the existing LOG logger.
oshi-core-java25/src/main/java/oshi/ffm/windows/SetupApiFFM.java (2)

184-211: Consider returning Optional<MemorySegment> for consistency.

SetupDiGetClassDevs (L47) returns Optional<MemorySegment>, but SetupDiOpenDevRegKey returns a raw MemorySegment/null. Both represent fallible handle-returning native calls; switching to Optional would align the API style and let callers use idiomatic .isPresent() / .ifPresent(...) patterns. Not a blocker — the current null contract works and is already handled correctly in WindowsDisplayFFM.

🤖 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/ffm/windows/SetupApiFFM.java` around
lines 184 - 211, Change SetupDiOpenDevRegKey to return Optional<MemorySegment>
(import java.util.Optional) instead of possibly returning null: update the
method signature public static Optional<MemorySegment>
SetupDiOpenDevRegKey(...), return Optional.empty() when
Kernel32FFM.isInvalidHandle(key) or on Throwable (preserve LOG.debug call), and
return Optional.of(key) on success; keep the existing downcall MethodHandle
SetupDiOpenDevRegKey and error logging. Also update all call sites (e.g.,
WindowsDisplayFFM and any other callers) to consume Optional with
isPresent()/ifPresent()/orElse as appropriate.

155-162: Minor inconsistency with the existing 32/64-bit handling in this file.

SP_DEVINFO_DATA_SIZE = 32 and SP_DEVINFO_DATA_DEVINST_OFFSET = 20 are x64 values only (on 32-bit the Reserved ULONG_PTR collapses to 4 bytes, making the struct 28 bytes — DEVINST_OFFSET remains 20). Elsewhere in this file (L129) is64Bit() is already consulted to pick the correct cbSize, so the hardcoded values here are a bit inconsistent with that pattern. In practice this is fine because the FFM build only targets 64-bit Windows, but a brief // x64 layout; FFM runtime is 64-bit only comment would document the assumption and pre-empt confusion if anyone ports this to 32-bit later.

🤖 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/ffm/windows/SetupApiFFM.java` around
lines 155 - 162, SP_DEVINFO_DATA_SIZE and SP_DEVINFO_DATA_DEVINST_OFFSET are x64
layout values but the file otherwise handles 32/64 selection via is64Bit();
annotate these constants to avoid confusion by adding a brief comment above
SP_DEVINFO_DATA_SIZE and SP_DEVINFO_DATA_DEVINST_OFFSET stating "x64 layout; FFM
runtime is 64-bit only" (or equivalent), and mention that the DEVINST offset
remains 20 on 32-bit; reference the existing is64Bit() usage (around the cbSize
handling) to show where 32/64 selection occurs.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java (1)

99-165: LGTM — FFM mirror looks solid.

Verified the key FFM specifics:

  • The confined Arena on Line 134 correctly scopes both mountPoint/volumeBuf/labelBuf to a single logical-drive iteration.
  • uuid (Line 132) is declared before the try-with-resources and is definitely assigned on the normal completion path, so its use at Line 155 is safe.
  • GetVolumeNameForVolumeMountPoint return value is intentionally ignored (mirrors the JNA version) and parseUuidOrDefault(..., "") handles a failed/empty buffer gracefully.
  • GetVolumeInformation handling through OptionalInt + GetLastError logging at Lines 144–150 is consistent with the existing FFM error-reporting pattern.
💡 Optional nit (not required)

The Arena.ofConfined() is allocated once per logical-drive entry. If profiling ever flags this, hoisting the arena to the outer for (int i = ...) (and re-using offsets per drive) would reduce arena churn — but the current per-iteration scoping is the safer default and matches other FFM sites in the codebase.

🤖 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/hardware/platform/windows/WindowsHWDiskStoreFFM.java`
around lines 99 - 165, The review approves the FFM implementation; no functional
changes required — keep queryPartitionMaps as-is, leaving the per-iteration
Arena.ofConfined() that scopes mountPoint, volumeBuf, and labelBuf inside the
logical-drive loop, but optionally consider hoisting the Arena allocation out of
the inner loop (reusing offsets per drive) if profiling shows arena churn; no
code edits required unless you choose to implement that micro-optimization.
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java (1)

14-141: Shared base and translation tables LGTM.

Extracting memoryType / smBiosMemoryType into oshi-common is the right move so the FFM and JNA paths can't drift. The SMBIOS table also covers the modern types (DDR5/LPDDR5/HBM3), and the 0x02 → default → "Unknown" fall-through correctly reflects the SMBIOS "Unknown" reservation.

Optional future polish (no action needed for this PR): this is a classic candidate for an EnumMap/Map<Integer, String> or a small enum lookup — would trim ~100 lines and make diffs for new SMBIOS codes one-liners. Totally fine as-is given it mirrors the shape of the legacy code.

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

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java`
around lines 14 - 141, The memoryType(int) and smBiosMemoryType(int) methods are
correct and require no changes—leave both functions as-is in
WindowsGlobalMemory; optionally consider a future refactor to a Map/Enum lookup
for smBiosMemoryType to reduce boilerplate, but do not modify behavior in this
PR.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java (1)

100-108: Nit: iterate entries instead of keySet() + get().

Micro-cleanup to avoid the extra map lookup in the hot loop:

♻️ Optional
-        long totalActive = 0L;
-        long totalBase = 0L;
-        for (String key : activeByType.keySet()) {
-            totalActive += activeByType.get(key);
-            totalBase += baseByType.getOrDefault(key, 0L);
-        }
+        long totalActive = 0L;
+        long totalBase = 0L;
+        for (Map.Entry<String, Long> e : activeByType.entrySet()) {
+            totalActive += e.getValue();
+            totalBase += baseByType.getOrDefault(e.getKey(), 0L);
+        }
🤖 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/hardware/platform/windows/WindowsGpuStatsFFM.java`
around lines 100 - 108, The loop in WindowsGpuStatsFFM that sums totals uses
activeByType.keySet() with map lookups inside the loop; change it to iterate the
entry set to avoid extra lookups by using Map.Entry from
activeByType.entrySet(), accumulating totalActive from entry.getValue() and
totalBase by looking up baseByType.getOrDefault(entry.getKey(), 0L), then
compute idle and return new GpuTicks(totalActive, idle).
oshi-core-java25/src/main/java/oshi/ffm/windows/DxgiFFM.java (2)

140-163: Cache the three MethodHandle instances for constant FunctionDescriptors.

Each vtableCall* method rebuilds a MethodHandle per invocation. Since the three FunctionDescriptors are constant, you can create them once as static fields using Linker.nativeLinker().downcallHandle(FunctionDescriptor) (available in Java 22+), which produces a handle that accepts the target function pointer as its first argument. This eliminates repeated handle creation and reduces overhead on multi-GPU systems.

private static final MethodHandle ENUM_ADAPTERS_MH = Linker.nativeLinker()
        .downcallHandle(FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS));
private static final MethodHandle GET_DESC_MH = Linker.nativeLinker()
        .downcallHandle(FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS));
private static final MethodHandle RELEASE_MH = Linker.nativeLinker()
        .downcallHandle(FunctionDescriptor.of(JAVA_INT, ADDRESS));

// Then in each method, invoke with the function pointer as the first argument:
// return (int) ENUM_ADAPTERS_MH.invokeExact(fn, factory, index, ppAdapter);
🤖 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/ffm/windows/DxgiFFM.java` around lines
140 - 163, The three vtableCall* methods rebuild MethodHandle instances on every
call; instead, create static final MethodHandle fields (e.g., ENUM_ADAPTERS_MH,
GET_DESC_MH, RELEASE_MH) using Linker.nativeLinker().downcallHandle(...) with
the constant FunctionDescriptor for each signature (enum adapters, getDesc,
release) and then change vtableCallEnumAdapters, vtableCallGetDesc, and
vtableRelease to call invokeExact with the native function pointer (fn) as the
first argument followed by the original parameters (e.g.,
ENUM_ADAPTERS_MH.invokeExact(fn, factory, index, ppAdapter)), leveraging the
Java 22+ downcallHandle form to avoid rebuilding handles per invocation.

165-176: Consider using MemorySegment.getString() with UTF-16LE charset to simplify this method.

The FFM API's getString(offset, Charset) method automatically scans for the NUL terminator and decodes using the specified charset, eliminating the manual length scan and character-by-character loop:

♻️ Optional simplification
-    private static String readDescriptionWchars(MemorySegment desc) {
-        // Description is WCHAR[128] at offset 0
-        int len = 0;
-        while (len < 128 && desc.get(JAVA_CHAR, len * 2L) != 0) {
-            len++;
-        }
-        char[] chars = new char[len];
-        for (int i = 0; i < len; i++) {
-            chars[i] = desc.get(JAVA_CHAR, i * 2L);
-        }
-        return new String(chars);
-    }
+    private static String readDescriptionWchars(MemorySegment desc) {
+        // Description is WCHAR[128] at offset 0; getString scans to NUL.
+        return desc.asSlice(0, 256).getString(0, java.nio.charset.StandardCharsets.UTF_16LE);
+    }
🤖 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/ffm/windows/DxgiFFM.java` around lines
165 - 176, The readDescriptionWchars method manually scans WCHAR[128] and builds
a char array; replace this with MemorySegment.getString to simplify and
correctly decode UTF-16LE: in readDescriptionWchars(MemorySegment desc) call
desc.getString(0, java.nio.charset.StandardCharsets.UTF_16LE) (or the variant
that stops at the NUL) and trim/limit to 128 characters if necessary, removing
the manual len loop and char-by-char reads.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java (1)

180-189: Nit: PROCESSOR_FEATURES / PROCESSOR_FEATURE_NAMES lookup is O(n²) and the UNKNOWN_ branch is unreachable.

Since the filter only yields values drawn from PROCESSOR_FEATURES, the inner linear scan to recover the name can never miss — the fallback "UNKNOWN_" + f is dead code. Indexing by position avoids both the dead branch and the quadratic behavior:

♻️ Proposed refactor
-        List<String> featureFlags = Arrays.stream(PROCESSOR_FEATURES).filter(Kernel32FFM::IsProcessorFeaturePresent)
-                .mapToObj(f -> {
-                    for (int i = 0; i < PROCESSOR_FEATURES.length; i++) {
-                        if (PROCESSOR_FEATURES[i] == f) {
-                            return PROCESSOR_FEATURE_NAMES[i];
-                        }
-                    }
-                    return "UNKNOWN_" + f;
-                }).collect(Collectors.toList());
+        List<String> featureFlags = java.util.stream.IntStream.range(0, PROCESSOR_FEATURES.length)
+                .filter(i -> Kernel32FFM.IsProcessorFeaturePresent(PROCESSOR_FEATURES[i]))
+                .mapToObj(i -> PROCESSOR_FEATURE_NAMES[i]).collect(Collectors.toList());
🤖 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/hardware/platform/windows/WindowsCentralProcessorFFM.java`
around lines 180 - 189, The current mapping from PROCESSOR_FEATURES to names
does a nested scan (O(n²)) and includes an unreachable "UNKNOWN_" fallback;
replace the stream that builds featureFlags with an index-based stream so you
directly select names by position: use IntStream.range(0,
PROCESSOR_FEATURES.length).filter(i ->
Kernel32FFM.IsProcessorFeaturePresent(PROCESSOR_FEATURES[i])).mapToObj(i ->
PROCESSOR_FEATURE_NAMES[i]).collect(Collectors.toList()) (remove the UNKNOWN_
branch and the inner for-loop), keeping the Quartet return using featureFlags
unchanged.
oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java (1)

182-190: Optional: consolidate the triple parse.

buildPciBusId re-scans locationInfo three times. Since all three PCI fields live at well-defined offsets within the same string, a single scan returning a small record/triplet would be cheaper and would also let callers like WindowsGraphicsCardFFM (which also calls parsePciBusNumber separately right before buildPciBusId) avoid a 4th pass. Happy to leave as-is given the string is short and this is not on a hot path.

🤖 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/gpu/DxgiUtil.java`
around lines 182 - 190, buildPciBusId currently calls parsePciBusNumber,
parsePciDevice, and parsePciFunction separately causing multiple rescans of the
same locationInfo; introduce a single helper that parses all three fields in one
pass (e.g., parsePciTriple or parsePciLocation returning a small POJO/array with
bus, device, function), update buildPciBusId to use that helper and return "" on
any negative value, and update other callers like WindowsGraphicsCardFFM that
previously called parsePciBusNumber to use the new triple parser (or extract the
bus from the returned triplet) to avoid a fourth pass.
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSensorsFFM.java (1)

141-164: Nit: avoid invoking getValue twice per sensor.

getValueMethod.invoke(sensor) is called once inside the filter and a second time in mapToInt. Each invocation crosses a reflection boundary and (potentially) a JNI call into the LHM native library. Mapping once and filtering on the primitive would be slightly cheaper and clearer.

♻️ Proposed refactor
-            return sensors.stream().filter(sensor -> {
-                try {
-                    double value = (double) getValueMethod.invoke(sensor);
-                    return value > 0;
-                } catch (Exception e) {
-                    LOG.warn(REFLECT_EXCEPTION_MSG, e.getMessage());
-                    return false;
-                }
-            }).mapToInt(sensor -> {
-                try {
-                    return (int) (double) getValueMethod.invoke(sensor);
-                } catch (Exception e) {
-                    LOG.warn(REFLECT_EXCEPTION_MSG, e.getMessage());
-                    return 0;
-                }
-            }).toArray();
+            return sensors.stream().mapToInt(sensor -> {
+                try {
+                    return (int) (double) getValueMethod.invoke(sensor);
+                } catch (Exception e) {
+                    LOG.warn(REFLECT_EXCEPTION_MSG, e.getMessage());
+                    return 0;
+                }
+            }).filter(v -> v > 0).toArray();
🤖 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/hardware/platform/windows/WindowsSensorsFFM.java`
around lines 141 - 164, In WindowsSensorsFFM, avoid calling
getValueMethod.invoke(sensor) twice in the stream; instead create a single
primitive stream from sensors by invoking getValueMethod once per sensor (e.g.,
use sensors.stream().mapToDouble(sensor -> { try { return (double)
getValueMethod.invoke(sensor); } catch (Exception e) {
LOG.warn(REFLECT_EXCEPTION_MSG, e.getMessage()); return 0d; } })), then apply
the filter (>0) and final cast to int (mapToInt(d -> (int) d)) so reflection/JNI
is crossed only once per sensor; update the code that currently calls
getValueMethod in both the filter and mapToInt to use this single mapped double
stream while preserving the same logging/exception behavior.
🤖 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/LogicalProcessorInformationFFM.java`:
- Around line 195-206: The parseCache method currently indexes
ProcessorCache.Type via Type.values()[type] without validating the 'type' value;
add a defensive bounds check in parseCache (the method in
LogicalProcessorInformationFFM) to ensure 'type' is within 0 and
Type.values().length-1 and if not use a safe fallback (e.g.,
ProcessorCache.Type.UNKNOWN or a default enum constant) before constructing new
ProcessorCache(level, associativity, lineSize, cacheSize, ...); mirror the same
guard when/if you adapt the JNA-side LogicalProcessorInformation code to keep
behavior consistent.

In `@oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java`:
- Around line 110-120: The inline comment in getDeviceId incorrectly states
MAX_DEVICE_ID_LEN = 260; update the comment next to the arena.allocate(520)
allocation in the getDeviceId(int dnDevInst, Arena arena) method to reflect that
MAX_DEVICE_ID_LEN is actually 200 in cfgmgr32.h (260 is MAX_PATH), e.g. note
that 200 chars * 2 = 400 bytes and the current 520 allocation still exceeds
that; keep the allocation as-is but correct the constant in the comment for
clarity.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java`:
- Around line 376-399: registryGetString currently allocates a fixed 512-byte
buffer which can truncate long registry values; change registryGetString to
first call Advapi32FFM.RegQueryValueEx with a NULL data buffer to obtain the
required dataSize (or call once and on ERROR_MORE_DATA retry), then allocate a
data MemorySegment of the required size and call RegQueryValueEx again; if
RegQueryValueEx returns ERROR_MORE_DATA, loop: reallocate data to the size
indicated in dataSize and retry until success or a real error; keep the existing
RegCloseKey in the finally and return
WindowsForeignFunctions.readWideString(data) on success, otherwise return "" as
before.
- Around line 232-254: queryCurrentFreq wrongly indexes percentMaxList by the
destination logical CPU and uses getOrDefault/parseIntOrDefault defaulting to 0,
causing unmapped/unparseable instances to overwrite CPU0 and to pair the wrong %
value with a CPU; fix queryCurrentFreq by iterating with an index (for i from 0
to instances.size()), get String instance = instances.get(i), map instance→cpu
but if mapping missing or parse fails skip that instance (do not default to 0),
ensure cpu < getLogicalProcessorCount() then set freqs[cpu] =
percentMaxList.get(i) * getMaxFreq() / 100L (and guard percentMaxList.size() >
i), referencing queryCurrentFreq, getNumaNodeProcToLogicalProcMap(),
ParseUtil.parseIntOrDefault(), percentMaxList, instances,
getLogicalProcessorCount(), and getMaxFreq().

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java`:
- Around line 142-179: In WindowsNetworkIfFFM.updateAttributes(), remove (or
change to debug) the two LOG.error calls so the method only signals failure via
its boolean return: drop the LOG.error after the IPHlpAPIFFM.GetIfEntry2(...)
non-zero check and drop the LOG.error in the catch (Throwable t) block (or
change both to LOG.debug), ensuring the method returns false on failure without
logging; refer to WindowsNetworkIfFFM.updateAttributes, the GetIfEntry2 error
branch, and the catch (Throwable) block to locate the two places to change.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java`:
- Around line 40-59: The current WindowsSoundCardFFM enumeration wraps the
entire registry key loop in a try that aborts on an access-denied
Win32Exception; change it so access-denied handling is scoped to each registry
subkey: call Advapi32UtilFFM.registryGetKeys() to get keys outside the per-key
try, then for each key wrap the registryValueExists/getRegString and
soundCards.add logic in its own try that catches Win32Exception and, if
e.getErrorCode() == WinErrorFFM.ERROR_ACCESS_DENIED, simply continue to the next
key (otherwise rethrow), and catch/log other Throwables locally (mirroring the
existing outer catch behavior) so one inaccessible subkey doesn’t stop
enumeration in WindowsSoundCardFFM.

In `@oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java`:
- Around line 142-159: adlMalloc currently allocates from Arena.global(),
causing unbounded JVM memory retention during periodic GPU polling; replace this
by using a ThreadLocal<Arena> (or an arena pool) that adlInit sets to a confined
Arena and adlUninit clears/recycles so adlMalloc uses the per-thread arena
instead of Arena.global(); update adlInit/adlUninit to create/attach the
ThreadLocal arena before ADL calls and to close/recycle it after, and add a
validation check (or comment) to ensure the native atiadlxx.dll only invokes the
malloc callback synchronously on the calling thread before relying on the
ThreadLocal approach.

---

Nitpick comments:
In `@oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java`:
- Around line 182-190: buildPciBusId currently calls parsePciBusNumber,
parsePciDevice, and parsePciFunction separately causing multiple rescans of the
same locationInfo; introduce a single helper that parses all three fields in one
pass (e.g., parsePciTriple or parsePciLocation returning a small POJO/array with
bus, device, function), update buildPciBusId to use that helper and return "" on
any negative value, and update other callers like WindowsGraphicsCardFFM that
previously called parsePciBusNumber to use the new triple parser (or extract the
bus from the returned triplet) to avoid a fourth pass.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java`:
- Around line 14-141: The memoryType(int) and smBiosMemoryType(int) methods are
correct and require no changes—leave both functions as-is in
WindowsGlobalMemory; optionally consider a future refactor to a Map/Enum lookup
for smBiosMemoryType to reduce boilerplate, but do not modify behavior in this
PR.

In `@oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java`:
- Around line 98-113: Add a debug log in the catch block that currently swallows
exceptions for CM_Get_Child/CM_Get_Sibling so the rare thrown case is
observable; inside the catch for Throwable t in the loop that calls
Cfgmgr32FFM.CM_Get_Child(childSeg, node, 0) and
Cfgmgr32FFM.CM_Get_Sibling(siblingSeg, child, 0) call
LOG.debug("CM_Get_Child/Sibling threw for node {}", node, t) (or equivalent
SLF4J-style formatting) while keeping the current behavior of skipping the
node's children and not propagating the exception; update imports if necessary
to reference the existing LOG logger.

In `@oshi-core-java25/src/main/java/oshi/ffm/windows/DxgiFFM.java`:
- Around line 140-163: The three vtableCall* methods rebuild MethodHandle
instances on every call; instead, create static final MethodHandle fields (e.g.,
ENUM_ADAPTERS_MH, GET_DESC_MH, RELEASE_MH) using
Linker.nativeLinker().downcallHandle(...) with the constant FunctionDescriptor
for each signature (enum adapters, getDesc, release) and then change
vtableCallEnumAdapters, vtableCallGetDesc, and vtableRelease to call invokeExact
with the native function pointer (fn) as the first argument followed by the
original parameters (e.g., ENUM_ADAPTERS_MH.invokeExact(fn, factory, index,
ppAdapter)), leveraging the Java 22+ downcallHandle form to avoid rebuilding
handles per invocation.
- Around line 165-176: The readDescriptionWchars method manually scans
WCHAR[128] and builds a char array; replace this with MemorySegment.getString to
simplify and correctly decode UTF-16LE: in readDescriptionWchars(MemorySegment
desc) call desc.getString(0, java.nio.charset.StandardCharsets.UTF_16LE) (or the
variant that stops at the NUL) and trim/limit to 128 characters if necessary,
removing the manual len loop and char-by-char reads.

In `@oshi-core-java25/src/main/java/oshi/ffm/windows/SetupApiFFM.java`:
- Around line 184-211: Change SetupDiOpenDevRegKey to return
Optional<MemorySegment> (import java.util.Optional) instead of possibly
returning null: update the method signature public static
Optional<MemorySegment> SetupDiOpenDevRegKey(...), return Optional.empty() when
Kernel32FFM.isInvalidHandle(key) or on Throwable (preserve LOG.debug call), and
return Optional.of(key) on success; keep the existing downcall MethodHandle
SetupDiOpenDevRegKey and error logging. Also update all call sites (e.g.,
WindowsDisplayFFM and any other callers) to consume Optional with
isPresent()/ifPresent()/orElse as appropriate.
- Around line 155-162: SP_DEVINFO_DATA_SIZE and SP_DEVINFO_DATA_DEVINST_OFFSET
are x64 layout values but the file otherwise handles 32/64 selection via
is64Bit(); annotate these constants to avoid confusion by adding a brief comment
above SP_DEVINFO_DATA_SIZE and SP_DEVINFO_DATA_DEVINST_OFFSET stating "x64
layout; FFM runtime is 64-bit only" (or equivalent), and mention that the
DEVINST offset remains 20 on 32-bit; reference the existing is64Bit() usage
(around the cbSize handling) to show where 32/64 selection occurs.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java`:
- Around line 180-189: The current mapping from PROCESSOR_FEATURES to names does
a nested scan (O(n²)) and includes an unreachable "UNKNOWN_" fallback; replace
the stream that builds featureFlags with an index-based stream so you directly
select names by position: use IntStream.range(0,
PROCESSOR_FEATURES.length).filter(i ->
Kernel32FFM.IsProcessorFeaturePresent(PROCESSOR_FEATURES[i])).mapToObj(i ->
PROCESSOR_FEATURE_NAMES[i]).collect(Collectors.toList()) (remove the UNKNOWN_
branch and the inner for-loop), keeping the Quartet return using featureFlags
unchanged.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java`:
- Around line 100-108: The loop in WindowsGpuStatsFFM that sums totals uses
activeByType.keySet() with map lookups inside the loop; change it to iterate the
entry set to avoid extra lookups by using Map.Entry from
activeByType.entrySet(), accumulating totalActive from entry.getValue() and
totalBase by looking up baseByType.getOrDefault(entry.getKey(), 0L), then
compute idle and return new GpuTicks(totalActive, idle).

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java`:
- Around line 99-165: The review approves the FFM implementation; no functional
changes required — keep queryPartitionMaps as-is, leaving the per-iteration
Arena.ofConfined() that scopes mountPoint, volumeBuf, and labelBuf inside the
logical-drive loop, but optionally consider hoisting the Arena allocation out of
the inner loop (reusing offsets per drive) if profiling shows arena churn; no
code edits required unless you choose to implement that micro-optimization.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSensorsFFM.java`:
- Around line 141-164: In WindowsSensorsFFM, avoid calling
getValueMethod.invoke(sensor) twice in the stream; instead create a single
primitive stream from sensors by invoking getValueMethod once per sensor (e.g.,
use sensors.stream().mapToDouble(sensor -> { try { return (double)
getValueMethod.invoke(sensor); } catch (Exception e) {
LOG.warn(REFLECT_EXCEPTION_MSG, e.getMessage()); return 0d; } })), then apply
the filter (>0) and final cast to int (mapToInt(d -> (int) d)) so reflection/JNI
is crossed only once per sensor; update the code that currently calls
getValueMethod in both the filter and mapToInt to use this single mapped double
stream while preserving the same logging/exception behavior.
🪄 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: 67dad615-4054-4fe5-b25c-c3b422c765ad

📥 Commits

Reviewing files that changed from the base of the PR and between d0ea166 and 3e09664.

📒 Files selected for processing (50)
  • CHANGELOG.md
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiAdapterInfo.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/package-info.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/DxgiFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/IPHlpAPIFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/SetupApiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSensorsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsUsbDeviceFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsDisplayJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsSensorsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDeviceJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
  • oshi-core/src/main/java/oshi/jna/platform/windows/Dxgi.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsGraphicsCardTest.java
  • oshi-core/src/test/java/oshi/util/gpu/DxgiUtilTest.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStore.java

Comment on lines +376 to +399
private static String registryGetString(Arena arena, String path, String valueName) {
try {
MemorySegment hKey = arena.allocate(ValueLayout.ADDRESS);
MemorySegment subKey = WindowsForeignFunctions.toWideString(arena, path);
if (Advapi32FFM.RegOpenKeyEx(HKLM, subKey, 0, WinNTFFM.KEY_READ, hKey) == 0) {
MemorySegment openedKey = hKey.get(ValueLayout.ADDRESS, 0);
try {
MemorySegment valueNameSeg = WindowsForeignFunctions.toWideString(arena, valueName);
MemorySegment dataSize = arena.allocate(ValueLayout.JAVA_INT);
dataSize.set(ValueLayout.JAVA_INT, 0, 512);
MemorySegment data = arena.allocate(512);
if (Advapi32FFM.RegQueryValueEx(openedKey, valueNameSeg, 0, MemorySegment.NULL, data,
dataSize) == 0) {
return WindowsForeignFunctions.readWideString(data);
}
} finally {
Advapi32FFM.RegCloseKey(openedKey);
}
}
} catch (Throwable t) {
LOG.debug("Failed to read registry string {}/{}: {}", path, valueName, t.getMessage());
}
return "";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor: fixed 512-byte registry buffer could truncate long values.

registryGetString allocates a fixed 512-byte (256 WCHAR) buffer and doesn't retry on ERROR_MORE_DATA. In practice the values read here (VendorIdentifier, ProcessorNameString, Identifier) fit comfortably, so this is not a production risk — just flagging in case the helper gets reused elsewhere later. The JNA side uses Advapi32Util.registryGetStringValue which handles sizing internally, so behavioral parity is preserved today.

🤖 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/hardware/platform/windows/WindowsCentralProcessorFFM.java`
around lines 376 - 399, registryGetString currently allocates a fixed 512-byte
buffer which can truncate long registry values; change registryGetString to
first call Advapi32FFM.RegQueryValueEx with a NULL data buffer to obtain the
required dataSize (or call once and on ERROR_MORE_DATA retry), then allocate a
data MemorySegment of the required size and call RegQueryValueEx again; if
RegQueryValueEx returns ERROR_MORE_DATA, loop: reallocate data to the size
indicated in dataSize and retry until success or a real error; keep the existing
RegCloseKey in the finally and return
WindowsForeignFunctions.readWideString(data) on success, otherwise return "" as
before.

Comment on lines +142 to +179
public boolean updateAttributes() {
// FFM targets JDK 25+ which requires Vista+; use GetIfEntry2 directly
try (Arena arena = Arena.ofConfined()) {
MemorySegment ifRow = arena.allocate(IPHlpAPIFFM.MIB_IF_ROW2_SIZE);
ifRow.fill((byte) 0);
// Set InterfaceIndex at offset 8
ifRow.set(ValueLayout.JAVA_INT, IPHlpAPIFFM.OFFSET_INTERFACE_INDEX, queryNetworkInterface().getIndex());
if (0 != IPHlpAPIFFM.GetIfEntry2(ifRow)) {
LOG.error("Failed to retrieve data for interface {}, {}", queryNetworkInterface().getIndex(),
getName());
return false;
}
this.ifType = ifRow.get(ValueLayout.JAVA_INT, IPHlpAPIFFM.OFFSET_TYPE);
this.ndisPhysicalMediumType = ifRow.get(ValueLayout.JAVA_INT, IPHlpAPIFFM.OFFSET_PHYSICAL_MEDIUM_TYPE);
byte flags = ifRow.get(ValueLayout.JAVA_BYTE, IPHlpAPIFFM.OFFSET_FLAGS);
this.connectorPresent = (flags & CONNECTOR_PRESENT_BIT) > 0;
this.speed = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_RECEIVE_LINK_SPEED);
this.bytesRecv = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_IN_OCTETS);
this.packetsRecv = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_IN_UCAST_PKTS);
this.inErrors = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_IN_ERRORS);
this.inDrops = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_IN_DISCARDS);
this.bytesSent = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_OUT_OCTETS);
this.packetsSent = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_OUT_UCAST_PKTS);
this.outErrors = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_OUT_ERRORS);
this.collisions = ifRow.get(ValueLayout.JAVA_LONG, IPHlpAPIFFM.OFFSET_OUT_DISCARDS);
// Alias is WCHAR[257] at OFFSET_ALIAS
MemorySegment aliasSlice = ifRow.asSlice(IPHlpAPIFFM.OFFSET_ALIAS, 257 * 2);
this.ifAlias = readWideString(aliasSlice);
int operStatus = ifRow.get(ValueLayout.JAVA_INT, IPHlpAPIFFM.OFFSET_OPER_STATUS);
this.ifOperStatus = IfOperStatus.byValue(operStatus);
} catch (Throwable t) {
LOG.error("Failed to retrieve data for interface {}, {}: {}", queryNetworkInterface().getIndex(), getName(),
t.getMessage());
return false;
}
this.timeStamp = System.currentTimeMillis();
return true;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

updateAttributes() logs on the failure path, against the established convention.

Per the project's convention for *FFM updateAttributes() implementations, the method should signal failure solely via the boolean return value — callers rely on that and do not expect log output from this path. Two spots here break from that:

  • L150-L152: LOG.error(...) when GetIfEntry2 returns non-zero. A transient or nonexistent interface will trip this on every call.
  • L173-L174: LOG.error(...) inside the outer catch (Throwable).

Consider dropping both log calls (or demoting them to debug) so this matches the rest of the FFM implementations.

♻️ Suggested change
-            if (0 != IPHlpAPIFFM.GetIfEntry2(ifRow)) {
-                LOG.error("Failed to retrieve data for interface {}, {}", queryNetworkInterface().getIndex(),
-                        getName());
+            int ifIndex = queryNetworkInterface().getIndex();
+            ifRow.set(ValueLayout.JAVA_INT, IPHlpAPIFFM.OFFSET_INTERFACE_INDEX, ifIndex);
+            if (0 != IPHlpAPIFFM.GetIfEntry2(ifRow)) {
                 return false;
             }
@@
-        } catch (Throwable t) {
-            LOG.error("Failed to retrieve data for interface {}, {}: {}", queryNetworkInterface().getIndex(), getName(),
-                    t.getMessage());
+        } catch (Throwable t) {
             return false;
         }

Based on learnings from MacHWDiskStoreFFM.java (PR #3110) which state that updateAttributes() should catch Throwable and return false without logging, since the method's contract is to signal failure via the boolean return value.

🤖 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/hardware/platform/windows/WindowsNetworkIfFFM.java`
around lines 142 - 179, In WindowsNetworkIfFFM.updateAttributes(), remove (or
change to debug) the two LOG.error calls so the method only signals failure via
its boolean return: drop the LOG.error after the IPHlpAPIFFM.GetIfEntry2(...)
non-zero check and drop the LOG.error in the catch (Throwable t) block (or
change both to LOG.debug), ensuring the method returns false on failure without
logging; refer to WindowsNetworkIfFFM.updateAttributes, the GetIfEntry2 error
branch, and the catch (Throwable) block to locate the two places to change.

Comment on lines +142 to +159
// Lazy adapter enumeration
private static volatile boolean adaptersEnumerated = false;
private static final AtomicReference<Map<Integer, Integer>> BUS_TO_INDEX = new AtomicReference<>(
Collections.emptyMap());

/**
* ADL malloc callback invoked by the native library.
*
* @param size the number of bytes to allocate
* @return a memory segment of the requested size, or NULL if size is non-positive
*/
@SuppressWarnings("unused")
private static MemorySegment adlMalloc(int size) {
if (size <= 0) {
return MemorySegment.NULL;
}
return Arena.global().allocate(size);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's understand the file structure and find the relevant code
git ls-files | grep -i adl

Repository: oshi/oshi

Length of output: 226


🏁 Script executed:

# Let's examine the AdlUtilFFM.java file to understand the context
wc -l oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java

Repository: oshi/oshi

Length of output: 117


🏁 Script executed:

# Read the entire file to understand the context of adlMalloc and adlInit/adlUninit
cat -n oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java | head -200

Repository: oshi/oshi

Length of output: 10342


🏁 Script executed:

# Look for adlInit and adlUninit methods
rg -n "adlInit|adlUninit" oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java -A 5

Repository: oshi/oshi

Length of output: 3118


🏁 Script executed:

# Look at the rest of the file to see public API methods and how they use arenas
cat -n oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java | tail -250

Repository: oshi/oshi

Length of output: 10953


🏁 Script executed:

# Look for the enumerateAdapters method and other methods that call ADL functions
sed -n '198,320p' oshi-core-java25/src/main/java/oshi/util/gpu/AdlUtilFFM.java

Repository: oshi/oshi

Length of output: 4854


🏁 Script executed:

# Check if there are any other FFM or callback-based code in the project
rg -i "arena.global" oshi-core-java25/src/main/java/oshi/util/ -A 2 -B 2

Repository: oshi/oshi

Length of output: 1893


🏁 Script executed:

# Search for any discussion or documentation about memory management in FFM
rg -i "memory|leak|arena" oshi-core-java25/src/main/java/oshi/util/gpu/ | head -30

Repository: oshi/oshi

Length of output: 4042


Memory accumulates in Arena.global() due to callback allocation design constraint.

The malloc callback allocates into Arena.global(), which persists for the JVM lifetime. In periodic GPU polling, this creates a memory leak. However, threading a per-call Arena.ofConfined() through adlInit/adlUninit won't work here—FFM callback stubs have fixed C signatures and cannot accept additional parameters for context.

Options to fix this:

  1. Use a ThreadLocal<Arena> to store the per-call arena and access it from the callback (requires JVM thread affinity awareness)
  2. Create a callback-free architecture that allocates larger buffers upfront instead of using native callbacks
  3. Implement an arena pool/recycling strategy to bound memory growth

Before implementation, please confirm that atiadlxx.dll only calls the malloc callback during API execution (not asynchronously or from other threads). If confirmed, a ThreadLocal approach would be viable and safe.

🤖 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/gpu/AdlUtilFFM.java` around lines
142 - 159, adlMalloc currently allocates from Arena.global(), causing unbounded
JVM memory retention during periodic GPU polling; replace this by using a
ThreadLocal<Arena> (or an arena pool) that adlInit sets to a confined Arena and
adlUninit clears/recycles so adlMalloc uses the per-thread arena instead of
Arena.global(); update adlInit/adlUninit to create/attach the ThreadLocal arena
before ADL calls and to close/recycle it after, and add a validation check (or
comment) to ensure the native atiadlxx.dll only invokes the malloc callback
synchronously on the calling thread before relying on the ThreadLocal approach.

@dbwiddis
dbwiddis force-pushed the migrate-windows-hal branch from 3e09664 to f880cf5 Compare April 20, 2026 04:31

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

379-402: ⚠️ Potential issue | 🟡 Minor

Duplicate: fixed registry string buffer can still truncate long values.

registryGetString() still uses a fixed 512-byte buffer and does not retry on ERROR_MORE_DATA. The currently read CPU registry values are usually short, so this remains low-risk, but the previous sizing/retry suggestion still applies if this helper may be reused.

🤖 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/hardware/platform/windows/WindowsCentralProcessorFFM.java`
around lines 379 - 402, registryGetString currently allocates a fixed 512-byte
buffer and ignores RegQueryValueEx returning ERROR_MORE_DATA, which can truncate
long values; update registryGetString to call Advapi32FFM.RegQueryValueEx in a
loop that checks the return code and, on ERROR_MORE_DATA, reads the required
length from the dataSize MemorySegment, reallocates the data buffer to that size
(using the value in dataSize), and retries until the call succeeds or returns a
non-retriable error; keep closing openedKey in the finally and propagate/log the
final failure as before.
🧹 Nitpick comments (1)
oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java (1)

54-82: Optional: minor arena-allocation hygiene.

Two small nits in the same scope — happy to defer both:

  • Line 55-56: guidSeg is sized to exactly 16 bytes and copied blindly from guidBytes. If a caller ever passes a non-16-byte array, copyFrom will throw IndexOutOfBoundsException with no context. A quick length precondition (or javadoc @throws) would make the contract explicit.
  • Line 82: Cfgmgr32FFM.getDeviceId(node, arena) allocates a fresh ~520-byte buffer inside the confined arena on every node, so memory grows O(devices) for the duration of the enumeration even though the value is read and immediately turned into a String. For typical device counts this is negligible, but since buf/sizeSeg are already being reused a few lines above, routing getDeviceId through a reusable buffer (e.g., an overload taking buf) would be consistent and bound the allocation.

Neither blocks the migration — feel free to punt to a follow-up.

🤖 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/DeviceTreeFFM.java` around
lines 54 - 82, Add a defensive precondition check before copying guidBytes into
guidSeg (the code around guidSeg and guidBytes before calling
SetupApiFFM.SetupDiGetClassDevs) to validate guidBytes.length == 16 and throw an
IllegalArgumentException with a clear message if not, and refactor
Cfgmgr32FFM.getDeviceId usage inside the device enumeration loop to avoid
per-node arena allocations by adding/using an overload that accepts a reusable
MemorySegment buffer (e.g., buf) and size segment (sizeSeg) allocated once from
the same confined Arena and pass those into Cfgmgr32FFM.getDeviceId(node, buf,
sizeSeg) so the temporary ~520-byte buffer is reused rather than reallocated for
every device.
🤖 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/hardware/platform/windows/WindowsCentralProcessorFFM.java`:
- Around line 234-253: The code scales percentMaxList by getMaxFreq()
unconditionally, which can produce zero/negative frequencies if getMaxFreq() <=
0; wrap the scaling logic with a guard like if (maxFreq > 0) before computing
freqs (around the lines using maxFreq, percentMaxList, freqs,
getLogicalProcessorCount(), getNumaNodeProcToLogicalProcMap()) and only return
the computed freqs when maxFreq > 0; otherwise skip this percent-based path so
the later NtPower current-frequency query is used as the fallback.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java`:
- Around line 125-131: The utilization delta calculation must guard against
counter resets and empty snapshots: in the method where getGpuTicks() is used
(class WindowsGpuStatsFFM, variable prevUtilTicks), if prevUtilTicks is null or
either snapshot has a zero total (prev or curr total == 0) or any delta (dActive
or dIdle) is negative, then reset prevUtilTicks = curr and return -1d; only
compute and return utilization when both samples are non-empty and all deltas
are non-negative. This ensures you ignore volatile/empty PDH instances and wait
for two comparable, non-empty snapshots before reporting a value.

---

Duplicate comments:
In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java`:
- Around line 379-402: registryGetString currently allocates a fixed 512-byte
buffer and ignores RegQueryValueEx returning ERROR_MORE_DATA, which can truncate
long values; update registryGetString to call Advapi32FFM.RegQueryValueEx in a
loop that checks the return code and, on ERROR_MORE_DATA, reads the required
length from the dataSize MemorySegment, reallocates the data buffer to that size
(using the value in dataSize), and retries until the call succeeds or returns a
non-retriable error; keep closing openedKey in the finally and propagate/log the
final failure as before.

---

Nitpick comments:
In `@oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java`:
- Around line 54-82: Add a defensive precondition check before copying guidBytes
into guidSeg (the code around guidSeg and guidBytes before calling
SetupApiFFM.SetupDiGetClassDevs) to validate guidBytes.length == 16 and throw an
IllegalArgumentException with a clear message if not, and refactor
Cfgmgr32FFM.getDeviceId usage inside the device enumeration loop to avoid
per-node arena allocations by adding/using an overload that accepts a reusable
MemorySegment buffer (e.g., buf) and size segment (sizeSeg) allocated once from
the same confined Arena and pass those into Cfgmgr32FFM.getDeviceId(node, buf,
sizeSeg) so the temporary ~520-byte buffer is reused rather than reallocated for
every device.
🪄 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: 4532e2df-c896-496d-b372-a667b9b20f06

📥 Commits

Reviewing files that changed from the base of the PR and between 3e09664 and f880cf5.

📒 Files selected for processing (17)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryHandler.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.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 (26)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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/WmiQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
📚 Learning: 2026-04-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
📚 Learning: 2026-04-18T23:21:41.153Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java:44-46
Timestamp: 2026-04-18T23:21:41.153Z
Learning: In OSHI's `Win32LogicalDisk.buildWmiClassNameWithWhere` (oshi-common), the `nameToMatch` parameter is always internally controlled (e.g., a drive name from a prior WMI query result), not arbitrary user input. Do not flag missing WQL escape sequences (backslash, single-quote) as a bug — the project maintainer (dbwiddis) confirmed only the existing double-quote escaping is needed.

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
📚 Learning: 2026-04-20T03:07:04.034Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3176
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java:53-60
Timestamp: 2026-04-20T03:07:04.034Z
Learning: In OSHI's Windows FFM paging file implementation (`oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java`), the `querySwapUsed()` method uses the Windows PDH raw counter for "% Usage" on the paging file. Despite its name, this raw counter returns page counts: `FirstValue` is the number of pages currently used and `SecondValue` is the total number of pages in the swap file. The formatted counter performs the division and multiplies by 100% to yield a true percentage. Therefore, computing swap used bytes as `pageSize * used.get()` (pages × page size) is correct — do not treat the return value as a percentage.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.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/ffm/windows/PsapiFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
📚 Learning: 2026-04-05T15:37:17.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:17.867Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
📚 Learning: 2026-04-06T21:48:11.921Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:85-111
Timestamp: 2026-04-06T21:48:11.921Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` (and `MacUsbDeviceFFM.java`), the `id = 0L` sentinel is intentional when `device.getParentEntry(IOSERVICE)` returns null. It acts as a catch-all controller group for devices whose controller cannot be identified (an edge case that "should never happen" given the IORegistry format). Do not flag this as a bug or suggest skipping such devices; the design intentionally avoids both silently dropping orphaned devices and placing them at the top level without a controller context.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

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

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
🔇 Additional comments (9)
oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java (1)

334-349: LGTM — nice parity with the JNA handler.

Reusing a single msg/args pair across both branches keeps the two log sites in sync, and demoting MSAcpi_ThermalZoneTemperature to debug is a sensible quieting for a class that's frequently absent on real hardware. Behavior matches the mirrored change in WmiQueryHandler.

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

160-176: LGTM — mirrors the FFM change cleanly.

The shared message + args array and the MSAcpi_ThermalZoneTemperature-specific debug level match WmiQueryHandlerFFM.handleComException, so JNA and FFM paths will produce consistent logs. Null-guarding ex.getHresult() before intValue() is correctly preserved here.

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java (4)

28-43: Clean JNA/common split.

The superclass move, JNA-specific logger category, and explicit WindowsGlobalMemoryJNA::readPerfInfo supplier are consistent with the three-tier migration and keep the PSAPI-backed implementation localized here.


68-70: Correctly preserves the JNA tier boundary.

createVirtualMemory() now instantiates WindowsVirtualMemoryJNA, and the provided constructor context confirms this WindowsGlobalMemoryJNA reference is the expected parent type.


82-97: Shared memory-type mapping looks properly reused.

The JNA implementation now delegates both SMBIOS and legacy memory-type mapping through the common Windows memory base, avoiding duplicate mapping logic in this tier.


107-117: Good fallback correction for failed performance-info reads.

Returning 4096L for the page size on the error path is a safer default than the previous odd value while keeping available and total memory at conservative zero values.

oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java (3)

10-30: Looks good.

The import set and superclass change line up cleanly with the FFM-backed HAL migration, and the class-level contract remains clear.


32-50: Factory wiring looks correct.

These overrides satisfy AbstractHardwareAbstractionLayer and consistently instantiate the Windows FFM implementations for processor, memory, sensors, and computer system.


57-90: Delegation is consistent across the migrated components.

Each HAL query now routes to its matching FFM implementation, with parameters preserved for network interfaces and USB tree mode.

- Fix processTickData loop to use index i for parallel list reads, cpu for destination array
- Initialize partitionList to Collections.emptyList() to prevent NPE
- Fix parseNumaNode to read GroupCount and iterate all GROUP_AFFINITY entries
- Fix PsapiFFM comment: 9 SIZE_T -> 10 SIZE_T
- Add debug log in WindowsDisplayFFM when EDID registry read fails
- Fix fallback page size typo 4098 -> 4096 in both JNA and FFM
- Fix Javadoc link in WindowsHardwareAbstractionLayerFFM
- Rename WindowsVirtualMemory to WindowsVirtualMemoryJNA for consistency
@dbwiddis
dbwiddis force-pushed the migrate-windows-hal branch from f880cf5 to e5653a2 Compare April 20, 2026 05:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

381-404: ⚠️ Potential issue | 🟡 Minor

Avoid the fixed 512-byte registry string buffer.

registryGetString() still drops longer registry values instead of retrying after ERROR_MORE_DATA. Current CPU registry values are probably short, but sizing first would keep this helper safe if it gets reused.

Run this read-only check to confirm the current helper still uses the fixed buffer and lacks retry handling:

#!/bin/bash
# Description: Inspect registryGetString() for fixed-size RegQueryValueEx handling.
# Expected: current output shows a 512-byte allocation and no ERROR_MORE_DATA retry loop.

file="$(fd -i '^WindowsCentralProcessorFFM\.java$' | head -n 1)"
if [ -z "$file" ]; then
  echo "WindowsCentralProcessorFFM.java not found"
  exit 1
fi

sed -n '381,404p' "$file"
printf '\n--- RegQueryValueEx / ERROR_MORE_DATA references ---\n'
rg -n 'RegQueryValueEx|ERROR_MORE_DATA|dataSize\.set\(ValueLayout\.JAVA_INT, 0, 512\)' "$file"
🤖 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/hardware/platform/windows/WindowsCentralProcessorFFM.java`
around lines 381 - 404, registryGetString currently allocates a fixed 512-byte
buffer and doesn't handle ERROR_MORE_DATA; change it to first call
Advapi32FFM.RegQueryValueEx(openedKey, valueNameSeg, 0, MemorySegment.NULL,
MemorySegment.NULL, dataSize) to obtain the required size, then allocate a data
buffer of that size and retry the RegQueryValueEx; if the call returns
ERROR_MORE_DATA loop to resize and retry until success or another error, then
readWideString(data) as before; ensure you still close openedKey in the finally
block and preserve logging on failures (refer to registryGetString, openedKey,
dataSize, data, and RegQueryValueEx).
🤖 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/DeviceTreeFFM.java`:
- Around line 93-99: When building the device label in DeviceTreeFFM, avoid
producing a leading-space name when CM_DRP_CLASS is empty but CM_DRP_SERVICE is
present: change the logic in the block that calls Cfgmgr32FFM.getDevNodeProperty
for CM_DRP_CLASS and CM_DRP_SERVICE (variables name and svc) so that if
name.isEmpty() and svc is not empty you set name = svc; otherwise if both are
present set name = name + " (" + svc + ")". Keep the use of
Cfgmgr32FFM.getDevNodeProperty and the CM_DRP_CLASS/CM_DRP_SERVICE constants and
update only the assignment logic for name and svc.

---

Duplicate comments:
In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java`:
- Around line 381-404: registryGetString currently allocates a fixed 512-byte
buffer and doesn't handle ERROR_MORE_DATA; change it to first call
Advapi32FFM.RegQueryValueEx(openedKey, valueNameSeg, 0, MemorySegment.NULL,
MemorySegment.NULL, dataSize) to obtain the required size, then allocate a data
buffer of that size and retry the RegQueryValueEx; if the call returns
ERROR_MORE_DATA loop to resize and retry until success or another error, then
readWideString(data) as before; ensure you still close openedKey in the finally
block and preserve logging on failures (refer to registryGetString, openedKey,
dataSize, data, and RegQueryValueEx).
🪄 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: fcdf0034-70fd-460f-823d-f766b8772977

📥 Commits

Reviewing files that changed from the base of the PR and between f880cf5 and e5653a2.

📒 Files selected for processing (17)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryHandler.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacDisplayFFM.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryHandler.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/LogicalProcessorInformationFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.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 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (25)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
📚 Learning: 2026-04-20T03:07:04.034Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3176
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java:53-60
Timestamp: 2026-04-20T03:07:04.034Z
Learning: In OSHI's Windows FFM paging file implementation (`oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java`), the `querySwapUsed()` method uses the Windows PDH raw counter for "% Usage" on the paging file. Despite its name, this raw counter returns page counts: `FirstValue` is the number of pages currently used and `SecondValue` is the total number of pages in the swap file. The formatted counter performs the division and multiplies by 100% to yield a true percentage. Therefore, computing swap used bytes as `pageSize * used.get()` (pages × page size) is correct — do not treat the return value as a percentage.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/PsapiFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Cfgmgr32FFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.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/hardware/platform/windows/WindowsSoundCardFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
📚 Learning: 2026-04-05T15:37:17.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:17.867Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
📚 Learning: 2026-04-06T21:48:11.921Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:85-111
Timestamp: 2026-04-06T21:48:11.921Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` (and `MacUsbDeviceFFM.java`), the `id = 0L` sentinel is intentional when `device.getParentEntry(IOSERVICE)` returns null. It acts as a catch-all controller group for devices whose controller cannot be identified (an edge case that "should never happen" given the IORegistry format). Do not flag this as a bug or suggest skipping such devices; the design intentionally avoids both silently dropping orphaned devices and placing them at the top level without a controller context.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/DeviceTreeFFM.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
📚 Learning: 2026-04-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java
📚 Learning: 2026-04-18T23:21:41.153Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java:44-46
Timestamp: 2026-04-18T23:21:41.153Z
Learning: In OSHI's `Win32LogicalDisk.buildWmiClassNameWithWhere` (oshi-common), the `nameToMatch` parameter is always internally controlled (e.g., a drive name from a prior WMI query result), not arbitrary user input. Do not flag missing WQL escape sequences (backslash, single-quote) as a bug — the project maintainer (dbwiddis) confirmed only the existing double-quote escaping is needed.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.java

@dbwiddis
dbwiddis merged commit af5b9f4 into oshi:master Apr 20, 2026
16 of 17 checks passed
@dbwiddis
dbwiddis deleted the migrate-windows-hal branch April 20, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant