Skip to content

Migrate macOS FFM arena calls to helpers - #3287

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

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

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • migrate straightforward macOS FFM arena/catch blocks to the new ForeignFunctions helpers
  • preserve existing fallback behavior, including macOS open file limit return logic pending Audit and test OSProcess open file limit implementations #3286
  • leave cleanup-heavy CoreFoundation/IOKit/deallocation paths for later targeted batches

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
    • Streamlined arena lifecycle management and error handling across macOS-specific modules (CPU processing, memory queries, virtual memory operations, network parameters, file storage, process limits, and OS information) through centralized helper methods, improving code consistency and maintainability in the platform-specific layer.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

This PR refactors seven macOS FFM platform implementations to use centralized callInArena*OrDefault helper methods instead of manual arena allocation and broad exception handling. Each file replaces its own try-with-resources and catch-all patterns with consistent, configurable arena lifecycle management and default return values.

Changes

macOS FFM Arena Helper Consolidation

Layer / File(s) Summary
CPU processor tick and load average queries
oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
CPU tick and load average queries now execute within callInArenaOrDefault, returning pre-initialized default arrays on failure and using ERROR logging for ticks (DEBUG for load averages).
Memory and virtual memory queries
oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacGlobalMemoryFFM.java, MacVirtualMemoryFFM.java
Page size, swap usage, and VM statistics queries centralize arena management via callInArenaLongOrDefault and callInArenaOrDefault, with standardized default returns (4096L for page size, (0L, 0L) for VM pairs).
Network hostname and domain name resolution
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
Hostname and canonical domain-name resolution now use callInArenaOrDefault for getaddrinfo calls, with DEBUG logging and fallback to empty string or parent implementation on failure.
File store statfs64 fast-path retrieval
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
File-system stat fast path wraps callInArenaBooleanOrDefault to allocate arenas and execute statfs64, returning true on success or falling back to full enumeration with DEBUG logging.
Process resource limit queries
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
Open file limit (soft and hard) queries use callInArenaLongOrDefault to invoke getrlimit, returning actual limits or 0L on failure, with DEBUG logging and special unsupported-PID handling.
Process and thread enumeration
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
Process listing and thread counting delegate arena management to callInArenaOrDefault and callInArenaIntOrDefault, returning empty list and 0 respectively on failure, with WARN-level logging.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • oshi/oshi#3284: Introduces the callInArena*OrDefault helper methods in oshi.ffm.ForeignFunctions that are used throughout this PR to centralize FFM arena lifecycle management.
  • oshi/oshi#3285: Applies the same arena helper refactoring pattern to Linux FFM implementations, showing parallel consolidation across platforms.
  • oshi/oshi#3273: Earlier iteration on macOS FFM refactoring that included CPU processor tick and load-average logic consolidation.

🐰 With arenas confined and helpers aligned,
Each platform call finds its path designed,
No more try-catch sprawl to sort and untangle,
Just defaults and logs at the perfect angle!
FFM flows flow free, from hardware to sky, 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'Migrate macOS FFM arena calls to helpers' accurately summarizes the main change: refactoring multiple macOS FFM classes to use new helper methods for arena management instead of explicit try-catch blocks.
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 62.16216% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.22%. Comparing base (e957b85) to head (7c4ff99).

Files with missing lines Patch % Lines
...n/java/oshi/software/os/mac/MacOSFileStoreFFM.java 0.00% 4 Missing ⚠️
...ain/java/oshi/software/os/mac/MacOSProcessFFM.java 0.00% 4 Missing ⚠️
...oshi/hardware/platform/mac/MacGlobalMemoryFFM.java 50.00% 2 Missing ⚠️
...shi/hardware/platform/mac/MacVirtualMemoryFFM.java 77.77% 2 Missing ⚠️
...java/oshi/software/os/mac/MacNetworkParamsFFM.java 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3287   +/-   ##
=========================================
  Coverage     75.21%   75.22%           
  Complexity       76       76           
=========================================
  Files           410      410           
  Lines         15848    15826   -22     
  Branches       2525     2518    -7     
=========================================
- Hits          11920    11905   -15     
+ Misses         2480     2465   -15     
- Partials       1448     1456    +8     
Flag Coverage Δ
linux 40.05% <0.00%> (+0.07%) ⬆️
macos 40.74% <62.16%> (+0.05%) ⬆️
windows 48.45% <0.00%> (-0.03%) ⬇️

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 merged commit 41285de into oshi:master May 23, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the ffm-arena-call-helpers-next branch May 23, 2026 17:06
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.
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