Skip to content

Migrate Linux FFM arena calls to helpers - #3285

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:ffm-arena-call-helpers-linux
May 23, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:ffm-arena-call-helpers-linux

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • migrate Linux FFM arena/catch blocks to the new ForeignFunctions helper methods
  • preserve existing fallback behavior by deferring fallback calls outside helper invocations where needed
  • leave more complex cleanup-heavy Linux paths for a later targeted helper/fallback cleanup

Testing

  • mvn -pl oshi-core-ffm -am spotless:apply
  • mvn -pl oshi-core-ffm -am clean compile
  • mvn -pl oshi-core-ffm -am checkstyle:check
  • mvn -pl oshi-core-ffm -am clean compile forbiddenapis:check
  • mvn -pl oshi-core-ffm -am javadoc:javadoc
  • mvn -pl oshi-core-ffm -am test -Dtest=oshi.ffm.ForeignFunctionsTest

Summary by CodeRabbit

  • Refactor
    • Standardized native-call handling across Linux platform components, improving reliability of hardware and OS queries (CPU load, power, USB, network, storage, processes), centralizing error/fallback behavior, and reducing noisy local exception logging to provide more consistent results and safer resource management.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

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: 6f3c323d-6cd9-4d56-89f2-a19974d817b1

📥 Commits

Reviewing files that changed from the base of the PR and between d1bc9fe and 58a33fd.

📒 Files selected for processing (7)
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOSProcessFFM.java
📜 Recent 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). (13)
  • GitHub Check: codecov/patch
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, windows-latest
  • 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: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: For OSHI Linux USB device implementations, the behavior of `getUsbDevices(boolean tree)` with `tree=false` is intentional: the returned flat list includes controller nodes (it is not meant to exclude them). In code review, do not flag the implementation for including controllers in flat mode; instead, only flag/update documentation/JavaDoc that incorrectly claims controllers are excluded (e.g., Javadoc text like "returns a flat list excluding controllers" should be corrected).

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
🔇 Additional comments (7)
oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java (1)

7-10: LGTM!

Also applies to: 59-69, 80-120, 127-170, 178-205

oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java (1)

7-9: LGTM!

Also applies to: 46-110

oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java (1)

7-9: LGTM!

Also applies to: 53-107

oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (1)

8-10: LGTM!

Also applies to: 68-76, 147-153

oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java (1)

7-9: LGTM!

Also applies to: 43-69

oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java (1)

7-9: LGTM!

Also applies to: 32-40, 51-75

oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOSProcessFFM.java (1)

8-10: LGTM!

Also applies to: 76-84, 88-96


📝 Walkthrough

Walkthrough

This PR refactors seven Linux FFM implementations to use shared callInArena*OrDefault helpers for confined Arena lifecycle and standardized error/default handling, replacing manual Arena.ofConfined() try-with-resources and local catch blocks across CPU, storage, network, USB, power, and process-limit code paths.

Changes

FFM Arena Lifecycle Centralization

Layer / File(s) Summary
CPU Load Average and Topology with Arena Helpers
oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
getSystemLoadAverage calls getloadavg inside callInArenaOrDefault and falls back to superclass on null; readTopologyWithUdev, queryCurrentFreqFromUdev, and queryMaxFreqFromUdev run udev logic inside callInArena* wrappers with sysfs fallbacks. Static imports updated.
Hardware Enumeration (LVM, Power, USB) with Arena Helpers
oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
Udev-based enumeration for LVMs, power sources, and USB devices moved into callInArenaOrDefault/boolean wrappers; lambdas build local results, return defaults on udev_new() == NULL, and the helper handles logging/fallbacks. Direct Arena imports removed.
Network Configuration Queries with Arena Helpers
oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java, oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
queryIfModel, getHostName, and getDomainName use callInArenaOrDefault for FFM calls (gethostname, getaddrinfo, udev device queries), preserving necessary finally cleanup and falling back to defaults or superclass on null.
Process Resource Limit Queries with Arena Helpers
oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOSProcessFFM.java
queryRlimitSoft() and queryRlimitHard() use callInArenaLongOrDefault to run getrlimit; on negative/default results they fall back to existing open-file-limit retrieval paths. Static imports updated.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • oshi/oshi#3284: Introduces the callInArena*OrDefault helper functions now applied across these Linux FFM files.
  • oshi/oshi#3120: Earlier PR that added the udev-based CPU topology and frequency query code now refactored here to use the shared arena helpers.
  • oshi/oshi#3157: Modifies hostname-related logic in LinuxNetworkParamsFFM, overlapping the same method refactored here.

Poem

🐰 In arenas neat I hop and peep,

Helpers hold the fences deep,
No more try-catch scattered wide,
FFM calls now safe inside,
A tidy hop through Linux stride.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% 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 'Migrate Linux FFM arena calls to helpers' accurately summarizes the main objective of the changeset, which is to refactor FFM arena lifecycle management across seven Linux platform files to use new helper methods.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@codecov

codecov Bot commented May 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.64912% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.11%. Comparing base (921b6f6) to head (58a33fd).

Files with missing lines Patch % Lines
...dware/platform/linux/LinuxCentralProcessorFFM.java 63.88% 5 Missing and 8 partials ⚠️
...java/oshi/software/os/linux/LinuxOSProcessFFM.java 0.00% 6 Missing ⚠️
.../oshi/software/os/linux/LinuxNetworkParamsFFM.java 40.00% 1 Missing and 2 partials ⚠️
...are/platform/linux/LinuxLogicalVolumeGroupFFM.java 87.50% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3285      +/-   ##
============================================
+ Coverage     75.03%   75.11%   +0.07%     
  Complexity       76       76              
============================================
  Files           410      410              
  Lines         15871    15848      -23     
  Branches       2526     2525       -1     
============================================
- Hits          11909    11904       -5     
+ Misses         2508     2485      -23     
- Partials       1454     1459       +5     
Flag Coverage Δ
linux 40.01% <59.64%> (+0.05%) ⬆️
macos 40.68% <0.00%> (+0.05%) ⬆️
windows 48.38% <0.00%> (+0.05%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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 force-pushed the ffm-arena-call-helpers-linux branch from d1bc9fe to 58a33fd Compare May 23, 2026 16:24
@dbwiddis
dbwiddis merged commit e957b85 into oshi:master May 23, 2026
19 checks passed
dbwiddis added a commit that referenced this pull request May 23, 2026
Migrate simple try-Arena-catch-Throwable patterns in Windows FFM
classes to use the centralized arena call helpers from
ForeignFunctions, consistent with the Linux (#3285) and macOS (#3287)
migrations.

Migrated methods:
- WindowsGlobalMemoryFFM.readPerfInfo() -> callInArenaOrDefault
- WindowsVirtualMemoryFFM.querySwapTotalVirtMaxVirtUsed() -> callInArenaOrDefault
- WindowsNetworkIfFFM.updateAttributes() -> callInArenaBooleanOrDefault
- WindowsOperatingSystemFFM.getPerformanceInfoField() -> callInArenaIntOrDefault

Methods requiring handle/resource closing in finally blocks are
deferred for a future refactoring pass.
@dbwiddis
dbwiddis deleted the ffm-arena-call-helpers-linux branch May 26, 2026 16:19
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