Repository navigation
Mirror the ADL Overdrive fixes from the FFM twin back to JNA - #3578
Conversation
PR #3490 fixed three defects in AdlUtilFFM that were never applied to AdlUtilJNA: * getPowerDraw reads power through ADL2_Overdrive6_CurrentPower_Get but gated on Overdrive N (version 8) support, so Overdrive 6-era Radeon cards were rejected before the call they actually implement and GpuStats#getPowerDraw() returned -1 instead of real wattage. Gate on Overdrive 6 instead; the return code still guards cards that do not implement the call. * The Overdrive capability check allocated the ADL2_Overdrive_Caps iSupported out-parameter and never read it, treating a card that reports a version but no Overdrive support as supported. Check both iSupported and the version, via a shared supportsOverdriveVersion helper matching the twin. * ensureAdaptersEnumerated was check-then-act on a @threadsafe class, so concurrent callers could both enumerate and both publish. Use double-checked locking on a dedicated lock, as the twin does. Also fix a separate divergence in the opposite direction: WindowsGraphicsCardFFM passed the full DXGI adapter list to the WMI fallback where the JNA twin deliberately passes the match-and-consume copy. Adapters are removed from that copy only after a card is successfully constructed, so an adapter whose registry reads threw remains available to the fallback. FFM reaches this path by swallowing the registry walk failure, which is exactly when it matters. The #3490 overflow guard has no JNA equivalent; JNA computes the buffer size from Structure.size() rather than manual int arithmetic. Compiles clean; these are Windows-only paths, not executable from a macOS host, and the power-draw fix additionally needs an AMD GPU. CI covers the rest.
📝 WalkthroughWalkthroughThe change updates Windows AMD GPU handling. JNA ADL enumeration and Overdrive checks now support Overdrive 6 power reporting. FFM WMI fallback filters consumed DXGI adapters. The changelog records the fix. ChangesWindows AMD GPU handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3578 +/- ##
============================================
- Coverage 79.95% 79.86% -0.09%
- Complexity 3858 4094 +236
============================================
Files 709 709
Lines 24206 24206
Branches 4048 4048
============================================
- Hits 19354 19333 -21
- Misses 2692 2710 +18
- Partials 2160 2163 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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/util/gpu/AdlUtilJNA.java (1)
144-201: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winAdd test coverage for the concurrency and Overdrive-6 gating paths.
AdlUtilJNAhas no existing test coverage for the newensureAdaptersEnumerateddouble-checked locking or thesupportsOverdriveVersionsupported +minVersiongating. Add tests that exercise concurrent enumeration calls and supported/unsupported Overdrive-6 return values before relying on these critical-path behavior changes.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java` around lines 144 - 201, Add tests for AdlUtilJNA.ensureAdaptersEnumerated that invoke adapter enumeration concurrently and verify it occurs only once, and add tests for supportsOverdriveVersion covering supported adapters meeting the Overdrive-6 minimum plus unsupported or lower-version results. Use the existing ADL/JNA test setup and mocks to validate both gating outcomes without changing production behavior.
🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java (1)
93-158: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider
Memoizer.memoizefor the adapter-enumeration cache.The new
ENUM_LOCK/adaptersEnumerated/BUS_TO_INDEXtriad hand-rolls a double-checked-locking cache for a value that is computed once and reused.oshi.util.Memoizer.memoize(Supplier<T>)already provides this pattern, computed once and thread-safe, with no separate lock object needed.This is optional. The current implementation is correct and consistent with the existing
Holderpattern already used in this class forHolder.LIB.As per coding guidelines, "Memoize constant or expensive, slowly changing system values with
oshi.util.Memoizer.memoize, generally using aSupplier<T>anddefaultExpiration()when refresh is required."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java` around lines 93 - 158, Optionally replace the manual ENUM_LOCK/adaptersEnumerated/BUS_TO_INDEX cache in ensureAdaptersEnumerated with Memoizer.memoize using a thread-safe Supplier-based computation. Preserve lazy adapter enumeration, reuse of the computed mapping, and the existing retry behavior when enumeration fails; retain the current Holder pattern if Memoizer cannot represent failed enumeration retries cleanly.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java`:
- Around line 144-201: Add tests for AdlUtilJNA.ensureAdaptersEnumerated that
invoke adapter enumeration concurrently and verify it occurs only once, and add
tests for supportsOverdriveVersion covering supported adapters meeting the
Overdrive-6 minimum plus unsupported or lower-version results. Use the existing
ADL/JNA test setup and mocks to validate both gating outcomes without changing
production behavior.
---
Nitpick comments:
In `@oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java`:
- Around line 93-158: Optionally replace the manual
ENUM_LOCK/adaptersEnumerated/BUS_TO_INDEX cache in ensureAdaptersEnumerated with
Memoizer.memoize using a thread-safe Supplier-based computation. Preserve lazy
adapter enumeration, reuse of the computed mapping, and the existing retry
behavior when enumeration fails; retain the current Holder pattern if Memoizer
cannot represent failed enumeration retries cleanly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 75ca6255-7e15-4f97-85ac-fe293dc2bbe5
📒 Files selected for processing (4)
CHANGELOG.mdoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.javaoshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout. (6)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
📓 Path-based instructions (7)
oshi-core/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
For changes to an
oshi-coreimplementation, apply the equivalent behavior change to its correspondingoshi-core-ffmtwin, or explain why the implementations intentionally differ.
Files:
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
{oshi-common,oshi-core}/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
Use Java 8 language and API compatibility: do not use
var, records, switch expressions, text blocks,List.of,Stream.toList(), or other post-Java-8 features.
Files:
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/*.java: Do not use banned numeric parsing APIs such asInteger.parseInt,Long.parseLong,Double.parseDouble, orInteger.decode; use the corresponding tolerantParseUtilmethods.
Do not importorg.slf4j.event.**; useoshi.util.LogLevelinstead.
Files:
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.javaoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
**/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/src/main/java/**/*.java: Keep external imports synchronized withconfig/import-control.xml, the module'smodule-info.java, and, when necessary, its Maven configuration.
Provide Javadoc for every public and protected type and method; use imported simple class names rather than fully qualified names in code and Javadoc links.
Use the repository's concurrency annotation (@ThreadSafe,@Immutable,@NotThreadSafe, or@GuardedBy) on new classes, matching the modeled class where appropriate.
Memoize constant or expensive, slowly changing system values withoshi.util.Memoizer.memoize, generally using aSupplier<T>anddefaultExpiration()when refresh is required.
Do not duplicate non-native logic between platform implementations; hoist parsing, conversion, filtering, caching, validation, and sentinel handling intooshi-commonwhere possible.
Files:
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.javaoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
**/*.{java,xml,properties,md}
📄 CodeRabbit inference engine (AGENTS.md)
Do not commit generated output,
target/, or IDE files.
Files:
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.javaCHANGELOG.mdoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
oshi-core-ffm/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-core-ffm/src/main/java/**/*.java: For changes to anoshi-core-ffmimplementation, apply the equivalent behavior change to its correspondingoshi-coretwin, or explain why the implementations intentionally differ.
Do not referencecom.sun.jnafrom FFM implementation sources.
Files:
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
CHANGELOG.md
📄 CodeRabbit inference engine (AGENTS.md)
Add a
Next Releasechangelog entry only for user-visible changes; omit pure refactors, deduplication, test-only changes, and CI configuration changes.
Files:
CHANGELOG.md
🧠 Learnings (4)
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.javaoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.
Applied to files:
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.javaoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.
Applied to files:
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.javaoshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
📚 Learning: 2026-08-02T23:56:23.866Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3565
File: oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java:51-56
Timestamp: 2026-08-02T23:56:23.866Z
Learning: For Java FFM bindings in the oshi-core-ffm module, assume a 64-bit JVM and 64-bit operating system. Do not flag 32-bit native ABI or memory-layout compatibility concerns, consistent with the project's JDK 25 support policy, unless that policy changes.
Applied to files:
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
🔇 Additional comments (4)
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java (1)
157-159: LGTM!oshi-core/src/main/java/oshi/jna/platform/windows/Adl.java (1)
8-13: LGTM!Also applies to: 23-23
oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java (1)
44-97: LGTM!Also applies to: 203-333, 349-380
CHANGELOG.md (1)
14-14: LGTM!
Found by a normalized JNA/FFM twin diff over the Windows and GPU clusters, following up on #3569 and #3577.
AdlUtilJNA never received #3490's fixes
PR #3490 fixed three defects in
AdlUtilFFM. None were mirrored to the JNA twin, sooshi-corehas carried them since:getPowerDrawreturns -1 on Overdrive 6-era Radeon cards. Power is read throughADL2_Overdrive6_CurrentPower_Get, but the call was gated on Overdrive N (version 8) support — so exactly the cards that implement the OD6 power API but predate OD N were rejected before reaching it, andGpuStats#getPowerDraw()returned -1 instead of real wattage. Now gated on Overdrive 6; the return code still guards cards that do not implement the call. This is the only user-visible change.iSupported.ADL2_Overdrive_Caps'siSupportedout-parameter was allocated and never read, so a card reporting a version but no Overdrive support was treated as supported. Both are now checked, through a sharedsupportsOverdriveVersion(context, adapterIndex, minVersion)helper matching the twin's shape.ensureAdaptersEnumeratedwas check-then-act on a@ThreadSafeclass. Two concurrent callers could both enumerate and both publish toBUS_TO_INDEX. Now double-checked locking on a dedicated lock, as the twin does.Adl.javagainsADL_OVERDRIVE_VERSION_6 = 6for the new gate.#3490's overflow guard has no JNA counterpart — JNA sizes the buffer from
Structure.size()rather than manualintarithmetic, so there is nothing to overflow.A divergence in the opposite direction
WindowsGraphicsCardFFMpassed the full DXGI adapter list to the WMI fallback where the JNA twin deliberately passes the match-and-consume copy. Adapters are removed from that copy only after a card is successfully constructed, so an adapter whose registry reads threw stays available to the fallback. FFM reaches this path precisely by swallowing the registry-walk failure, which is when it matters. Too marginal to describe in the changelog, so this PR's entry covers the ADL fix only.Why not hoist the shared logic
oshi-commonmay not referencecom.sun.jna, and neither mayoshi-core-ffm. The ADL constants and gating logic are necessarily duplicated across the two implementations, so the JNA side is patched in place to match the reviewed twin.Verification
Compiles clean;
spotless:apply sortpom:sort checkstyle:check install forbiddenapis:checkandjavadoc:javadocall pass locally on macOS/JDK 25. Spotless also reordered a pre-existing import block inAdl.java.These are Windows-only paths, not executable from a macOS host, and the power-draw fix additionally needs an AMD GPU — so it is not runtime-verified. The correctness argument is that #3490 already made these exact three changes to the FFM twin and they were reviewed and merged; the JNA half was simply missed. Windows CI dispatched against this branch is green on all six JDK/runner combinations.
Summary by CodeRabbit