Skip to content

Hoist common OSProcess fields + add Solaris/AIX /proc base - #3390

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:osprocess-common-fields
Jun 13, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:osprocess-common-fields

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Two cross-platform OSProcess deduplications (the per-OS bases all extend AbstractOSProcess):

  • Hoist 13 uniform attribute fields + trivial getters into AbstractOSProcess — name, path, state, parentProcessID, threadCount, priority, virtualSize, kernelTime, userTime, startTime, upTime, bytesRead, bytesWritten. Declared protected (with a VisibilityModifier suppression) so each platform's updateAttributes() keeps assigning them directly — no setter churn. Removed from all six bases (Linux, Windows, macOS, BSD, Solaris, AIX). macOS preserves its historical empty-string name default via its constructor.
  • Add AbstractProcOSProcess (oshi.software.common.os.unix) for the /proc-struct readers Solaris and AIX, sharing getCurrentWorkingDirectory, fd-count getOpenFiles, pflags getBitness, the /proc/<pid>/lwp thread skeleton (via a createThread hook; AIX now implements it concretely), the command-line backup fallback, and the user/group/resident-memory accessors.
  • Eliminates ~450 duplicated lines.

Fixes a pre-existing AIX bug: getCurrentWorkingDirectory built "/proc" + pid (missing the slash) instead of "/proc/" + pid; the shared base uses the correct path.

Deliberately left per-OS (genuine divergence): updateAttributes, getAffinityMask, thread factories, args/env container plumbing, and the state-char mappings (R means RUNNING on Linux/BSD but WAITING on Solaris; macOS uses ints).

Test plan

  • Pre-commit checks (spotless, checkstyle, forbiddenapis, javadoc) + clean full-reactor build
  • NativeComparisonTest (JNA==FFM) on macOS: 39/39 (covers currentProcess, currentProcessUpdateAttributes, threads)
  • Linux / Windows / macOS via PR CI
  • BSD + OpenIndiana (Solaris) via dispatched unix.yml; AIX via cfarm

Summary by CodeRabbit

  • Refactor

    • Consolidated common process attribute handling across platforms for more consistent process metadata.
  • New Features

    • Improved /proc-backed Unix implementations: memoized command-line/environment, robust current working directory lookup, open-file counts, bitness detection, and unified thread enumeration.

Two cross-platform OSProcess dedups:

- Hoist the 13 uniform attribute fields (name, path, state, parentProcessID,
  threadCount, priority, virtualSize, kernelTime, userTime, startTime, upTime,
  bytesRead, bytesWritten) and their trivial getters into AbstractOSProcess.
  Declared protected (with a VisibilityModifier suppression) so each platform's
  updateAttributes() keeps assigning them directly. Removed from all six per-OS
  bases (Linux, Windows, macOS, BSD, Solaris, AIX). macOS keeps its historical
  empty-string name default via its constructor.

- Add AbstractProcOSProcess (oshi.software.common.os.unix) for the /proc-struct
  readers Solaris and AIX, sharing getCurrentWorkingDirectory, fd-count
  getOpenFiles, pflags getBitness, the /proc/<pid>/lwp thread skeleton (via a
  createThread hook; AIX now implements it concretely), the command-line backup
  fallback, and the user/group/resident-memory accessors.

Fixes a pre-existing AIX bug: getCurrentWorkingDirectory built "/proc" + pid
(missing the slash) instead of "/proc/" + pid; the shared base uses the correct
path. Left per-OS: updateAttributes, getAffinityMask, thread factories, args/env
plumbing, and the (genuinely divergent) state-char mappings.

Net -452 LOC. Validated locally on macOS via NativeComparisonTest (39/39,
JNA==FFM); Linux/Windows via PR CI, BSD/Solaris via unix.yaml, AIX via cfarm.
@coderabbitai

coderabbitai Bot commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 73be9028-2eb3-4749-bc77-4b17cbd30ec2

📥 Commits

Reviewing files that changed from the base of the PR and between 85b40cc and cf70c01.

📒 Files selected for processing (1)
  • oshi-common/src/test/java/oshi/software/common/AbstractOSProcessTest.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-common/src/test/java/oshi/software/common/AbstractOSProcessTest.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). (15)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Analyze (java)

📝 Walkthrough

Walkthrough

This PR refactors OS process attribute handling across multiple platforms by moving common process attributes and their getter implementations from duplicate code in platform-specific classes into shared abstract base classes. AbstractOSProcess now defines protected fields for standard attributes (name, path, state, etc.) with concrete getters, while a new AbstractProcOSProcess adds Unix-specific memoization and /proc interaction patterns. Platform implementations (AIX, Solaris, Linux, Mac, BSD, Windows) are simplified by removing duplicate getter overrides and, where applicable, extending the new Unix base class.

