Repository navigation
Extract FreeBsdCentralProcessor common base (JNA/FFM dedup) - #3380
Conversation
|
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 (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 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)
🔇 Additional comments (2)
📝 WalkthroughWalkthroughThis PR refactors FreeBSD CPU processor support by centralizing shared parsing and query logic into the base ChangesFreeBSD CPU Implementation Refactoring
Sequence DiagramsequenceDiagram
participant Caller
participant FreeBsdCentralProcessor
participant Subclass as FFM/JNA Subclass
participant BsdSysctlUtil as BsdSysctlUtil(FFM/JNA)
Caller->>FreeBsdCentralProcessor: queryProcessorId()
FreeBsdCentralProcessor->>Subclass: sysctlString("hw.model", "")
Subclass->>BsdSysctlUtil: sysctl(...)
BsdSysctlUtil-->>Subclass: sysctl result
Subclass-->>FreeBsdCentralProcessor: sysctl result
FreeBsdCentralProcessor-->>Caller: ProcessorIdentifier
Caller->>FreeBsdCentralProcessor: initProcessorCounts()
FreeBsdCentralProcessor->>Subclass: sysctlString("kern.sched.topology_spec", "")
Subclass->>BsdSysctlUtil: sysctl(...)
BsdSysctlUtil-->>Subclass: topology XML/text
Subclass-->>FreeBsdCentralProcessor: topology XML/text
FreeBsdCentralProcessor->>FreeBsdCentralProcessor: parseTopology(), matchBitmasks()
FreeBsdCentralProcessor-->>Caller: Logical/Physical processors, caches
Caller->>FreeBsdCentralProcessor: queryCurrentFreq()
FreeBsdCentralProcessor->>Subclass: sysctlLong("dev.cpu.0.freq", 0)
Subclass->>BsdSysctlUtil: sysctl(...)
BsdSysctlUtil-->>Subclass: frequency MHz
Subclass-->>FreeBsdCentralProcessor: frequency MHz
FreeBsdCentralProcessor-->>Caller: frequency Hz
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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 #3380 +/- ##
============================================
+ Coverage 74.86% 75.02% +0.15%
Complexity 76 76
============================================
Files 573 573
Lines 21909 21773 -136
Branches 3641 3607 -34
============================================
- Hits 16402 16335 -67
+ Misses 3455 3394 -61
+ Partials 2052 2044 -8
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:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java`:
- Around line 306-313: In the loop inside FreeBsdCentralProcessor that iterates
ExecutingCommand.runNative("dmidecode -t processor"), guard against
ArrayIndexOutOfBounds when splitting on "ID:" by checking the split result (or
using indexOf/substring) before accessing the second element: when procInfo &&
checkLine.contains(marker) compute the substring after the marker, verify it
exists and .trim() is non-empty, and only then return it; otherwise continue the
loop (or skip empty values) to avoid accessing parts[1] when the marker is at
the end of the line.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 514cd090-def9-4b70-a94a-6549dc473f0a
📒 Files selected for processing (3)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdCentralProcessorFFM.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdCentralProcessorJNA.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). (14)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdCentralProcessorJNA.java
🔇 Additional comments (11)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java (7)
1-31: LGTM!
33-49: LGTM!
51-99: LGTM!
101-142: LGTM!
144-162: LGTM!
164-261: LGTM!
263-294: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdCentralProcessorFFM.java (2)
42-50: LGTM!
52-120: LGTM!oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdCentralProcessorJNA.java (2)
37-45: LGTM!
47-129: LGTM!
Move shared logic (queryProcessorId, initProcessorCounts, topology parsing, cache info, frequency queries, dmidecode lookup) into the FreeBsdCentralProcessor superclass with abstract sysctlString/Long methods. JNA and FFM subclasses now only contain native-specific code (cpu ticks, load average, context switches, interrupts), eliminating ~189 duplicated lines.
21daff1 to
722e144
Compare
Summary
queryProcessorId,initProcessorCounts, topology parsing, cache info from lscpu, frequency queries,getProcessorIDfromDmiDecode) into theFreeBsdCentralProcessorsuperclasssysctlString/sysctlLongmethods let JNA and FFM subclasses provide their sysctl backendTest plan
Summary by CodeRabbit