Skip to content

Convert static memoized suppliers to instance fields for memory reclaim - #3442

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:instance-memoizers
Jul 10, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:instance-memoizers

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Convert static memoized Supplier fields to instance fields in NetBsdHWDiskStore, SolarisFileSystemJNA, and SolarisOperatingSystemJNA, allowing cached data to be garbage-collected when users create new SystemInfo instances.
  • Make systemLog suppliers in WindowsOperatingSystemJNA and Advapi32UtilFFM properly static final with conventional naming (these hold OS-constant data so static is appropriate, but they were missing final).
  • Separate boot-time (queried once, constant) from uptime (periodically refreshed) in SolarisOperatingSystemJNA to eliminate a paired static memoizer that bundled both.

Test plan

  • mvn compile passes for all affected modules
  • mvn test passes for oshi-common, oshi-core-ffm
  • mvn test passes for oshi-benchmark (JNA vs FFM comparison)

Summary by CodeRabbit

  • Bug Fixes
    • Improved system information caching to better reclaim cached data when new system instances are created.
    • Enhanced Solaris/illumos uptime and boot-time reporting, including more robust Kstat2 and legacy fallbacks.
    • Improved accuracy and consistency of disk info, file descriptor counts, and Windows “System” event-log name retrieval across supported platforms.
  • Documentation
    • Updated the changelog to reflect the above improvements and fixes.

@coderabbitai

coderabbitai Bot commented Jul 10, 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: bdf75258-9f62-4ffc-875d-7c5b8ed60550

📥 Commits

Reviewing files that changed from the base of the PR and between dbe0040 and 0482bc3.

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

32-37: LGTM! The shared iostatSupplier created once at line 48 and passed to all disk store instances ensures iostat -x -I executes only once per getDisks() call, with subsequent iostat.get() calls returning the memoized cached result. This addresses the prior concern about per-disk command invocation while also allowing GC of cached data when stores are no longer referenced.

Also applies to: 48-48, 92-92, 105-105


📝 Walkthrough

Walkthrough

Memoized suppliers were changed across NetBSD, Solaris, and Windows platform implementations. Solaris uptime and boot-time handling was separated, with Kstat2 and legacy kstat retrieval paths retained. The changelog records the update.

Changes

System information lifecycle

Layer / File(s) Summary
Platform instance-scoped suppliers
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java, oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemJNA.java
NetBSD iostat and Solaris file-descriptor memoized suppliers now use instance fields, and attribute accessors read from those fields.
Solaris uptime and boot-time separation
oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java
Uptime uses a dedicated memoized supplier with Kstat2 and legacy kstat fallbacks, while boot-time initialization remains separate.
Windows event-log supplier standardization
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java, oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java, CHANGELOG.md
Windows event-log suppliers are declared as SYSTEM_LOG, boot-time queries use the renamed fields, and the changelog records the changes.

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

Sequence Diagram(s)

sequenceDiagram
  participant SolarisOperatingSystemJNA
  participant Kstat2
  participant LegacyKstat
  SolarisOperatingSystemJNA->>Kstat2: Query system_misc snaptime
  Kstat2-->>SolarisOperatingSystemJNA: Return uptime seconds
  SolarisOperatingSystemJNA->>LegacyKstat: Fall back to ks_snaptime
  LegacyKstat-->>SolarisOperatingSystemJNA: Return uptime or 0
Loading

Possibly related PRs

  • oshi/oshi#3398: Both changes update how Advapi32UtilFFM obtains the Windows “System” event log for boot-time queries.

Poem

I’m a rabbit with caches tucked neat,
New instances make old data retreat.
Kstats hop through the night,
Boot times stay separate and bright,
While memoized fields keep things fleet!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% 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 accurately captures the main change: converting static memoized suppliers to instance fields to let cached data be reclaimed.
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.

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

Actionable comments posted: 1

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

Inline comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java`:
- Line 32: Update NetBsdHWDiskStore.getDisks() to execute iostat -x -I once and
share the resulting output while creating and initializing each disk store,
rather than allowing each instance’s iostat supplier to invoke the command
separately. Preserve the GC-friendly instance-scoped cache and adjust
initialization/updateAttributes() flow and related symbols as needed to consume
the shared result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7b69ce8c-6eb4-4668-811c-92777880bdb1

📥 Commits

Reviewing files that changed from the base of the PR and between a8c8624 and dbe0040.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout. (9)
  • 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: Test JDK 26, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • 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/unix/netbsd/NetBsdHWDiskStore.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/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.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/software/os/windows/WindowsOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java
🔇 Additional comments (7)
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java (2)

61-62: LGTM!


390-390: LGTM!

oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java (2)

101-102: LGTM!


360-360: LGTM!

CHANGELOG.md (1)

6-6: LGTM!

oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemJNA.java (1)

27-50: LGTM!

oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java (1)

92-96: LGTM!

Also applies to: 129-129, 137-169

@codecov

codecov Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.37%. Comparing base (a8c8624) to head (0482bc3).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...are/os/unix/solaris/SolarisOperatingSystemJNA.java 35.29% 8 Missing and 3 partials ⚠️
...software/os/unix/solaris/SolarisFileSystemJNA.java 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3442      +/-   ##
============================================
- Coverage     74.39%   74.37%   -0.03%     
  Complexity       76       76              
============================================
  Files           580      580              
  Lines         21946    21947       +1     
  Branches       3668     3668              
============================================
- Hits          16326    16322       -4     
- Misses         3581     3585       +4     
- Partials       2039     2040       +1     
Flag Coverage Δ
freebsd 26.76% <0.00%> (+0.01%) ⬆️
linux 31.28% <0.00%> (+<0.01%) ⬆️
macos 31.67% <0.00%> (-0.03%) ⬇️
openbsd 26.24% <0.00%> (+<0.01%) ⬆️
solaris 28.26% <30.76%> (+<0.01%) ⬆️
windows 39.59% <19.23%> (-0.04%) ⬇️

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 2623f13 into oshi:master Jul 10, 2026
18 checks passed
@dbwiddis
dbwiddis deleted the instance-memoizers branch July 10, 2026 16:13
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