Repository navigation
Migrate remaining mac OperatingSystem JNA to FFM - #3104
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 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). (5)
🔇 Additional comments (3)
📝 WalkthroughWalkthroughThis PR continues migrating macOS platform code from JNA to the Java FFM API. It adds FFM bindings and macOS-specific structs, introduces FFM-based drivers for sessions, window enumeration, network params, and file-store representations, and wires these FFM drivers into the macOS OS layer. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3104 +/- ##
==========================================
+ Coverage 68.69% 69.28% +0.58%
==========================================
Files 36 36
Lines 1875 1875
Branches 305 305
==========================================
+ Hits 1288 1299 +11
+ Misses 492 478 -14
- Partials 95 98 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@oshi-core-java25/src/main/java/oshi/driver/mac/WhoFFM.java`:
- Around line 56-58: The code currently calls getString(0) on unbounded slices
(in WhoFFM using UTMPX.byteOffset(UT_USER), UT_LINE, UT_HOST), which can
over-read or throw; replace those calls with a bounded C-string reader: add a
helper (e.g., readCStringField(MemorySegment struct, long offset, int maxLen))
that slices the struct with the fixed field length, reads bytes up to the first
NUL, and returns an ASCII String, then call readCStringField(struct,
UTMPX.byteOffset(UT_USER), USER_FIELD_LEN) etc. so each field is read within its
fixed max length rather than to the end of the struct.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: faaa282b-4843-4aeb-ba51-aa3399e8dd59
📒 Files selected for processing (11)
CHANGELOG.mdconfig/checkstyle-suppressions.xmloshi-core-java25/src/main/java/oshi/driver/mac/WhoFFM.javaoshi-core-java25/src/main/java/oshi/driver/mac/WindowInfoFFM.javaoshi-core-java25/src/main/java/oshi/ffm/mac/CoreGraphicsFunctions.javaoshi-core-java25/src/main/java/oshi/ffm/mac/MacSystem.javaoshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.javaoshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.javaoshi-core-java25/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.javaoshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
📜 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). (6)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-03-29T20:01:01.877Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:01.877Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.javaoshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.javaoshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.javaoshi-core-java25/src/main/java/oshi/ffm/mac/MacSystem.java
📚 Learning: 2026-03-29T20:02:58.470Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:02:58.470Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.
Applied to files:
oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
🔇 Additional comments (13)
oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java (1)
188-190: FFM file-store instantiation is correctly wired.Line 188 now constructs
MacOSFileStoreFFMwith the existing argument flow intact, so file-store creation stays on the FFM path without changing matching behavior.oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (3)
30-42: Constructor field mapping looks consistent and complete.The
super(...)call and subsequent assignments correctly capture all file-store attributes required by this FFM implementation.
44-82: Accessor overrides are clean and consistent.These getters correctly expose the stored filesystem metadata and capacity/inode values without extra side effects.
85-100:updateAttributes()matching logic preserves existing behavior.The refresh loop uses the expected
name + localityquery and then disambiguates on volume/mount before copying updated values, which mirrors the prior macOS file-store strategy.config/checkstyle-suppressions.xml (1)
33-34: Scoped suppression looks appropriate.The
ConstantNamesuppression is tightly targeted toWindowInfoFFM.javaand matches the CoreGraphicskCG...constant style used in that file.oshi-core-java25/src/main/java/oshi/ffm/mac/CoreGraphicsFunctions.java (1)
29-50: CoreGraphics FFM bindings are clean and correctly scoped.The symbol lookup, downcall descriptors, and wrapper methods are consistent and correctly minimal for the two CoreGraphics APIs being introduced.
oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.java (1)
158-223: New libSystem downcalls are consistent with existing FFM wrappers.The added utmpx and addrinfo-related bindings follow the same invocation/error-handling pattern already used across this class.
oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystem.java (1)
87-407: Struct and constant additions align with new macOS FFM callers.The new utmpx/addrinfo/CoreGraphics layouts and constants are well-factored and fit the new drivers introduced in this PR.
oshi-core-java25/src/main/java/oshi/driver/mac/WhoFFM.java (1)
62-73: Fallback and cleanup flow is solid.The invalid-session fallback path and guaranteed
endutxent()cleanup mirror the previous behavior and keep failure handling robust.oshi-core-java25/src/main/java/oshi/driver/mac/WindowInfoFFM.java (1)
57-139: FFM window enumeration implementation looks good.The CoreGraphics traversal, CGRect extraction, and CoreFoundation release handling are well-structured and consistent with the migration goal.
oshi-core-java25/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java (1)
45-121: Network params migration is coherent and complete.Domain/hostname resolution moved to FFM cleanly, while IPv4/IPv6 gateway logic correctly preserves the established command-based approach.
oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java (1)
100-190: Wiring changes correctly complete the macOS OS-layer migration path.Line 100, Line 184, and Line 189 now route sessions, network params, and desktop windows through the new FFM implementations as expected.
CHANGELOG.md (1)
16-16: LGTM!The changelog entry is well-formatted, accurately documents the PR's changes, and follows the established conventions of the file.
This PR completes the FFM migration of all classes called from MacOperatingSystemFFM, eliminating all remaining JNA dependencies from the macOS OperatingSystem interface implementation.
Changes
New FFM bindings (oshi.ffm.mac)
New driver classes (oshi.driver.mac)
New OS classes (oshi.software.os.mac)
Modified
Summary by CodeRabbit