Repository navigation
Use native WTSEnumerateProcessesEx in FFM ProcessWtsData - #3216
Conversation
📝 WalkthroughWalkthroughFFM bindings for WTSEnumerateProcessesEx and WTSFreeMemoryEx were added. ProcessWtsDataFFM.queryProcessWtsMap() now uses a native WTSEnumerateProcessesEx path on Windows 7+ and falls back to the previous WMI-based enumeration on older Windows, with explicit native memory freeing and logging. Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Driver as ProcessWtsDataFFM
participant Version as VersionCheck
participant Native as Wtsapi32FFM / WTSEnumerateProcessesEx
participant WMI as WMI (Win32_Process)
participant Free as Wtsapi32FFM / WTSFreeMemoryEx
App->>Driver: queryProcessWtsMap(pids)
Driver->>Version: IS_WINDOWS7_OR_GREATER?
alt Windows 7+
Version-->>Driver: true
Driver->>Native: WTSEnumerateProcessesEx(...)
Native-->>Driver: PROCESS_INFO_EX buffer + count
Driver->>Driver: parse entries, convert units, filter pids
Driver->>Free: WTSFreeMemoryEx(...)
Free-->>Driver: freed
Driver-->>App: Map<Integer, WtsInfo>
else Pre-Windows 7
Version-->>Driver: false
Driver->>WMI: queryProcesses (Win32_Process)
WMI-->>Driver: WMI results
Driver->>Driver: map to WtsInfo
Driver-->>App: Map<Integer, WtsInfo>
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
ff5ef22 to
603d7f9
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (3)
.github/workflows/pr.yaml (1)
76-83: Consider gating and timing out the benchmark job to reduce wasted CI minutes.Optional but useful: add dependencies on
lint+test, and a timeout, so benchmarks don’t run after earlier failures or hang indefinitely.Suggested workflow tweak
benchmarks: + needs: [lint, test] runs-on: ${{ matrix.os }} + timeout-minutes: 30 strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/pr.yaml around lines 76 - 83, The "benchmarks" job should be gated and bounded to avoid wasted CI minutes: add a needs: entry referencing the upstream jobs (e.g., needs: [lint, test]) to skip benchmarks when prior checks fail, and add a timeout-minutes: value (e.g., 60) on the "benchmarks" job to prevent indefinite hangs; update the "benchmarks" job block (the job named "JMH Benchmarks, ${{ matrix.os }}" with strategy.matrix/os and fail-fast) to include these fields and optionally a concurrency or if-needed conditional to further control runs.oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java (1)
89-90: Optional: normalizepidsto aSetfor faster filtering.Inside the per-process loop,
Collection.containscan become costly for large non-Set inputs.Possible tweak
private static Map<Integer, WtsInfo> queryProcessWtsMapFromWTS(Collection<Integer> pids) { Map<Integer, WtsInfo> wtsMap = new HashMap<>(); + Collection<Integer> pidFilter = pids instanceof java.util.Set || pids == null ? pids : new HashSet<>(pids); try (Arena arena = Arena.ofConfined()) { @@ - if (pids != null && !pids.contains(pid)) { + if (pidFilter != null && !pidFilter.contains(pid)) { continue; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java` around lines 89 - 90, The loop in ProcessWtsDataFFM checks membership with pids.contains(pid) which can be slow for non-Set collections; before the per-process loop, normalize the incoming pids Collection to a Set (e.g., new HashSet<>(pids) or an emptySet when null) and then use that Set for contains checks so lookups become O(1) — update references in the per-process loop that use pids to use the new Set variable and preserve the existing null/empty semantics.oshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.java (1)
29-40: Add an explicit 64-bit pointer guard to make the struct assumption clear.The hardcoded offsets in
WTS_PROCESS_INFO_EXWassume 64-bit pointers (e.g.,pProcessNameat offset 8 is an 8-byte pointer). While this matches current FFM usage, a minimal static initializer block documents the constraint and prevents accidental misuse if the code is ever adapted to other architectures.Proposed minimal guard
+ static { + if (ADDRESS.byteSize() != 8) { + throw new UnsupportedOperationException("WTS_PROCESS_INFO_EXW offsets require 64-bit pointers."); + } + } + // WTS_PROCESS_INFO_EXW struct layout (64-bit):🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.java` around lines 29 - 40, Add a static initializer in Wtsapi32FFM that asserts the code’s 64-bit pointer assumption by checking java.nio.ByteOrder or, better, com.sun.jna.Pointer.SIZE == 8 and throwing an IllegalStateException with a clear message if the platform is not 64-bit; reference the related constants (PROCESS_INFO_EX_SIZE, PROCESS_INFO_EX_PROCESS_ID, PROCESS_INFO_EX_PROCESS_NAME, etc.) in the error message to make it obvious these offsets only apply to 64-bit. Ensure the guard runs at class load time so the hardcoded offsets are never used on non-64-bit platforms.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.github/workflows/pr.yaml:
- Around line 76-83: The "benchmarks" job should be gated and bounded to avoid
wasted CI minutes: add a needs: entry referencing the upstream jobs (e.g.,
needs: [lint, test]) to skip benchmarks when prior checks fail, and add a
timeout-minutes: value (e.g., 60) on the "benchmarks" job to prevent indefinite
hangs; update the "benchmarks" job block (the job named "JMH Benchmarks, ${{
matrix.os }}" with strategy.matrix/os and fail-fast) to include these fields and
optionally a concurrency or if-needed conditional to further control runs.
In
`@oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java`:
- Around line 89-90: The loop in ProcessWtsDataFFM checks membership with
pids.contains(pid) which can be slow for non-Set collections; before the
per-process loop, normalize the incoming pids Collection to a Set (e.g., new
HashSet<>(pids) or an emptySet when null) and then use that Set for contains
checks so lookups become O(1) — update references in the per-process loop that
use pids to use the new Set variable and preserve the existing null/empty
semantics.
In `@oshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.java`:
- Around line 29-40: Add a static initializer in Wtsapi32FFM that asserts the
code’s 64-bit pointer assumption by checking java.nio.ByteOrder or, better,
com.sun.jna.Pointer.SIZE == 8 and throwing an IllegalStateException with a clear
message if the platform is not 64-bit; reference the related constants
(PROCESS_INFO_EX_SIZE, PROCESS_INFO_EX_PROCESS_ID, PROCESS_INFO_EX_PROCESS_NAME,
etc.) in the error message to make it obvious these offsets only apply to
64-bit. Ensure the guard runs at class load time so the hardcoded offsets are
never used on non-64-bit platforms.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ea5b0144-f028-499c-ad61-cfcad8ddbe2e
📒 Files selected for processing (6)
.github/workflows/linux.yaml.github/workflows/macos.yaml.github/workflows/pr.yaml.github/workflows/windows.yamloshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.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 (5)
📓 Common learnings
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:47.155Z
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.
📚 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-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.javaoshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
📚 Learning: 2026-04-17T23:43:35.860Z
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:35.860Z
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-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.javaoshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
📚 Learning: 2026-04-18T22:53:56.149Z
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:56.149Z
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-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
📚 Learning: 2026-04-19T01:28:47.155Z
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:47.155Z
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-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
🔇 Additional comments (8)
.github/workflows/macos.yaml (1)
55-70: Great split of benchmarks into a dedicated job.This keeps the test/coverage path faster while still preserving JMH performance checks. Nice improvement.
.github/workflows/linux.yaml (1)
79-94: Looks good — benchmark isolation is implemented cleanly.The dedicated Linux benchmark job is straightforward and aligns with the CI decoupling goal.
.github/workflows/windows.yaml (1)
51-66: Nice addition of a standalone Windows benchmark lane.This mirrors the other workflows well and keeps perf benchmarking separate from regular test execution.
.github/workflows/pr.yaml (1)
75-94: Good PR workflow extraction for JMH benchmarks.The new dedicated benchmark matrix is clear and consistent with the platform-specific workflow changes.
oshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.java (2)
50-56: Nice addition ofWTSEnumerateProcessesExWbinding.Signature and wrapper flow look aligned with the WinAPI contract and existing FFM downcall style.
73-79:WTSFreeMemoryExWbinding looks good.Good to see this exposed directly; it matches the allocation/free pairing needed by the new WTS fast path.
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java (2)
63-67: Version-gated fast path + fallback is cleanly implemented.This matches the intended behavior: native WTS on Win7+ and WMI fallback otherwise.
77-107: Great job preserving safe native cleanup semantics.The
try/finallyaroundWTSFreeMemoryExmirrors the JNA path and keeps failure logging in place.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java (1)
89-90: Optional perf tweak for PID filtering in the loop.Line 89 currently does
Collection.contains(...)per process entry. If callers pass aList, this becomes O(processes × pids). Consider normalizing once to aSetbefore iteration.♻️ Suggested micro-refactor
+import java.util.Set; ... private static Map<Integer, WtsInfo> queryProcessWtsMapFromWTS(Collection<Integer> pids) { Map<Integer, WtsInfo> wtsMap = new HashMap<>(); + Set<Integer> pidFilter = pids == null ? null : (pids instanceof Set ? (Set<Integer>) pids : new HashSet<>(pids)); try (Arena arena = Arena.ofConfined()) { ... - if (pids != null && !pids.contains(pid)) { + if (pidFilter != null && !pidFilter.contains(pid)) { continue; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java` around lines 89 - 90, The loop currently calls pids.contains(pid) for each process which is O(n) if pids is a List; to avoid quadratic behavior convert/normalize the incoming Collection pids to a Set once before iterating (e.g., create a local Set<Integer> pidSet = pids == null ? null : (pids instanceof Set ? (Set)pids : new HashSet<>(pids))) and then replace checks of pids.contains(pid) with pidSet.contains(pid); update references in ProcessWtsDataFFM.java (the loop using variables pids and pid) so null semantics are preserved.
🤖 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-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java`:
- Around line 89-90: The loop currently calls pids.contains(pid) for each
process which is O(n) if pids is a List; to avoid quadratic behavior
convert/normalize the incoming Collection pids to a Set once before iterating
(e.g., create a local Set<Integer> pidSet = pids == null ? null : (pids
instanceof Set ? (Set)pids : new HashSet<>(pids))) and then replace checks of
pids.contains(pid) with pidSet.contains(pid); update references in
ProcessWtsDataFFM.java (the loop using variables pids and pid) so null semantics
are preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 02607b06-08e7-414b-883c-aa9f0c9b9f4c
📒 Files selected for processing (2)
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.java
🚧 Files skipped from review as they are similar to previous changes (1)
- oshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-18T22:53:56.149Z
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:56.149Z
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-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
📚 Learning: 2026-04-19T01:28:47.155Z
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:47.155Z
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-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
🔇 Additional comments (2)
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java (2)
63-67: Nice OS-gated fast-path split.This keeps behavior aligned with the PR goal: native WTS on supported systems and a clear WMI fallback path.
71-107: Native memory lifecycle looks solid.Good use of
finallyto guaranteeWTSFreeMemoryExcleanup and consistent error/warn logging on failure paths.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3216 +/- ##
==========================================
- Coverage 61.50% 61.50% -0.01%
==========================================
Files 423 423
Lines 20371 20408 +37
Branches 3572 3578 +6
==========================================
+ Hits 12530 12552 +22
- Misses 6055 6063 +8
- Partials 1786 1793 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Replace WMI-based process enumeration in ProcessWtsDataFFM with native WTSEnumerateProcessesEx calls on Windows 7+, matching the JNA implementation's fast path. Keep WMI as a fallback for pre-Win7. Add WTSEnumerateProcessesEx and WTSFreeMemoryEx bindings to Wtsapi32FFM along with WTS_PROCESS_INFO_EX struct offset constants. Fixes #3186
603d7f9 to
d5fd6d3
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java (1)
96-96: Extract the process-name buffer size into a constant.Line 96 currently uses a magic number (
512); a named constant would make intent and future tuning clearer.♻️ Small refactor
+ private static final long WTS_PROCESS_NAME_MAX_BYTES = 512; ... - String name = pName.equals(MemorySegment.NULL) ? "" : readWideString(pName.reinterpret(512)); + String name = pName.equals(MemorySegment.NULL) ? "" + : readWideString(pName.reinterpret(WTS_PROCESS_NAME_MAX_BYTES));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java` at line 96, Replace the magic number 512 in ProcessWtsDataFFM with a named constant to clarify intent and make future tuning easier: add a private static final int PROCESS_NAME_BUFFER_BYTES = 512 (or PROCESS_NAME_BUFFER_SIZE_BYTES) at the top of the class and use it in the readWideString call (change pName.reinterpret(512) to pName.reinterpret(PROCESS_NAME_BUFFER_BYTES)); include a brief comment that this size is the byte buffer for the wide-char process name to document the unit.
🤖 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-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java`:
- Line 96: Replace the magic number 512 in ProcessWtsDataFFM with a named
constant to clarify intent and make future tuning easier: add a private static
final int PROCESS_NAME_BUFFER_BYTES = 512 (or PROCESS_NAME_BUFFER_SIZE_BYTES) at
the top of the class and use it in the readWideString call (change
pName.reinterpret(512) to pName.reinterpret(PROCESS_NAME_BUFFER_BYTES)); include
a brief comment that this size is the byte buffer for the wide-char process name
to document the unit.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 73d044f7-445e-4abb-a160-f2f613f65d2a
📒 Files selected for processing (3)
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.javasrc/site/markdown/Performance.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2026-04-18T03:18:06.205Z
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:06.205Z
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:
src/site/markdown/Performance.md
📚 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-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.java
📚 Learning: 2026-04-18T22:53:56.149Z
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:56.149Z
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-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
📚 Learning: 2026-04-19T01:28:47.155Z
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:47.155Z
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-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
🔇 Additional comments (5)
oshi-core-ffm/src/main/java/oshi/ffm/windows/Wtsapi32FFM.java (2)
20-40: Good addition of WTS process constants and offsets.This is a clean, focused extension and matches the downstream parser needs well.
50-79: Native bindings look consistent with existing FFM wrapper style.The new
WTSEnumerateProcessesEx/WTSFreeMemoryExwrappers fit the module’s established downcall pattern and error-handling flow.oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java (2)
64-115: Nice split between Win7+ native path and legacy WMI fallback.The routing logic is straightforward, and the native buffer free in
finallykeeps the WTS path robust.
117-132: Fallback extraction is clean and preserved well.Keeping the WMI path isolated in its own method improves readability and keeps behavior easy to reason about.
src/site/markdown/Performance.md (1)
33-36: Docs update aligns well with the implementation change.The revised Windows “Processes” numbers and summary text are coherent with the new native WTS fast path.
Summary
Replace WMI-based process enumeration in
ProcessWtsDataFFMwith nativeWTSEnumerateProcessesExcalls on Windows 7+, matching the JNA implementation's fast path. Keep WMI as a fallback for pre-Win7.Changes
Wtsapi32FFM.javaWTSEnumerateProcessesExandWTSFreeMemoryExdowncall bindingsWTS_PROCESS_INFO_EXstruct offset constantsWTS_ANY_SESSION,WTS_PROCESS_INFO_LEVEL_1,WTS_TYPE_PROCESS_INFO_LEVEL_1constantsProcessWtsDataFFM.javaWTSEnumerateProcessesEx(Win7+)Motivation
The FFM process benchmark was ~4x slower than JNA because it always used WMI (
Win32_Process) instead of the native kernel call. This should bring FFM process enumeration performance in line with JNA.Fixes #3186
Summary by CodeRabbit
New Features
Performance Improvements
Reliability
Documentation