Skip to content

Java9 fixes #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: acquireCore-fix
Choose a base branch
from
Open

Java9 fixes #181

wants to merge 2 commits into from

Conversation

peter-lawrey
Copy link
Member

@peter-lawrey peter-lawrey commented May 23, 2025

This two-patch set brings better test coverage for AffinityLock edge-cases and full Java 9+ compatibility across the project.


1️⃣ New unit-tests

  • AffinityLockTest
    • Verifies non-binding acquisition leaves the calling thread’s mask unchanged.
    • Confirms illegal CPU IDs and double-bind scenarios raise/behave as expected.
  • FileLockLockCheckTest
    • Covers lock-file deletion while held and requests for CPUs with no lock file.
  • LockCheckTest
    • Adds negative-PID sanity check.

Total: +49 LOC in AffinityLockTest and +30 + lines in lock-checker tests.


2️⃣ Java 9+ support & misc fixes

Area Update
Maven native profile make-c now activates only on Linux x86_64 (skips ARM and non-Linux builds).
Boot class-path scanner BootClassPath falls back to walking the modular jrt:/ filesystem when sun.boot.class.path is absent (JDK 9+).
Process ID retrieval New util Utilities.currentProcessId() uses ProcessHandle.current().pid() when available; all PID calls routed through it (LockCheck, NullAffinity, macOS/Solaris impls, etc.).
LockCheck Guards getProcessForCpu() on unsupported OS, uses new PID helper.
WindowsJNAAffinity Safer “set affinity” verification and SLF4J-parameterised logging.
Generic logging / warnings Switched to parameterised SLF4J in several files.
BootClassPathTest No longer restricted to JDK 8.

Behavioural notes

  • Invalid CPU-ID acquisition now returns an unbound lock instead of throwing, so assertions were adjusted in tests.
  • Lock-file logic robust to manual deletion on disk.
  • Java 11+ builds succeed without additional flags; class-path scanning works inside modules.

These changes strengthen edge-case validation and ensure the library runs cleanly on modern JDK versions while keeping legacy behaviour intact.

@peter-lawrey peter-lawrey requested a review from tgd May 23, 2025 11:34
t.start();

while (!lock.isBound()) {
Thread.sleep(10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing with Waiters.await... with an upper time bound to stop this hanging in CI if an error occurs

public static int currentProcessId() {
try {
// Java 9+ provides ProcessHandle which has a pid() method.
Class<?> phClass = Class.forName("java.lang.ProcessHandle");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

2 participants