Skip to content

Add FFM arena call helpers - #3284

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

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

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add lambda-first ForeignFunctions helpers for running FFM work in a confined arena while logging Throwable failures and returning defaults.
  • Include object, int, long, double, boolean, and void helper variants to avoid boxing for common primitive paths.
  • Migrate a small representative set of existing arena/Throwable call sites to validate the pattern before broader follow-up migration.
  • Add focused tests covering success and thrown-Throwable fallback behavior for every helper variant.

Notes

This intentionally keeps scope small as a pattern-validation PR. Cleanup-aware variants for cases such as CoreFoundation/native-resource release paths can be considered separately after this base API is reviewed.

Validation

  • mvn -pl oshi-core-ffm -am spotless:apply
  • 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 (passes with existing warnings)
  • mvn -pl oshi-core-ffm -am test -Dtest=oshi.ffm.ForeignFunctionsTest

Summary by CodeRabbit

  • Refactor

    • Improved error handling and resource management for Foreign Function & Memory operations with new helper utilities.
    • Standardized exception logging and arena lifecycle management across FFM-dependent modules for better debugging and consistency.
  • Tests

    • Added comprehensive test coverage for Foreign Function & Memory execution helpers.

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: 7e93c8df-3563-4961-be5f-e937bad6683b

📥 Commits

Reviewing files that changed from the base of the PR and between 989e40e and 1b08927.

📒 Files selected for processing (6)
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacGlobalMemoryFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxFileSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core-ffm/src/test/java/oshi/ffm/ForeignFunctionsTest.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). (11)
  • 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 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Analyze (java)
🔇 Additional comments (6)
oshi-core-ffm/src/test/java/oshi/ffm/ForeignFunctionsTest.java (1)

24-137: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java (1)

20-23: LGTM!

Also applies to: 33-123, 146-292, 398-402

oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacGlobalMemoryFFM.java (1)

9-10: LGTM!

Also applies to: 35-46

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

7-9: LGTM!

Also applies to: 29-40

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

7-9: LGTM!

Also applies to: 43-53

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

7-9: LGTM!

Also applies to: 169-176


📝 Walkthrough

Walkthrough

This PR centralizes confined-Arena execution and throwable handling for FFM calls. It adds functional interfaces and wrapper methods in ForeignFunctions, refactors macOS/Linux FFM sites to use those helpers, and includes JUnit tests for all wrapper variants.

Changes

FFM Arena Execution and Error Handling

Layer / File(s) Summary
Core Arena Execution Infrastructure and Logging
oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
Introduces six functional interfaces (ArenaCallable<T>, ArenaIntCallable, ArenaLongCallable, ArenaDoubleCallable, ArenaBooleanCallable, ArenaRunnable) and six public static wrapper methods that open a confined Arena, execute the provided operation, catch any Throwable, log via SLF4J at a caller-specified Level using a private logThrowable helper, and return typed defaults or swallow failures for the void variant.
Arena Execution Test Suite
oshi-core-ffm/src/test/java/oshi/ffm/ForeignFunctionsTest.java
Adds JUnit 5 tests covering all wrapper variants: each test verifies success returns computed results and that thrown Throwable triggers the supplied default (or is swallowed for the void runnable).
Platform-Specific FFM Call Refactorings
oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacGlobalMemoryFFM.java, oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxFileSystemFFM.java, oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOSProcessFFM.java, oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
Refactors four FFM call sites to use the new wrappers: macOS VM stats → callInArenaLongOrDefault; Linux statvfs → callInArenaOrDefault; Linux getrusage → runInArenaCatchingThrowable; Linux sysinfo → callInArenaIntOrDefault. Inline Arena.ofConfined() try-with-resources and manual catch blocks are removed and logging/defaults are delegated to the wrappers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped in an Arena, neat and small,
With Try-with-resources to guard us all,
SLF4J hummed, logged every fall,
Defaults held steady, standing tall,
A rabbit-approved FFM ball.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% 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 'Add FFM arena call helpers' directly and accurately describes the main change: introducing new helper methods for executing FFM operations within confined arenas.
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.

@dbwiddis
dbwiddis marked this pull request as ready for review May 23, 2026 15:38
@codecov

codecov Bot commented May 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.01%. Comparing base (989e40e) to head (1b08927).

Files with missing lines Patch % Lines
...oshi/hardware/platform/mac/MacGlobalMemoryFFM.java 50.00% 1 Missing ⚠️
...ava/oshi/software/os/linux/LinuxFileSystemFFM.java 50.00% 1 Missing ⚠️
...shi/software/os/linux/LinuxOperatingSystemFFM.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3284      +/-   ##
============================================
- Coverage     75.07%   75.01%   -0.06%     
  Complexity       76       76              
============================================
  Files           410      410              
  Lines         15881    15871      -10     
  Branches       2529     2526       -3     
============================================
- Hits          11922    11905      -17     
- Misses         2508     2509       +1     
- Partials       1451     1457       +6     
Flag Coverage Δ
linux 39.95% <50.00%> (-0.01%) ⬇️
macos 40.62% <12.50%> (+0.01%) ⬆️
windows 48.29% <0.00%> (-0.06%) ⬇️

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.

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