Repository navigation
Fix ADL GPU concurrency/overflow/OD6 gating and WMI handler thread-safety - #3490
Conversation
…fety AdlUtilFFM: - ensureAdaptersEnumerated had a check-then-act race on adaptersEnumerated: two threads could both enumerate and reset BUS_TO_INDEX. Guard it with double-checked locking so enumeration happens at most once. - enumerateAdapters passed ADAPTER_INFO_SIZE * num (a plain int) to the native adapter-info call while allocating the buffer with a long. Add an overflow guard so the int argument can never wrap (implausible in practice). - getPowerDraw gated on Overdrive N (version >= 8) but calls the Overdrive 6 power API, wrongly rejecting OD6-only cards. Gate on OD6 (version >= 6) instead; the native return code still guards cards lacking the call. WmiQueryHandler (JNA): the @threadsafe class cached failed class names in a plain HashSet mutated without synchronization, and wmiTimeout was a plain int. Match the FFM twin: a ConcurrentHashMap-backed set and a volatile wmiTimeout.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (15)
📝 WalkthroughWalkthroughADL runtime binding now synchronizes lazy adapter enumeration, rejects oversized native allocations, and distinguishes Overdrive 6 power support from Overdrive-N. WMI handling uses a concurrent failed-class cache and a volatile timeout field. ChangesADL runtime handling
WMI concurrency state
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java (1)
273-274: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueExplicitly verify that Overdrive is supported.
While FFM safely zero-initializes the allocated memory (so if an unsupported device leaves the buffer untouched, the evaluation safely defaults to
0 >= minVersionwhich is false), it is safer and more explicit to verify thesupportedflag returned by the API.♻️ Proposed refactor
- if ((int) ADL2_OVERDRIVE_CAPS.invokeExact(context, adapterIndex, supported, enabled, version) == ADL_OK) { - return version.get(JAVA_INT, 0) >= minVersion; - } + if ((int) ADL2_OVERDRIVE_CAPS.invokeExact(context, adapterIndex, supported, enabled, version) == ADL_OK) { + return supported.get(JAVA_INT, 0) != 0 && version.get(JAVA_INT, 0) >= minVersion; + }🤖 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-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java` around lines 273 - 274, Update the Overdrive capability check in the ADL2_OVERDRIVE_CAPS invocation to require the returned supported flag before evaluating version against minVersion. Preserve the existing ADL_OK and version checks, and return false when Overdrive is unsupported.
🤖 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.
Nitpick comments:
In `@oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java`:
- Around line 273-274: Update the Overdrive capability check in the
ADL2_OVERDRIVE_CAPS invocation to require the returned supported flag before
evaluating version against minVersion. Preserve the existing ADL_OK and version
checks, and return false when Overdrive is unsupported.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f269ea1e-b041-4116-9bb4-2b4179135bd4
📒 Files selected for processing (2)
oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/WmiQueryHandler.java
📜 Review details
⏰ Context from checks skipped due to timeout. (11)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (1)
📚 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/util/platform/windows/WmiQueryHandler.javaoshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
🔇 Additional comments (4)
oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryHandler.java (1)
8-10: LGTM!Also applies to: 45-48
oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java (3)
204-214: LGTM!
228-233: LGTM!
432-434: LGTM!
ADL2_Overdrive_Caps returns a supported flag alongside the version; check it so an adapter reporting a version but supported=0 is not treated as capable.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3490 +/- ##
============================================
- Coverage 74.93% 74.87% -0.07%
Complexity 76 76
============================================
Files 591 591
Lines 21584 21584
Branches 3614 3614
============================================
- Hits 16175 16161 -14
- Misses 3436 3444 +8
- Partials 1973 1979 +6
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:
|
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.
Summary
Concurrency and correctness fixes surfaced by CodeQL/AI review in the AMD ADL GPU (FFM) path and the JNA WMI query handler.
AdlUtilFFMensureAdaptersEnumerateddid a check-then-act on thevolatile adaptersEnumeratedflag, so two threads could both runenumerateAdaptersand resetBUS_TO_INDEX. Now guarded with double-checked locking so enumeration happens at most once.enumerateAdapterspassedADAPTER_INFO_SIZE * num(a plainint) to the native adapter-info call while allocating the buffer with along. The native argument must stay 32-bit, so an overflow guard now rejects an implausibly large adapter count rather than letting theintmultiplication wrap.getPowerDrawcalls the Overdrive 6 power API but gated on Overdrive N (version >= 8), wrongly returning-1on OD6-only cards. It now gates on OD6 (version >= 6); the native return code still guards any card that doesn't implement the call. (AMD-hardware-specific; validated by code inspection, consistent with the rest of the best-effort Windows GPU path.)WmiQueryHandler(JNA)The
@ThreadSafehandler cached failed class names in a plainHashSetmutated without synchronization (concurrentadd/containscan corrupt or spin), andwmiTimeoutwas a plainint. Brought to parity with the FFM twin: aConcurrentHashMap-backed set and avolatile wmiTimeout. (comThreadingstays plain — guarded by the existingsynchronizedaccessors;securityInitializedwas alreadyvolatile.)Testing
./mvnw clean install(full reactor) plus spotless, checkstyle, forbiddenapis, and javadoc all pass.🤖 Generated with Claude Code
Summary by CodeRabbit