Skip to content

Mirror the ADL Overdrive fixes from the FFM twin back to JNA - #3578

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:fix-adl-jna-divergences
Aug 4, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:fix-adl-jna-divergences

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

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, so oshi-core has carried them since:

  • getPowerDraw returns -1 on Overdrive 6-era Radeon cards. Power is read through ADL2_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, and GpuStats#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.
  • The Overdrive capability check ignored iSupported. ADL2_Overdrive_Caps's iSupported out-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 shared supportsOverdriveVersion(context, adapterIndex, minVersion) helper matching the twin's shape.
  • ensureAdaptersEnumerated was check-then-act on a @ThreadSafe class. Two concurrent callers could both enumerate and both publish to BUS_TO_INDEX. Now double-checked locking on a dedicated lock, as the twin does.

Adl.java gains ADL_OVERDRIVE_VERSION_6 = 6 for the new gate.

#3490's overflow guard has no JNA counterpart — JNA sizes the buffer from Structure.size() rather than manual int arithmetic, so there is nothing to overflow.

A 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 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-common may not reference com.sun.jna, and neither may oshi-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:check and javadoc:javadoc all pass locally on macOS/JDK 25. Spotless also reordered a pre-existing import block in Adl.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

  • Bug Fixes
    • Fixed Windows AMD GPU power-draw detection for older Radeon cards using Overdrive 6.
    • Improved GPU adapter detection to prevent duplicate or missed graphics cards.
    • Corrected capability checks for AMD GPU monitoring features.
    • Improved reliability when enumerating AMD GPU adapters.

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.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Windows AMD GPU handling

Layer / File(s) Summary
ADL enumeration and Overdrive power gating
oshi-core/src/main/java/oshi/jna/platform/windows/Adl.java, oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java, CHANGELOG.md
ADL enumeration now uses synchronized double-checked locking. Overdrive checks require support flags and minimum versions. Power draw now accepts Overdrive 6 or newer adapters.
DXGI fallback filtering
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
The WMI fallback now receives only DXGI adapters not consumed by registry processing.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • oshi/oshi#3087: Related Windows GPU enumeration and DXGI adapter filtering.
  • oshi/oshi#3490: Applies related ADL enumeration and Overdrive 6 fixes to the FFM implementation.
  • oshi/oshi#3544: Modifies the same Windows FFM WMI fallback method.

Poem

A rabbit hops through Radeon light,
Overdrive six now reads just right.
DXGI cards stay in their queue,
ADL checks know what to do.
Power blooms in Windows bright!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: applying ADL Overdrive fixes from the FFM implementation to the JNA implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.86%. Comparing base (b2f5ce3) to head (e537891).

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     
Flag Coverage Δ
linux 37.58% <ø> (+0.01%) ⬆️
macos 38.40% <ø> (-0.04%) ⬇️
windows 45.35% <ø> (-0.01%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

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 win

Add test coverage for the concurrency and Overdrive-6 gating paths.

AdlUtilJNA has no existing test coverage for the new ensureAdaptersEnumerated double-checked locking or the supportsOverdriveVersion supported + minVersion gating. 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 value

Consider Memoizer.memoize for the adapter-enumeration cache.

The new ENUM_LOCK/adaptersEnumerated/BUS_TO_INDEX triad 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 Holder pattern already used in this class for Holder.LIB.

As per coding guidelines, "Memoize constant or expensive, slowly changing system values with oshi.util.Memoizer.memoize, generally using a Supplier<T> and defaultExpiration() 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

📥 Commits

Reviewing files that changed from the base of the PR and between b2f5ce3 and e537891.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-core/src/main/java/oshi/jna/platform/windows/Adl.java
  • oshi-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-core implementation, apply the equivalent behavior change to its corresponding oshi-core-ffm twin, or explain why the implementations intentionally differ.

Files:

  • oshi-core/src/main/java/oshi/jna/platform/windows/Adl.java
  • oshi-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.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/*.java: Do not use banned numeric parsing APIs such as Integer.parseInt, Long.parseLong, Double.parseDouble, or Integer.decode; use the corresponding tolerant ParseUtil methods.
Do not import org.slf4j.event.**; use oshi.util.LogLevel instead.

Files:

  • oshi-core/src/main/java/oshi/jna/platform/windows/Adl.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-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 with config/import-control.xml, the module's module-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 with oshi.util.Memoizer.memoize, generally using a Supplier<T> and defaultExpiration() when refresh is required.
Do not duplicate non-native logic between platform implementations; hoist parsing, conversion, filtering, caching, validation, and sentinel handling into oshi-common where possible.

Files:

  • oshi-core/src/main/java/oshi/jna/platform/windows/Adl.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-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.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • CHANGELOG.md
  • oshi-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 an oshi-core-ffm implementation, apply the equivalent behavior change to its corresponding oshi-core twin, or explain why the implementations intentionally differ.
Do not reference com.sun.jna from 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 Release changelog 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.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-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.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-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.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-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!

@dbwiddis
dbwiddis merged commit 74b015c into oshi:master Aug 4, 2026
17 checks passed
@dbwiddis
dbwiddis deleted the fix-adl-jna-divergences branch August 4, 2026 16:14
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