Skip to content

Share Windows GlobalMemory/VirtualMemory logic across JNA and FFM - #3453

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-windows-memory
Jul 12, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-windows-memory

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of the cross-OS consistency/dedup audit (Item 5, memory). Every platform's GlobalMemory/VirtualMemory classes already follow the shared-base + thin-native-twin shape (done during the FFM ports) except Windows, whose JNA and FFM twins still carried the full logic in both backends. This brings Windows into line.

Changes

GlobalMemory — WindowsGlobalMemory (existing base, previously just the memory-type lookup tables) now holds:

  • the memoized available/total/pageSize suppliers + getters
  • the memoized virtual-memory supplier + getVirtualMemory()
  • the full getPhysicalMemory() WMI bank-assembly loop

with protected abstract hooks for the native pieces: readPerfInfo(), createVirtualMemory(), isWindows10OrGreater(), queryPhysicalMemory(), queryPhysicalMemoryWin8().

VirtualMemory — VirtualMemory had no shared base, so WindowsVirtualMemory is new: it holds the parent-global reference, the memoized used/totalVmaxVused/swapInOut suppliers, and the six page-size-scaled getters, with hooks querySwapUsed(), querySwapTotalVirtMaxVirtUsed(), queryPageSwaps().

The JNA and FFM twins shrink to just those native hooks:

  • GlobalMemory: JNA 119 → 67, FFM 128 → 79
  • VirtualMemory: JNA 106 → 65, FFM 111 → 71

~182 lines of duplicated twin logic eliminated. (Raw net LOC is roughly flat because WindowsVirtualMemory is a new file and WindowsGlobalMemory absorbs the loop that was duplicated in both twins — the win is single-source-of-truth / reduced duplication, matching every other platform.)

Behavior

No user-facing change — the hoisted logic is identical to what both twins previously duplicated; only the native queries remain per-backend.

Testing

  • spotless / checkstyle / forbiddenapis / javadoc: clean
  • Clean full-reactor install: BUILD SUCCESS, 0 tests failed (compiles the Windows JNA + FFM classes on all modules); WindowsGlobalMemoryTest passes
  • Windows runtime memory values (perf-info, WMI banks, swap) are exercised only on the Windows CI runner — please confirm there.

Summary by CodeRabbit

  • Improvements
    • Improved Windows memory reporting consistency across supported backends.
    • Improved caching and performance for global, virtual, and physical memory metrics.
    • Enhanced physical memory details, including capacity, speed, manufacturer, type, part number, and serial number.
    • Improved compatibility across Windows 10 and earlier Windows versions.

Windows was the last platform whose memory twins still carried full logic in
both backends; every other platform already has a base + thin native-only
twins. Bring Windows into line.

WindowsGlobalMemory (existing base, previously only the memory-type tables)
now holds the memoized available/total/page-size suppliers, the virtual-memory
supplier, and the WMI physical-memory assembly loop, with protected abstract
hooks for the native queries (readPerfInfo, createVirtualMemory,
isWindows10OrGreater, queryPhysicalMemory[Win8]).

WindowsVirtualMemory is new (VirtualMemory had no shared base): it holds the
parent-global reference, memoized suppliers, and the six page-size-scaled
getters, with hooks querySwapUsed / querySwapTotalVirtMaxVirtUsed /
queryPageSwaps.

The JNA and FFM twins shrink to just those native hooks (GlobalMemory
119/128 -> 67/79 lines, VirtualMemory 106/111 -> 65/71). No behavior change;
the hoisted logic is identical to what both twins previously duplicated.
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d1dad3bb-083a-4566-af20-36f3b8a73b6b

📥 Commits

Reviewing files that changed from the base of the PR and between e62d2de and 56a359d.

📒 Files selected for processing (6)
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsVirtualMemory.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (16)
  • GitHub Check: CodeRabbit
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📚 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/WindowsVirtualMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java
📚 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-common/src/main/java/oshi/hardware/common/platform/windows/WindowsVirtualMemory.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.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
🔇 Additional comments (6)
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGlobalMemory.java (1)

7-27: LGTM!

Also applies to: 36-127

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

1-93: LGTM!

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

39-79: LGTM!

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

25-47: LGTM!

Also applies to: 65-66

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

34-66: LGTM!

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

20-20: LGTM!

Also applies to: 29-48, 59-60


📝 Walkthrough

Walkthrough

Windows memory handling was centralized into shared global and virtual memory base classes. JNA and FFM implementations now provide protected hooks for native metrics, WMI queries, OS detection, and backend object creation.

Changes

Windows memory abstraction

Layer / File(s) Summary
Shared global memory implementation
oshi-common/.../WindowsGlobalMemory.java
Centralizes memoized global-memory getters, virtual-memory creation, and WMI physical-memory mapping.
Shared virtual memory implementation
oshi-common/.../WindowsVirtualMemory.java
Centralizes memoized swap and virtual-memory getters and converts page-based values using the global page size.
JNA and FFM backend hooks
oshi-core/.../windows/Windows*MemoryJNA.java, oshi-core-ffm/.../windows/Windows*MemoryFFM.java
Supplies native metric queries, WMI results, OS-version checks, and platform-specific virtual-memory construction through protected overrides.

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

Poem

I’m a rabbit with pages to spare,
Caching memory metrics with care.
JNA and FFM
Now share the same stem—
Neat Windows bytes hop through the air!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.21% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main refactor: sharing Windows GlobalMemory and VirtualMemory logic across JNA and FFM.
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 Jul 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.87500% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.57%. Comparing base (e62d2de) to head (56a359d).

Files with missing lines Patch % Lines
...e/common/platform/windows/WindowsGlobalMemory.java 62.50% 11 Missing and 1 partial ⚠️
...dware/platform/windows/WindowsGlobalMemoryJNA.java 61.53% 4 Missing and 1 partial ⚠️
...dware/platform/windows/WindowsGlobalMemoryFFM.java 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3453      +/-   ##
============================================
- Coverage     74.59%   74.57%   -0.02%     
  Complexity       76       76              
============================================
  Files           583      584       +1     
  Lines         21961    21923      -38     
  Branches       3682     3679       -3     
============================================
- Hits          16381    16350      -31     
+ Misses         3539     3534       -5     
+ Partials       2041     2039       -2     
Flag Coverage Δ
freebsd 26.85% <0.00%> (+0.04%) ⬆️
linux 31.51% <0.00%> (+0.07%) ⬆️
macos 31.99% <0.00%> (+0.01%) ⬆️
openbsd 26.33% <0.00%> (+0.05%) ⬆️
solaris 28.38% <0.00%> (+0.04%) ⬆️
windows 39.74% <71.87%> (-0.02%) ⬇️

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.

@dbwiddis
dbwiddis merged commit 6aa6bb8 into oshi:master Jul 12, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the dedup-windows-memory branch July 12, 2026 21:03
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