Repository navigation
Extract MacOSProcess common base (JNA/FFM dedup) - #3376
Conversation
The JNA and FFM macOS OSProcess implementations duplicated their field storage, all the trivial accessors, the command-line/argument/environment memoization, thread enumeration, the affinity mask, and the pbi_status state mapping (~243 duplicated lines per Sonar). Mirroring the BSD/Solaris OSProcess pattern, extract an abstract MacOSProcess base in oshi-common holding that shared surface, with the macOS state mapping pulled into a shared stateFromStatus() helper. The native attribute reads stay in the JNA and FFM subclasses behind hooks: updateAttributes() (proc_pidinfo), queryArgsAndEnvironment() (KERN_PROCARGS2 sysctl), getSoft/HardOpenFileLimit() (getrlimit), and queryLogicalProcessorCount() (hw.logicalcpu sysctl). The os field is typed as the MacOperatingSystem base, so the FFM subclass constructor widens its parameter accordingly (the OS classes pass 'this', which already IS-A MacOperatingSystem). Validated by the macOS NativeComparisonTest (JNA==FFM parity).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📜 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). (14)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
🔇 Additional comments (17)
📝 WalkthroughWalkthroughThis PR extracts shared macOS process logic into a new abstract base class, reducing duplication across JNA and FFM backends. Both implementations now inherit common behavior for state mapping, thread details, memory metrics, and counter tracking, while retaining backend-specific queries for arguments and logical processor count. ChangesmacOS Process Abstraction Extraction
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3376 +/- ##
============================================
- Coverage 75.04% 75.01% -0.04%
Complexity 76 76
============================================
Files 570 571 +1
Lines 21948 21893 -55
Branches 3640 3637 -3
============================================
- Hits 16471 16422 -49
+ Misses 3425 3412 -13
- Partials 2052 2059 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Extends the OSProcess deduplication to macOS (after the BSD #3370/#3372 and Solaris #3367 work). The JNA and FFM macOS
OSProcessimplementations duplicated their field storage, all the trivial accessors, the command-line/argument/environment memoization, thread enumeration, the affinity mask, and thepbi_statusstate mapping (~243 duplicated lines each per Sonar — the #2/#3 files on the project).This extracts an abstract
MacOSProcessbase inoshi-commonholding that shared surface, with the macOS state mapping pulled into a sharedstateFromStatus()helper. The native attribute reads stay in the JNA and FFM subclasses behind hooks:updateAttributes()—proc_pidinfo(PROC_PIDTASKALLINFO / vnode / rusage)queryArgsAndEnvironment()—KERN_PROCARGS2sysctlgetSoftOpenFileLimit()/getHardOpenFileLimit()—getrlimitqueryLogicalProcessorCount()—hw.logicalcpusysctl (forgetAffinityMask)The
osfield is typed as theMacOperatingSystembase, so the FFM subclass constructor widens its parameter to match (the OS classes passthis, which already IS-AMacOperatingSystem, so no call-site change is needed).MacOSThread(single common class) andMacOperatingSystem(base + JNA/FFM) already followed this pattern;MacOSProcesswas the last Mac class lacking a common base. The subclasses keep their (genuinely divergent) native struct reads. Net −190 lines.Testing
Validated on macOS by the full test suite including
NativeComparisonTest, which asserts JNA and FFM produce identical results — the strongest parity check available. Local spotless / checkstyle / forbidden-APIs / javadoc and a clean full-reactor build also pass. (A checkstyleVisibilityModifiersuppression was extended to coverMacOSProcess, consistent with the existingBsdOSProcess/BsdOSThreadshared-base entries.)Summary by CodeRabbit