Changes

OS Process Attribute Abstraction

Layer / File(s) Summary
AbstractOSProcess common attributes and getters
oshi-common/src/main/java/oshi/software/common/AbstractOSProcess.java
Introduces protected fields for process identity, state, hierarchy, sizing, timing, and I/O metrics; implements concrete @Override getters for all platforms to inherit and populate via updateAttributes().
AbstractProcOSProcess Unix /proc abstraction
oshi-common/src/main/java/oshi/software/common/os/unix/AbstractProcOSProcess.java
New abstract base for /proc-backed Unix systems extending AbstractOSProcess, with memoized suppliers for command line, arguments, environment, and bitness; defines protected abstract hooks for subclasses to implement thread creation and command-line/environment retrieval.
Module export and package documentation
oshi-common/src/main/java/module-info.java, oshi-common/src/main/java/oshi/software/common/os/unix/package-info.java
Exports oshi.software.common.os.unix package in module descriptor and adds package-level Javadoc with copyright and license headers.
AIX and Solaris refactoring to extend AbstractProcOSProcess
oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java
Both classes refactored to extend AbstractProcOSProcess and leverage shared /proc behavior; removes duplicate implementations of command-line, environment, thread enumeration, and bitness logic; adopts new protected hook overrides.
Linux, Mac, and BSD cleanup: remove duplicate attribute getters
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/mac/MacOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
Platform implementations eliminate duplicate getter overrides for attributes now provided by AbstractOSProcess (name, path, state, priority, sizing, timing, I/O).
Windows cleanup: remove duplicate attribute getters
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
Windows implementation removes duplicate getter overrides and field declarations for standard attributes inherited from AbstractOSProcess.
Checkstyle visibility suppression configuration
config/checkstyle-suppressions.xml
Adds suppression rules for VisibilityModifier violations in abstract base classes, documenting the rationale for exposing protected fields to subclasses for direct population in updateAttributes().
Test helper rename
oshi-common/src/test/java/oshi/software/common/AbstractOSProcessTest.java
Renames test helper time parameters and updates anonymous overrides to return the renamed parameters.

Possibly related PRs

  • oshi/oshi#3376: Related macOS process class changes that interact with the shared AbstractOSProcess refactor.
  • oshi/oshi#3370: Earlier refactor work on sharing OS process attribute backing fields across implementations.
  • oshi/oshi#3288: Tests and updates touching OSProcess/OSThread behavior that are affected by centralizing attribute getters.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

"A rabbit hops through code and logs with cheer,
Moving fields to bases so implementations steer,
Unix /proc whispers its memoized song,
Platforms now lean on one place all along,
Hooray — less duplicate hopping here!" 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.47% 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 accurately captures the main changes: hoisting common OSProcess fields into a base class and introducing a new Unix /proc-based abstract class for Solaris and AIX.
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.

Hoisting kernelTime/userTime/upTime into AbstractOSProcess as fields caused
the test double's captured constructor params of the same name to be shadowed
by the new inherited fields: inside the anonymous subclass, the bare name
'upTime' resolved to the inherited field (0) rather than the captured param,
so getProcessCpuLoadCumulative computed 0.0 instead of the expected value.
Rename the createProcess params (kernelTimeArg/userTimeArg/upTimeArg) to remove
the collision. Test-only; behavior unchanged.
@codecov

codecov Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.36508% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.13%. Comparing base (6156ca4) to head (cf70c01).

Files with missing lines Patch % Lines
...software/common/os/unix/AbstractProcOSProcess.java 71.73% 8 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3390      +/-   ##
============================================
- Coverage     75.14%   75.13%   -0.01%     
- Complexity       76     2443    +2367     
============================================
  Files           578      579       +1     
  Lines         21455    21397      -58     
  Branches       3560     3560              
============================================
- Hits          16122    16077      -45     
+ Misses         3307     3293      -14     
- Partials       2026     2027       +1     
Flag Coverage Δ
freebsd 26.41% <23.80%> (+0.07%) ⬆️
linux 31.05% <23.80%> (+0.17%) ⬆️
macos 31.34% <25.39%> (+0.08%) ⬆️
openbsd 25.82% <23.80%> (+0.06%) ⬆️
solaris 27.98% <77.77%> (+0.07%) ⬆️
windows 39.56% <23.80%> (+0.08%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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 fdaad80 into oshi:master Jun 13, 2026
38 of 39 checks passed
@dbwiddis
dbwiddis deleted the osprocess-common-fields branch June 13, 2026 16:38
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