From a73913cd2fc067a99e7b61f03dbf97f01223f095 Mon Sep 17 00:00:00 2001 From: foroughgoudarzi Date: Tue, 25 May 2021 16:15:06 +0100 Subject: [PATCH 001/226] Move images to docs/images. --- README.adoc | 2 +- {images => docs/images}/Thread-Affinity_line.png | Bin 2 files changed, 1 insertion(+), 1 deletion(-) rename {images => docs/images}/Thread-Affinity_line.png (100%) diff --git a/README.adoc b/README.adoc index 3916ae8a4..584aa96aa 100644 --- a/README.adoc +++ b/README.adoc @@ -1,6 +1,6 @@ = Thread Affinity -image::/images/Thread-Affinity_line.png[width=20%] +image::docs/images/Thread-Affinity_line.png[width=20%] == Version diff --git a/images/Thread-Affinity_line.png b/docs/images/Thread-Affinity_line.png similarity index 100% rename from images/Thread-Affinity_line.png rename to docs/images/Thread-Affinity_line.png From 41ed40f0c8355cc73b41eeb72c5f752fb9318360 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Thu, 27 May 2021 09:15:28 +1000 Subject: [PATCH 002/226] Remove java.lang classes and NonForkingAffinityLock to support Java 12+, Fixes #58 --- .../java/lang/ThreadLifecycleListener.java | 45 ----- .../java/java/lang/ThreadTrackingGroup.java | 53 ----- .../java/net/openhft/affinity/Affinity.java | 13 +- .../affinity/NonForkingAffinityLock.java | 184 ------------------ 4 files changed, 4 insertions(+), 291 deletions(-) delete mode 100644 affinity/src/main/java/java/lang/ThreadLifecycleListener.java delete mode 100644 affinity/src/main/java/java/lang/ThreadTrackingGroup.java delete mode 100644 affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java diff --git a/affinity/src/main/java/java/lang/ThreadLifecycleListener.java b/affinity/src/main/java/java/lang/ThreadLifecycleListener.java deleted file mode 100644 index f2e4c01e3..000000000 --- a/affinity/src/main/java/java/lang/ThreadLifecycleListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package java.lang; - -/** - * A listener for various events in a Thread's life: creation, termination, etc. - */ -public interface ThreadLifecycleListener { - - /** - * The specified thread is about to be started. - * - * @param t the thread which is being started - */ - void started(Thread t); - - /** - * The specified thread failed to start. - * - * @param t the thread that had a failed start - */ - void startFailed(Thread t); - - /** - * The specified thread has been terminated. - * - * @param t the thread that has been terminated - */ - void terminated(Thread t); -} diff --git a/affinity/src/main/java/java/lang/ThreadTrackingGroup.java b/affinity/src/main/java/java/lang/ThreadTrackingGroup.java deleted file mode 100644 index 7a4d6bb35..000000000 --- a/affinity/src/main/java/java/lang/ThreadTrackingGroup.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package java.lang; - -/** - * A wrapper of {@link java.lang.ThreadGroup} that tracks the creation and termination of threads. - */ -public class ThreadTrackingGroup extends ThreadGroup { - - /** - * Listener to be notified of various events in thread lifecycles. - */ - private final ThreadLifecycleListener listener; - - public ThreadTrackingGroup(ThreadGroup parent, ThreadLifecycleListener listener) { - super(parent, ThreadTrackingGroup.class.getSimpleName().toLowerCase() + System.identityHashCode(listener)); - this.listener = listener; - } - - @Override - void add(Thread t) { - // System.out.println("ThreadTrackingGroup.add: " + t); //todo: remove - super.add(t); - listener.started(t); - } - - @Override - void threadStartFailed(Thread t) { - super.threadStartFailed(t); - listener.startFailed(t); - } - - @Override - void threadTerminated(Thread t) { - super.threadTerminated(t); - listener.terminated(t); - } -} diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index e9025f248..ef31c61ee 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -198,24 +198,19 @@ public static boolean isJNAAvailable() { } public static AffinityLock acquireLock() { - return isNonForkingAffinityAvailable() ? NonForkingAffinityLock.acquireLock() : AffinityLock.acquireLock(); + return AffinityLock.acquireLock(); } public static AffinityLock acquireCore() { - return isNonForkingAffinityAvailable() ? NonForkingAffinityLock.acquireCore() : AffinityLock.acquireCore(); + return AffinityLock.acquireCore(); } public static AffinityLock acquireLock(boolean bind) { - return isNonForkingAffinityAvailable() ? NonForkingAffinityLock.acquireLock(bind) : AffinityLock.acquireLock(bind); + return AffinityLock.acquireLock(bind); } public static AffinityLock acquireCore(boolean bind) { - return isNonForkingAffinityAvailable() ? NonForkingAffinityLock.acquireCore(bind) : AffinityLock.acquireCore(bind); - } - - private static boolean isNonForkingAffinityAvailable() { - BootClassPath bootClassPath = BootClassPath.INSTANCE; - return bootClassPath.has("java.lang.ThreadTrackingGroup") && bootClassPath.has("java.lang.ThreadLifecycleListener"); + return AffinityLock.acquireCore(bind); } public static void resetToBaseAffinity() { diff --git a/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java b/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java deleted file mode 100644 index d6e3440f2..000000000 --- a/affinity/src/main/java/net/openhft/affinity/NonForkingAffinityLock.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.affinity; - -import net.openhft.affinity.impl.NoCpuLayout; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; - -public class NonForkingAffinityLock extends AffinityLock implements ThreadLifecycleListener { - - private static final Field GROUP_FIELD = makeThreadFieldModifiable("group"); - - private static final Field TARGET_FIELD = makeThreadFieldModifiable("target"); - - private static final LockInventory LOCK_INVENTORY = new LockInventory(new NoCpuLayout(PROCESSORS)) { - @Override - protected AffinityLock newLock(int cpuId, boolean base, boolean reservable) { - return new NonForkingAffinityLock(cpuId, base, reservable, this); - } - }; - - NonForkingAffinityLock(int cpuId, boolean base, boolean reservable, LockInventory lockInventory) { - super(cpuId, base, reservable, lockInventory); - } - - /** - * Assign any free cpu to this thread. - * - * @return A handle for the current AffinityLock. - */ - public static AffinityLock acquireLock() { - return acquireLock(true); - } - - /** - * Assign any free core to this thread. - *

- * In reality, only one cpu is assigned, the rest of the threads for that core are reservable so they are not used. - * - * @return A handle for the current AffinityLock. - */ - public static AffinityLock acquireCore() { - return acquireCore(true); - } - - /** - * Assign a cpu which can be bound to the current thread or another thread. - *

- * This can be used for defining your thread layout centrally and passing the handle via dependency injection. - * - * @param bind if true, bind the current thread, if false, reserve a cpu which can be bound later. - * @return A handle for an affinity lock. - */ - public static AffinityLock acquireLock(boolean bind) { - return acquireLock(bind, AffinityLock.ANY_CPU, AffinityStrategies.ANY); - } - - /** - * Assign a core(and all its cpus) which can be bound to the current thread or another thread. - *

- * This can be used for defining your thread layout centrally and passing the handle via dependency injection. - * - * @param bind if true, bind the current thread, if false, reserve a cpu which can be bound later. - * @return A handle for an affinity lock. - */ - public static AffinityLock acquireCore(boolean bind) { - return acquireCore(bind, AffinityLock.ANY_CPU, AffinityStrategies.ANY); - } - - private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { - return LOCK_INVENTORY.acquireLock(bind, cpuId, strategies); - } - - private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { - return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies); - } - - /** - * Set the CPU layout for this machine. CPUs which are not mentioned will be ignored. - *

- * Changing the layout will have no impact on thread which have already been assigned. - * It only affects subsequent assignments. - * - * @param cpuLayout for this application to use for this machine. - */ - public static void cpuLayout(@NotNull CpuLayout cpuLayout) { - LOCK_INVENTORY.set(cpuLayout); - } - - /** - * @return The current CpuLayout for the application. - */ - @NotNull - public static CpuLayout cpuLayout() { - return LOCK_INVENTORY.getCpuLayout(); - } - - /** - * @return All the current locks as a String. - */ - @NotNull - public static String dumpLocks() { - return LOCK_INVENTORY.dumpLocks(); - } - - private static Field makeThreadFieldModifiable(String fieldName) { - try { - Field field = Thread.class.getDeclaredField(fieldName); - field.setAccessible(true); - return field; - } catch (NoSuchFieldException e) { - throw new RuntimeException(Thread.class.getName() + " class doesn't have a " + fieldName + " field! Quite unexpected!"); - } - } - - private static void changeGroupOfThread(Thread thread, ThreadGroup group) { - try { - GROUP_FIELD.set(thread, group); - } catch (IllegalAccessException e) { - throw new RuntimeException("Failed changing " + Thread.class.getName() + "'s the '" + GROUP_FIELD.getName() + "' field! Reason: " + e.getMessage()); - } - } - - private static void wrapRunnableOfThread(Thread thread, final AffinityLock lock) { - try { - final Runnable originalRunnable = (Runnable) TARGET_FIELD.get(thread); - TARGET_FIELD.set( - thread, - new Runnable() { - @Override - public void run() { - lock.release(); - originalRunnable.run(); - } - } - ); - } catch (IllegalAccessException e) { - throw new RuntimeException("Failed wrapping " + Thread.class.getName() + "'s '" + TARGET_FIELD.getName() + "' field! Reason: " + e.getMessage()); - } - } - - @Override - public void bind(boolean wholeCore) { - super.bind(wholeCore); - Thread thread = Thread.currentThread(); - changeGroupOfThread(thread, new ThreadTrackingGroup(thread.getThreadGroup(), this)); - } - - @Override - public void release() { - Thread thread = Thread.currentThread(); - changeGroupOfThread(thread, thread.getThreadGroup().getParent()); - super.release(); - } - - @Override - public void started(Thread t) { - wrapRunnableOfThread(t, this); - } - - @Override - public void startFailed(Thread t) { - } - - @Override - public void terminated(Thread t) { - } -} From da11412523aff99853c187ca58e06ab971d50f4a Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 27 May 2021 06:11:02 +0200 Subject: [PATCH 003/226] Updating to bom version 2.21ea147 From 1db3c37a6f80b744362eea4c16c53838860fe281 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 27 May 2021 06:11:19 +0200 Subject: [PATCH 004/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea2 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index b085626b3..e49124b50 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea2-SNAPSHOT + 3.21ea2 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea2 diff --git a/affinity/pom.xml b/affinity/pom.xml index 56be3e094..f3238730c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea2-SNAPSHOT + 3.21ea2 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea2 diff --git a/pom.xml b/pom.xml index 7682635bb..d2bb95a33 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea2-SNAPSHOT + 3.21ea2 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea2 From 4b9cc072ce6755517d09f4380ee8d2a84790f831 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 27 May 2021 06:11:24 +0200 Subject: [PATCH 005/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index e49124b50..ae4dc309c 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea2 + 3.21ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea2 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index f3238730c..467027588 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea2 + 3.21ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea2 + ea diff --git a/pom.xml b/pom.xml index d2bb95a33..5eed94fe4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea2 + 3.21ea3-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea2 + ea From 5ef467cf697e06ee701ccb55202df4454b213840 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 27 May 2021 06:11:42 +0200 Subject: [PATCH 006/226] Reverting back to bom version 2.21ea-SNAPSHOT From 55a3af1e7f4a0c84af11fbda733ce63e4dc27131 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Jun 2021 14:02:07 +0200 Subject: [PATCH 007/226] Updating to bom version 2.21ea173 From 60254599ef140dc8d0ac65b34c2fda113d318457 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Jun 2021 14:02:26 +0200 Subject: [PATCH 008/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea3 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ae4dc309c..ecd833961 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea3-SNAPSHOT + 3.21ea3 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea3 diff --git a/affinity/pom.xml b/affinity/pom.xml index 467027588..60d4e2f11 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea3-SNAPSHOT + 3.21ea3 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea3 diff --git a/pom.xml b/pom.xml index 5eed94fe4..1840e09c9 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea3-SNAPSHOT + 3.21ea3 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea3 From ce9b86eed32cffd23df7c9d2e65b2278f3d321d0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Jun 2021 14:02:31 +0200 Subject: [PATCH 009/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ecd833961..f0e1ad5b6 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea3 + 3.21ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea3 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 60d4e2f11..5fee01f92 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea3 + 3.21ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea3 + ea diff --git a/pom.xml b/pom.xml index 1840e09c9..b89104462 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea3 + 3.21ea4-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea3 + ea From 4ff58df8152fea9c2bbacc5f3d213e1917fffef6 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 16 Jun 2021 14:02:49 +0200 Subject: [PATCH 010/226] Reverting back to bom version 2.21ea-SNAPSHOT From 6f689854847b18eb0d07551e0105296fb10cb538 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Thu, 17 Jun 2021 11:38:55 +1000 Subject: [PATCH 011/226] tidy doco --- README.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.adoc b/README.adoc index 584aa96aa..773c4ffa7 100644 --- a/README.adoc +++ b/README.adoc @@ -129,21 +129,21 @@ try (final AffinityLock al = AffinityLock.acquireLock()) { ---- In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. -=== Getting the thread id. +=== Getting the thread id You can get the current thread id using [source, java] ---- int threadId = AffinitySupport.getThreadId(); ---- -=== Determining which CPU you are running on. +=== Determining which CPU you are running on You can get the current CPU being used by [source, java] ---- int cpuId = AffinitySupport.getCpu(); ---- -=== Controlling the affinity more directly. +=== Controlling the affinity more directly The affinity of the process on start up is [source, java] ---- @@ -223,7 +223,7 @@ try (AffinityLock lock = AffinityLock.acquireLockLastMinus(n)) { I have the cpuId in a configuration file, how can I set it using a string? -=== Answer: use one of the following. +=== Answer: use one of the following [source,java] ---- From 25390273dd5d44b906d9e8ad7479f749d75791f0 Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Thu, 17 Jun 2021 09:25:13 +0100 Subject: [PATCH 012/226] AffinityThreadFactory should bind all thread created, not just the first one. #75 --- .../main/java/net/openhft/affinity/AffinityThreadFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java index a1b15f372..a70bfbe3d 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java @@ -66,7 +66,8 @@ public void run() { } private synchronized AffinityLock acquireLockBasedOnLast() { - AffinityLock al = lastAffinityLock == null ? AffinityLock.acquireLock() : lastAffinityLock.acquireLock(strategies); + AffinityLock al = lastAffinityLock == null ? AffinityLock.acquireLock(false) : lastAffinityLock.acquireLock(strategies); + al.bind(); if (al.cpuId() >= 0) lastAffinityLock = al; return al; From f824225eab5850c5501b1c6eccbe93777abec4e0 Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Thu, 17 Jun 2021 09:26:31 +0100 Subject: [PATCH 013/226] When SetThreadAffinityMask silently fails, give a warning and retain the affinity mask. #76 --- .../affinity/impl/WindowsJNAAffinity.java | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index 1fdb8dc6a..ba37fca1e 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -25,6 +25,7 @@ import com.sun.jna.platform.win32.WinDef; import com.sun.jna.ptr.LongByReference; import net.openhft.affinity.IAffinity; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +43,7 @@ public enum WindowsJNAAffinity implements IAffinity { INSTANCE; public static final boolean LOADED; private static final Logger LOGGER = LoggerFactory.getLogger(WindowsJNAAffinity.class); + private static final ThreadLocal currentAffinity = new ThreadLocal<>(); static { boolean loaded = false; @@ -58,26 +60,11 @@ public enum WindowsJNAAffinity implements IAffinity { @Override public BitSet getAffinity() { - final CLibrary lib = CLibrary.INSTANCE; - final LongByReference cpuset1 = new LongByReference(0); - final LongByReference cpuset2 = new LongByReference(0); - try { - - final int ret = lib.GetProcessAffinityMask(-1, cpuset1, cpuset2); - // Successful result is positive, according to the docs - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683213%28v=vs.85%29.aspx - if (ret <= 0) { - throw new IllegalStateException("GetProcessAffinityMask(( -1 ), &(" + cpuset1 + "), &(" + cpuset2 + ") ) return " + ret); - } - - long[] longs = new long[1]; - longs[0] = cpuset1.getValue(); - return BitSet.valueOf(longs); - } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } - - return new BitSet(); + BitSet bitSet = currentAffinity.get(); + if (bitSet != null) + return bitSet; + BitSet longs = getAffinity0(); + return longs != null ? longs : new BitSet(); } @Override @@ -103,6 +90,34 @@ public void setAffinity(final BitSet affinity) { } catch (LastErrorException e) { throw new IllegalStateException("SetThreadAffinityMask((" + pid + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e); } + BitSet affinity2 = getAffinity0(); + if (!affinity2.equals(affinity)) { + LoggerFactory.getLogger(WindowsJNAAffinity.class).warn("Tried to set affinity to " + affinity + " but was " + affinity2 + " you may have in sufficient access rights"); + } + currentAffinity.set((BitSet) affinity.clone()); + } + + @Nullable + private BitSet getAffinity0() { + final CLibrary lib = CLibrary.INSTANCE; + final LongByReference cpuset1 = new LongByReference(0); + final LongByReference cpuset2 = new LongByReference(0); + try { + + final int ret = lib.GetProcessAffinityMask(-1, cpuset1, cpuset2); + // Successful result is positive, according to the docs + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683213%28v=vs.85%29.aspx + if (ret <= 0) { + throw new IllegalStateException("GetProcessAffinityMask(( -1 ), &(" + cpuset1 + "), &(" + cpuset2 + ") ) return " + ret); + } + + long[] longs = new long[1]; + longs[0] = cpuset1.getValue(); + return BitSet.valueOf(longs); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + } + return null; } public int getTid() { From 4758ecfaf8b64b1d3bb7cf067ef87622cb05212b Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 17 Jun 2021 11:39:02 +0100 Subject: [PATCH 014/226] Allow for some CPUs to be turned off. --- .../main/java/net/openhft/affinity/impl/VanillaCpuLayout.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java index d30c8bba3..55790d734 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VanillaCpuLayout.java @@ -20,6 +20,7 @@ import net.openhft.affinity.CpuLayout; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.LoggerFactory; import java.io.*; import java.util.*; @@ -60,7 +61,7 @@ public class VanillaCpuLayout implements CpuLayout { for (CpuInfo detail : cpuDetails) { error.append(detail).append('\n'); } - throw new AssertionError(error); + LoggerFactory.getLogger(VanillaCpuLayout.class).warn(error.toString()); } } From c10e9f8be999ce7f30a70f6f546302defee09be9 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 17 Jun 2021 14:26:33 +0200 Subject: [PATCH 015/226] Updating to bom version 2.21ea176 From 490a930b7855fdad55696f1fe0581c0ebb600f5f Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 17 Jun 2021 14:26:55 +0200 Subject: [PATCH 016/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea4 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index f0e1ad5b6..98368e773 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea4-SNAPSHOT + 3.21ea4 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea4 diff --git a/affinity/pom.xml b/affinity/pom.xml index 5fee01f92..9ab9cfd71 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea4-SNAPSHOT + 3.21ea4 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea4 diff --git a/pom.xml b/pom.xml index b89104462..c14ef7e28 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea4-SNAPSHOT + 3.21ea4 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea4 From 6de4f343bf5ac75890fdef0591a9aa59df1bb01e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 17 Jun 2021 14:27:01 +0200 Subject: [PATCH 017/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 98368e773..b613673ec 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea4 + 3.21ea5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea4 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 9ab9cfd71..3907c284d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea4 + 3.21ea5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -214,7 +214,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea4 + ea diff --git a/pom.xml b/pom.xml index c14ef7e28..09de56907 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea4 + 3.21ea5-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea4 + ea From fc830d4a3564269b8361f6b07a1c1b7b8a35b03c Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 17 Jun 2021 14:27:20 +0200 Subject: [PATCH 018/226] Reverting back to bom version 2.21ea-SNAPSHOT From af951fd6437e51bb08c6c54fbaffe1ae80745641 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Tue, 22 Jun 2021 09:31:00 +1000 Subject: [PATCH 019/226] Makefile optional for easier windows build --- affinity/pom.xml | 54 ++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 3907c284d..c111b518c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -95,6 +95,38 @@ + + make-c + + + !dontMake + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + build-native + process-classes + + exec + + + ${project.basedir}/${native.source.dir}/Makefile + ${project.basedir}/${native.source.dir} + + + + + + + @@ -109,28 +141,6 @@ - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - - - build-native - process-classes - - exec - - - ${project.basedir}/${native.source.dir}/Makefile - ${project.basedir}/${native.source.dir} - - - - - org.apache.maven.plugins maven-scm-publish-plugin From 0638a3ac7aef7073d46b8342a96b1884026cd8cd Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 21 Jun 2021 14:41:30 +1000 Subject: [PATCH 020/226] JNA 5.8.0 --- affinity/pom.xml | 1 + .../openhft/affinity/impl/LinuxHelper.java | 2 +- .../openhft/affinity/impl/OSXJNAAffinity.java | 3 +-- .../affinity/impl/PosixJNAAffinity.java | 3 +-- .../affinity/impl/SolarisJNAAffinity.java | 3 +-- .../affinity/impl/WindowsJNAAffinity.java | 20 ++++++++++--------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index c111b518c..b6e3e8d3f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -128,6 +128,7 @@ + diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index deee9a908..459e474f0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -158,7 +158,7 @@ public static int syscall(int number, Object... args) { } interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) Native.loadLibrary(LIBRARY_NAME, CLibrary.class); + CLibrary INSTANCE = Native.load(LIBRARY_NAME, CLibrary.class); int sched_setaffinity(final int pid, final int cpusetsize, diff --git a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java index c9b7fa4b8..39ed90d55 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/OSXJNAAffinity.java @@ -72,8 +72,7 @@ public int getThreadId() { } interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) - Native.loadLibrary("libpthread.dylib", CLibrary.class); + CLibrary INSTANCE = Native.load("libpthread.dylib", CLibrary.class); int pthread_self() throws LastErrorException; } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java index f3efd1947..25e3053f0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/PosixJNAAffinity.java @@ -191,8 +191,7 @@ public int getThreadId() { * @author BegemoT */ interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) - Native.loadLibrary(LIBRARY_NAME, CLibrary.class); + CLibrary INSTANCE = Native.load(LIBRARY_NAME, CLibrary.class); int sched_setaffinity(final int pid, final int cpusetsize, diff --git a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java index 2718187c5..a9c6b011b 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/SolarisJNAAffinity.java @@ -72,8 +72,7 @@ public int getThreadId() { } interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) - Native.loadLibrary("c", CLibrary.class); + CLibrary INSTANCE = Native.load("c", CLibrary.class); int pthread_self() throws LastErrorException; } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index ba37fca1e..1a8bb2cd0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -17,12 +17,10 @@ package net.openhft.affinity.impl; -import com.sun.jna.LastErrorException; -import com.sun.jna.Library; -import com.sun.jna.Native; -import com.sun.jna.PointerType; +import com.sun.jna.*; import com.sun.jna.platform.win32.Kernel32; import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinNT; import com.sun.jna.ptr.LongByReference; import net.openhft.affinity.IAffinity; import org.jetbrains.annotations.Nullable; @@ -86,7 +84,7 @@ public void setAffinity(final BitSet affinity) { int pid = getTid(); try { - lib.SetThreadAffinityMask(pid, aff); + lib.SetThreadAffinityMask(handle(pid), aff); } catch (LastErrorException e) { throw new IllegalStateException("SetThreadAffinityMask((" + pid + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e); } @@ -104,7 +102,7 @@ private BitSet getAffinity0() { final LongByReference cpuset2 = new LongByReference(0); try { - final int ret = lib.GetProcessAffinityMask(-1, cpuset1, cpuset2); + final int ret = lib.GetProcessAffinityMask(handle(-1), cpuset1, cpuset2); // Successful result is positive, according to the docs // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683213%28v=vs.85%29.aspx if (ret <= 0) { @@ -120,6 +118,10 @@ private BitSet getAffinity0() { return null; } + private WinNT.HANDLE handle(int pid) { + return new WinNT.HANDLE(new Pointer(pid)); + } + public int getTid() { final CLibrary lib = CLibrary.INSTANCE; @@ -152,11 +154,11 @@ public int getThreadId() { * @author BegemoT */ private interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary) Native.loadLibrary("kernel32", CLibrary.class); + CLibrary INSTANCE = Native.load("kernel32", CLibrary.class); - int GetProcessAffinityMask(final int pid, final PointerType lpProcessAffinityMask, final PointerType lpSystemAffinityMask) throws LastErrorException; + int GetProcessAffinityMask(final WinNT.HANDLE pid, final PointerType lpProcessAffinityMask, final PointerType lpSystemAffinityMask) throws LastErrorException; - void SetThreadAffinityMask(final int pid, final WinDef.DWORD lpProcessAffinityMask) throws LastErrorException; + void SetThreadAffinityMask(final WinNT.HANDLE pid, final WinDef.DWORD lpProcessAffinityMask) throws LastErrorException; int GetCurrentThread() throws LastErrorException; } From 7a264a8e4022b9b482f7f5e0afffa38efa3df58b Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 21 Jun 2021 14:46:16 +1000 Subject: [PATCH 021/226] clean up and de-deprecate --- .../affinity/impl/NativeAffinityImpTest.java | 4 +- .../affinity/impl/PosixJNAAffinityTest.java | 3 +- .../affinity/impl/VanillaCpuLayoutTest.java | 2 +- affinity/src/test/java/org/junit/Assert.java | 886 ------------------ 4 files changed, 4 insertions(+), 891 deletions(-) delete mode 100644 affinity/src/test/java/org/junit/Assert.java diff --git a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java index 4f038e3d1..3c98d9683 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java @@ -17,7 +17,7 @@ package net.openhft.affinity.impl; -import net.openhft.affinity.AffinitySupport; +import net.openhft.affinity.Affinity; import net.openhft.affinity.IAffinity; import org.junit.Assume; import org.junit.BeforeClass; @@ -45,7 +45,7 @@ public IAffinity getImpl() { public void testGettid() { System.out.println("pid=" + getImpl().getProcessId()); System.out.println("tid=" + getImpl().getThreadId()); - AffinitySupport.setThreadId(); + Affinity.setThreadId(); for (int j = 0; j < 3; j++) { final int runs = 100000; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index 034aa0a69..a763cef05 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -18,7 +18,6 @@ package net.openhft.affinity.impl; import net.openhft.affinity.Affinity; -import net.openhft.affinity.AffinitySupport; import net.openhft.affinity.IAffinity; import org.junit.Assume; import org.junit.BeforeClass; @@ -44,7 +43,7 @@ public IAffinity getImpl() { public void testGettid() { System.out.println("pid=" + getImpl().getProcessId()); System.out.println("tid=" + getImpl().getThreadId()); - AffinitySupport.setThreadId(); + Affinity.setThreadId(); for (int j = 0; j < 3; j++) { final int runs = 100000; diff --git a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java index e58206818..581874871 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.io.InputStream; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; /** * @author peter.lawrey diff --git a/affinity/src/test/java/org/junit/Assert.java b/affinity/src/test/java/org/junit/Assert.java deleted file mode 100644 index 994c64395..000000000 --- a/affinity/src/test/java/org/junit/Assert.java +++ /dev/null @@ -1,886 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.junit; - -import org.hamcrest.Matcher; -import org.hamcrest.MatcherAssert; -import org.junit.internal.ArrayComparisonFailure; -import org.junit.internal.ExactComparisonCriteria; -import org.junit.internal.InexactComparisonCriteria; - -/** - * TODO replace with 4.12 when it is released with a simple bug fix. - *

- * A set of assertion methods useful for writing tests. Only failed assertions - * are recorded. These methods can be used directly: - * Assert.assertEquals(...), however, they read better if they - * are referenced through static import:
- *

- *

- * import static org.junit.Assert.*;
- *    ...
- *    assertEquals(...);
- * 
- * - * @see AssertionError - * @since 4.0 - */ -public class Assert { - /** - * Protect constructor since it is a static only class - */ - protected Assert() { - } - - /** - * Asserts that a condition is true. If it isn't it throws an - * {@link AssertionError} with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param condition condition to be checked - */ - static public void assertTrue(String message, boolean condition) { - if (!condition) { - fail(message); - } - } - - /** - * Asserts that a condition is true. If it isn't it throws an - * {@link AssertionError} without a message. - * - * @param condition condition to be checked - */ - static public void assertTrue(boolean condition) { - assertTrue(null, condition); - } - - /** - * Asserts that a condition is false. If it isn't it throws an - * {@link AssertionError} with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param condition condition to be checked - */ - static public void assertFalse(String message, boolean condition) { - assertTrue(message, !condition); - } - - /** - * Asserts that a condition is false. If it isn't it throws an - * {@link AssertionError} without a message. - * - * @param condition condition to be checked - */ - static public void assertFalse(boolean condition) { - assertFalse(null, condition); - } - - /** - * Fails a test with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @see AssertionError - */ - static public void fail(String message) { - if (message == null) { - throw new AssertionError(); - } - throw new AssertionError(message); - } - - /** - * Fails a test with no message. - */ - static public void fail() { - fail(null); - } - - /** - * Asserts that two objects are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. If - * expected and actual are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected expected value - * @param actual actual value - */ - static public void assertEquals(String message, Object expected, - Object actual) { - if (equalsRegardingNull(expected, actual)) { - return; - - } else if (expected instanceof String && actual instanceof String) { - String cleanMessage = message == null ? "" : message; - throw new ComparisonFailure(cleanMessage, (String) expected, - (String) actual); - - } else { - failNotEquals(message, expected, actual); - } - } - - private static boolean equalsRegardingNull(Object expected, Object actual) { - if (expected == null) { - return actual == null; - } - - return isEquals(expected, actual); - } - - private static boolean isEquals(Object expected, Object actual) { - return expected.equals(actual); - } - - /** - * Asserts that two objects are equal. If they are not, an - * {@link AssertionError} without a message is thrown. If - * expected and actual are null, - * they are considered equal. - * - * @param expected expected value - * @param actual the value to check against expected - */ - static public void assertEquals(Object expected, Object actual) { - assertEquals(null, expected, actual); - } - - /** - * Asserts that two objects are not equals. If they are, an - * {@link AssertionError} is thrown with the given message. If - * first and second are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param first first value to check - * @param second the value to check against first - */ - static public void assertNotEquals(String message, Object first, - Object second) { - if (equalsRegardingNull(first, second)) { - failEquals(message, first); - } - } - - /** - * Asserts that two objects are not equals. If they are, an - * {@link AssertionError} without a message is thrown. If - * first and second are null, - * they are considered equal. - * - * @param first first value to check - * @param second the value to check against first - */ - static public void assertNotEquals(Object first, Object second) { - assertNotEquals(null, first, second); - } - - private static void failEquals(String message, Object actual) { - String formatted = "Values should be different. "; - if (message != null) { - formatted = message + ". "; - } - - formatted += "Actual: " + actual; - fail(formatted); - } - - /** - * Asserts that two longs are not equals. If they are, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param first first value to check - * @param second the value to check against first - */ - static public void assertNotEquals(String message, long first, long second) { - assertNotEquals(message, (Long) first, (Long) second); - } - - /** - * Asserts that two longs are not equals. If they are, an - * {@link AssertionError} without a message is thrown. - * - * @param first first value to check - * @param second the value to check against first - */ - static public void assertNotEquals(long first, long second) { - assertNotEquals(null, first, second); - } - - /** - * Asserts that two doubles or floats are not equal to within a positive delta. - * If they are, an {@link AssertionError} is thrown with the given - * message. If the expected value is infinity then the delta value is - * ignored. NaNs are considered equal: - * assertNotEquals(Double.NaN, Double.NaN, *) fails - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param first first value to check - * @param second the value to check against first - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertNotEquals(String message, double first, - double second, double delta) { - if (!doubleIsDifferent(first, second, delta)) { - failEquals(message, new Double(first)); - } - } - - /** - * Asserts that two doubles or floats are not equal to within a positive delta. - * If they are, an {@link AssertionError} is thrown. If the expected - * value is infinity then the delta value is ignored.NaNs are considered - * equal: assertNotEquals(Double.NaN, Double.NaN, *) fails - * - * @param first first value to check - * @param second the value to check against first - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertNotEquals(double first, double second, double delta) { - assertNotEquals(null, first, second, delta); - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. If - * expecteds and actuals are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values. - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - */ - public static void assertArrayEquals(String message, Object[] expecteds, - Object[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown. If expected and - * actual are null, they are considered - * equal. - * - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - */ - public static void assertArrayEquals(Object[] expecteds, Object[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two byte arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds byte array with expected values. - * @param actuals byte array with actual values - */ - public static void assertArrayEquals(String message, byte[] expecteds, - byte[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two byte arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds byte array with expected values. - * @param actuals byte array with actual values - */ - public static void assertArrayEquals(byte[] expecteds, byte[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two char arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds char array with expected values. - * @param actuals char array with actual values - */ - public static void assertArrayEquals(String message, char[] expecteds, - char[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two char arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds char array with expected values. - * @param actuals char array with actual values - */ - public static void assertArrayEquals(char[] expecteds, char[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two short arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds short array with expected values. - * @param actuals short array with actual values - */ - public static void assertArrayEquals(String message, short[] expecteds, - short[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two short arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds short array with expected values. - * @param actuals short array with actual values - */ - public static void assertArrayEquals(short[] expecteds, short[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two int arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds int array with expected values. - * @param actuals int array with actual values - */ - public static void assertArrayEquals(String message, int[] expecteds, - int[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two int arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds int array with expected values. - * @param actuals int array with actual values - */ - public static void assertArrayEquals(int[] expecteds, int[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two long arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds long array with expected values. - * @param actuals long array with actual values - */ - public static void assertArrayEquals(String message, long[] expecteds, - long[] actuals) throws ArrayComparisonFailure { - internalArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two long arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds long array with expected values. - * @param actuals long array with actual values - */ - public static void assertArrayEquals(long[] expecteds, long[] actuals) { - assertArrayEquals(null, expecteds, actuals); - } - - /** - * Asserts that two double arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds double array with expected values. - * @param actuals double array with actual values - */ - public static void assertArrayEquals(String message, double[] expecteds, - double[] actuals, double delta) throws ArrayComparisonFailure { - new InexactComparisonCriteria(delta).arrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two double arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds double array with expected values. - * @param actuals double array with actual values - */ - public static void assertArrayEquals(double[] expecteds, double[] actuals, double delta) { - assertArrayEquals(null, expecteds, actuals, delta); - } - - /** - * Asserts that two float arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds float array with expected values. - * @param actuals float array with actual values - */ - public static void assertArrayEquals(String message, float[] expecteds, - float[] actuals, float delta) throws ArrayComparisonFailure { - new InexactComparisonCriteria(delta).arrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two float arrays are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expecteds float array with expected values. - * @param actuals float array with actual values - */ - public static void assertArrayEquals(float[] expecteds, float[] actuals, float delta) { - assertArrayEquals(null, expecteds, actuals, delta); - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. If - * expecteds and actuals are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values. - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - */ - private static void internalArrayEquals(String message, Object expecteds, - Object actuals) throws ArrayComparisonFailure { - new ExactComparisonCriteria().arrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two doubles are equal to within a positive delta. - * If they are not, an {@link AssertionError} is thrown with the given - * message. If the expected value is infinity then the delta value is - * ignored. NaNs are considered equal: - * assertEquals(Double.NaN, Double.NaN, *) passes - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected expected value - * @param actual the value to check against expected - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertEquals(String message, double expected, - double actual, double delta) { - if (doubleIsDifferent(expected, actual, delta)) { - failNotEquals(message, new Double(expected), new Double(actual)); - } - } - - /** - * Asserts that two floats are equal to within a positive delta. - * If they are not, an {@link AssertionError} is thrown with the given - * message. If the expected value is infinity then the delta value is - * ignored. NaNs are considered equal: - * assertEquals(Float.NaN, Float.NaN, *) passes - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected expected value - * @param actual the value to check against expected - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertEquals(String message, float expected, - float actual, float delta) { - if (Float.compare(expected, actual) == 0) { - return; - } - if (!(Math.abs(expected - actual) <= delta)) { - failNotEquals(message, new Float(expected), new Float(actual)); - } - } - - static private boolean doubleIsDifferent(double d1, double d2, double delta) { - if (Double.compare(d1, d2) == 0) { - return false; - } - return (Math.abs(d1 - d2) > delta); - - } - - /** - * Asserts that two longs are equal. If they are not, an - * {@link AssertionError} is thrown. - * - * @param expected expected long value. - * @param actual actual long value - */ - static public void assertEquals(long expected, long actual) { - if (expected != actual) - assertEquals(null, expected, actual); - } - - /** - * Asserts that two longs are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected long expected value. - * @param actual long actual value - */ - static public void assertEquals(String message, long expected, long actual) { - assertEquals(message, (Long) expected, (Long) actual); - } - - /** - * @deprecated Use - * assertEquals(double expected, double actual, double delta) - * instead - */ - @Deprecated(/* to be removed in x.22 */) -static public void assertEquals(double expected, double actual) { - assertEquals(null, expected, actual); - } - - /** - * @deprecated Use - * assertEquals(String message, double expected, double actual, double delta) - * instead - */ - @Deprecated(/* to be removed in x.22 */) -static public void assertEquals(String message, double expected, - double actual) { - fail("Use assertEquals(expected, actual, delta) to compare floating-point numbers"); - } - - /** - * Asserts that two doubles are equal to within a positive delta. - * If they are not, an {@link AssertionError} is thrown. If the expected - * value is infinity then the delta value is ignored.NaNs are considered - * equal: assertEquals(Double.NaN, Double.NaN, *) passes - * - * @param expected expected value - * @param actual the value to check against expected - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertEquals(double expected, double actual, double delta) { - assertEquals(null, expected, actual, delta); - } - - /** - * Asserts that two floats are equal to within a positive delta. - * If they are not, an {@link AssertionError} is thrown. If the expected - * value is infinity then the delta value is ignored. NaNs are considered - * equal: assertEquals(Float.NaN, Float.NaN, *) passes - * - * @param expected expected value - * @param actual the value to check against expected - * @param delta the maximum delta between expected and - * actual for which both numbers are still - * considered equal. - */ - static public void assertEquals(float expected, float actual, float delta) { - assertEquals(null, expected, actual, delta); - } - - /** - * Asserts that an object isn't null. If it is an {@link AssertionError} is - * thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param object Object to check or null - */ - static public void assertNotNull(String message, Object object) { - assertTrue(message, object != null); - } - - /** - * Asserts that an object isn't null. If it is an {@link AssertionError} is - * thrown. - * - * @param object Object to check or null - */ - static public void assertNotNull(Object object) { - assertNotNull(null, object); - } - - /** - * Asserts that an object is null. If it is not, an {@link AssertionError} - * is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param object Object to check or null - */ - static public void assertNull(String message, Object object) { - if (object == null) { - return; - } - failNotNull(message, object); - } - - /** - * Asserts that an object is null. If it isn't an {@link AssertionError} is - * thrown. - * - * @param object Object to check or null - */ - static public void assertNull(Object object) { - assertNull(null, object); - } - - static private void failNotNull(String message, Object actual) { - String formatted = ""; - if (message != null) { - formatted = message + " "; - } - fail(formatted + "expected null, but was:<" + actual + ">"); - } - - /** - * Asserts that two objects refer to the same object. If they are not, an - * {@link AssertionError} is thrown with the given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expected the expected object - * @param actual the object to compare to expected - */ - static public void assertSame(String message, Object expected, Object actual) { - if (expected == actual) { - return; - } - failNotSame(message, expected, actual); - } - - /** - * Asserts that two objects refer to the same object. If they are not the - * same, an {@link AssertionError} without a message is thrown. - * - * @param expected the expected object - * @param actual the object to compare to expected - */ - static public void assertSame(Object expected, Object actual) { - assertSame(null, expected, actual); - } - - /** - * Asserts that two objects do not refer to the same object. If they do - * refer to the same object, an {@link AssertionError} is thrown with the - * given message. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param unexpected the object you don't expect - * @param actual the object to compare to unexpected - */ - static public void assertNotSame(String message, Object unexpected, - Object actual) { - if (unexpected == actual) { - failSame(message); - } - } - - /** - * Asserts that two objects do not refer to the same object. If they do - * refer to the same object, an {@link AssertionError} without a message is - * thrown. - * - * @param unexpected the object you don't expect - * @param actual the object to compare to unexpected - */ - static public void assertNotSame(Object unexpected, Object actual) { - assertNotSame(null, unexpected, actual); - } - - static private void failSame(String message) { - String formatted = ""; - if (message != null) { - formatted = message + " "; - } - fail(formatted + "expected not same"); - } - - static private void failNotSame(String message, Object expected, - Object actual) { - String formatted = ""; - if (message != null) { - formatted = message + " "; - } - fail(formatted + "expected same:<" + expected + "> was not:<" + actual - + ">"); - } - - static private void failNotEquals(String message, Object expected, - Object actual) { - fail(format(message, expected, actual)); - } - - static String format(String message, Object expected, Object actual) { - String formatted = ""; - if (message != null && !message.equals("")) { - formatted = message + " "; - } - String expectedString = String.valueOf(expected); - String actualString = String.valueOf(actual); - if (expectedString.equals(actualString)) { - return formatted + "expected: " - + formatClassAndValue(expected, expectedString) - + " but was: " + formatClassAndValue(actual, actualString); - - } else { - return formatted + "expected:<" + expectedString + "> but was:<" - + actualString + ">"; - } - } - - private static String formatClassAndValue(Object value, String valueString) { - String className = value == null ? "null" : value.getClass().getName(); - return className + "<" + valueString + ">"; - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown with the given message. If - * expecteds and actuals are null, - * they are considered equal. - * - * @param message the identifying message for the {@link AssertionError} (null - * okay) - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values. - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - * @deprecated use assertArrayEquals - */ - @Deprecated(/* to be removed in x.22 */) -public static void assertEquals(String message, Object[] expecteds, - Object[] actuals) { - assertArrayEquals(message, expecteds, actuals); - } - - /** - * Asserts that two object arrays are equal. If they are not, an - * {@link AssertionError} is thrown. If expected and - * actual are null, they are considered - * equal. - * - * @param expecteds Object array or array of arrays (multi-dimensional array) with - * expected values - * @param actuals Object array or array of arrays (multi-dimensional array) with - * actual values - * @deprecated use assertArrayEquals - */ - @Deprecated(/* to be removed in x.22 */) -public static void assertEquals(Object[] expecteds, Object[] actuals) { - assertArrayEquals(expecteds, actuals); - } - - /** - * Asserts that actual satisfies the condition specified by - * matcher. If not, an {@link AssertionError} is thrown with - * information about the matcher and failing value. Example: - *

- *

-     *   assertThat(0, is(1)); // fails:
-     *     // failure message:
-     *     // expected: is <1>
-     *     // got value: <0>
-     *   assertThat(0, is(not(1))) // passes
-     * 
- *

- * org.hamcrest.Matcher does not currently document the meaning - * of its type parameter T. This method assumes that a matcher - * typed as Matcher<T> can be meaningfully applied only - * to values that could be assigned to a variable of type T. - * - * @param the static type accepted by the matcher (this can flag obvious - * compile-time problems such as {@code assertThat(1, is("a"))} - * @param actual the computed value being compared - * @param matcher an expression, built of {@link Matcher}s, specifying allowed - * values - * @see org.hamcrest.CoreMatchers - * @see org.hamcrest.MatcherAssert - */ - public static void assertThat(T actual, Matcher matcher) { - assertThat("", actual, matcher); - } - - /** - * Asserts that actual satisfies the condition specified by - * matcher. If not, an {@link AssertionError} is thrown with - * the reason and information about the matcher and failing value. Example: - *

- *

-     *   assertThat("Help! Integers don't work", 0, is(1)); // fails:
-     *     // failure message:
-     *     // Help! Integers don't work
-     *     // expected: is <1>
-     *     // got value: <0>
-     *   assertThat("Zero is one", 0, is(not(1))) // passes
-     * 
- *

- * org.hamcrest.Matcher does not currently document the meaning - * of its type parameter T. This method assumes that a matcher - * typed as Matcher<T> can be meaningfully applied only - * to values that could be assigned to a variable of type T. - * - * @param reason additional information about the error - * @param the static type accepted by the matcher (this can flag obvious - * compile-time problems such as {@code assertThat(1, is("a"))} - * @param actual the computed value being compared - * @param matcher an expression, built of {@link Matcher}s, specifying allowed - * values - * @see org.hamcrest.CoreMatchers - * @see org.hamcrest.MatcherAssert - */ - public static void assertThat(String reason, T actual, - Matcher matcher) { - MatcherAssert.assertThat(reason, actual, matcher); - } -} From 73529b073c65d4862f561b3895e91093f4d968ed Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 22 Jun 2021 09:07:57 +0200 Subject: [PATCH 022/226] Updating to bom version 2.21ea178 From 1330882333bf30b5c89735b5ee4603fccc678cb6 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 22 Jun 2021 09:08:16 +0200 Subject: [PATCH 023/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea5 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index b613673ec..ba668bf6b 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea5-SNAPSHOT + 3.21ea5 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea5 diff --git a/affinity/pom.xml b/affinity/pom.xml index b6e3e8d3f..d7381e9a2 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea5-SNAPSHOT + 3.21ea5 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -225,7 +225,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea5 diff --git a/pom.xml b/pom.xml index 09de56907..a17e342ef 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea5-SNAPSHOT + 3.21ea5 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea5 From 065840da1f5d4b6942fedd3150eb23251c0443d0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 22 Jun 2021 09:08:22 +0200 Subject: [PATCH 024/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ba668bf6b..e9596bcce 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea5 + 3.21ea6-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea5 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index d7381e9a2..0b6dc4803 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea5 + 3.21ea6-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -225,7 +225,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea5 + ea diff --git a/pom.xml b/pom.xml index a17e342ef..b8118a6dd 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea5 + 3.21ea6-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea5 + ea From 761dd09735412afe14fe139c68a099d584511edc Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Tue, 22 Jun 2021 09:08:41 +0200 Subject: [PATCH 025/226] Reverting back to bom version 2.21ea-SNAPSHOT From 71915d19769a23e410d530035f1e7d3def41cf4c Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Wed, 23 Jun 2021 15:05:13 +1000 Subject: [PATCH 026/226] latest parent and third-party pom/bom --- affinity/pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 0b6dc4803..6ed2f25b3 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.23 + 1.1.26 @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.19.4 + 3.19.9 import @@ -108,7 +108,6 @@ org.codehaus.mojo exec-maven-plugin - 1.2.1 From 66cd3002e9d86bf2f6d193c10d2d8614bdc77353 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Thu, 24 Jun 2021 10:06:33 +1000 Subject: [PATCH 027/226] latest third-party-pom --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index e9596bcce..f13eedf8b 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.23 + 1.1.26 @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.19.4 + 3.19.10 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 6ed2f25b3..2f47ba9b1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.19.9 + 3.19.10 import From 5f30051f6345ca71a900fb67f2608b73a8d75f42 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 28 Jun 2021 12:49:39 +0100 Subject: [PATCH 028/226] Use Jvm.{level}() handlers instead of calling loggers directly, and unit tests cleanup esp use of @After, https://github.com/OpenHFT/Chronicle-Core/issues/233 --- affinity/src/main/java/net/openhft/affinity/Affinity.java | 3 +-- affinity/src/main/java/net/openhft/affinity/LockCheck.java | 3 +-- .../src/main/java/net/openhft/affinity/impl/LinuxHelper.java | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index ef31c61ee..bf185147c 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -33,8 +33,7 @@ * * @author peter.lawrey */ -public enum Affinity { - ; +public enum Affinity {; static final Logger LOGGER = LoggerFactory.getLogger(Affinity.class); @NotNull private static final IAffinity AFFINITY_IMPL; diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 2fe67ad8c..3a3551b6d 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -28,8 +28,7 @@ /** * @author Rob Austin. */ -enum LockCheck { - ; +enum LockCheck {; private static final Logger LOGGER = LoggerFactory.getLogger(LockCheck.class); private static final String OS = System.getProperty("os.name").toLowerCase(); diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index 459e474f0..3b4d301de 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -41,7 +41,7 @@ public class LinuxHelper { ver = new VersionHelper(uname.getRealeaseVersion()); } } catch (Throwable e) { - //logger.warn("Failed to determine Linux version: " + e); + //Jvm.warn().on(getClass(), "Failed to determine Linux version: " + e); } version = ver; From 3f2faf1ed2c1d2e41a17c064e2ddac570e1b48fc Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 28 Jun 2021 16:19:20 +0100 Subject: [PATCH 029/226] Release of all main libraries to x.21.80, https://github.com/OpenHFT/OpenHFT/issues/55 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index f13eedf8b..318f5defc 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea6-SNAPSHOT + 3.21ea80-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 2f47ba9b1..24b19a7a5 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea6-SNAPSHOT + 3.21ea80-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index b8118a6dd..c90304bc4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea6-SNAPSHOT + 3.21ea80-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From e7f871325f8b46c438b2f9cf5338a442b6b69b35 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 29 Jun 2021 09:16:03 +0100 Subject: [PATCH 030/226] Reduce redundant newlines --- affinity/src/main/java/net/openhft/affinity/Affinity.java | 3 ++- affinity/src/main/java/net/openhft/affinity/LockCheck.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index bf185147c..83986b2bc 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -33,7 +33,8 @@ * * @author peter.lawrey */ -public enum Affinity {; +public enum Affinity { + ; // none static final Logger LOGGER = LoggerFactory.getLogger(Affinity.class); @NotNull private static final IAffinity AFFINITY_IMPL; diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 3a3551b6d..cfe4e78f6 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -28,7 +28,8 @@ /** * @author Rob Austin. */ -enum LockCheck {; +enum LockCheck { + ; // none private static final Logger LOGGER = LoggerFactory.getLogger(LockCheck.class); private static final String OS = System.getProperty("os.name").toLowerCase(); From 9d9483e27d9443eb5dcee7c25e90e1e47fd22f4b Mon Sep 17 00:00:00 2001 From: Peter K Lawrey Date: Tue, 27 Jul 2021 11:39:26 +0100 Subject: [PATCH 031/226] Update MicroJitterSampler.java --- .../java/net/openhft/affinity/MicroJitterSampler.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index dc4ac4a91..6dc025cbf 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -20,6 +20,15 @@ import java.io.PrintStream; /* e.g. +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) +After 360 seconds, the average per hour was +2us 35600 +3us 22230 +4us 390 +10us 10 +20us 10 +30us 10 + Windows 10 i7-4770 laptop After 1845 seconds, the average per hour was 2us 2435969 From 70bcc79a33e763338847bbca8188a5f028cb629d Mon Sep 17 00:00:00 2001 From: Peter K Lawrey Date: Tue, 27 Jul 2021 11:53:53 +0100 Subject: [PATCH 032/226] Update MicroJitterSampler.java --- .../java/net/openhft/affinity/MicroJitterSampler.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 6dc025cbf..f22d3efdf 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -20,11 +20,11 @@ import java.io.PrintStream; /* e.g. -Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance After 360 seconds, the average per hour was -2us 35600 -3us 22230 -4us 390 +2us 1566 +3us 526 +4us 80 10us 10 20us 10 30us 10 From 6994fc4a95ade566b8e22fd9ed34e36f0f49fdf3 Mon Sep 17 00:00:00 2001 From: Peter K Lawrey Date: Tue, 27 Jul 2021 14:21:27 +0100 Subject: [PATCH 033/226] Update MicroJitterSampler.java --- .../openhft/affinity/MicroJitterSampler.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index f22d3efdf..c7418c53b 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -21,13 +21,16 @@ import java.io.PrintStream; /* e.g. Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance -After 360 seconds, the average per hour was -2us 1566 -3us 526 -4us 80 -10us 10 -20us 10 -30us 10 +After 3600 seconds, the average per hour was +2us 2571 +3us 2304 +4us 376 +6us 1 +10us 1 +20us 1 +30us 1 +40us 2 +60us 1 Windows 10 i7-4770 laptop After 1845 seconds, the average per hour was From dd26283aad8ff73e7d4ce370a79e01cf506c0646 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 3 Aug 2021 09:15:19 +0100 Subject: [PATCH 034/226] Added results for a new Ryzen 5950X --- .../openhft/affinity/MicroJitterSampler.java | 141 +++++++++++------- 1 file changed, 83 insertions(+), 58 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index c7418c53b..c79e5b1e2 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -19,64 +19,6 @@ package net.openhft.affinity; import java.io.PrintStream; -/* e.g. -Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance -After 3600 seconds, the average per hour was -2us 2571 -3us 2304 -4us 376 -6us 1 -10us 1 -20us 1 -30us 1 -40us 2 -60us 1 - -Windows 10 i7-4770 laptop -After 1845 seconds, the average per hour was -2us 2435969 -3us 548812 -4us 508041 -6us 60320 -8us 25374 -10us 1832324 -14us 2089216 -20us 391901 -30us 16063 -40us 6440 -60us 2617 -80us 1487 -100us 1241 -140us 826 -200us 2108 -300us 601 -400us 159 -600us 129 -800us 215 -1ms 155 -2ms 229 -5ms 24 -10ms 38 -20ms 32 - -On an Centos 7 machine with an isolated CPU. -After 2145 seconds, the average per hour was -2us 781271 -3us 1212123 -4us 13504 -6us 489 -8us 2 -10us 3032577 -14us 17475 -20us 628 -30us 645 -40us 1301 -60us 1217 -80us 1306 -100us 1526 -140us 22 - - */ /** * User: peter.lawrey Date: 30/06/13 Time: 13:13 @@ -166,3 +108,86 @@ void print(PrintStream ps) { ps.println(); } } + +/* e.g. +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance, run from command line +After 3600 seconds, the average per hour was +2us 2571 +3us 2304 +4us 376 +6us 1 +10us 1 +20us 1 +30us 1 +40us 2 +60us 1 + +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 5) sudo cpupower -c {cpu} -g performance, run from command line +After 3600 seconds, the average per hour was +2us 2157 +3us 3444 +4us 3654 +6us 135 +8us 4 +14us 1 +20us 1 +40us 2 +60us 1 + +Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 5) sudo cpupower -c {cpu} -g performance, run from IntelliJ CE +After 7200 seconds, the average per hour was +2us 2189 +3us 3341 +4us 2335 +6us 191 +8us 4 +14us 1 +20us 1 + + + +Windows 10 i7-4770 laptop +After 1845 seconds, the average per hour was +2us 2435969 +3us 548812 +4us 508041 +6us 60320 +8us 25374 +10us 1832324 +14us 2089216 +20us 391901 +30us 16063 +40us 6440 +60us 2617 +80us 1487 +100us 1241 +140us 826 +200us 2108 +300us 601 +400us 159 +600us 129 +800us 215 +1ms 155 +2ms 229 +5ms 24 +10ms 38 +20ms 32 + +On an Centos 7 machine with an isolated CPU. +After 2145 seconds, the average per hour was +2us 781271 +3us 1212123 +4us 13504 +6us 489 +8us 2 +10us 3032577 +14us 17475 +20us 628 +30us 645 +40us 1301 +60us 1217 +80us 1306 +100us 1526 +140us 22 + + */ From 552cf8a53be6173a38a93361508178a928e092f9 Mon Sep 17 00:00:00 2001 From: rogersimmons Date: Mon, 9 Aug 2021 09:19:02 +0100 Subject: [PATCH 035/226] Split jitter test from main thread, and add explicit CPU binding option --- .../openhft/affinity/MicroJitterSampler.java | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index c79e5b1e2..fc9a84c49 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -34,8 +34,8 @@ public class MicroJitterSampler { }; private static final double UTIL = Double.parseDouble(System.getProperty("util", "50")); private static final boolean BUSYWAIT = Boolean.parseBoolean(System.getProperty("busywait", "false")); + private static final int CPU = Integer.parseInt(System.getProperty("cpu", "-1")); - // static final int CPU = Integer.getInteger("cpu", 0); private final int[] count = new int[DELAY.length]; private long totalTime = 0; @@ -50,25 +50,46 @@ private static void pause() throws InterruptedException } public static void main(String... ignored) throws InterruptedException { - // AffinityLock al = AffinityLock.acquireLock(); - - // warmup. - new MicroJitterSampler().sample(1000 * 1000 * 1000); - - MicroJitterSampler microJitterSampler = new MicroJitterSampler(); - while (!Thread.currentThread().isInterrupted()) { - if (UTIL >= 100) { - microJitterSampler.sample(30L * 1000 * 1000 * 1000); - } else { - long sampleLength = (long) ((1 / (1 - UTIL / 100) - 1) * 1000 * 1000); - for (int i = 0; i < 30 * 1000; i += 2) { - microJitterSampler.sample(sampleLength); - //noinspection BusyWait - pause(); - } + MicroJitterSampler sampler = new MicroJitterSampler(); + + Thread t = new Thread( sampler::run ); + t.start(); + t.join(); + } + + private void once() throws InterruptedException { + if (UTIL >= 100) { + sample(30L * 1000 * 1000 * 1000); + } else { + long sampleLength = (long) ((1 / (1 - UTIL / 100) - 1) * 1000 * 1000); + for (int i = 0; i < 30 * 1000; i += 2) { + sample(sampleLength); + //noinspection BusyWait + pause(); } + } + } + + public void run() { + if(CPU != -1) + Affinity.setAffinity(CPU); + + try { + boolean first = true; + System.out.println("Warming up..."); + while (!Thread.currentThread().isInterrupted()) { + once(); + + if(first) { + reset(); + first = false; + System.out.println("Warmup complete. Running jitter tests..."); + continue; + } - microJitterSampler.print(System.out); + print(System.out); + } + } catch(InterruptedException e) { } } @@ -79,6 +100,12 @@ private static String asString(long timeNS) { timeNS / 1000000000 + "sec"; } + void reset() { + for(int i=0; i Date: Tue, 7 Sep 2021 12:21:47 +0100 Subject: [PATCH 036/226] Remove redundant newlines. --- .../src/main/java/net/openhft/affinity/MicroJitterSampler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index fc9a84c49..05d0c344c 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -171,8 +171,6 @@ void print(PrintStream ps) { 14us 1 20us 1 - - Windows 10 i7-4770 laptop After 1845 seconds, the average per hour was 2us 2435969 From b2292655085dd3915fffbfe9c36ffc9b7cabf8fd Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Wed, 22 Sep 2021 16:24:20 +0100 Subject: [PATCH 037/226] Use off-heap rather than a ByteBuffer in this test. --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100755 new mode 100644 From d35a426932aaafbae2fb1e1ca39e0e1a2ecf5bdb Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Sun, 17 Oct 2021 21:49:34 +1100 Subject: [PATCH 038/226] Fix getMetaInfo when another process holds the lock, Fixes #79 --- .../affinity/common/ProcessRunner.java | 113 ++++++++++++++++++ .../lockchecker/FileLockBasedLockChecker.java | 16 ++- .../affinity/MultiProcessAffinityTest.java | 59 +++++++++ 3 files changed, 183 insertions(+), 5 deletions(-) create mode 100644 affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java create mode 100644 affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java diff --git a/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java b/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java new file mode 100644 index 000000000..a3d7522e1 --- /dev/null +++ b/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java @@ -0,0 +1,113 @@ +package net.openhft.affinity.common; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.nio.charset.Charset; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class ProcessRunner { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProcessRunner.class); + + /** + * Spawn a process running the main method of a specified class + * + * @param clazz The class to execute + * @param args Any arguments to pass to the process + * @return the Process spawned + * @throws IOException if there is an error starting the process + */ + public static Process runClass(Class clazz, String... args) throws IOException { + // Because Java17 must be run using various module flags, these must be propagated + // to the child processes + // https://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application + final RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); + + // filter out javaagent params, or this confuses the IntelliJ debugger + final List jvmArgsWithoutJavaAgents = runtimeMxBean.getInputArguments().stream() + .filter(arg -> !arg.startsWith("-javaagent:")) + .filter(arg -> !arg.startsWith("-agentlib:")) + .collect(Collectors.toList()); + + String classPath = System.getProperty("java.class.path"); + String className = clazz.getName(); + String javaBin = findJavaBinPath().toString(); + List allArgs = new ArrayList<>(); + allArgs.add(javaBin); + allArgs.addAll(jvmArgsWithoutJavaAgents); + allArgs.add("-cp"); + allArgs.add(classPath); + allArgs.add(className); + allArgs.addAll(Arrays.asList(args)); + ProcessBuilder processBuilder = new ProcessBuilder(allArgs.toArray(new String[]{})); +// processBuilder.inheritIO(); // this doesn't place nice with surefire + return processBuilder.start(); + } + + /** + * Log stdout and stderr for a process + *

+ * ProcessBuilder.inheritIO() didn't play nicely with Maven failsafe plugin + *

+ * https://maven.apache.org/surefire/maven-failsafe-plugin/faq.html#corruptedstream + */ + public static void printProcessOutput(String processName, Process process) { + LOGGER.info("\n" + + "Output for " + processName + "\n" + + "stdout:\n" + + copyStreamToString(process.getInputStream()) + "\n" + + "stderr:\n" + + copyStreamToString(process.getErrorStream())); + } + + /** + * Copies a stream to a string, up to the point where reading more would block + * + * @param inputStream The stream to read from + * @return The output as a string + */ + private static String copyStreamToString(InputStream inputStream) { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int read; + try { + while (inputStream.available() > 0 && (read = inputStream.read(buffer)) >= 0) { + os.write(buffer, 0, read); + } + } catch (IOException e) { + // Ignore + } + return new String(os.toByteArray(), Charset.defaultCharset()); + } + + /** + * Try and work out what the java executable is cross platform + * + * @return the Path to the java executable + * @throws IllegalStateException if the executable couldn't be located + */ + private static Path findJavaBinPath() { + final Path javaBinPath = Paths.get(System.getProperty("java.home")).resolve("bin"); + final Path linuxJavaExecutable = javaBinPath.resolve("java"); + if (linuxJavaExecutable.toFile().exists()) { + return linuxJavaExecutable; + } else { + Path windowsJavaExecutable = javaBinPath.resolve("java.exe"); + if (windowsJavaExecutable.toFile().exists()) { + return windowsJavaExecutable; + } + } + throw new IllegalStateException("Couldn't locate java executable!"); + } +} diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index c27a65bf9..10f2a2203 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -134,15 +134,21 @@ public String getMetaInfo(int id) throws IOException { } LockReference lr = locks[id]; - if (lr == null) { - return null; + if (lr != null) { + return readMetaInfoFromLockFileChannel(file, lr.channel); + } else { + try (FileChannel fc = FileChannel.open(file.toPath(), READ)) { + return readMetaInfoFromLockFileChannel(file, fc); + } } - FileChannel fc = lr.channel; + } + + private String readMetaInfoFromLockFileChannel(File lockFile, FileChannel lockFileChannel) throws IOException { ByteBuffer buffer = ByteBuffer.allocate(64); - int len = fc.read(buffer, 0); + int len = lockFileChannel.read(buffer, 0); String content = len < 1 ? "" : new String(buffer.array(), 0, len); if (content.isEmpty()) { - LOGGER.warn("Empty lock file {}", file.getAbsolutePath()); + LOGGER.warn("Empty lock file {}", lockFile.getAbsolutePath()); return null; } return content.substring(0, content.indexOf("\n")); diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java new file mode 100644 index 000000000..bf1516e96 --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -0,0 +1,59 @@ +package net.openhft.affinity; + +import net.openhft.affinity.common.ProcessRunner; +import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; + +public class MultiProcessAffinityTest { + + @Test + public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { + // run the separate affinity locker + final Process last = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); + try { + int lastCpuId = AffinityLock.PROCESSORS - 1; + + // wait for the CPU to be locked + long endTime = System.currentTimeMillis() + 5_000; + while (FileLockBasedLockChecker.getInstance().isLockFree(lastCpuId)) { + Thread.sleep(100); + if (System.currentTimeMillis() > endTime) { + fail("Timed out waiting for the sub-process to acquire the lock"); + } + } + + try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertNotEquals(lastCpuId, lock.cpuId()); + } + } finally { + last.destroy(); + if (!last.waitFor(5, TimeUnit.SECONDS)) { + fail("Sub-process didn't terminate!"); + } + } + } + + static class AffinityLockerProcess { + + private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLockerProcess.class); + + public static void main(String[] args) { + String cpuIdToLock = args[0]; + + try (final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock)) { + LOGGER.info("Got affinity lock " + affinityLock); + Thread.sleep(Integer.MAX_VALUE); + } catch (InterruptedException e) { + // expected, just end + } + } + } +} From ce6fb637d41e8f77366a1c31dec8fc37e9e50437 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Mon, 18 Oct 2021 09:37:44 +1100 Subject: [PATCH 039/226] Disable test for non-linux builds --- .../java/net/openhft/affinity/MultiProcessAffinityTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index bf1516e96..81cb52009 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -2,6 +2,7 @@ import net.openhft.affinity.common.ProcessRunner; import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; +import org.junit.Assume; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,6 +10,7 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; +import static net.openhft.affinity.LockCheck.IS_LINUX; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.fail; @@ -16,6 +18,7 @@ public class MultiProcessAffinityTest { @Test public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { + Assume.assumeTrue(IS_LINUX); // run the separate affinity locker final Process last = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); try { From 255bc4dbecedfea863e4f9ba1e93653b0cdad13f Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 18 Oct 2021 14:49:13 +0200 Subject: [PATCH 040/226] Updating to bom version 2.22ea38 From f70e211425a3e9be66239a58f0ffe808a59a839b Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 18 Oct 2021 14:49:58 +0200 Subject: [PATCH 041/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea80 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 318f5defc..21cff5d9d 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea80-SNAPSHOT + 3.21ea80 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea80 diff --git a/affinity/pom.xml b/affinity/pom.xml index 24b19a7a5..095d41d4f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea80-SNAPSHOT + 3.21ea80 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea80 diff --git a/pom.xml b/pom.xml index c90304bc4..ecba1f972 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea80-SNAPSHOT + 3.21ea80 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea80 From e5b9177d4bcf3a3c973c9782c3fbfaeb3e4ac0de Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 18 Oct 2021 14:50:02 +0200 Subject: [PATCH 042/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 21cff5d9d..90d16a5a2 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea80 + 3.21ea81-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea80 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 095d41d4f..873b8789e 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea80 + 3.21ea81-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea80 + ea diff --git a/pom.xml b/pom.xml index ecba1f972..7abbfc40a 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea80 + 3.21ea81-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea80 + ea From cd1cc3f15fe78e2b2d0f48ddddc1a0ea557761b5 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 18 Oct 2021 14:50:24 +0200 Subject: [PATCH 043/226] Reverting back to bom version 2.22ea-SNAPSHOT From a57cc41d3f71b860a1316f9bd271602c4ed98633 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Tue, 19 Oct 2021 11:24:31 +1100 Subject: [PATCH 044/226] MultiProcessAffinityTest: Print sub-process output when it fails to acquire the lock --- .../net/openhft/affinity/MultiProcessAffinityTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 81cb52009..230dfd9eb 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -20,7 +20,7 @@ public class MultiProcessAffinityTest { public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { Assume.assumeTrue(IS_LINUX); // run the separate affinity locker - final Process last = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); + final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); try { int lastCpuId = AffinityLock.PROCESSORS - 1; @@ -29,6 +29,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti while (FileLockBasedLockChecker.getInstance().isLockFree(lastCpuId)) { Thread.sleep(100); if (System.currentTimeMillis() > endTime) { + ProcessRunner.printProcessOutput("AffinityLockerProcess", affinityLockerProcess); fail("Timed out waiting for the sub-process to acquire the lock"); } } @@ -37,8 +38,8 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti assertNotEquals(lastCpuId, lock.cpuId()); } } finally { - last.destroy(); - if (!last.waitFor(5, TimeUnit.SECONDS)) { + affinityLockerProcess.destroy(); + if (!affinityLockerProcess.waitFor(5, TimeUnit.SECONDS)) { fail("Sub-process didn't terminate!"); } } From 1af6529dd7f34d874f35458f41c5c847e4b756e9 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Tue, 19 Oct 2021 17:34:46 +1100 Subject: [PATCH 045/226] Manage java.io.tmpdir better to make multi-process test pass reliably, move ProcessRunner into tests where it belongs --- .../affinity/FileLockLockCheckTest.java | 10 ++++---- .../net/openhft/affinity/LockCheckTest.java | 10 ++++---- .../affinity/MultiProcessAffinityTest.java | 23 ++++++++++++++++--- .../affinity/common/ProcessRunner.java | 16 ++++++++++++- 4 files changed, 47 insertions(+), 12 deletions(-) rename affinity/src/{main => test}/java/net/openhft/affinity/common/ProcessRunner.java (87%) diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index e59d0a805..1a41b2e47 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -18,10 +18,7 @@ package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import java.io.File; import java.io.IOException; @@ -54,6 +51,11 @@ public void before() { System.setProperty("java.io.tmpdir", TARGET + "/" + System.nanoTime()); } + @After + public void after() { + System.setProperty("java.io.tmpdir", TMP); + } + @Test public void test() throws IOException { Assert.assertTrue(LockCheck.isCpuFree(cpu)); diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index 55cd8f7a6..595269bb7 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -18,10 +18,7 @@ package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileBasedLockChecker; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import java.io.File; import java.io.FileWriter; @@ -55,6 +52,11 @@ public void before() { System.setProperty("java.io.tmpdir", TARGET + "/" + System.nanoTime()); } + @After + public void after() { + System.setProperty("java.io.tmpdir", TMP); + } + @Test public void test() throws IOException { Assert.assertTrue(LockCheck.isCpuFree(cpu)); diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 230dfd9eb..a6c7dd8f8 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -2,8 +2,8 @@ import net.openhft.affinity.common.ProcessRunner; import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; -import org.junit.Assume; -import org.junit.Test; +import org.junit.*; +import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,11 +16,28 @@ public class MultiProcessAffinityTest { + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + private String originalTmpDir; + + @Before + public void setUp() { + originalTmpDir = System.getProperty("java.io.tmpdir"); + System.setProperty("java.io.tmpdir", folder.getRoot().getAbsolutePath()); + } + + @After + public void tearDown() { + System.setProperty("java.io.tmpdir", originalTmpDir); + } + @Test public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { Assume.assumeTrue(IS_LINUX); // run the separate affinity locker - final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, "last"); + final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, + new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, + new String[]{"last"}); try { int lastCpuId = AffinityLock.PROCESSORS - 1; diff --git a/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java b/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java similarity index 87% rename from affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java rename to affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java index a3d7522e1..73169e020 100644 --- a/affinity/src/main/java/net/openhft/affinity/common/ProcessRunner.java +++ b/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java @@ -29,6 +29,19 @@ public class ProcessRunner { * @throws IOException if there is an error starting the process */ public static Process runClass(Class clazz, String... args) throws IOException { + return runClass(clazz, new String[]{}, args); + } + + /** + * Spawn a process running the main method of a specified class + * + * @param clazz The class to execute + * @param jvmArgs Any arguments to pass to the process + * @param programArgs Any arguments to pass to the process + * @return the Process spawned + * @throws IOException if there is an error starting the process + */ + public static Process runClass(Class clazz, String[] jvmArgs, String[] programArgs) throws IOException { // Because Java17 must be run using various module flags, these must be propagated // to the child processes // https://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application @@ -46,10 +59,11 @@ public static Process runClass(Class clazz, String... args) throws IOExceptio List allArgs = new ArrayList<>(); allArgs.add(javaBin); allArgs.addAll(jvmArgsWithoutJavaAgents); + allArgs.addAll(Arrays.asList(jvmArgs)); allArgs.add("-cp"); allArgs.add(classPath); allArgs.add(className); - allArgs.addAll(Arrays.asList(args)); + allArgs.addAll(Arrays.asList(programArgs)); ProcessBuilder processBuilder = new ProcessBuilder(allArgs.toArray(new String[]{})); // processBuilder.inheritIO(); // this doesn't place nice with surefire return processBuilder.start(); From 0bdef1808617b84d9391a7859baf024f16457a36 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Tue, 19 Oct 2021 17:40:42 +1100 Subject: [PATCH 046/226] Add more logging for when MultiProcessAffinityTest fails --- .../net/openhft/affinity/MultiProcessAffinityTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index a6c7dd8f8..840b53f28 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.time.LocalDateTime; import java.util.concurrent.TimeUnit; import static net.openhft.affinity.LockCheck.IS_LINUX; @@ -16,6 +17,8 @@ public class MultiProcessAffinityTest { + private static final Logger LOGGER = LoggerFactory.getLogger(MultiProcessAffinityTest.class); + @Rule public TemporaryFolder folder = new TemporaryFolder(); private String originalTmpDir; @@ -46,6 +49,8 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti while (FileLockBasedLockChecker.getInstance().isLockFree(lastCpuId)) { Thread.sleep(100); if (System.currentTimeMillis() > endTime) { + LOGGER.info("Timed out waiting for the lock to be acquired: isAlive={}, exitCode={}", + affinityLockerProcess.isAlive(), affinityLockerProcess.isAlive() ? "N/A" : affinityLockerProcess.exitValue()); ProcessRunner.printProcessOutput("AffinityLockerProcess", affinityLockerProcess); fail("Timed out waiting for the sub-process to acquire the lock"); } @@ -70,10 +75,12 @@ public static void main(String[] args) { String cpuIdToLock = args[0]; try (final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock)) { - LOGGER.info("Got affinity lock " + affinityLock); + LOGGER.info("Got affinity lock " + affinityLock + " at " + LocalDateTime.now() + ", CPU=" + affinityLock.cpuId()); Thread.sleep(Integer.MAX_VALUE); + LOGGER.error("Woke from sleep? this should never happen"); } catch (InterruptedException e) { // expected, just end + LOGGER.info("Interrupted at " + LocalDateTime.now() + " lock is released"); } } } From 6a7883dae5a8f0e8b4b7a6d4fbe48b614361d6ca Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Thu, 28 Oct 2021 07:15:17 +1100 Subject: [PATCH 047/226] Reproduction of and fix for #81 * Reproduction of #81 * Make lock acquisition atomic, Fixes #81 --- .../java/net/openhft/affinity/LockCheck.java | 47 +-- .../net/openhft/affinity/LockInventory.java | 41 +- .../lockchecker/FileBasedLockChecker.java | 83 ---- .../lockchecker/FileLockBasedLockChecker.java | 375 ++++++++++-------- .../openhft/affinity/AffinityLockTest.java | 10 +- .../openhft/affinity/BaseAffinityTest.java | 28 ++ .../affinity/FileLockLockCheckTest.java | 24 +- .../net/openhft/affinity/LockCheckTest.java | 28 +- .../affinity/MultiProcessAffinityTest.java | 213 +++++++++- .../testimpl/TestFileBasedLockChecker.java | 12 - .../TestFileLockBasedLockChecker.java | 24 +- 11 files changed, 495 insertions(+), 390 deletions(-) delete mode 100644 affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java create mode 100644 affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java delete mode 100644 affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index cfe4e78f6..8acaf4e23 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -28,7 +28,7 @@ /** * @author Rob Austin. */ -enum LockCheck { +public enum LockCheck { ; // none private static final Logger LOGGER = LoggerFactory.getLogger(LockCheck.class); @@ -38,7 +38,7 @@ enum LockCheck { private static final LockChecker lockChecker = FileLockBasedLockChecker.getInstance(); - static long getPID() { + public static long getPID() { String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); return Long.parseLong(processName.split("@")[0]); @@ -52,30 +52,14 @@ public static boolean isCpuFree(int cpu) { if (!canOSSupportOperation()) return true; - if (isLockFree(cpu)) { - return true; - } else { - int currentProcess = 0; - try { - currentProcess = getProcessForCpu(cpu); - } catch (RuntimeException | IOException e) { - LOGGER.warn("Failed to determine process on cpu " + cpu, e); - e.printStackTrace(); - return true; - } - if (!isProcessRunning(currentProcess)) { - lockChecker.releaseLock(cpu); - return true; - } - return false; - } + return isLockFree(cpu); } - static void replacePid(int cpu, long processID) throws IOException { - storePid(processID, cpu); + static boolean replacePid(int cpu, long processID) throws IOException { + return storePid(processID, cpu); } - static boolean isProcessRunning(long pid) { + public static boolean isProcessRunning(long pid) { if (canOSSupportOperation()) return new File("/proc/" + pid).exists(); else @@ -86,17 +70,15 @@ static boolean isProcessRunning(long pid) { * stores the pid in a file, named by the core, the pid is written to the file with the date * below */ - private synchronized static void storePid(long processID, int cpu) throws IOException { - if (!lockChecker.obtainLock(cpu, Long.toString(processID))) { - throw new IOException(String.format("Cannot obtain file lock for cpu %d", cpu)); - } + private synchronized static boolean storePid(long processID, int cpu) throws IOException { + return lockChecker.obtainLock(cpu, Long.toString(processID)); } private synchronized static boolean isLockFree(int id) { return lockChecker.isLockFree(id); } - static int getProcessForCpu(int core) throws IOException { + public static int getProcessForCpu(int core) throws IOException { String meta = lockChecker.getMetaInfo(core); if (meta != null && !meta.isEmpty()) { @@ -109,15 +91,10 @@ static int getProcessForCpu(int core) throws IOException { return EMPTY_PID; } - static void updateCpu(int cpu) { + static boolean updateCpu(int cpu) throws IOException { if (!canOSSupportOperation()) - return; - try { - replacePid(cpu, getPID()); - } catch (IOException e) { - LOGGER.warn("Failed to update lock file for cpu " + cpu, e); - e.printStackTrace(); - } + return true; + return replacePid(cpu, getPID()); } public static void releaseLock(int cpu) { diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 7523e5e28..6a68b1321 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -22,6 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.util.NavigableMap; import java.util.TreeMap; @@ -69,9 +70,24 @@ private static boolean isAnyCpu(final int cpuId) { return cpuId == AffinityLock.ANY_CPU; } - private static void updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean b) { - al.assignCurrentThread(bind, b); - LockCheck.updateCpu(al.cpuId()); + /** + * Update the lock for the current thread + * + * @param bind Whether to also bind the thread to the core + * @param al The lock to update + * @param wholeCore Whether to bind the whole core + * @return true if the lock was acquired, false otherwise + */ + private static boolean updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean wholeCore) { + try { + if (LockCheck.updateCpu(al.cpuId())) { + al.assignCurrentThread(bind, wholeCore); + return true; + } + } catch (IOException e) { + LOGGER.warn("Error occurred acquiring lock", e); + } + return false; } public final synchronized CpuLayout getCpuLayout() { @@ -106,8 +122,9 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi final boolean specificCpuRequested = !isAnyCpu(cpuId); if (specificCpuRequested && cpuId != 0) { final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve(true) && anyStrategyMatches(cpuId, cpuId, strategies)) { - updateLockForCurrentThread(bind, required, false); + if (required.canReserve(true) + && anyStrategyMatches(cpuId, cpuId, strategies) + && updateLockForCurrentThread(bind, required, false)) { return required; } LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", @@ -119,8 +136,9 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi // if you have only one core, this library is not appropriate in any case. for (int i = logicalCoreLocks.length - 1; i > 0; i--) { AffinityLock al = logicalCoreLocks[i]; - if (al.canReserve(false) && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId()))) { - updateLockForCurrentThread(bind, al, false); + if (al.canReserve(false) + && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId())) + && updateLockForCurrentThread(bind, al, false)) { return al; } } @@ -136,8 +154,8 @@ public final synchronized AffinityLock tryAcquireLock(boolean bind, int cpuId) { return null; final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve(true)) { - updateLockForCurrentThread(bind, required, false); + if (required.canReserve(true) + && updateLockForCurrentThread(bind, required, false)) { return required; } @@ -156,8 +174,9 @@ public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, Affi continue LOOP; final AffinityLock al = als[0]; - updateLockForCurrentThread(bind, al, true); - return al; + if (updateLockForCurrentThread(bind, al, true)) { + return al; + } } } diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java deleted file mode 100644 index 37224e104..000000000 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java +++ /dev/null @@ -1,83 +0,0 @@ -package net.openhft.affinity.lockchecker; - -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static java.nio.charset.StandardCharsets.UTF_8; - -@SuppressWarnings("ResultOfMethodCallIgnored") -public class FileBasedLockChecker implements LockChecker { - - static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); - private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLockChecker.class); - private static final LockChecker instance = new FileBasedLockChecker(); - - protected FileBasedLockChecker() { - //nothing - } - - public static LockChecker getInstance() { - return instance; - } - - private static File tmpDir() { - final File tempDir = new File(System.getProperty("java.io.tmpdir")); - - if (!tempDir.exists()) - tempDir.mkdirs(); - - return tempDir; - } - - @Override - public boolean isLockFree(int id) { - return !toFile(id).exists(); - } - - @Override - public boolean obtainLock(int id, String metaInfo) throws IOException { - File file = toFile(id); - file.delete(); - - try (Writer writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file, false), UTF_8))) { - writer.write(metaInfo + "\n" + df.format(new Date())); - file.setWritable(true, false); - file.setExecutable(false, false); - return true; - } - } - - @Override - public boolean releaseLock(int id) { - return toFile(id).delete(); - } - - @Override - public String getMetaInfo(int id) throws IOException { - File file = toFile(id); - - if (!file.exists()) { - return null; - } - - try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), UTF_8))) { - final String firstLine = reader.readLine(); - if (firstLine == null) { - LOGGER.error(String.format("Empty lock file %s%n", file.getAbsolutePath())); - return null; - } - return firstLine.trim(); - } - } - - @NotNull - protected File toFile(int id) { - return new File(tmpDir(), "cpu-" + id + ".lock"); - } -} diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 10f2a2203..9cd219523 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -1,170 +1,205 @@ -package net.openhft.affinity.lockchecker; - -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.channels.OverlappingFileLockException; -import java.nio.file.Files; -import java.nio.file.StandardOpenOption; -import java.nio.file.attribute.FileAttribute; -import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -import static java.nio.file.StandardOpenOption.*; -import static net.openhft.affinity.impl.VanillaCpuLayout.MAX_CPUS_SUPPORTED; - -public class FileLockBasedLockChecker extends FileBasedLockChecker { - - private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class); - private static final String OS = System.getProperty("os.name").toLowerCase(); - - private static final LockChecker instance = new FileLockBasedLockChecker(); - private static final HashSet openOptions = new HashSet<>(Arrays.asList(CREATE_NEW, WRITE, READ, SYNC)); - private static final FileAttribute> fileAttr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")); - private final LockReference[] locks = new LockReference[MAX_CPUS_SUPPORTED]; - - protected FileLockBasedLockChecker() { - //nothing - } - - public static LockChecker getInstance() { - return instance; - } - - @Override - public boolean isLockFree(int id) { - return isLockFree(toFile(id), id); - } - - private boolean isLockFree(File file, int id) { - //if no file exists - nobody has the lock for sure - if (!file.exists()) { - return true; - } - - //do we have the lock already? - LockReference existingLock = locks[id]; - if (existingLock != null) { - return false; - } - - //does another process have the lock? - try { - FileChannel fc = FileChannel.open(file.toPath(), WRITE); - FileLock fileLock = fc.tryLock(); - if (fileLock == null) { - return false; - } - } catch (IOException | OverlappingFileLockException e) { - LOGGER.error(String.format("Exception occurred whilst trying to check lock on file %s : %s%n", file.getAbsolutePath(), e)); - } - - //file is present but nobody has it locked - delete it - boolean deleted = file.delete(); - if (deleted) - LOGGER.info(String.format("Deleted %s as nobody has the lock", file.getAbsolutePath())); - else - LOGGER.warn(String.format("Nobody has the lock on %s. Delete failed", file.getAbsolutePath())); - - return true; - } - - @Override - public boolean obtainLock(int id, String metaInfo) throws IOException { - final File file = toFile(id); - if (!isLockFree(file, id)) { - return false; - } - - FileChannel fc = FileChannel.open(file.toPath(), openOptions, fileAttr); - FileLock fl = fc.tryLock(); - - if (fl == null) { - LOGGER.error(String.format("Could not obtain lock on file %s%n", file.getAbsolutePath())); - return false; - } else { - LOGGER.debug(String.format("Obtained lock on file %s (%s)%n", file.getAbsolutePath(), metaInfo)); - locks[id] = new LockReference(fc, fl); - - byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes(); - ByteBuffer buffer = ByteBuffer.wrap(content); - while (buffer.hasRemaining()) { - fc.write(buffer); - } - return true; - } - } - - @Override - public boolean releaseLock(int id) { - LockReference lock = locks[id]; - if (lock == null) { - LOGGER.error(String.format("Cannot release lock for id %d as don't have it!", id)); - return false; - } - - try { - locks[id] = null; - lock.lock.release(); - lock.channel.close(); - toFile(id).delete(); - return true; - } catch (IOException e) { - LOGGER.error(String.format("Couldn't release lock for id %d due to exception: %s%n", id, e.getMessage())); - return false; - } - } - - @Override - public String getMetaInfo(int id) throws IOException { - final File file = toFile(id); - if (isLockFree(file, id)) { - LOGGER.warn("Cannot obtain lock on lock file {}", file.getAbsolutePath()); - return null; - } - - LockReference lr = locks[id]; - if (lr != null) { - return readMetaInfoFromLockFileChannel(file, lr.channel); - } else { - try (FileChannel fc = FileChannel.open(file.toPath(), READ)) { - return readMetaInfoFromLockFileChannel(file, fc); - } - } - } - - private String readMetaInfoFromLockFileChannel(File lockFile, FileChannel lockFileChannel) throws IOException { - ByteBuffer buffer = ByteBuffer.allocate(64); - int len = lockFileChannel.read(buffer, 0); - String content = len < 1 ? "" : new String(buffer.array(), 0, len); - if (content.isEmpty()) { - LOGGER.warn("Empty lock file {}", lockFile.getAbsolutePath()); - return null; - } - return content.substring(0, content.indexOf("\n")); - } - - @NotNull - @Override - protected File toFile(int id) { - File file = super.toFile(id); - try { - if (file.exists() && OS.startsWith("linux")) { - Files.setPosixFilePermissions(file.toPath(), PosixFilePermissions.fromString("rwxrwxrwx")); - } - } catch (IOException e) { - LOGGER.warn("Unable to set file permissions \"rwxrwxrwx\" for {} due to {}", file.toString(), e); - } - return file; - } -} +package net.openhft.affinity.lockchecker; + +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.file.NoSuchFileException; +import java.nio.file.OpenOption; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import static java.nio.file.StandardOpenOption.*; +import static net.openhft.affinity.impl.VanillaCpuLayout.MAX_CPUS_SUPPORTED; + +public class FileLockBasedLockChecker implements LockChecker { + + private static final int MAX_LOCK_RETRIES = 5; + private static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + private static final FileAttribute> LOCK_FILE_ATTRIBUTES = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")); + private static final Set LOCK_FILE_OPEN_OPTIONS = new HashSet<>(Arrays.asList(READ, WRITE, CREATE, SYNC)); + private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class); + private static final FileLockBasedLockChecker instance = new FileLockBasedLockChecker(); + private final LockReference[] locks = new LockReference[MAX_CPUS_SUPPORTED]; + + protected FileLockBasedLockChecker() { + //nothing + } + + public static LockChecker getInstance() { + return instance; + } + + @Override + public synchronized boolean isLockFree(int id) { + // check if this process already has the lock + if (locks[id] != null) { + return false; + } + + // check if another process has the lock + File lockFile = toFile(id); + try (final FileChannel channel = FileChannel.open(lockFile.toPath(), READ)) { + // if we can acquire a shared lock, nobody has an exclusive lock + try (final FileLock fileLock = channel.tryLock(0, Long.MAX_VALUE, true)) { + if (fileLock != null && fileLock.isValid()) { + lockFile.delete(); // clean up the orphaned lock file + return true; + } else { + // another process has an exclusive lock + return false; + } + } + } catch (NoSuchFileException e) { + // no lock file exists, nobody has the lock + return true; + } catch (IOException e) { + LOGGER.warn("An unexpected error occurred checking if the lock was free, assuming it's not", e); + return false; + } + } + + @Override + public synchronized boolean obtainLock(int id, String metaInfo) throws IOException { + int attempt = 0; + while (attempt < MAX_LOCK_RETRIES) { + try { + LockReference lockReference = tryAcquireLockOnFile(id, metaInfo); + if (lockReference != null) { + locks[id] = lockReference; + return true; + } + return false; + } catch (ConcurrentLockFileDeletionException e) { + attempt++; + } + } + LOGGER.warn("Exceeded maximum retries for locking CPU " + id + ", failing acquire"); + return false; + } + + /** + * Attempts to acquire an exclusive lock on the core lock file. + *

+ * It will fail if another process already has an exclusive lock on the file. + * + * @param id The CPU ID to acquire + * @param metaInfo The meta-info to write to the file upon successful acquisition + * @return The {@link LockReference} if the lock was successfully acquired, null otherwise + * @throws IOException If an IOException occurs creating or writing to the file + * @throws ConcurrentLockFileDeletionException If another process deleted the file between us opening it and locking it + */ + private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOException, ConcurrentLockFileDeletionException { + final File lockFile = toFile(id); + final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); + final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false); + if (fileLock == null) { + // someone else has a lock (exclusive or shared), fail to acquire + closeQuietly(fileChannel); + return null; + } else { + if (!lockFile.exists()) { + // someone deleted the file between us opening it and acquiring the lock, signal to retry + closeQuietly(fileLock, fileChannel); + throw new ConcurrentLockFileDeletionException(); + } else { + // we have the lock, the file exists. That's success. + writeMetaInfoToFile(fileChannel, metaInfo); + return new LockReference(fileChannel, fileLock); + } + } + } + + private void writeMetaInfoToFile(FileChannel fc, String metaInfo) throws IOException { + byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes(); + ByteBuffer buffer = ByteBuffer.wrap(content); + while (buffer.hasRemaining()) { + fc.write(buffer); + } + } + + @Override + public synchronized boolean releaseLock(int id) { + if (locks[id] != null) { + final File lockFile = toFile(id); + if (!lockFile.delete()) { + LOGGER.warn("Couldn't delete lock file on release: " + lockFile); + } + closeQuietly(locks[id].lock, locks[id].channel); + locks[id] = null; + return true; + } + return false; + } + + private void closeQuietly(AutoCloseable... closeables) { + for (AutoCloseable closeable : closeables) { + try { + if (closeable != null) { + closeable.close(); + } + } catch (Exception e) { + LOGGER.warn("Error closing " + closeable.getClass().getName(), e); + } + } + } + + @Override + public String getMetaInfo(int id) throws IOException { + final File file = toFile(id); + + LockReference lr = locks[id]; + if (lr != null) { + return readMetaInfoFromLockFileChannel(file, lr.channel); + } else { + try (FileChannel fc = FileChannel.open(file.toPath(), READ)) { + return readMetaInfoFromLockFileChannel(file, fc); + } catch (NoSuchFileException e) { + return null; + } + } + } + + private String readMetaInfoFromLockFileChannel(File lockFile, FileChannel lockFileChannel) throws IOException { + ByteBuffer buffer = ByteBuffer.allocate(64); + int len = lockFileChannel.read(buffer, 0); + String content = len < 1 ? "" : new String(buffer.array(), 0, len); + if (content.isEmpty()) { + LOGGER.warn("Empty lock file {}", lockFile.getAbsolutePath()); + return null; + } + return content.substring(0, content.indexOf("\n")); + } + + @NotNull + protected File toFile(int id) { + assert id >= 0; + return new File(tmpDir(), "cpu-" + id + ".lock"); + } + + private File tmpDir() { + final File tempDir = new File(System.getProperty("java.io.tmpdir")); + + if (!tempDir.exists()) + tempDir.mkdirs(); + + return tempDir; + } + + /** + * Thrown when another process deleted the lock file between us opening the file and acquiring the lock + */ + class ConcurrentLockFileDeletionException extends Exception { + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index c4f8aa769..80ff1fc77 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -19,7 +19,7 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; -import net.openhft.affinity.testimpl.TestFileBasedLockChecker; +import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,10 +39,10 @@ /** * @author peter.lawrey */ -public class AffinityLockTest { +public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); - private final TestFileBasedLockChecker lockChecker = new TestFileBasedLockChecker(); + private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); @Test public void dumpLocksI7() throws IOException { @@ -254,11 +254,11 @@ public void lockFilesShouldBeRemovedOnRelease() { } final AffinityLock lock = AffinityLock.acquireLock(); - assertThat(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath())), is(true)); + assertTrue(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath()))); lock.release(); - assertThat(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath())), is(false)); + assertFalse(Files.exists(Paths.get(lockChecker.doToFile(lock.cpuId()).getAbsolutePath()))); } private void displayStatus() { diff --git a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java new file mode 100644 index 000000000..9728f32a4 --- /dev/null +++ b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java @@ -0,0 +1,28 @@ +package net.openhft.affinity; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; + +public class BaseAffinityTest { + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + private String originalTmpDir; + + @Before + public void setTmpDirectory() { + originalTmpDir = System.getProperty("java.io.tmpdir"); + System.setProperty("java.io.tmpdir", folder.getRoot().getAbsolutePath()); + } + + @After + public void restoreTmpDirectoryAndReleaseAllLocks() { + // don't leave any locks locked + for (int i = 0; i < AffinityLock.PROCESSORS; i++) { + LockCheck.releaseLock(i); + } + System.setProperty("java.io.tmpdir", originalTmpDir); + } +} diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 1a41b2e47..7268f26c6 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -18,7 +18,10 @@ package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; -import org.junit.*; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; import java.io.File; import java.io.IOException; @@ -29,31 +32,14 @@ /** * @author Tom Shercliff */ -public class FileLockLockCheckTest { +public class FileLockLockCheckTest extends BaseAffinityTest { - private static final String TMP = System.getProperty("java.io.tmpdir"); - private static final String TARGET = System.getProperty("project.build.directory", findTarget()); private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); private int cpu = 11; - private static String findTarget() { - for (File dir = new File(System.getProperty("user.dir")); dir != null; dir = dir.getParentFile()) { - File target = new File(dir, "target"); - if (target.exists()) - return target.getAbsolutePath(); - } - return TMP + "/target"; - } - @Before public void before() { Assume.assumeTrue(IS_LINUX); - System.setProperty("java.io.tmpdir", TARGET + "/" + System.nanoTime()); - } - - @After - public void after() { - System.setProperty("java.io.tmpdir", TMP); } @Test diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index 595269bb7..c6ab5e042 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -17,8 +17,11 @@ package net.openhft.affinity; -import net.openhft.affinity.testimpl.TestFileBasedLockChecker; -import org.junit.*; +import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; import java.io.File; import java.io.FileWriter; @@ -30,31 +33,14 @@ /** * @author Rob Austin. */ -public class LockCheckTest { +public class LockCheckTest extends BaseAffinityTest { - private static final String TMP = System.getProperty("java.io.tmpdir"); - private static final String TARGET = System.getProperty("project.build.directory", findTarget()); - private final TestFileBasedLockChecker lockChecker = new TestFileBasedLockChecker(); + private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); private int cpu = 11; - private static String findTarget() { - for (File dir = new File(System.getProperty("user.dir")); dir != null; dir = dir.getParentFile()) { - File target = new File(dir, "target"); - if (target.exists()) - return target.getAbsolutePath(); - } - return TMP + "/target"; - } - @Before public void before() { Assume.assumeTrue(IS_LINUX); - System.setProperty("java.io.tmpdir", TARGET + "/" + System.nanoTime()); - } - - @After - public void after() { - System.setProperty("java.io.tmpdir", TMP); } @Test diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 840b53f28..30bb03a53 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -1,42 +1,43 @@ package net.openhft.affinity; import net.openhft.affinity.common.ProcessRunner; -import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; -import org.junit.*; -import org.junit.rules.TemporaryFolder; +import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import org.jetbrains.annotations.NotNull; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.StandardOpenOption; import java.time.LocalDateTime; -import java.util.concurrent.TimeUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.*; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import static java.lang.String.format; import static net.openhft.affinity.LockCheck.IS_LINUX; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; -public class MultiProcessAffinityTest { +public class MultiProcessAffinityTest extends BaseAffinityTest { private static final Logger LOGGER = LoggerFactory.getLogger(MultiProcessAffinityTest.class); - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - private String originalTmpDir; - @Before public void setUp() { - originalTmpDir = System.getProperty("java.io.tmpdir"); - System.setProperty("java.io.tmpdir", folder.getRoot().getAbsolutePath()); - } - - @After - public void tearDown() { - System.setProperty("java.io.tmpdir", originalTmpDir); + Assume.assumeTrue(IS_LINUX); } @Test public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { - Assume.assumeTrue(IS_LINUX); // run the separate affinity locker final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, @@ -46,7 +47,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti // wait for the CPU to be locked long endTime = System.currentTimeMillis() + 5_000; - while (FileLockBasedLockChecker.getInstance().isLockFree(lastCpuId)) { + while (LockCheck.isCpuFree(lastCpuId)) { Thread.sleep(100); if (System.currentTimeMillis() > endTime) { LOGGER.info("Timed out waiting for the lock to be acquired: isAlive={}, exitCode={}", @@ -61,12 +62,134 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti } } finally { affinityLockerProcess.destroy(); - if (!affinityLockerProcess.waitFor(5, TimeUnit.SECONDS)) { - fail("Sub-process didn't terminate!"); + waitForProcessToEnd(5, "Affinity locker process", affinityLockerProcess, false); + } + } + + @Test + public void shouldAllocateCoresCorrectlyUnderContention() throws IOException, InterruptedException { + final int numberOfLockers = Math.max(2, Math.min(12, Runtime.getRuntime().availableProcessors())) / 2; + List lockers = new ArrayList<>(); + LOGGER.info("Running test with {} locker processes", numberOfLockers); + for (int i = 0; i < numberOfLockers; i++) { + lockers.add(ProcessRunner.runClass(RepeatedAffinityLocker.class, + new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, + new String[]{"last", "30", "2"})); + } + for (int i = 0; i < numberOfLockers; i++) { + final Process process = lockers.get(i); + waitForProcessToEnd(20, "Locking process", process); + } + } + + @Test + public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOException, InterruptedException { + final int numberOfLockers = Math.max(2, Math.min(12, Runtime.getRuntime().availableProcessors())) / 2; + List lockers = new ArrayList<>(); + LOGGER.info("Running test with {} locker processes", numberOfLockers); + Process lockFileDropper = ProcessRunner.runClass(LockFileDropper.class); + for (int i = 0; i < numberOfLockers; i++) { + lockers.add(ProcessRunner.runClass(RepeatedAffinityLocker.class, + new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, + new String[]{"last", "30", "2"})); + } + for (int i = 0; i < numberOfLockers; i++) { + final Process process = lockers.get(i); + waitForProcessToEnd(20, "Locking process", process); + } + lockFileDropper.destroy(); + waitForProcessToEnd(5, "Lock file droppper", lockFileDropper); + } + + @Test + public void shouldBeAbleToAcquireLockLeftByOtherProcess() throws IOException, InterruptedException { + final Process process = ProcessRunner.runClass(AffinityLockerThatDoesNotReleaseProcess.class, + new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, + new String[]{"last"}); + waitForProcessToEnd(5, "Locking process", process); + // We should be able to acquire the lock despite the other process not explicitly releasing it + try (final AffinityLock acquired = AffinityLock.acquireLock("last")) { + assertEquals(AffinityLock.PROCESSORS - 1, acquired.cpuId()); + } + } + + private void waitForProcessToEnd(int timeToWaitSeconds, String processDescription, Process process) throws InterruptedException { + waitForProcessToEnd(timeToWaitSeconds, processDescription, process, true); + } + + private void waitForProcessToEnd(int timeToWaitSeconds, String processDescription, Process process, boolean checkExitCode) throws InterruptedException { + if (!process.waitFor(timeToWaitSeconds, TimeUnit.SECONDS)) { + ProcessRunner.printProcessOutput(processDescription, process); + fail(processDescription + " didn't end in time"); + } + if (checkExitCode && process.exitValue() != 0) { + ProcessRunner.printProcessOutput(processDescription, process); + fail(processDescription + " failed, see output above (exit value " + process.exitValue() + ")"); + } + } + + /** + * Repeatedly acquires and releases a lock on the specified core + */ + static class RepeatedAffinityLocker implements Callable { + + private static final Logger LOGGER = LoggerFactory.getLogger(RepeatedAffinityLocker.class); + private static final long PID = LockCheck.getPID(); + private final int iterations; + private final String cpuIdToLock; + + public static void main(String[] args) throws InterruptedException, ExecutionException { + String cpuIdToLock = args[0]; + int iterations = Integer.parseInt(args[1]); + int threads = Integer.parseInt(args[2]); + + LOGGER.info("Acquiring lock with {} threads, {} iterations", threads, iterations); + ExecutorService executorService = Executors.newFixedThreadPool(threads); + final List> futures = executorService.invokeAll(IntStream.range(0, threads) + .mapToObj(tid -> new RepeatedAffinityLocker(cpuIdToLock, iterations)) + .collect(Collectors.toList())); + for (Future future : futures) { + future.get(); + } + executorService.shutdown(); + if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) { + throw new IllegalStateException("Executor service didn't shut down"); + } + } + + public RepeatedAffinityLocker(String cpuIdToLock, int iterations) { + this.iterations = iterations; + this.cpuIdToLock = cpuIdToLock; + } + + @Override + public Void call() throws Exception { + for (int i = 0; i < iterations; i++) { + LOGGER.info("******* Starting iteration {} at {}", i, LocalDateTime.now()); + try (final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock)) { + if (affinityLock.isAllocated()) { + assertLockFileContainsMyPid(affinityLock); + Thread.sleep(ThreadLocalRandom.current().nextInt(50)); + assertLockFileContainsMyPid(affinityLock); + } else { + LOGGER.info("Couldn't get a lock"); + } + } + } + return null; + } + + private void assertLockFileContainsMyPid(AffinityLock affinityLock) throws IOException { + int lockPID = LockCheck.getProcessForCpu(affinityLock.cpuId()); + if (lockPID != PID) { + throw new IllegalStateException(format("PID in lock file is not mine (lockPID=%d, myPID=%d)", lockPID, PID)); } } } + /** + * Acquires a lock on the specified CPU, holds it until interrupted + */ static class AffinityLockerProcess { private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLockerProcess.class); @@ -84,4 +207,50 @@ public static void main(String[] args) { } } } + + /** + * Acquires a lock then ends + */ + static class AffinityLockerThatDoesNotReleaseProcess { + private static final Logger LOGGER = LoggerFactory.getLogger(AffinityLockerProcess.class); + + public static void main(String[] args) { + String cpuIdToLock = args[0]; + + final AffinityLock affinityLock = AffinityLock.acquireLock(cpuIdToLock); + LOGGER.info("Got affinity lock " + affinityLock + " at " + LocalDateTime.now() + ", CPU=" + affinityLock.cpuId()); + } + } + + /** + * Simulate failing processes by repeatedly dropping lock files + * with PIDs of non-existent processes + */ + static class LockFileDropper { + + public static void main(String[] args) throws InterruptedException, IOException { + while (Thread.currentThread().isInterrupted()) { + for (int cpu = 0; cpu < AffinityLock.PROCESSORS; cpu++) { + try { + File lockFile = toFile(cpu); + try (final FileChannel fc = FileChannel.open(lockFile.toPath(), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) { + final long maxValue = Long.MAX_VALUE; // a PID that never exists + ByteBuffer buffer = ByteBuffer.wrap((maxValue + "\n").getBytes(StandardCharsets.UTF_8)); + while (buffer.hasRemaining()) { + fc.write(buffer); + } + } + } catch (FileAlreadyExistsException e) { + LOGGER.info("Failed, trying again"); + } + Thread.sleep(ThreadLocalRandom.current().nextInt(50)); + } + } + } + + @NotNull + protected static File toFile(int id) { + return new TestFileLockBasedLockChecker().doToFile(id); + } + } } diff --git a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java deleted file mode 100644 index dd9b61881..000000000 --- a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileBasedLockChecker.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.openhft.affinity.testimpl; - -import net.openhft.affinity.lockchecker.FileBasedLockChecker; - -import java.io.File; - -public class TestFileBasedLockChecker extends FileBasedLockChecker { - - public File doToFile(int cpu) { - return toFile(cpu); - } -} diff --git a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java index 75d15f449..955be5d77 100644 --- a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java +++ b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java @@ -1,12 +1,12 @@ -package net.openhft.affinity.testimpl; - -import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; - -import java.io.File; - -public class TestFileLockBasedLockChecker extends FileLockBasedLockChecker { - - public File doToFile(int cpu) { - return toFile(cpu); - } -} +package net.openhft.affinity.testimpl; + +import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; + +import java.io.File; + +public class TestFileLockBasedLockChecker extends FileLockBasedLockChecker { + + public File doToFile(int cpu) { + return toFile(cpu); + } +} From 4d9a0626dcfe26db217cdabddda5881f2cf2fb5e Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 28 Oct 2021 22:14:58 +0200 Subject: [PATCH 048/226] Updating to bom version 2.22ea49 From bc263a582de0916810a3afe039526b9585ef6f64 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 28 Oct 2021 22:15:19 +0200 Subject: [PATCH 049/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea81 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 90d16a5a2..5d0122477 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea81-SNAPSHOT + 3.21ea81 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea81 diff --git a/affinity/pom.xml b/affinity/pom.xml index 873b8789e..7a86296b5 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea81-SNAPSHOT + 3.21ea81 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea81 diff --git a/pom.xml b/pom.xml index 7abbfc40a..61a8d3b43 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea81-SNAPSHOT + 3.21ea81 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea81 From 3c36d1b2d0bb89fe17c932378b6e2e45b2dfc706 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 28 Oct 2021 22:15:22 +0200 Subject: [PATCH 050/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 5d0122477..d729240c3 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea81 + 3.21ea82-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea81 + HEAD diff --git a/affinity/pom.xml b/affinity/pom.xml index 7a86296b5..da3dcdd8b 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea81 + 3.21ea82-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -224,7 +224,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea81 + ea diff --git a/pom.xml b/pom.xml index 61a8d3b43..1203bb495 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea81 + 3.21ea82-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea81 + ea From 44d434cfee2dbada553412d42b69460fd4adbaff Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Thu, 28 Oct 2021 22:15:38 +0200 Subject: [PATCH 051/226] Reverting back to bom version 2.22ea-SNAPSHOT From 738d7d06ac116922b81125282d886c5348f71bb5 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 29 Oct 2021 07:55:43 +1100 Subject: [PATCH 052/226] Add sonar profile, update parent POM --- pom.xml | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7abbfc40a..f0815fedd 100644 --- a/pom.xml +++ b/pom.xml @@ -15,14 +15,15 @@ ~ limitations under the License. --> - + 4.0.0 net.openhft root-parent-pom - 1.2.1 - + 1.2.13 + Java-Thread-Affinity @@ -37,12 +38,44 @@ affinity-test + + + sonar + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + org.jacoco + jacoco-maven-plugin + + + + prepare-agent + + + + report + prepare-package + + report + + + + + + + + + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + ea From 914c7d7968f7980ff96f858a03bbfea9575b057a Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 29 Oct 2021 08:17:38 +1100 Subject: [PATCH 053/226] Move sonar plugin into affinity module (it's not a child of parent POM) --- affinity/pom.xml | 36 +++++++++++++++++++++++++++++++++--- pom.xml | 32 -------------------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index da3dcdd8b..a1f84a169 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -15,14 +15,15 @@ ~ limitations under the License. --> - + 4.0.0 net.openhft java-parent-pom 1.1.26 - + affinity @@ -126,6 +127,35 @@ + + sonar + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + org.jacoco + jacoco-maven-plugin + + + + prepare-agent + + + + report + prepare-package + + report + + + + + + + @@ -224,7 +254,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + ea diff --git a/pom.xml b/pom.xml index decdca724..8e3824fa9 100644 --- a/pom.xml +++ b/pom.xml @@ -38,38 +38,6 @@ affinity-test - - - sonar - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - - - org.jacoco - jacoco-maven-plugin - - - - prepare-agent - - - - report - prepare-package - - report - - - - - - - - - scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git From e1df39dbb11983c1ec827870c2bddc9548236b90 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 29 Oct 2021 10:23:37 +1100 Subject: [PATCH 054/226] Fix some Sonar smells --- .../net/openhft/affinity/BootClassPath.java | 3 +- .../openhft/affinity/MicroJitterSampler.java | 19 ++++++------ .../lockchecker/FileLockBasedLockChecker.java | 10 ++++--- .../affinity/main/AffinityTestMain.java | 29 +++++++++---------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java index 383e6576f..392ea7df6 100644 --- a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java +++ b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java @@ -67,8 +67,7 @@ private static Set findResources(final Path path, final Logger logger) { private static Set findResourcesInJar(final Path path, final Logger logger) { final Set jarResources = new HashSet<>(); - try { - final JarFile jarFile = new JarFile(path.toFile()); + try (final JarFile jarFile = new JarFile(path.toFile())) { final Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry jarEntry = entries.nextElement(); diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 05d0c344c..d637640bb 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -39,20 +39,20 @@ public class MicroJitterSampler { private final int[] count = new int[DELAY.length]; private long totalTime = 0; - private static void pause() throws InterruptedException - { - if(BUSYWAIT) { + private static void pause() throws InterruptedException { + if (BUSYWAIT) { long now = System.nanoTime(); - while(System.nanoTime() - now < 1_000_000); + while (System.nanoTime() - now < 1_000_000) ; } else { Thread.sleep(1); } } + public static void main(String... ignored) throws InterruptedException { MicroJitterSampler sampler = new MicroJitterSampler(); - Thread t = new Thread( sampler::run ); + Thread t = new Thread(sampler::run); t.start(); t.join(); } @@ -71,7 +71,7 @@ private void once() throws InterruptedException { } public void run() { - if(CPU != -1) + if (CPU != -1) Affinity.setAffinity(CPU); try { @@ -80,7 +80,7 @@ public void run() { while (!Thread.currentThread().isInterrupted()) { once(); - if(first) { + if (first) { reset(); first = false; System.out.println("Warmup complete. Running jitter tests..."); @@ -89,7 +89,8 @@ public void run() { print(System.out); } - } catch(InterruptedException e) { + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } @@ -101,7 +102,7 @@ private static String asString(long timeNS) { } void reset() { - for(int i=0; i dfTL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z")); private static final FileAttribute> LOCK_FILE_ATTRIBUTES = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")); private static final Set LOCK_FILE_OPEN_OPTIONS = new HashSet<>(Arrays.asList(READ, WRITE, CREATE, SYNC)); private static final Logger LOGGER = LoggerFactory.getLogger(FileLockBasedLockChecker.class); @@ -54,7 +54,9 @@ public synchronized boolean isLockFree(int id) { // if we can acquire a shared lock, nobody has an exclusive lock try (final FileLock fileLock = channel.tryLock(0, Long.MAX_VALUE, true)) { if (fileLock != null && fileLock.isValid()) { - lockFile.delete(); // clean up the orphaned lock file + if (!lockFile.delete()) { // try and clean up the orphaned lock file + LOGGER.debug("Couldn't delete orphaned lock file " + lockFile); + } return true; } else { // another process has an exclusive lock @@ -102,7 +104,7 @@ public synchronized boolean obtainLock(int id, String metaInfo) throws IOExcepti */ private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOException, ConcurrentLockFileDeletionException { final File lockFile = toFile(id); - final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); + final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); // NOSONAR final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false); if (fileLock == null) { // someone else has a lock (exclusive or shared), fail to acquire @@ -122,7 +124,7 @@ private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOExc } private void writeMetaInfoToFile(FileChannel fc, String metaInfo) throws IOException { - byte[] content = String.format("%s%n%s", metaInfo, df.format(new Date())).getBytes(); + byte[] content = String.format("%s%n%s", metaInfo, dfTL.get().format(new Date())).getBytes(); ByteBuffer buffer = ByteBuffer.wrap(content); while (buffer.hasRemaining()) { fc.write(buffer); diff --git a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java index ef9070316..cae66db53 100644 --- a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java +++ b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java @@ -10,7 +10,6 @@ * @author Tom Shercliff */ public class AffinityTestMain { - private static final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); public static void main(String[] args) { @@ -28,21 +27,19 @@ public static void main(String[] args) { private static void acquireAndDoWork() { - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try (AffinityLock al = Affinity.acquireLock()) { - String threadName = Thread.currentThread().getName(); - System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId()); - - while (true) { - System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al.toString()); - - try { - Thread.sleep(10000L); - } catch (InterruptedException e) { - //nothing - } + Thread t = new Thread(() -> { + final SimpleDateFormat df = new SimpleDateFormat("yyyy.MM" + ".dd 'at' HH:mm:ss z"); + try (AffinityLock al = Affinity.acquireLock()) { + String threadName = Thread.currentThread().getName(); + System.out.println("Thread (" + threadName + ") locked onto cpu " + al.cpuId()); + + while (true) { + System.out.println(df.format(new Date()) + " - Thread (" + threadName + ") doing work on cpu " + al.cpuId() + ". IsAllocated = " + al.isAllocated() + ", isBound = " + al.isBound() + ". " + al.toString()); + + try { + Thread.sleep(10000L); + } catch (InterruptedException e) { + //nothing } } } From bde620b15a2c2fa29c9096a374e545bd8e362c31 Mon Sep 17 00:00:00 2001 From: Peter Lawrwy Date: Sat, 30 Oct 2021 21:42:59 +0100 Subject: [PATCH 055/226] Skip test on mac. --- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 80ff1fc77..92991fc79 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -151,6 +151,7 @@ public void assignReleaseThread() throws IOException { @Test public void resetAffinity() { + assumeTrue(System.getProperty("os.name").contains("nux")); assertTrue(Affinity.getAffinity().cardinality() > 1); try (AffinityLock lock = AffinityLock.acquireLock()) { assertEquals(1, Affinity.getAffinity().cardinality()); From a8b1a2248faa5b1cbfabaefaf6e190616836da3c Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 29 Oct 2021 17:17:17 +1100 Subject: [PATCH 056/226] Handle OverlappingFileLockException --- .../lockchecker/FileLockBasedLockChecker.java | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 1f84c834f..a6eb4e983 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -9,6 +9,7 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; +import java.nio.channels.OverlappingFileLockException; import java.nio.file.NoSuchFileException; import java.nio.file.OpenOption; import java.nio.file.attribute.FileAttribute; @@ -62,6 +63,14 @@ public synchronized boolean isLockFree(int id) { // another process has an exclusive lock return false; } + } catch (OverlappingFileLockException e) { + // someone else (in the same JVM) has an exclusive lock + /* + * This shouldn't happen under normal circumstances, we have the singleton + * {@link #locks} array to prevent overlapping locks from the same JVM, but + * it can occur when there are multiple classloaders in the JVM + */ + return false; } } catch (NoSuchFileException e) { // no lock file exists, nobody has the lock @@ -105,21 +114,32 @@ public synchronized boolean obtainLock(int id, String metaInfo) throws IOExcepti private LockReference tryAcquireLockOnFile(int id, String metaInfo) throws IOException, ConcurrentLockFileDeletionException { final File lockFile = toFile(id); final FileChannel fileChannel = FileChannel.open(lockFile.toPath(), LOCK_FILE_OPEN_OPTIONS, LOCK_FILE_ATTRIBUTES); // NOSONAR - final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false); - if (fileLock == null) { - // someone else has a lock (exclusive or shared), fail to acquire - closeQuietly(fileChannel); - return null; - } else { - if (!lockFile.exists()) { - // someone deleted the file between us opening it and acquiring the lock, signal to retry - closeQuietly(fileLock, fileChannel); - throw new ConcurrentLockFileDeletionException(); + try { + final FileLock fileLock = fileChannel.tryLock(0, Long.MAX_VALUE, false); + if (fileLock == null) { + // someone else has a lock (exclusive or shared), fail to acquire + closeQuietly(fileChannel); + return null; } else { - // we have the lock, the file exists. That's success. - writeMetaInfoToFile(fileChannel, metaInfo); - return new LockReference(fileChannel, fileLock); + if (!lockFile.exists()) { + // someone deleted the file between us opening it and acquiring the lock, signal to retry + closeQuietly(fileLock, fileChannel); + throw new ConcurrentLockFileDeletionException(); + } else { + // we have the lock, the file exists. That's success. + writeMetaInfoToFile(fileChannel, metaInfo); + return new LockReference(fileChannel, fileLock); + } } + } catch (OverlappingFileLockException e) { + // someone else (in the same JVM) has a lock, fail to acquire + /* + * This shouldn't happen under normal circumstances, we have the singleton + * {@link #locks} array to prevent overlapping locks from the same JVM, but + * it can occur when there are multiple classloaders in the JVM + */ + closeQuietly(fileChannel); + return null; } } From 754b6b55e236adce1f45586f93c5ff384b491038 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Wed, 3 Nov 2021 10:21:15 +1100 Subject: [PATCH 057/226] Make Makefile executable again --- affinity/src/main/c/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 affinity/src/main/c/Makefile diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile old mode 100644 new mode 100755 From dc2eb2f4f08a6badf555adb5679f6bf1f0b98a72 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 3 Nov 2021 21:04:00 +0100 Subject: [PATCH 058/226] Updating to bom version 2.22ea50 From f8fef3984d273d8de9efc41492187238cc10c4e9 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 3 Nov 2021 21:04:21 +0100 Subject: [PATCH 059/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea82 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 9 ++++----- pom.xml | 9 ++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index d729240c3..ae5abd3b8 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea82-SNAPSHOT + 3.21ea82 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - HEAD + Java-Thread-Affinity-3.21ea82 diff --git a/affinity/pom.xml b/affinity/pom.xml index a1f84a169..8683bf411 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -15,19 +15,18 @@ ~ limitations under the License. --> - + 4.0.0 net.openhft java-parent-pom 1.1.26 - + affinity - 3.21ea82-SNAPSHOT + 3.21ea82 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -254,7 +253,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea82 diff --git a/pom.xml b/pom.xml index 8e3824fa9..df7a6b4f2 100644 --- a/pom.xml +++ b/pom.xml @@ -15,19 +15,18 @@ ~ limitations under the License. --> - + 4.0.0 net.openhft root-parent-pom 1.2.13 - + Java-Thread-Affinity - 3.21ea82-SNAPSHOT + 3.21ea82 pom OpenHFT/Java-Thread-Affinity Parent @@ -43,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea82 From 72e3264fb0e6209133d0ec5d0f9fb15fbbc24206 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 3 Nov 2021 21:04:24 +0100 Subject: [PATCH 060/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 8 +++++--- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ae5abd3b8..606fa9505 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea82 + 3.21ea83-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -202,8 +202,10 @@ - scm:git:https://github.com/OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea82 + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git + ea + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git + scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 8683bf411..ffddf67c1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea82 + 3.21ea83-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -253,7 +253,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea82 + ea diff --git a/pom.xml b/pom.xml index df7a6b4f2..466f12800 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea82 + 3.21ea83-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea82 + ea From 9bdca1a83891864fa7c8d19b5fc610242b0df4d0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Wed, 3 Nov 2021 21:04:40 +0100 Subject: [PATCH 061/226] Reverting back to bom version 2.22ea-SNAPSHOT From b1179db2b8e30d4d4b70e1067957885c302c4704 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Thu, 18 Nov 2021 08:39:46 +1100 Subject: [PATCH 062/226] Use ProcessRunner from chronicle-test-framework --- affinity/pom.xml | 14 +- .../affinity/MultiProcessAffinityTest.java | 2 +- .../affinity/common/ProcessRunner.java | 127 ------------------ 3 files changed, 14 insertions(+), 129 deletions(-) delete mode 100644 affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java diff --git a/affinity/pom.xml b/affinity/pom.xml index ffddf67c1..98410fa76 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,14 @@ net.openhft third-party-bom pom - 3.19.10 + 3.22.1 + import + + + net.openhft + chronicle-bom + 2.22ea-SNAPSHOT + pom import @@ -82,6 +89,11 @@ slf4j-simple test + + net.openhft + chronicle-test-framework + test + diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 30bb03a53..a3914f1db 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -1,7 +1,7 @@ package net.openhft.affinity; -import net.openhft.affinity.common.ProcessRunner; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import net.openhft.chronicle.testframework.process.ProcessRunner; import org.jetbrains.annotations.NotNull; import org.junit.Assume; import org.junit.Before; diff --git a/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java b/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java deleted file mode 100644 index 73169e020..000000000 --- a/affinity/src/test/java/net/openhft/affinity/common/ProcessRunner.java +++ /dev/null @@ -1,127 +0,0 @@ -package net.openhft.affinity.common; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.nio.charset.Charset; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class ProcessRunner { - - private static final Logger LOGGER = LoggerFactory.getLogger(ProcessRunner.class); - - /** - * Spawn a process running the main method of a specified class - * - * @param clazz The class to execute - * @param args Any arguments to pass to the process - * @return the Process spawned - * @throws IOException if there is an error starting the process - */ - public static Process runClass(Class clazz, String... args) throws IOException { - return runClass(clazz, new String[]{}, args); - } - - /** - * Spawn a process running the main method of a specified class - * - * @param clazz The class to execute - * @param jvmArgs Any arguments to pass to the process - * @param programArgs Any arguments to pass to the process - * @return the Process spawned - * @throws IOException if there is an error starting the process - */ - public static Process runClass(Class clazz, String[] jvmArgs, String[] programArgs) throws IOException { - // Because Java17 must be run using various module flags, these must be propagated - // to the child processes - // https://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application - final RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); - - // filter out javaagent params, or this confuses the IntelliJ debugger - final List jvmArgsWithoutJavaAgents = runtimeMxBean.getInputArguments().stream() - .filter(arg -> !arg.startsWith("-javaagent:")) - .filter(arg -> !arg.startsWith("-agentlib:")) - .collect(Collectors.toList()); - - String classPath = System.getProperty("java.class.path"); - String className = clazz.getName(); - String javaBin = findJavaBinPath().toString(); - List allArgs = new ArrayList<>(); - allArgs.add(javaBin); - allArgs.addAll(jvmArgsWithoutJavaAgents); - allArgs.addAll(Arrays.asList(jvmArgs)); - allArgs.add("-cp"); - allArgs.add(classPath); - allArgs.add(className); - allArgs.addAll(Arrays.asList(programArgs)); - ProcessBuilder processBuilder = new ProcessBuilder(allArgs.toArray(new String[]{})); -// processBuilder.inheritIO(); // this doesn't place nice with surefire - return processBuilder.start(); - } - - /** - * Log stdout and stderr for a process - *

- * ProcessBuilder.inheritIO() didn't play nicely with Maven failsafe plugin - *

- * https://maven.apache.org/surefire/maven-failsafe-plugin/faq.html#corruptedstream - */ - public static void printProcessOutput(String processName, Process process) { - LOGGER.info("\n" - + "Output for " + processName + "\n" - + "stdout:\n" - + copyStreamToString(process.getInputStream()) + "\n" - + "stderr:\n" - + copyStreamToString(process.getErrorStream())); - } - - /** - * Copies a stream to a string, up to the point where reading more would block - * - * @param inputStream The stream to read from - * @return The output as a string - */ - private static String copyStreamToString(InputStream inputStream) { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int read; - try { - while (inputStream.available() > 0 && (read = inputStream.read(buffer)) >= 0) { - os.write(buffer, 0, read); - } - } catch (IOException e) { - // Ignore - } - return new String(os.toByteArray(), Charset.defaultCharset()); - } - - /** - * Try and work out what the java executable is cross platform - * - * @return the Path to the java executable - * @throws IllegalStateException if the executable couldn't be located - */ - private static Path findJavaBinPath() { - final Path javaBinPath = Paths.get(System.getProperty("java.home")).resolve("bin"); - final Path linuxJavaExecutable = javaBinPath.resolve("java"); - if (linuxJavaExecutable.toFile().exists()) { - return linuxJavaExecutable; - } else { - Path windowsJavaExecutable = javaBinPath.resolve("java.exe"); - if (windowsJavaExecutable.toFile().exists()) { - return windowsJavaExecutable; - } - } - throw new IllegalStateException("Couldn't locate java executable!"); - } -} From 48da7af23ee5ef1e96985a72988b5ad4822cfb65 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 6 Dec 2021 08:43:54 +1100 Subject: [PATCH 063/226] latest java-parent-pom --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 606fa9505..627d05365 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.26 + 1.1.29 diff --git a/affinity/pom.xml b/affinity/pom.xml index 98410fa76..e22b6af0c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.26 + 1.1.29 From 49f7b7a5ba05925a90780fb021b3238d5de98c06 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Fri, 21 Jan 2022 13:06:25 +0300 Subject: [PATCH 064/226] Support oligocore agents --- .../test/java/net/openhft/affinity/FileLockLockCheckTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 7268f26c6..5f39b87ce 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -35,7 +35,7 @@ public class FileLockLockCheckTest extends BaseAffinityTest { private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); - private int cpu = 11; + private int cpu = 5; @Before public void before() { From 5b3fa81975d18fae1b62d9734933eb7d9f6ac984 Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Mon, 31 Jan 2022 16:11:59 +1100 Subject: [PATCH 065/226] Allow use of descriptive core names for MicroJitterSampler affinity --- .../main/java/net/openhft/affinity/MicroJitterSampler.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index d637640bb..696479b5f 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -34,7 +34,7 @@ public class MicroJitterSampler { }; private static final double UTIL = Double.parseDouble(System.getProperty("util", "50")); private static final boolean BUSYWAIT = Boolean.parseBoolean(System.getProperty("busywait", "false")); - private static final int CPU = Integer.parseInt(System.getProperty("cpu", "-1")); + private static final String CPU = System.getProperty("cpu", "none"); private final int[] count = new int[DELAY.length]; private long totalTime = 0; @@ -71,10 +71,7 @@ private void once() throws InterruptedException { } public void run() { - if (CPU != -1) - Affinity.setAffinity(CPU); - - try { + try (final AffinityLock lock = AffinityLock.acquireLock(CPU)) { boolean first = true; System.out.println("Warming up..."); while (!Thread.currentThread().isInterrupted()) { From fe7533072b768de4978d27167f651fd4ee6e5715 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 31 Jan 2022 17:52:57 +0000 Subject: [PATCH 066/226] Updating to bom version 2.22ea99 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index e22b6af0c..72da8b21a 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.22ea-SNAPSHOT + 2.22ea99 pom import From aa97cd5d2c2b327332d0ef47bdda96809cbe7e27 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 31 Jan 2022 17:53:18 +0000 Subject: [PATCH 067/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.21ea83 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 627d05365..853af3907 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea83-SNAPSHOT + 3.21ea83 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea83 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 72da8b21a..70aa37b74 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea83-SNAPSHOT + 3.21ea83 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -265,7 +265,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea83 diff --git a/pom.xml b/pom.xml index 466f12800..d7038e25d 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea83-SNAPSHOT + 3.21ea83 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.21ea83 From 06bc0b72370e5ed0be7beffeda02a197b08526a0 Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 31 Jan 2022 17:53:21 +0000 Subject: [PATCH 068/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 853af3907..18452bf9a 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea83 + 3.21ea84-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea83 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 70aa37b74..06e4a7503 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea83 + 3.21ea84-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -265,7 +265,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea83 + ea diff --git a/pom.xml b/pom.xml index d7038e25d..b3ff64b9d 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea83 + 3.21ea84-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.21ea83 + ea From e33976b81dafa367f4ea44dfef28878637eea6ba Mon Sep 17 00:00:00 2001 From: teamcity_hft Date: Mon, 31 Jan 2022 17:53:36 +0000 Subject: [PATCH 069/226] Reverting back to bom version 2.22ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 06e4a7503..f51ea293e 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.22ea99 + 2.22ea-SNAPSHOT pom import From 8da4b622453cac49dca3424653cdfd83a6d476e9 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Wed, 2 Feb 2022 17:39:36 +0300 Subject: [PATCH 070/226] Use javac -h for C headers generation --- affinity/pom.xml | 6 +++++- affinity/src/main/c/Makefile | 10 ++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f51ea293e..20d066339 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -175,7 +175,11 @@ org.apache.maven.plugins maven-compiler-plugin - -Xlint:deprecation + + -h + ${project.build.directory}/jni + -Xlint:deprecation + 1.8 1.8 UTF-8 diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile index 58a06e53a..0138fe1af 100755 --- a/affinity/src/main/c/Makefile +++ b/affinity/src/main/c/Makefile @@ -13,15 +13,13 @@ WORKING_DIR := $(TARGET_DIR)/../jni JAVA_CLASSES = software.chronicle.enterprise.internals.impl.NativeAffinity net.openhft.ticker.impl.JNIClock JNI_STUBS := $(subst .,_,$(JAVA_CLASSES)) -JNI_HEADERS := $(patsubst %,$(WORKING_DIR)/%.h,$(JNI_STUBS)) JNI_SOURCES := $(patsubst %,%.cpp,$(JNI_STUBS)) -JNI_JAVA_SOURCES := $(patsubst %,$(TARGET_DIR)/%.class,$(subst .,/,$(JAVA_CLASSES))) JAVA_BUILD_DIR := $(TARGET_DIR) JAVA_HOME ?= /usr/java/default JAVA_LIB := $(JAVA_HOME)/jre/lib -JVM_SHARED_LIBS := -L$(JAVA_LIB)/amd64/server -L$(JAVA_LIB)/i386/server -L$(JAVA_LIB)/amd64/jrockit/ -L$(JAVA_LIB)/i386/jrockit/ -L$(JAVA_LIB)/ppc64le/server -L$(JAVA_LIB)/ppc64le/jrockit/ +JVM_SHARED_LIBS := -L$(JAVA_LIB)/amd64/server -L$(JAVA_LIB)/i386/server -L$(JAVA_LIB)/amd64/jrockit/ -L$(JAVA_LIB)/i386/jrockit/ -L$(JAVA_LIB)/ppc64le/server -L$(JAVA_LIB)/ppc64le/jrockit/ -L$(JAVA_HOME)/lib/server CXX=g++ INCLUDES := -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(WORKING_DIR) @@ -37,12 +35,8 @@ endif all: $(TARGET) -$(TARGET): $(JNI_HEADERS) $(JNI_SOURCES) +$(TARGET): $(JNI_SOURCES) $(CXX) -O3 -Wall -shared -fPIC $(JVM_SHARED_LIBS) -ljvm -lrt $(INCLUDES) $(JNI_SOURCES) -o $(TARGET) -$(JNI_HEADERS): $(JNI_JAVA_SOURCES) - mkdir -p $(TARGET_DIR)/jni - javah -force -classpath $(JAVAH_CLASSPATH) -d $(WORKING_DIR) $(JAVA_CLASSES) - clean: rm $(TARGET) From 1965f0283c21b9b9a8ad5fc41112753a9d747832 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 9 Feb 2022 12:28:37 +0000 Subject: [PATCH 071/226] Third-party-bom v 3.22.3 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 18452bf9a..5cc1e1e59 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.19.10 + 3.22.3 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 20d066339..ae863ac0c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.22.1 + 3.22.3 import From 82dc0bb50ee729a135798977c07100a1e80fcab3 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 9 Feb 2022 16:57:08 +0000 Subject: [PATCH 072/226] Bump org.apache.felix.framework to 7.0.3 https://github.com/OpenHFT/OpenHFT/issues/69 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 5cc1e1e59..9ca5af3f6 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.22.3 + 3.22.4-SNAPSHOT import diff --git a/affinity/pom.xml b/affinity/pom.xml index ae863ac0c..30af7a8ee 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.22.3 + 3.22.4-SNAPSHOT import From 8df6c63cbf0741d23abf6e34b07523a22ae179c2 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Tue, 12 Apr 2022 12:51:20 +0100 Subject: [PATCH 073/226] 'Updating parent POM (automated)' --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 9ca5af3f6..564fae94a 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.29 + 1.1.31 diff --git a/affinity/pom.xml b/affinity/pom.xml index 30af7a8ee..b67e5bcb8 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.29 + 1.1.31 diff --git a/pom.xml b/pom.xml index b3ff64b9d..d91d0b47a 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom - 1.2.13 + 1.2.18 From 323b3daeea2af568cf2b7e3e6b6e894088f01f09 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 1 Jun 2022 05:24:34 +0100 Subject: [PATCH 074/226] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 564fae94a..659641a06 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.31 + 1.1.32 diff --git a/affinity/pom.xml b/affinity/pom.xml index b67e5bcb8..0e2af0fdc 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.31 + 1.1.32 diff --git a/pom.xml b/pom.xml index d91d0b47a..c13c5bc36 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom - 1.2.18 + 1.2.20 From 2ceef30aaaa88678d73f138aaf627921e79cbc83 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 6 Jun 2022 07:32:03 +0100 Subject: [PATCH 075/226] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 659641a06..919c1b1f6 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.32 + 1.1.33 diff --git a/affinity/pom.xml b/affinity/pom.xml index 0e2af0fdc..b58029abd 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.32 + 1.1.33 diff --git a/pom.xml b/pom.xml index c13c5bc36..293d771e9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom - 1.2.20 + 1.2.21 From 20d58159a24d651907db5a3d2e251a2fe2b7b846 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Jul 2022 14:21:56 +0100 Subject: [PATCH 076/226] Handle ClosedByInterruptException for when acquireLock() is interrupted #92 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- .../net/openhft/affinity/LockInventory.java | 65 ++++++++++++------- pom.xml | 2 +- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 919c1b1f6..ca58fd9df 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.21ea84-SNAPSHOT + 3.23ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index b58029abd..f1aa7bb3e 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.21ea84-SNAPSHOT + 3.23ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 6a68b1321..304c6b45f 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.nio.channels.ClosedByInterruptException; import java.util.NavigableMap; import java.util.TreeMap; @@ -78,12 +79,15 @@ private static boolean isAnyCpu(final int cpuId) { * @param wholeCore Whether to bind the whole core * @return true if the lock was acquired, false otherwise */ - private static boolean updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean wholeCore) { + private static boolean updateLockForCurrentThread(final boolean bind, final AffinityLock al, final boolean wholeCore) throws ClosedByInterruptException { try { if (LockCheck.updateCpu(al.cpuId())) { al.assignCurrentThread(bind, wholeCore); return true; } + } catch (ClosedByInterruptException e) { + throw e; + } catch (IOException e) { LOGGER.warn("Error occurred acquiring lock", e); } @@ -120,30 +124,36 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi return noLock(); final boolean specificCpuRequested = !isAnyCpu(cpuId); - if (specificCpuRequested && cpuId != 0) { - final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve(true) - && anyStrategyMatches(cpuId, cpuId, strategies) - && updateLockForCurrentThread(bind, required, false)) { - return required; + try { + if (specificCpuRequested && cpuId != 0) { + final AffinityLock required = logicalCoreLocks[cpuId]; + if (required.canReserve(true) + && anyStrategyMatches(cpuId, cpuId, strategies) + && updateLockForCurrentThread(bind, required, false)) { + return required; + } + LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", + cpuId, Thread.currentThread()); } - LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", - cpuId, Thread.currentThread()); - } - for (AffinityStrategy strategy : strategies) { - // consider all processors except cpu 0 which is usually used by the OS. - // if you have only one core, this library is not appropriate in any case. - for (int i = logicalCoreLocks.length - 1; i > 0; i--) { - AffinityLock al = logicalCoreLocks[i]; - if (al.canReserve(false) - && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId())) - && updateLockForCurrentThread(bind, al, false)) { - return al; + for (AffinityStrategy strategy : strategies) { + // consider all processors except cpu 0 which is usually used by the OS. + // if you have only one core, this library is not appropriate in any case. + for (int i = logicalCoreLocks.length - 1; i > 0; i--) { + AffinityLock al = logicalCoreLocks[i]; + if (al.canReserve(false) + && (isAnyCpu(cpuId) || strategy.matches(cpuId, al.cpuId())) + && updateLockForCurrentThread(bind, al, false)) { + return al; + } } } + } catch (ClosedByInterruptException e) { + Thread.currentThread().interrupt(); + return noLock(); } + LOGGER.warn("No reservable CPU for {}", Thread.currentThread()); return noLock(); @@ -154,11 +164,17 @@ public final synchronized AffinityLock tryAcquireLock(boolean bind, int cpuId) { return null; final AffinityLock required = logicalCoreLocks[cpuId]; - if (required.canReserve(true) - && updateLockForCurrentThread(bind, required, false)) { - return required; + try { + if (required.canReserve(true) + && updateLockForCurrentThread(bind, required, false)) { + return required; + } + } catch (ClosedByInterruptException e) { + Thread.currentThread().interrupt(); + return noLock(); } + LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", cpuId, Thread.currentThread()); @@ -174,9 +190,14 @@ public final synchronized AffinityLock acquireCore(boolean bind, int cpuId, Affi continue LOOP; final AffinityLock al = als[0]; + try { if (updateLockForCurrentThread(bind, al, true)) { return al; } + } catch (ClosedByInterruptException e) { + Thread.currentThread().interrupt(); + return noLock(); + } } } diff --git a/pom.xml b/pom.xml index 293d771e9..9d4bf8f84 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.21ea84-SNAPSHOT + 3.23ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 1e4bbc6dba8d516fbfc3511f13c381df9f6ed76d Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Aug 2022 14:36:00 +0100 Subject: [PATCH 077/226] Added Copyright headers --- .../openhft/affinity/MicroJitterSampler.java | 4 ++-- .../lockchecker/FileLockBasedLockChecker.java | 18 ++++++++++++++++++ .../affinity/lockchecker/LockChecker.java | 18 ++++++++++++++++++ .../affinity/lockchecker/LockReference.java | 18 ++++++++++++++++++ .../affinity/main/AffinityTestMain.java | 18 ++++++++++++++++++ .../net/openhft/affinity/BaseAffinityTest.java | 18 ++++++++++++++++++ .../openhft/affinity/BootClassPathTest.java | 18 ++++++++++++++++++ .../affinity/MultiProcessAffinityTest.java | 18 ++++++++++++++++++ .../testimpl/TestFileLockBasedLockChecker.java | 18 ++++++++++++++++++ 9 files changed, 146 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index 696479b5f..c2a8ef3aa 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -1,13 +1,13 @@ /* * Copyright 2014 Higher Frequency Trading * - * http://chronicle.software + * https://chronicle.software * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index a6eb4e983..77095375c 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.lockchecker; import org.jetbrains.annotations.NotNull; diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java index 0c95c335f..f0a02f6d5 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockChecker.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.lockchecker; import java.io.IOException; diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java index d5ed1c707..419073fe6 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/LockReference.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.lockchecker; import java.nio.channels.FileChannel; diff --git a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java index cae66db53..6aa280014 100644 --- a/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java +++ b/affinity/src/main/java/net/openhft/affinity/main/AffinityTestMain.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.main; import net.openhft.affinity.Affinity; diff --git a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java index 9728f32a4..5bfeacf95 100644 --- a/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity; import org.junit.After; diff --git a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java index 6c101e18e..d4c555938 100644 --- a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity; import org.junit.Test; diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index a3914f1db..61f3fa33a 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; diff --git a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java index 955be5d77..68b3f3566 100644 --- a/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java +++ b/affinity/src/test/java/net/openhft/affinity/testimpl/TestFileLockBasedLockChecker.java @@ -1,3 +1,21 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.openhft.affinity.testimpl; import net.openhft.affinity.lockchecker.FileLockBasedLockChecker; From 1933c596ea18f498e6a1aa5823b099fa4904bcc3 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 8 Aug 2022 10:49:39 +1000 Subject: [PATCH 078/226] log warning instead of throw exception for too high cpuId. Closes #93 --- .../java/net/openhft/affinity/LockInventory.java | 9 ++++++++- .../java/net/openhft/affinity/AffinityLockTest.java | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 304c6b45f..ce15aebed 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -126,6 +126,12 @@ public final synchronized AffinityLock acquireLock(boolean bind, int cpuId, Affi final boolean specificCpuRequested = !isAnyCpu(cpuId); try { if (specificCpuRequested && cpuId != 0) { + if (cpuId > logicalCoreLocks.length) { + LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, as not enough CPUs", + cpuId, Thread.currentThread()); + return noLock(); + } + final AffinityLock required = logicalCoreLocks[cpuId]; if (required.canReserve(true) && anyStrategyMatches(cpuId, cpuId, strategies) @@ -162,7 +168,8 @@ && updateLockForCurrentThread(bind, al, false)) { public final synchronized AffinityLock tryAcquireLock(boolean bind, int cpuId) { if (getAffinityImpl() instanceof NullAffinity) return null; - + if (cpuId > logicalCoreLocks.length) + return null; final AffinityLock required = logicalCoreLocks[cpuId]; try { if (required.canReserve(true) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 92991fc79..a44716375 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -296,4 +296,16 @@ public void testAffinityLockDescriptions() { assertFalse(lock.bound); } } + + @Test + public void testTooHighCpuId() { + try (AffinityLock ignored = AffinityLock.acquireLock(123456)) { + } + } + + @Test + public void testTooHighCpuId2() { + try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) { + } + } } From 404cd9cd595a14e3579b623b5cf2ab3c2798dc9f Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 8 Aug 2022 17:52:07 +0100 Subject: [PATCH 079/226] Updating to bom version 2.23ea104 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f1aa7bb3e..da506bb76 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.22ea-SNAPSHOT + 2.23ea104 pom import From 00807ffbd33323b2f0f54b5593610c9af172a99d Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 8 Aug 2022 17:52:34 +0100 Subject: [PATCH 080/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.23ea0 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ca58fd9df..1599c31da 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea0-SNAPSHOT + 3.23ea0 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea0 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index da506bb76..cd3bf582f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea0-SNAPSHOT + 3.23ea0 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea0 diff --git a/pom.xml b/pom.xml index 9d4bf8f84..f1948f8e4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea0-SNAPSHOT + 3.23ea0 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea0 From ded1728e5b4fa29758be197b6dcb4840e7da8daf Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 8 Aug 2022 17:52:37 +0100 Subject: [PATCH 081/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 1599c31da..c603c89f8 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea0 + 3.23ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea0 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index cd3bf582f..aaf3d1485 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea0 + 3.23ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea0 + ea diff --git a/pom.xml b/pom.xml index f1948f8e4..2a0394833 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea0 + 3.23ea1-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea0 + ea From 09de384f68af3817989c82297abf702f020e0f8a Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 8 Aug 2022 17:52:51 +0100 Subject: [PATCH 082/226] Reverting back to bom version 2.23ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index aaf3d1485..9b4a54b56 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.23ea104 + 2.23ea-SNAPSHOT pom import From 125ec45f376a3d6441d195a037dd5f18c063e554 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 24 Aug 2022 08:37:46 +0100 Subject: [PATCH 083/226] Bump maven-exec-plugin to 3.1.0 --- affinity/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/affinity/pom.xml b/affinity/pom.xml index 9b4a54b56..b456abb62 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -120,6 +120,7 @@ org.codehaus.mojo exec-maven-plugin + 3.1.0 From eae579be0d8980b48c43856711cbb11e56011b6f Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 5 Sep 2022 11:31:45 +0100 Subject: [PATCH 084/226] Delay producing a warning until a lock is actually used --- .../main/java/net/openhft/affinity/AffinityLock.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index fc2eae07c..67642daf5 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -121,7 +121,6 @@ private static BitSet getReservedAffinity0() { reserverable.set(1, PROCESSORS, true); reserverable.andNot(BASE_AFFINITY); if (reserverable.isEmpty() && PROCESSORS > 1) { - LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1)); // make all but first CPUs available reserverable.set(1, PROCESSORS); return reserverable; @@ -149,6 +148,14 @@ public static AffinityLock acquireLock() { return acquireLock(true); } + static class Warnings { + static void warmNoReservedCPUs() { + if (RESERVED_AFFINITY.isEmpty() && PROCESSORS > 1) { + LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1)); + } + } + } + /** * Assign any free core to this thread.

In reality, only one cpu is assigned, the rest of * the threads for that core are reservable so they are not used. @@ -294,6 +301,7 @@ public static AffinityLock acquireCore(boolean bind) { } private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { + Warnings.warmNoReservedCPUs(); return LOCK_INVENTORY.acquireLock(bind, cpuId, strategies); } @@ -310,6 +318,7 @@ private static AffinityLock tryAcquireLock(boolean bind, int cpuId) { } private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { + Warnings.warmNoReservedCPUs(); return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies); } From 5f8cf471e44c666f80833d11b25783f62603258d Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 7 Sep 2022 07:20:09 +0100 Subject: [PATCH 085/226] Updating to bom version 2.23ea116 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index b456abb62..03c143051 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.23ea-SNAPSHOT + 2.23ea116 pom import From 12c79a1fde0b09c3cdc4013a23b58528b877f926 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 7 Sep 2022 07:20:30 +0100 Subject: [PATCH 086/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.23ea1 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c603c89f8..fe88c793d 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea1-SNAPSHOT + 3.23ea1 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea1 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 03c143051..3e290daaf 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea1-SNAPSHOT + 3.23ea1 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -270,7 +270,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea1 diff --git a/pom.xml b/pom.xml index 2a0394833..e0df04c8f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea1-SNAPSHOT + 3.23ea1 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.23ea1 From f318a1d90d503c8ee867c04f795f8fb56d491a25 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 7 Sep 2022 07:20:33 +0100 Subject: [PATCH 087/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index fe88c793d..20f3f4535 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea1 + 3.23ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea1 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 3e290daaf..9485d323f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea1 + 3.23ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -270,7 +270,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea1 + ea diff --git a/pom.xml b/pom.xml index e0df04c8f..23c6815fa 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea1 + 3.23ea2-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.23ea1 + ea From 515830b6006fe2c3a3571a2577103386d6a9ea97 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 7 Sep 2022 07:20:49 +0100 Subject: [PATCH 088/226] Reverting back to bom version 2.23ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 9485d323f..1331ddc7f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.23ea116 + 2.23ea-SNAPSHOT pom import From 4fe6e86d3e25b625f874390c119c1e571ee7908f Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Thu, 29 Sep 2022 19:12:39 +1000 Subject: [PATCH 089/226] de-snapshot third-party-bom --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 20f3f4535..87d7a4d2d 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.22.4-SNAPSHOT + 3.22.4 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 1331ddc7f..e767d0ffa 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.22.4-SNAPSHOT + 3.22.4 import From 77e83117e0164f1a7f08d3ad8c7e8652f27f19d6 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Thu, 29 Sep 2022 13:50:41 +0300 Subject: [PATCH 090/226] Bump to new BOM version --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 87d7a4d2d..564aef2ee 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.23ea2-SNAPSHOT + 3.24ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index e767d0ffa..6468d6586 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.23ea2-SNAPSHOT + 3.24ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.23ea-SNAPSHOT + 2.24ea-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index 23c6815fa..7b59a1516 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.23ea2-SNAPSHOT + 3.24ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 7ee83543b17a0e960f4391d7c6da29ba00891b36 Mon Sep 17 00:00:00 2001 From: Ilya Kaznacheev Date: Thu, 29 Sep 2022 13:56:17 +0300 Subject: [PATCH 091/226] Fixes following breaking changes of 2.24 --- .../affinity/MultiProcessAffinityTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java index 61f3fa33a..fc5678cf3 100644 --- a/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java @@ -19,7 +19,7 @@ package net.openhft.affinity; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; -import net.openhft.chronicle.testframework.process.ProcessRunner; +import net.openhft.chronicle.testframework.process.JavaProcessBuilder; import org.jetbrains.annotations.NotNull; import org.junit.Assume; import org.junit.Before; @@ -57,9 +57,9 @@ public void setUp() { @Test public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOException, InterruptedException { // run the separate affinity locker - final Process affinityLockerProcess = ProcessRunner.runClass(AffinityLockerProcess.class, - new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, - new String[]{"last"}); + final Process affinityLockerProcess = JavaProcessBuilder.create(AffinityLockerProcess.class) + .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) + .withProgramArguments("last").start(); try { int lastCpuId = AffinityLock.PROCESSORS - 1; @@ -70,7 +70,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti if (System.currentTimeMillis() > endTime) { LOGGER.info("Timed out waiting for the lock to be acquired: isAlive={}, exitCode={}", affinityLockerProcess.isAlive(), affinityLockerProcess.isAlive() ? "N/A" : affinityLockerProcess.exitValue()); - ProcessRunner.printProcessOutput("AffinityLockerProcess", affinityLockerProcess); + JavaProcessBuilder.printProcessOutput("AffinityLockerProcess", affinityLockerProcess); fail("Timed out waiting for the sub-process to acquire the lock"); } } @@ -90,9 +90,9 @@ public void shouldAllocateCoresCorrectlyUnderContention() throws IOException, In List lockers = new ArrayList<>(); LOGGER.info("Running test with {} locker processes", numberOfLockers); for (int i = 0; i < numberOfLockers; i++) { - lockers.add(ProcessRunner.runClass(RepeatedAffinityLocker.class, - new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, - new String[]{"last", "30", "2"})); + lockers.add(JavaProcessBuilder.create(RepeatedAffinityLocker.class) + .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) + .withProgramArguments("last", "30", "2").start()); } for (int i = 0; i < numberOfLockers; i++) { final Process process = lockers.get(i); @@ -105,11 +105,11 @@ public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOE final int numberOfLockers = Math.max(2, Math.min(12, Runtime.getRuntime().availableProcessors())) / 2; List lockers = new ArrayList<>(); LOGGER.info("Running test with {} locker processes", numberOfLockers); - Process lockFileDropper = ProcessRunner.runClass(LockFileDropper.class); + Process lockFileDropper = JavaProcessBuilder.create(LockFileDropper.class).start(); for (int i = 0; i < numberOfLockers; i++) { - lockers.add(ProcessRunner.runClass(RepeatedAffinityLocker.class, - new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, - new String[]{"last", "30", "2"})); + lockers.add(JavaProcessBuilder.create(RepeatedAffinityLocker.class) + .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) + .withProgramArguments("last", "30", "2").start()); } for (int i = 0; i < numberOfLockers; i++) { final Process process = lockers.get(i); @@ -121,9 +121,9 @@ public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOE @Test public void shouldBeAbleToAcquireLockLeftByOtherProcess() throws IOException, InterruptedException { - final Process process = ProcessRunner.runClass(AffinityLockerThatDoesNotReleaseProcess.class, - new String[]{"-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()}, - new String[]{"last"}); + final Process process = JavaProcessBuilder.create(AffinityLockerThatDoesNotReleaseProcess.class) + .withJvmArguments("-Djava.io.tmpdir=" + folder.getRoot().getAbsolutePath()) + .withProgramArguments("last").start(); waitForProcessToEnd(5, "Locking process", process); // We should be able to acquire the lock despite the other process not explicitly releasing it try (final AffinityLock acquired = AffinityLock.acquireLock("last")) { @@ -137,11 +137,11 @@ private void waitForProcessToEnd(int timeToWaitSeconds, String processDescriptio private void waitForProcessToEnd(int timeToWaitSeconds, String processDescription, Process process, boolean checkExitCode) throws InterruptedException { if (!process.waitFor(timeToWaitSeconds, TimeUnit.SECONDS)) { - ProcessRunner.printProcessOutput(processDescription, process); + JavaProcessBuilder.printProcessOutput(processDescription, process); fail(processDescription + " didn't end in time"); } if (checkExitCode && process.exitValue() != 0) { - ProcessRunner.printProcessOutput(processDescription, process); + JavaProcessBuilder.printProcessOutput(processDescription, process); fail(processDescription + " failed, see output above (exit value " + process.exitValue() + ")"); } } From 711cd191c7a3910a4b7f6e39dc457974cbb399d8 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Thu, 10 Nov 2022 03:18:57 +0000 Subject: [PATCH 092/226] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 564aef2ee..f4cda02be 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.33 + 1.1.36 diff --git a/affinity/pom.xml b/affinity/pom.xml index 6468d6586..d9dba943f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.33 + 1.1.36 diff --git a/pom.xml b/pom.xml index 7b59a1516..30e513006 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft root-parent-pom - 1.2.21 + 1.2.23 From c3a83b32ff2ce3da99c631fbc56d2dd8322c15ea Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Wed, 21 Dec 2022 19:44:28 +1100 Subject: [PATCH 093/226] spelling --- .../main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java index 1a8bb2cd0..2c0fc2d7c 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java @@ -90,7 +90,7 @@ public void setAffinity(final BitSet affinity) { } BitSet affinity2 = getAffinity0(); if (!affinity2.equals(affinity)) { - LoggerFactory.getLogger(WindowsJNAAffinity.class).warn("Tried to set affinity to " + affinity + " but was " + affinity2 + " you may have in sufficient access rights"); + LoggerFactory.getLogger(WindowsJNAAffinity.class).warn("Tried to set affinity to " + affinity + " but was " + affinity2 + " you may have insufficient access rights"); } currentAffinity.set((BitSet) affinity.clone()); } From 75814b29ce30b188ac3d4b35a950c7619fb4ecdf Mon Sep 17 00:00:00 2001 From: Jorge Villarreal Date: Sun, 19 Feb 2023 20:24:21 -0600 Subject: [PATCH 094/226] Typo in isMacJNAAffinityUsable warning message --- affinity/src/main/java/net/openhft/affinity/Affinity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index 83986b2bc..f089d4da7 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -128,7 +128,7 @@ private static boolean isMacJNAAffinityUsable() { return true; } else { - LOGGER.warn("MAX OSX JNA-based affinity not usable due to JNA not being available!"); + LOGGER.warn("MAC OSX JNA-based affinity not usable due to JNA not being available!"); return false; } } From 44d1d3fcb93741bfa0ed2951aca34cbd8ce7eb6d Mon Sep 17 00:00:00 2001 From: rogersimmons <42873823+rogersimmons@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:21:13 +0100 Subject: [PATCH 095/226] Add JNA minimum version check (#104) Co-authored-by: rogersimmons --- .../java/net/openhft/affinity/Affinity.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index f089d4da7..89f049621 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -17,6 +17,7 @@ package net.openhft.affinity; +import com.sun.jna.Native; import net.openhft.affinity.impl.*; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -187,13 +188,21 @@ public static void setThreadId() { } public static boolean isJNAAvailable() { - if (JNAAvailable == null) - try { - Class.forName("com.sun.jna.Platform"); - JNAAvailable = true; - } catch (ClassNotFoundException ignored) { + if (JNAAvailable == null) { + int majorVersion = Integer.parseInt(Native.VERSION.split("\\.")[0]); + if(majorVersion < 5) { + LOGGER.warn("Affinity library requires JNA version >= 5"); JNAAvailable = false; } + else { + try { + Class.forName("com.sun.jna.Platform"); + JNAAvailable = true; + } catch (ClassNotFoundException ignored) { + JNAAvailable = false; + } + } + } return JNAAvailable; } From 5497748938ab378386056286e722eaf032ec6af0 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 11 Aug 2023 10:24:26 +0100 Subject: [PATCH 096/226] Bring all versions to the same level so we test the version that a Chronicle ALL jar uses --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 5 ++--- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index f4cda02be..69c307d07 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.36 + 1.24.0-SNAPSHOT @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.22.4 + 3.24.0-SNAPSHOT import diff --git a/affinity/pom.xml b/affinity/pom.xml index d9dba943f..5cca00581 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.1.36 + 1.24.0-SNAPSHOT @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.22.4 + 3.24.0-SNAPSHOT import @@ -120,7 +120,6 @@ org.codehaus.mojo exec-maven-plugin - 3.1.0 diff --git a/pom.xml b/pom.xml index 30e513006..46f74b415 100644 --- a/pom.xml +++ b/pom.xml @@ -20,8 +20,8 @@ net.openhft - root-parent-pom - 1.2.23 + java-parent-pom + 1.24.0-SNAPSHOT From 980f26e8e81efdf7ad463a953adfa1a48fd2d1c2 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 30 Aug 2023 15:50:59 +0100 Subject: [PATCH 097/226] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 69c307d07..021ed5bd4 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0-SNAPSHOT + 1.24.0 diff --git a/affinity/pom.xml b/affinity/pom.xml index 5cca00581..3b13191ce 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0-SNAPSHOT + 1.24.0 diff --git a/pom.xml b/pom.xml index 46f74b415..0dc355831 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0-SNAPSHOT + 1.24.0 From 6bfff924944d0af6e0597d10e846d974a1b34a57 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 31 Aug 2023 10:48:23 +0100 Subject: [PATCH 098/226] java-parent-pom version 1.24.0 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 021ed5bd4..a603a8b62 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.24.0-SNAPSHOT + 3.24.0 import diff --git a/affinity/pom.xml b/affinity/pom.xml index 3b13191ce..bc65cfe05 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.24.0-SNAPSHOT + 3.24.0 import From 894231a7fc8d5de476b53672dcd22858d87947ac Mon Sep 17 00:00:00 2001 From: "yevgen.pavlenko" Date: Thu, 2 Nov 2023 13:24:09 +0200 Subject: [PATCH 099/226] Disable AffinityLockTest.dumpLocks for Java 21. --- .../openhft/affinity/AffinityLockTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index a44716375..b3ff7def5 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -26,14 +26,18 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import static java.lang.Runtime.getRuntime; import static net.openhft.affinity.AffinityLock.PROCESSORS; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; +import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; /** @@ -41,11 +45,13 @@ */ public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); + private static final int JDK_VERSION = getMajorVersion(); private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); @Test public void dumpLocksI7() throws IOException { + assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i7.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -83,6 +89,7 @@ public void dumpLocksI7() throws IOException { @Test public void dumpLocksI3() throws IOException { + assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i3.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -106,6 +113,7 @@ public void dumpLocksI3() throws IOException { @Test public void dumpLocksCoreDuo() throws IOException { + assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("core.duo.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -308,4 +316,22 @@ public void testTooHighCpuId2() { try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) { } } + + private static int getMajorVersion() { + try { + final Method method = Runtime.class.getDeclaredMethod("version"); + final Object version = method.invoke(getRuntime()); + final Class clz = Class.forName("java.lang.Runtime$Version"); + return (Integer) clz.getDeclaredMethod("major").invoke(version); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | + IllegalArgumentException e) { + // ignore and fall back to pre-jdk9 + } + try { + return Integer.parseInt(Runtime.class.getPackage().getSpecificationVersion().split("\\.")[1]); + } catch (Exception e) { + System.err.println("Unable to get the major version, defaulting to 8 " + e); + return 8; + } + } } From afed6998b341adf2f94fae723fe767c98c786ae2 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 10 Jan 2024 14:31:52 +0000 Subject: [PATCH 100/226] Remove class that was moved --- .../net/openhft/affinity/AffinitySupport.java | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 affinity/src/main/java/net/openhft/affinity/AffinitySupport.java diff --git a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java b/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java deleted file mode 100644 index d4cc6e249..000000000 --- a/affinity/src/main/java/net/openhft/affinity/AffinitySupport.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.affinity; - -/** - * For backward compatibility with Affinity 2.x - */ -@Deprecated(/* to be removed in x.22 */) -public class AffinitySupport { - - public static int getThreadId() { - return Affinity.getThreadId(); - } - - public static void setThreadId() { - Affinity.setThreadId(); - } -} From 2a31656397765343879de8d00319c9daf0aed379 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 25 Jan 2024 15:11:43 +0000 Subject: [PATCH 101/226] Fix AffinityLockTest on Java 21 (#113) Was broken because Thread#toString includes thread ID on Java 21. Ignore this in the test cases. --- .../openhft/affinity/AffinityLockTest.java | 38 ++++++------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index b3ff7def5..a2decf585 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -20,24 +20,21 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import org.jetbrains.annotations.NotNull; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import static java.lang.Runtime.getRuntime; import static net.openhft.affinity.AffinityLock.PROCESSORS; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; -import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; /** @@ -45,13 +42,11 @@ */ public class AffinityLockTest extends BaseAffinityTest { private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class); - private static final int JDK_VERSION = getMajorVersion(); private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker(); @Test public void dumpLocksI7() throws IOException { - assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i7.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -70,7 +65,7 @@ public void dumpLocksI7() throws IOException { locks[6].assignedThread = new Thread(new InterrupedThread(), "main"); locks[7].assignedThread = new Thread(new InterrupedThread(), "tcp"); locks[7].assignedThread.start(); - final String actual = LockInventory.dumpLocks(locks); + final String actual = dumpLocks(locks); assertEquals("0: General use CPU\n" + "1: CPU not available\n" + "2: Thread[logger,5,main] alive=true\n" + @@ -89,7 +84,6 @@ public void dumpLocksI7() throws IOException { @Test public void dumpLocksI3() throws IOException { - assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i3.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -101,7 +95,7 @@ public void dumpLocksI3() throws IOException { locks[1].assignedThread.start(); locks[3].assignedThread = new Thread(new InterrupedThread(), "main"); - final String actual = LockInventory.dumpLocks(locks); + final String actual = dumpLocks(locks); assertEquals("0: General use CPU\n" + "1: Thread[engine,5,main] alive=true\n" + "2: General use CPU\n" + @@ -113,7 +107,6 @@ public void dumpLocksI3() throws IOException { @Test public void dumpLocksCoreDuo() throws IOException { - assumeFalse(JDK_VERSION > 20); LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("core.duo.cpuinfo")); AffinityLock[] locks = { new AffinityLock(0, true, false, lockInventory), @@ -122,7 +115,7 @@ public void dumpLocksCoreDuo() throws IOException { locks[1].assignedThread = new Thread(new InterrupedThread(), "engine"); locks[1].assignedThread.start(); - final String actual = LockInventory.dumpLocks(locks); + final String actual = dumpLocks(locks); assertEquals("0: General use CPU\n" + "1: Thread[engine,5,main] alive=true\n", actual); System.out.println(actual); @@ -317,21 +310,12 @@ public void testTooHighCpuId2() { } } - private static int getMajorVersion() { - try { - final Method method = Runtime.class.getDeclaredMethod("version"); - final Object version = method.invoke(getRuntime()); - final Class clz = Class.forName("java.lang.Runtime$Version"); - return (Integer) clz.getDeclaredMethod("major").invoke(version); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | - IllegalArgumentException e) { - // ignore and fall back to pre-jdk9 - } - try { - return Integer.parseInt(Runtime.class.getPackage().getSpecificationVersion().split("\\.")[1]); - } catch (Exception e) { - System.err.println("Unable to get the major version, defaulting to 8 " + e); - return 8; - } + /** + * In Java 21 the toString contents of Thread changed to include an ID. This breaks the tests here in Java 21. + * Strip out the thread ID here so that existing tests continue to pass. + */ + private static String dumpLocks(AffinityLock[] locks) { + String value = LockInventory.dumpLocks(locks); + return value.replaceAll("#[0-9]+(,)?", ""); } } From f83ea94d2af56bcc3f2c767beca94e2b09a2bf04 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 9 Feb 2024 00:54:51 +0000 Subject: [PATCH 102/226] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index a603a8b62..0c06e6569 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.25.3 diff --git a/affinity/pom.xml b/affinity/pom.xml index bc65cfe05..465215613 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.25.3 diff --git a/pom.xml b/pom.xml index 0dc355831..f96e7e5e3 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.25.3 From 3cebc6f6ccf41671a3752128f990f667612b359c Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 4 Mar 2024 21:03:07 +0000 Subject: [PATCH 103/226] Updating parent POM (automated) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 0c06e6569..694444f84 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.3 + 1.25.4 diff --git a/affinity/pom.xml b/affinity/pom.xml index 465215613..d63ec73fa 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.3 + 1.25.4 diff --git a/pom.xml b/pom.xml index f96e7e5e3..0416056c1 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.3 + 1.25.4 From 959768b27877f57560c81b87d45165652d3275a3 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 25 Mar 2024 11:45:32 +0000 Subject: [PATCH 104/226] Initial branch of x.26 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 6 +++--- pom.xml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 694444f84..5cfe6cc26 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.24ea0-SNAPSHOT + 3.26ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.24.0 + 3.25.2 import diff --git a/affinity/pom.xml b/affinity/pom.xml index d63ec73fa..7387a7601 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.24ea0-SNAPSHOT + 3.26ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -43,13 +43,13 @@ net.openhft third-party-bom pom - 3.24.0 + 3.25.2 import net.openhft chronicle-bom - 2.24ea-SNAPSHOT + 2.26ea-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index 0416056c1..a4b88a58f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.24ea0-SNAPSHOT + 3.64ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From c05061f567317cc41a386da8e22a35deadc0277b Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Mar 2024 10:48:52 +0000 Subject: [PATCH 105/226] fix deprecated usage --- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index a2decf585..96c19f341 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -20,6 +20,7 @@ import net.openhft.affinity.impl.Utilities; import net.openhft.affinity.impl.VanillaCpuLayout; import net.openhft.affinity.testimpl.TestFileLockBasedLockChecker; +import org.hamcrest.MatcherAssert; import org.jetbrains.annotations.NotNull; import org.junit.Test; import org.slf4j.Logger; @@ -244,7 +245,7 @@ public void shouldReturnLockForSpecifiedCpu() { assumeTrue(Runtime.getRuntime().availableProcessors() > 3); try (final AffinityLock affinityLock = AffinityLock.acquireLock(3)) { - assertThat(affinityLock.cpuId(), is(3)); + MatcherAssert.assertThat(affinityLock.cpuId(), is(3)); } assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity()); } From f4c5df52f8e00f7371fd4af8579e7dad8320dddc Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 11:39:43 +0100 Subject: [PATCH 106/226] Tidy up compiler setting and some warnings --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 5cfe6cc26..dc06e7229 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom pom - 3.25.2 + 3.26.0-SNAPSHOT import diff --git a/affinity/pom.xml b/affinity/pom.xml index 7387a7601..8655b4567 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -43,7 +43,7 @@ net.openhft third-party-bom pom - 3.25.2 + 3.26.0-SNAPSHOT import From cfdc2f6e4760019fc272736c70871cb3cf51764f Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 10 Apr 2024 10:53:28 +0100 Subject: [PATCH 107/226] tidy SuppressWarnings --- .../java/net/openhft/affinity/impl/LinuxHelper.java | 12 ++++++------ .../net/openhft/affinity/impl/VersionHelper.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index 3b4d301de..f2e456286 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -239,7 +239,7 @@ public String getSysname() { return new String(sysname, 0, length(sysname)); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("unused") public String getNodename() { return new String(nodename, 0, length(nodename)); } @@ -270,7 +270,7 @@ public String getMachine() { return new String(machine, 0, length(machine)); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public String getDomainname() { return new String(domainname, 0, length(domainname)); } @@ -295,7 +295,7 @@ public cpu_set_t() { } } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public static void __CPU_ZERO(cpu_set_t cpuset) { for (NativeLong bits : cpuset.__bits) { bits.setValue(0L); @@ -310,19 +310,19 @@ public static long __CPUMASK(int cpu) { return 1L << (cpu % __NCPUBITS); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public static void __CPU_SET(int cpu, cpu_set_t cpuset) { cpuset.__bits[__CPUELT(cpu)].setValue( cpuset.__bits[__CPUELT(cpu)].longValue() | __CPUMASK(cpu)); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public static void __CPU_CLR(int cpu, cpu_set_t cpuset) { cpuset.__bits[__CPUELT(cpu)].setValue( cpuset.__bits[__CPUELT(cpu)].longValue() & ~__CPUMASK(cpu)); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public static boolean __CPU_ISSET(int cpu, cpu_set_t cpuset) { return (cpuset.__bits[__CPUELT(cpu)].longValue() & __CPUMASK(cpu)) != 0; } diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java index b54d75081..9729c2980 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java @@ -61,7 +61,7 @@ public int hashCode() { return (major << 16) | (minor << 8) | release; } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("unused") public boolean majorMinorEquals(final VersionHelper ver) { return ver != null && this.major == ver.major From 9a9148f9f5073cb4c8ff4a59804d3f7c74d84ce2 Mon Sep 17 00:00:00 2001 From: rogersimmons Date: Wed, 17 Apr 2024 09:33:05 +0100 Subject: [PATCH 108/226] Remove old comment (long since addressed) --- .../main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java index 1a4463319..5f93ca361 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java @@ -72,7 +72,6 @@ public BitSet getAffinity() { return ret; } - // TODO: FIXME!!! CHANGE IAffinity TO SUPPORT PLATFORMS WITH 64+ CORES FIXME!!! @Override public void setAffinity(final BitSet affinity) { LinuxHelper.sched_setaffinity(affinity); From 25b21069372bb0feee5d3e3cf266f29fb65fec12 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 7 May 2024 18:48:15 +0100 Subject: [PATCH 109/226] Fix newlines --- .../src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java | 1 - affinity/src/main/java/net/openhft/affinity/LockCheck.java | 2 +- affinity/src/main/java/net/openhft/affinity/LockInventory.java | 2 -- .../src/main/java/net/openhft/affinity/MicroJitterSampler.java | 2 -- .../src/main/java/net/openhft/affinity/impl/LinuxHelper.java | 2 +- .../src/main/java/net/openhft/affinity/impl/VersionHelper.java | 1 - affinity/src/main/java/net/openhft/ticker/Ticker.java | 2 +- affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java | 2 +- affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java | 2 +- .../src/test/java/net/openhft/affinity/BootClassPathTest.java | 2 +- .../test/java/net/openhft/affinity/FileLockLockCheckTest.java | 2 +- affinity/src/test/java/net/openhft/affinity/LockCheckTest.java | 2 +- .../src/test/java/net/openhft/ticker/impl/JNIClockTest.java | 2 +- 13 files changed, 9 insertions(+), 15 deletions(-) diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java index deb9d9d5f..3dc8d2652 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java @@ -61,4 +61,3 @@ public static Bundle findBundle(BundleContext context, String symbolicName) { return null; } } - diff --git a/affinity/src/main/java/net/openhft/affinity/LockCheck.java b/affinity/src/main/java/net/openhft/affinity/LockCheck.java index 8acaf4e23..29b962f07 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockCheck.java +++ b/affinity/src/main/java/net/openhft/affinity/LockCheck.java @@ -100,4 +100,4 @@ static boolean updateCpu(int cpu) throws IOException { public static void releaseLock(int cpu) { lockChecker.releaseLock(cpu); } -} \ No newline at end of file +} diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index ce15aebed..2ca7eb39e 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -159,7 +159,6 @@ && updateLockForCurrentThread(bind, al, false)) { return noLock(); } - LOGGER.warn("No reservable CPU for {}", Thread.currentThread()); return noLock(); @@ -181,7 +180,6 @@ && updateLockForCurrentThread(bind, required, false)) { return noLock(); } - LOGGER.warn("Unable to acquire lock on CPU {} for thread {}, trying to find another CPU", cpuId, Thread.currentThread()); diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index c2a8ef3aa..d0a971806 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -46,7 +46,6 @@ private static void pause() throws InterruptedException { } else { Thread.sleep(1); } - } public static void main(String... ignored) throws InterruptedException { @@ -133,7 +132,6 @@ void print(PrintStream ps) { ps.println(); } } - /* e.g. Ubuntu 20.04, Ryzen 5950X with an isolated CPU. (init 3) sudo cpupower -c {cpu} -g performance, run from command line After 3600 seconds, the average per hour was diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index f2e456286..da85e247f 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -69,7 +69,7 @@ cpu_set_t sched_getaffinity() { public static void sched_setaffinity(final BitSet affinity) { sched_setaffinity(0, affinity); } - + public static void sched_setaffinity(final int pid, final BitSet affinity) { final CLibrary lib = CLibrary.INSTANCE; final cpu_set_t cpuset = new cpu_set_t(); diff --git a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java index 9729c2980..98e1c19f0 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/VersionHelper.java @@ -77,4 +77,3 @@ public boolean isSameOrNewer(final VersionHelper ver) { && this.release >= ver.release)); } } - diff --git a/affinity/src/main/java/net/openhft/ticker/Ticker.java b/affinity/src/main/java/net/openhft/ticker/Ticker.java index d8ac5a1e6..6e17c653c 100644 --- a/affinity/src/main/java/net/openhft/ticker/Ticker.java +++ b/affinity/src/main/java/net/openhft/ticker/Ticker.java @@ -58,4 +58,4 @@ public static long toNanos(long ticks) { public static double toMicros(long ticks) { return INSTANCE.toMicros(ticks); } -} \ No newline at end of file +} diff --git a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java index 0115c19cd..1808af9a7 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java @@ -103,4 +103,4 @@ public long toNanos(long ticks) { public double toMicros(double ticks) { return ticks * RDTSC_MICRO_FACTOR; } -} \ No newline at end of file +} diff --git a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java index 8844ab460..2c3402433 100644 --- a/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java +++ b/affinity/src/main/java/net/openhft/ticker/impl/SystemClock.java @@ -47,4 +47,4 @@ public long toNanos(long ticks) { public double toMicros(double ticks) { return ticks / 1e3; } -} \ No newline at end of file +} diff --git a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java index d4c555938..3c0c29df8 100644 --- a/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java +++ b/affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java @@ -30,4 +30,4 @@ public void shouldDetectClassesOnClassPath() { assertTrue(BootClassPath.INSTANCE.has("java.lang.Thread")); assertTrue(BootClassPath.INSTANCE.has("java.lang.Runtime")); } -} \ No newline at end of file +} diff --git a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java index 5f39b87ce..1576851f4 100644 --- a/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java @@ -71,4 +71,4 @@ public void shouldNotBlowUpIfPidFileIsEmpty() throws Exception { LockCheck.isCpuFree(cpu); } -} \ No newline at end of file +} diff --git a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java index c6ab5e042..11ec9463f 100644 --- a/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java +++ b/affinity/src/test/java/net/openhft/affinity/LockCheckTest.java @@ -84,4 +84,4 @@ public void shouldNotBlowUpIfPidFileIsCorrupt() throws Exception { LockCheck.isCpuFree(cpu); } -} \ No newline at end of file +} diff --git a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java index 8af7760de..b87b793fe 100644 --- a/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java +++ b/affinity/src/test/java/net/openhft/ticker/impl/JNIClockTest.java @@ -78,4 +78,4 @@ public void testJitter() { System.out.println(((long) (clock.toMicros(time[i]) * 10)) / 10.0 + ", " + ((long) (clock.toMicros(length[i]) * 10) / 10.0)); } } -} \ No newline at end of file +} From 4b8f50d83ee7dd2411e13a4d034306cb78d4df4e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 20 May 2024 13:31:13 +0100 Subject: [PATCH 110/226] type:pom order --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index dc06e7229..9722d19fc 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -41,8 +41,8 @@ net.openhft third-party-bom - pom 3.26.0-SNAPSHOT + pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index 8655b4567..ca116fbe0 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -42,8 +42,8 @@ net.openhft third-party-bom - pom 3.26.0-SNAPSHOT + pom import From 8386232d9a0848dec9e7946401d27f279cbe9ecd Mon Sep 17 00:00:00 2001 From: rogersimmons Date: Wed, 17 Apr 2024 09:33:05 +0100 Subject: [PATCH 111/226] Remove old comment (long since addressed) --- .../main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java index 1a4463319..5f93ca361 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java @@ -72,7 +72,6 @@ public BitSet getAffinity() { return ret; } - // TODO: FIXME!!! CHANGE IAffinity TO SUPPORT PLATFORMS WITH 64+ CORES FIXME!!! @Override public void setAffinity(final BitSet affinity) { LinuxHelper.sched_setaffinity(affinity); From eb3ec15b9c881fafbc358fef2f5bae5e8c95f089 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 22 May 2024 19:16:40 +0100 Subject: [PATCH 112/226] parent poms -> x.26.0 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 9722d19fc..c894212c9 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -41,7 +41,7 @@ net.openhft third-party-bom - 3.26.0-SNAPSHOT + 3.26.0 pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index ca116fbe0..fd303d10a 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -42,7 +42,7 @@ net.openhft third-party-bom - 3.26.0-SNAPSHOT + 3.26.0 pom import From b21836e42701e6db0ef3cfbc5b41a1110b55c799 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 13:06:41 +0100 Subject: [PATCH 113/226] correct version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a4b88a58f..2e42b312a 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.64ea0-SNAPSHOT + 3.26ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From bec873c5e1ff97fa7178ab5c5f21d8549ae27e16 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 13:31:12 +0100 Subject: [PATCH 114/226] Bump the snapshot version for affinity --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fd303d10a..9a4a91acd 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea0-SNAPSHOT + 3.26ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From 4a33d97715d77acf6102a8eb117b71cb9cb8a630 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 13:32:01 +0100 Subject: [PATCH 115/226] Bump the snapshot version for affinity --- affinity-test/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c894212c9..7cf2554a9 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea0-SNAPSHOT + 3.26ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/pom.xml b/pom.xml index 2e42b312a..48714d4dc 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea0-SNAPSHOT + 3.26ea1-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 91e88fd51b6af8b082191b34a827767cc02f46fd Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 13:54:35 +0100 Subject: [PATCH 116/226] java-parent-pom -> 1.26.0 --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 4 ++-- .../src/main/java/net/openhft/affinity/AffinityLock.java | 1 + .../java/net/openhft/affinity/AffinityThreadFactory.java | 1 + .../main/java/net/openhft/affinity/MicroJitterSampler.java | 1 + .../main/java/net/openhft/affinity/impl/LinuxHelper.java | 4 ++-- .../affinity/lockchecker/FileLockBasedLockChecker.java | 1 + .../test/java/net/openhft/affinity/AffinityLockTest.java | 7 +++++++ .../net/openhft/affinity/impl/NativeAffinityImpTest.java | 4 +++- .../net/openhft/affinity/impl/PosixJNAAffinityTest.java | 4 +++- pom.xml | 2 +- 11 files changed, 23 insertions(+), 8 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 7cf2554a9..c4f20dd60 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.4 + 1.26.0 diff --git a/affinity/pom.xml b/affinity/pom.xml index 9a4a91acd..833855bf1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.4 + 1.26.0 @@ -178,7 +178,7 @@ -h ${project.build.directory}/jni - -Xlint:deprecation + -Xlint:all,-options 1.8 1.8 diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 67642daf5..2fba8ce46 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -446,6 +446,7 @@ public void close() { release(); } + @SuppressWarnings("removal") @Override protected void finalize() throws Throwable { if (bound) { diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java index a70bfbe3d..5962f4b62 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityThreadFactory.java @@ -57,6 +57,7 @@ public synchronized Thread newThread(@NotNull final Runnable r) { @Override public void run() { try (AffinityLock ignored = acquireLockBasedOnLast()) { + assert ignored != null; r.run(); } } diff --git a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java index d0a971806..f9e34715d 100644 --- a/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java +++ b/affinity/src/main/java/net/openhft/affinity/MicroJitterSampler.java @@ -71,6 +71,7 @@ private void once() throws InterruptedException { public void run() { try (final AffinityLock lock = AffinityLock.acquireLock(CPU)) { + assert lock != null; boolean first = true; System.out.println("Warming up..."); while (!Thread.currentThread().isInterrupted()) { diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index da85e247f..448d37bd7 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -231,7 +231,7 @@ static int length(final byte[] data) { } @Override - protected List getFieldOrder() { + protected List getFieldOrder() { return FIELD_ORDER; } @@ -328,7 +328,7 @@ public static boolean __CPU_ISSET(int cpu, cpu_set_t cpuset) { } @Override - protected List getFieldOrder() { + protected List getFieldOrder() { return FIELD_ORDER; } } diff --git a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java index 77095375c..6b596a49f 100644 --- a/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java +++ b/affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java @@ -241,5 +241,6 @@ private File tmpDir() { * Thrown when another process deleted the lock file between us opening the file and acquiring the lock */ class ConcurrentLockFileDeletionException extends Exception { + private static final long serialVersionUID = 0L; } } diff --git a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java index 96c19f341..dd286686f 100644 --- a/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java +++ b/affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java @@ -162,6 +162,7 @@ public void resetAffinity() { } assertEquals(1, Affinity.getAffinity().cardinality()); try (AffinityLock lock = AffinityLock.acquireLock()) { + assertNotNull(lock); } assertTrue(Affinity.getAffinity().cardinality() > 1); } @@ -274,15 +275,19 @@ public void testAffinityLockDescriptions() { return; } try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertNotNull(lock); assertEquals(PROCESSORS - 1, Affinity.getCpu()); } try (AffinityLock lock = AffinityLock.acquireLock("last")) { + assertNotNull(lock); assertEquals(PROCESSORS - 1, Affinity.getCpu()); } try (AffinityLock lock = AffinityLock.acquireLock("last-1")) { + assertNotNull(lock); assertEquals(PROCESSORS - 2, Affinity.getCpu()); } try (AffinityLock lock = AffinityLock.acquireLock("1")) { + assertNotNull(lock); assertEquals(1, Affinity.getCpu()); } try (AffinityLock lock = AffinityLock.acquireLock("any")) { @@ -302,12 +307,14 @@ public void testAffinityLockDescriptions() { @Test public void testTooHighCpuId() { try (AffinityLock ignored = AffinityLock.acquireLock(123456)) { + assertNotNull(ignored); } } @Test public void testTooHighCpuId2() { try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) { + assertNotNull(ignored); } } diff --git a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java index 3c98d9683..04c200e3f 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/NativeAffinityImpTest.java @@ -53,7 +53,9 @@ public void testGettid() { long time = 0; for (int i = 0; i < runs; i++) { long start = System.nanoTime(); - tid = Thread.currentThread().getId(); + @SuppressWarnings("deprecation") + long tid0 = Thread.currentThread().getId(); + tid = tid0; time += System.nanoTime() - start; assertTrue(tid > 0); assertTrue(tid < 1 << 16); diff --git a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java index a763cef05..d25aa89ae 100644 --- a/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java +++ b/affinity/src/test/java/net/openhft/affinity/impl/PosixJNAAffinityTest.java @@ -51,7 +51,9 @@ public void testGettid() { long time = 0; for (int i = 0; i < runs; i++) { long start = System.nanoTime(); - tid = Thread.currentThread().getId(); + @SuppressWarnings("deprecation") + long tid0 = Thread.currentThread().getId(); + tid = tid0; time += System.nanoTime() - start; assertTrue(tid > 0); assertTrue(tid < 1 << 24); diff --git a/pom.xml b/pom.xml index 48714d4dc..79ab1d2c7 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.4 + 1.26.0 From 5dcf176422ec646922127458a43a0dc6adcb3727 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 15:47:36 +0100 Subject: [PATCH 117/226] java-parent-pom -> 1.26.0 (finalize) --- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 2fba8ce46..f7a01619d 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -446,7 +446,7 @@ public void close() { release(); } - @SuppressWarnings("removal") + @SuppressWarnings({"deprecation", "removal"}) @Override protected void finalize() throws Throwable { if (bound) { From 461408b2b9a3ccc2e59a60178fee5c15b72d8e21 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 16:27:53 +0100 Subject: [PATCH 118/226] Updating to bom version 2.26ea0 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 833855bf1..fc8b062b0 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea0 pom import From 730f7f688c89b2a9db4914312c37945c8235d207 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 16:28:11 +0100 Subject: [PATCH 119/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fc8b062b0..43f964c8d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea1-SNAPSHOT + 3.26ea1 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea0 + 2.26ea-SNAPSHOT pom import @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea1 From dd79316f2b37cc562d7069ba267177038ddc9821 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 16:35:19 +0100 Subject: [PATCH 120/226] Updating to bom version 2.26ea1 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 43f964c8d..143ff8dc2 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea1 pom import From a0a58fb320320bc3267732691669db27169f79ec Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 16:35:33 +0100 Subject: [PATCH 121/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 143ff8dc2..43f964c8d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea1 + 2.26ea-SNAPSHOT pom import From bfcfd600d765db61a768076b651ac9d7f7b7af3e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 29 May 2024 17:13:50 +0100 Subject: [PATCH 122/226] Re-release affinity --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index c4f20dd60..ae07c3ea9 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea1-SNAPSHOT + 3.26ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 43f964c8d..56851c13d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea1 + 3.26ea2-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index 79ab1d2c7..b871d1851 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea1-SNAPSHOT + 3.26ea2-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From db1264b730358131e853aa9f20f45c22b4a67da2 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 18:56:31 +0100 Subject: [PATCH 123/226] Updating to bom version 2.26ea1 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 56851c13d..3cb0a0047 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea1 pom import From 7e25a795341deb2c8c974b57f1e3396a2bb55c57 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Wed, 29 May 2024 18:56:47 +0100 Subject: [PATCH 124/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 3cb0a0047..6736c3564 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea2-SNAPSHOT + 3.26ea2 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea1 + 2.26ea-SNAPSHOT pom import @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea1 + Java-Thread-Affinity-3.26ea2 From ea37beb018cc4759ebcc23fd9ac1e3ff7b5a5935 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 30 May 2024 08:01:44 +0100 Subject: [PATCH 125/226] Re-release affinity --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index ae07c3ea9..93e457d06 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea2-SNAPSHOT + 3.26ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 6736c3564..d1fe17ab9 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea2 + 3.26ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index b871d1851..1e11e7cb4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea2-SNAPSHOT + 3.26ea3-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 0122ee6e4a6a91d54d821b7fcade97fa5d397921 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Tue, 11 Jun 2024 10:34:22 +0100 Subject: [PATCH 126/226] Updating to bom version 2.26ea8 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index d1fe17ab9..fbe386bcb 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea8 pom import From 2897de818ef4b41e160a57a70a1ccde957ded6b6 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Tue, 11 Jun 2024 10:34:38 +0100 Subject: [PATCH 127/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fbe386bcb..45be8631c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea3-SNAPSHOT + 3.26ea3 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea8 + 2.26ea-SNAPSHOT pom import @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea2 + Java-Thread-Affinity-3.26ea3 From 041a62c492c96b13893d7c1637358dd1e120ff48 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 11 Jun 2024 11:02:40 +0100 Subject: [PATCH 128/226] Release affinity --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 45be8631c..5c493be2c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea3 + 3.26ea3-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From 3258abc52130de6c39a032044c696e8f2a4a5392 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Thu, 13 Jun 2024 09:10:23 +0100 Subject: [PATCH 129/226] Updating to bom version 2.26ea9 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 5c493be2c..60c1276d1 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea9 pom import From ae4ee4ebdbfc2c8d14631b1cdf3d7e8759aff43b Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Thu, 13 Jun 2024 09:10:38 +0100 Subject: [PATCH 130/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 60c1276d1..45be8631c 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea3-SNAPSHOT + 3.26ea3 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea9 + 2.26ea-SNAPSHOT pom import From d0c0cb130a1aed71f09b7b324f9b7b2088ce50dd Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 14 Jun 2024 14:36:45 +0100 Subject: [PATCH 131/226] revert affinity to 3.23.3 (#124) --- affinity-test/pom.xml | 2 +- affinity/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 93e457d06..d324ab26d 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea3-SNAPSHOT + 3.26ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test diff --git a/affinity/pom.xml b/affinity/pom.xml index 45be8631c..410f53d28 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea3 + 3.26ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index 1e11e7cb4..3271c1b61 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea3-SNAPSHOT + 3.26ea4-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From a6be0bc146afa42756896abdfd44a9cf6c46b43e Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 21:47:10 +0100 Subject: [PATCH 132/226] Updating to bom version 2.26ea11 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 410f53d28..45523d0a3 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea11 pom import From af618862835862cc8856fcc98bd4ce3a2c8bf824 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 21:47:25 +0100 Subject: [PATCH 133/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 45523d0a3..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4-SNAPSHOT + 3.26ea4 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea11 + 2.26ea-SNAPSHOT pom import @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea3 + Java-Thread-Affinity-3.26ea4 From a881052293ddb83191db4788ad9028d9ce9252d9 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 22:30:41 +0100 Subject: [PATCH 134/226] Updating to bom version 2.26ea12 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..2d0fb3c6b 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea12 pom import From 999da9e5ec3179564e56970d80c22161734e1010 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 22:30:53 +0100 Subject: [PATCH 135/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 2d0fb3c6b..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea12 + 2.26ea-SNAPSHOT pom import From 60033e4d9625ad6b284548f86abbddb294e9035f Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 22:55:51 +0100 Subject: [PATCH 136/226] Updating to bom version 2.26ea13 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..ba2a60708 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea13 pom import From e41a026b61c211f32378abe55c8f0797a9fdbf98 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 14 Jun 2024 22:56:03 +0100 Subject: [PATCH 137/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ba2a60708..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea13 + 2.26ea-SNAPSHOT pom import From 60fc755bab401f51b4d120aa1c83d30ddfa352a4 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 15 Jun 2024 13:17:41 +0100 Subject: [PATCH 138/226] Align snapshot versions 3.26ea4-SNAPSHOT (#125) --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..ca2a401d6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4 + 3.26ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From f28cdb37f0108f914eb4db5d5c9700b4486c94f5 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 16:29:43 +0100 Subject: [PATCH 139/226] Updating to bom version 2.26ea14 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ca2a401d6..cbe50eab6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea14 pom import From c099d7106e2be55896c99cc3f7eaf30f830bb171 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 16:29:58 +0100 Subject: [PATCH 140/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index cbe50eab6..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4-SNAPSHOT + 3.26ea4 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea14 + 2.26ea-SNAPSHOT pom import From 3e66fe1c35b9260516facfa00bd86cebe141d7ba Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 18:10:32 +0100 Subject: [PATCH 141/226] Updating to bom version 2.26ea15 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..cdd631c61 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea15 pom import From 680d0b2e1c2480156c1927db15a8bab6d07f5a8a Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 18:10:46 +0100 Subject: [PATCH 142/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index cdd631c61..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea15 + 2.26ea-SNAPSHOT pom import From c744a7b7282becd561edaf0071d237917411ea9e Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 18:15:29 +0100 Subject: [PATCH 143/226] Updating to bom version 2.26ea16 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..0b6183d08 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea16 pom import From 3cd3d15b388704ec8794318978ca41f8dd9604e2 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 18:15:42 +0100 Subject: [PATCH 144/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 0b6183d08..fadcb8df6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea16 + 2.26ea-SNAPSHOT pom import From 3bc506762a4a1680218929f69d8a510fb8d6b700 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:05:26 +0100 Subject: [PATCH 145/226] Set snapshot version --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index fadcb8df6..ca2a401d6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4 + 3.26ea4-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity From 4f7c73c9f73c460e7b3daf0ce1ac18d27c468913 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:54:01 +0100 Subject: [PATCH 146/226] Updating to bom version 2.26ea17 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ca2a401d6..2aa138538 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea17 pom import From 065f5b028845ab5aeafdf82d52a982ebab4cfcda Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:54:20 +0100 Subject: [PATCH 147/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.26ea4 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 2 +- pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index d324ab26d..df7887064 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea4-SNAPSHOT + 3.26ea4 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea4 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 2aa138538..1f1213a2d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4-SNAPSHOT + 3.26ea4 bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index 3271c1b61..f21e294b4 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea4-SNAPSHOT + 3.26ea4 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea4 From 562f22f6bda298a309c28ccb43d3b2ed0a412c13 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:54:23 +0100 Subject: [PATCH 148/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 2 +- pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index df7887064..6ab139997 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea4 + 3.26ea5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 1f1213a2d..03c1f2733 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea4 + 3.26ea5-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity diff --git a/pom.xml b/pom.xml index f21e294b4..4c0fee020 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea4 + 3.26ea5-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + ea From f44ec43781aede29ae8d43b221de5d23b6c1587f Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Sat, 15 Jun 2024 19:54:38 +0100 Subject: [PATCH 149/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 03c1f2733..caec040d6 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea17 + 2.26ea-SNAPSHOT pom import From 73cc564b0e7beb666b0d201e40a458340e6abdd5 Mon Sep 17 00:00:00 2001 From: rogersimmons <42873823+rogersimmons@users.noreply.github.com> Date: Sat, 29 Jun 2024 18:39:30 +0100 Subject: [PATCH 150/226] Add rdtsc for ARM 64 and 32 bit (#129) * Add rdtsc for ARM 64 and 32 bit * Remove link lib which isn't needed * Add macOS and Widows support for rdtsc() * Add OS detect to Makefile mac build * Add windows support Tweak macOS support * More macOS tweaks --------- Co-authored-by: rogersimmons --- affinity/pom.xml | 2 +- affinity/src/main/c/Makefile | 17 +++++++-- .../c/net_openhft_ticker_impl_JNIClock.cpp | 24 ++++++++++++ ...terprise_internals_impl_NativeAffinity.cpp | 37 ++++++++++++++++--- 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index caec040d6..ef717e9d5 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -129,7 +129,7 @@ exec - ${project.basedir}/${native.source.dir}/Makefile + make ${project.basedir}/${native.source.dir} diff --git a/affinity/src/main/c/Makefile b/affinity/src/main/c/Makefile index 0138fe1af..ac448e568 100755 --- a/affinity/src/main/c/Makefile +++ b/affinity/src/main/c/Makefile @@ -1,4 +1,3 @@ -#!/usr/bin/make -f # # Makefile for C code # @@ -10,6 +9,16 @@ TARGET := $(TARGET_DIR)/libCEInternals.so WORKING_DIR := $(TARGET_DIR)/../jni +JNI_OS := win32 +UNAME_S:= $(shell uname -s) +ifeq ($(UNAME_S), Linux) + JNI_OS := linux + LRT := -lrt +endif +ifeq ($(UNAME_S), Darwin) + JNI_OS := darwin +endif + JAVA_CLASSES = software.chronicle.enterprise.internals.impl.NativeAffinity net.openhft.ticker.impl.JNIClock JNI_STUBS := $(subst .,_,$(JAVA_CLASSES)) @@ -19,10 +28,10 @@ JAVA_BUILD_DIR := $(TARGET_DIR) JAVA_HOME ?= /usr/java/default JAVA_LIB := $(JAVA_HOME)/jre/lib -JVM_SHARED_LIBS := -L$(JAVA_LIB)/amd64/server -L$(JAVA_LIB)/i386/server -L$(JAVA_LIB)/amd64/jrockit/ -L$(JAVA_LIB)/i386/jrockit/ -L$(JAVA_LIB)/ppc64le/server -L$(JAVA_LIB)/ppc64le/jrockit/ -L$(JAVA_HOME)/lib/server +JVM_SHARED_LIBS := -L"$(JAVA_LIB)/amd64/server" -L"$(JAVA_LIB)/i386/server" -L"$(JAVA_LIB)/amd64/jrockit" -L"$(JAVA_LIB)/i386/jrockit" -L"$(JAVA_LIB)/ppc64le/server" -L"$(JAVA_LIB)/ppc64le/jrockit" -L"$(JAVA_HOME)/lib/server" CXX=g++ -INCLUDES := -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(WORKING_DIR) +INCLUDES := -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/$(JNI_OS)" -I"$(WORKING_DIR)" # classpath for javah ifdef CLASSPATH @@ -36,7 +45,7 @@ endif all: $(TARGET) $(TARGET): $(JNI_SOURCES) - $(CXX) -O3 -Wall -shared -fPIC $(JVM_SHARED_LIBS) -ljvm -lrt $(INCLUDES) $(JNI_SOURCES) -o $(TARGET) + $(CXX) -O3 -Wall -shared -fPIC $(JVM_SHARED_LIBS) $(LRT) $(INCLUDES) $(JNI_SOURCES) -o $(TARGET) clean: rm $(TARGET) diff --git a/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp b/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp index e269308a5..d5534c073 100644 --- a/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp +++ b/affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp @@ -53,6 +53,30 @@ unsigned long long rdtsc(){ __asm__ __volatile__("mfspr %%r3, 268": "=r" (rval)); return rval; } +#elif defined(__aarch64__) // ARMv8-A (AArch64) +#include +inline uint64_t rdtsc() { + uint64_t virtual_timer_value; + asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value)); + return virtual_timer_value; +} +#elif defined(__ARM_ARCH) && (__ARM_ARCH >= 7) // ARMv7-A (32-bit) +#include +inline uint64_t rdtsc() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec; +} +#elif defined(__APPLE__) +#include +inline uint64_t rdtsc() { + return mach_absolute_time(); +} +#elif defined(_MSC_VER) +#include +inline uint64_t rdtsc() { + return __rdtsc(); +} #endif /* diff --git a/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp b/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp index 0a2384022..013b85433 100644 --- a/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp +++ b/affinity/src/main/c/software_chronicle_enterprise_internals_impl_NativeAffinity.cpp @@ -19,12 +19,14 @@ #endif #include -#include -#include -#include -#include -#include - +#ifdef __linux__ + #include + #include + #include + #include + #include +#endif +#include #include "software_chronicle_enterprise_internals_impl_NativeAffinity.h" /* @@ -35,6 +37,7 @@ JNIEXPORT jbyteArray JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getAffinity0 (JNIEnv *env, jclass c) { +#ifdef __linux__ // The default size of the structure supports 1024 CPUs, should be enough // for now In the future we can use dynamic sets, which can support more // CPUs, given OS can handle them as well @@ -53,6 +56,9 @@ JNIEXPORT jbyteArray JNICALL Java_software_chronicle_enterprise_internals_impl_N env->SetByteArrayRegion(ret, 0, size, bytes); return ret; +#else + throw std::runtime_error("Not supported"); +#endif } /* @@ -63,6 +69,7 @@ JNIEXPORT jbyteArray JNICALL Java_software_chronicle_enterprise_internals_impl_N JNIEXPORT void JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_setAffinity0 (JNIEnv *env, jclass c, jbyteArray affinity) { +#ifdef __linux__ cpu_set_t mask; const size_t size = sizeof(mask); CPU_ZERO(&mask); @@ -71,6 +78,9 @@ JNIEXPORT void JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA memcpy(&mask, bytes, size); sched_setaffinity(0, size, &mask); +#else + throw std::runtime_error("Not supported"); +#endif } /* @@ -80,7 +90,12 @@ JNIEXPORT void JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA */ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getProcessId0 (JNIEnv *env, jclass c) { +#ifndef __linux__ + throw std::runtime_error("Not supported"); +#else + return (jint) getpid(); +#endif } /* @@ -90,7 +105,12 @@ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA */ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getThreadId0 (JNIEnv *env, jclass c) { +#ifndef __linux__ + throw std::runtime_error("Not supported"); +#else + return (jint) (pid_t) syscall (SYS_gettid); +#endif } /* @@ -100,6 +120,11 @@ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeA */ JNIEXPORT jint JNICALL Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getCpu0 (JNIEnv *env, jclass c) { +#ifndef __linux__ + throw std::runtime_error("Not supported"); +#else + return (jint) sched_getcpu(); +#endif } From 830b24f0716104d44e3ac65172746914290c90e1 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 11 Jul 2024 18:06:12 +0100 Subject: [PATCH 151/226] Retrying acquiring a lock after failure to obtain lock file should be an info message, Fixes #130 --- affinity/src/main/java/net/openhft/affinity/LockInventory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index 2ca7eb39e..f1b9b1a6d 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -89,7 +89,7 @@ private static boolean updateLockForCurrentThread(final boolean bind, final Affi throw e; } catch (IOException e) { - LOGGER.warn("Error occurred acquiring lock", e); + LOGGER.info("Error occurred acquiring lock, trying another " + e); } return false; } From ef4c9d0bfc4517a7c8a2afcbdf272bf67653cd64 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Jul 2024 17:54:28 +0100 Subject: [PATCH 152/226] Updating to bom version 2.26ea26 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index ef717e9d5..ec8c8e166 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea26 pom import From 7a51a6bc2440d5eca4eaaf9c38a0d913bb205087 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Jul 2024 17:54:50 +0100 Subject: [PATCH 153/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.26ea5 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 6ab139997..75fd793e9 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea5-SNAPSHOT + 3.26ea5 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea5 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index ec8c8e166..51dd91634 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea5-SNAPSHOT + 3.26ea5 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + Java-Thread-Affinity-3.26ea5 diff --git a/pom.xml b/pom.xml index 4c0fee020..b5c9c6806 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea5-SNAPSHOT + 3.26ea5 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea5 From 439e7be8180dcd982fc82a070e56f9683a4ea7cb Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Jul 2024 17:54:54 +0100 Subject: [PATCH 154/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 75fd793e9..3edb7f160 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea5 + 3.26ea6-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea5 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 51dd91634..f27fb9f6d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea5 + 3.26ea6-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea5 + Java-Thread-Affinity-3.26ea4 diff --git a/pom.xml b/pom.xml index b5c9c6806..0d24f5c1e 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea5 + 3.26ea6-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea5 + ea From 9d92e04c421a491a2389b49fc473f79229bdec05 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 19 Jul 2024 17:55:09 +0100 Subject: [PATCH 155/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index f27fb9f6d..65f0dd99d 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea26 + 2.26ea-SNAPSHOT pom import From 7f2e43e8d18a9cb0a5425aeffa9935a49093a682 Mon Sep 17 00:00:00 2001 From: Jerry Shea Date: Mon, 7 Oct 2024 11:20:24 +1100 Subject: [PATCH 156/226] fix NPE --- .../net/openhft/affinity/LockInventory.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/affinity/src/main/java/net/openhft/affinity/LockInventory.java b/affinity/src/main/java/net/openhft/affinity/LockInventory.java index f1b9b1a6d..25714b1d1 100644 --- a/affinity/src/main/java/net/openhft/affinity/LockInventory.java +++ b/affinity/src/main/java/net/openhft/affinity/LockInventory.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.nio.channels.ClosedByInterruptException; +import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; @@ -117,6 +118,24 @@ public final synchronized void set(CpuLayout cpuLayout) { } locks[cpuLayout.threadId(layoutId)] = lock; } + shrink(physicalCoreLocks); + } + + /** + * If some CPUs are hyper-threaded, but not others, fix up the HT CPUs + */ + private void shrink(NavigableMap physicalCoreLocks) { + for (Map.Entry e : physicalCoreLocks.entrySet()) { + final AffinityLock[] locks = e.getValue(); + for (int i=0; i Date: Mon, 14 Oct 2024 12:11:48 +0100 Subject: [PATCH 157/226] Updating to bom version 2.26ea50 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 65f0dd99d..28b0d7136 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.26ea50 pom import From 14153ba8f339f13e54015bbc7aaa3e816f580e0e Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 14 Oct 2024 12:12:07 +0100 Subject: [PATCH 158/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.26ea6 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 3edb7f160..64931363a 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea6-SNAPSHOT + 3.26ea6 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea6 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 28b0d7136..6235f5a5f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea6-SNAPSHOT + 3.26ea6 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + Java-Thread-Affinity-3.26ea6 diff --git a/pom.xml b/pom.xml index 0d24f5c1e..cf2b41a59 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea6-SNAPSHOT + 3.26ea6 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.26ea6 From 3969334cfdebcf8dde596ee26baede100bb0470f Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 14 Oct 2024 12:12:11 +0100 Subject: [PATCH 159/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 64931363a..6219ae0cd 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.26ea6 + 3.26ea7-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea6 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 6235f5a5f..af2486979 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.26ea6 + 3.26ea7-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea6 + Java-Thread-Affinity-3.26ea4 diff --git a/pom.xml b/pom.xml index cf2b41a59..95460b583 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.26ea6 + 3.26ea7-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea6 + ea From 59952c6f297cf837288b2c9466c0c7bc216be7ad Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Mon, 14 Oct 2024 12:12:25 +0100 Subject: [PATCH 160/226] Reverting back to bom version 2.26ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index af2486979..aeb2f4a2f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.26ea50 + 2.26ea-SNAPSHOT pom import From 8ba321ce658b3aa498e3785818e34ef19571d0ae Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 11 Nov 2024 16:21:23 +0000 Subject: [PATCH 161/226] x27ea release roll * Roll version to 2.27ea0-SNAPSHOT * Update pom versions to x.27 snapshot versions --- affinity-test/pom.xml | 6 +++--- affinity/pom.xml | 8 ++++---- pom.xml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 6219ae0cd..10a19d819 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,12 +21,12 @@ net.openhft java-parent-pom - 1.26.0 + 1.27ea0-SNAPSHOT affinity-test - 3.26ea7-SNAPSHOT + 3.27ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -41,7 +41,7 @@ net.openhft third-party-bom - 3.26.0 + 3.27ea0-SNAPSHOT pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index aeb2f4a2f..d5cbfa12b 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,12 +21,12 @@ net.openhft java-parent-pom - 1.26.0 + 1.27ea0-SNAPSHOT affinity - 3.26ea7-SNAPSHOT + 3.27ea0-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -42,14 +42,14 @@ net.openhft third-party-bom - 3.26.0 + 3.27ea0-SNAPSHOT pom import net.openhft chronicle-bom - 2.26ea-SNAPSHOT + 2.27ea-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index 95460b583..5eb4759bf 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,12 @@ net.openhft java-parent-pom - 1.26.0 + 1.27ea0-SNAPSHOT Java-Thread-Affinity - 3.26ea7-SNAPSHOT + 3.27ea0-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent From 79dfb0475aad8dcf2aa558c3c2d41dc78fe04cb7 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 13 Nov 2024 14:51:15 +0000 Subject: [PATCH 162/226] Bump parent pom and third party bom to release versions (#136) --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 10a19d819..232e47006 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0-SNAPSHOT + 1.27ea0 @@ -41,7 +41,7 @@ net.openhft third-party-bom - 3.27ea0-SNAPSHOT + 3.27ea0 pom import diff --git a/affinity/pom.xml b/affinity/pom.xml index d5cbfa12b..9e8839580 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0-SNAPSHOT + 1.27ea0 @@ -42,7 +42,7 @@ net.openhft third-party-bom - 3.27ea0-SNAPSHOT + 3.27ea0 pom import diff --git a/pom.xml b/pom.xml index 5eb4759bf..3f4a19ddc 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.27ea0-SNAPSHOT + 1.27ea0 From 39b85e398acf76c1c7aab9ccdbbea61e999f4891 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 15 Nov 2024 17:37:21 +0000 Subject: [PATCH 163/226] Updating to bom version 2.27ea0 --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index 9e8839580..74fe31427 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.27ea-SNAPSHOT + 2.27ea0 pom import From a4890dab52e0afe3b89217df6a9c2707a8734c11 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 15 Nov 2024 17:37:41 +0000 Subject: [PATCH 164/226] [maven-release-plugin] prepare release Java-Thread-Affinity-3.27ea0 --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 232e47006..eba35edf0 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.27ea0-SNAPSHOT + 3.27ea0 bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.27ea0 scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index 74fe31427..f41c60851 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.27ea0-SNAPSHOT + 3.27ea0 bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + Java-Thread-Affinity-3.27ea0 diff --git a/pom.xml b/pom.xml index 3f4a19ddc..9982c35aa 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.27ea0-SNAPSHOT + 3.27ea0 pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - ea + Java-Thread-Affinity-3.27ea0 From 880125221b17a20e9a44c3d50809c6495d45ac72 Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 15 Nov 2024 17:37:44 +0000 Subject: [PATCH 165/226] [maven-release-plugin] prepare for next development iteration --- affinity-test/pom.xml | 4 ++-- affinity/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index eba35edf0..97b6857dc 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -26,7 +26,7 @@ affinity-test - 3.27ea0 + 3.27ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity-test @@ -203,7 +203,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea0 + ea scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git diff --git a/affinity/pom.xml b/affinity/pom.xml index f41c60851..a308d774f 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -26,7 +26,7 @@ affinity - 3.27ea0 + 3.27ea1-SNAPSHOT bundle OpenHFT/Java-Thread-Affinity/affinity @@ -269,7 +269,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea0 + Java-Thread-Affinity-3.26ea4 diff --git a/pom.xml b/pom.xml index 9982c35aa..d6bd9c4a0 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ Java-Thread-Affinity - 3.27ea0 + 3.27ea1-SNAPSHOT pom OpenHFT/Java-Thread-Affinity Parent @@ -42,7 +42,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.27ea0 + ea From 28d8ca876d57ceb3b40ca6e09bd10d8f883ad63d Mon Sep 17 00:00:00 2001 From: hft-team-city Date: Fri, 15 Nov 2024 17:37:59 +0000 Subject: [PATCH 166/226] Reverting back to bom version 2.27ea-SNAPSHOT --- affinity/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/affinity/pom.xml b/affinity/pom.xml index a308d774f..6e84f2418 100644 --- a/affinity/pom.xml +++ b/affinity/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.27ea0 + 2.27ea-SNAPSHOT pom import From 36c1cec731014df49e16f55419d45f7919178a56 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 22 May 2025 15:16:29 +0100 Subject: [PATCH 167/226] Update copyright year to 2025 in multiple files --- LICENSE | 2 +- affinity-test/pom.xml | 2 +- .../main/java/net/openhft/affinity/osgi/OSGiPlaceholder.java | 2 +- .../test/java/net/openhft/affinity/osgi/OSGiBundleTest.java | 2 +- .../src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java | 2 +- affinity/pom.xml | 2 +- affinity/src/main/c/net_openhft_ticker_impl_JNIClock.cpp | 2 +- ...are_chronicle_enterprise_internals_impl_NativeAffinity.cpp | 2 +- ...hronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c | 2 +- affinity/src/main/java/net/openhft/affinity/Affinity.java | 2 +- affinity/src/main/java/net/openhft/affinity/AffinityLock.java | 2 +- .../main/java/net/openhft/affinity/AffinityStrategies.java | 2 +- .../src/main/java/net/openhft/affinity/AffinityStrategy.java | 2 +- .../main/java/net/openhft/affinity/AffinityThreadFactory.java | 2 +- .../src/main/java/net/openhft/affinity/BootClassPath.java | 2 +- affinity/src/main/java/net/openhft/affinity/CpuLayout.java | 2 +- affinity/src/main/java/net/openhft/affinity/IAffinity.java | 2 +- affinity/src/main/java/net/openhft/affinity/LockCheck.java | 2 +- .../src/main/java/net/openhft/affinity/LockInventory.java | 2 +- .../main/java/net/openhft/affinity/MicroJitterSampler.java | 4 +--- .../src/main/java/net/openhft/affinity/impl/LinuxHelper.java | 2 +- .../main/java/net/openhft/affinity/impl/LinuxJNAAffinity.java | 2 +- .../src/main/java/net/openhft/affinity/impl/NoCpuLayout.java | 2 +- .../src/main/java/net/openhft/affinity/impl/NullAffinity.java | 2 +- .../main/java/net/openhft/affinity/impl/OSXJNAAffinity.java | 2 +- .../main/java/net/openhft/affinity/impl/PosixJNAAffinity.java | 2 +- .../java/net/openhft/affinity/impl/SolarisJNAAffinity.java | 2 +- .../src/main/java/net/openhft/affinity/impl/Utilities.java | 2 +- .../main/java/net/openhft/affinity/impl/VanillaCpuLayout.java | 2 +- .../main/java/net/openhft/affinity/impl/VersionHelper.java | 2 +- .../java/net/openhft/affinity/impl/WindowsJNAAffinity.java | 2 +- .../affinity/lockchecker/FileLockBasedLockChecker.java | 4 +--- .../java/net/openhft/affinity/lockchecker/LockChecker.java | 4 +--- .../java/net/openhft/affinity/lockchecker/LockReference.java | 4 +--- .../main/java/net/openhft/affinity/main/AffinityTestMain.java | 4 +--- affinity/src/main/java/net/openhft/ticker/ITicker.java | 2 +- affinity/src/main/java/net/openhft/ticker/Ticker.java | 2 +- affinity/src/main/java/net/openhft/ticker/impl/JNIClock.java | 2 +- .../src/main/java/net/openhft/ticker/impl/SystemClock.java | 2 +- .../chronicle/enterprise/internals/impl/NativeAffinity.java | 2 +- .../test/java/net/openhft/affinity/AffinityLockBindMain.java | 2 +- .../src/test/java/net/openhft/affinity/AffinityLockMain.java | 2 +- .../src/test/java/net/openhft/affinity/AffinityLockTest.java | 2 +- .../test/java/net/openhft/affinity/AffinitySupportMain.java | 2 +- .../java/net/openhft/affinity/AffinityThreadFactoryMain.java | 2 +- .../src/test/java/net/openhft/affinity/BaseAffinityTest.java | 4 +--- .../src/test/java/net/openhft/affinity/BootClassPathTest.java | 4 +--- .../test/java/net/openhft/affinity/FileLockLockCheckTest.java | 2 +- .../src/test/java/net/openhft/affinity/InterrupedThread.java | 2 +- .../src/test/java/net/openhft/affinity/LockCheckTest.java | 2 +- .../java/net/openhft/affinity/MultiProcessAffinityTest.java | 4 +--- .../net/openhft/affinity/impl/AbstractAffinityImplTest.java | 2 +- .../java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java | 2 +- .../java/net/openhft/affinity/impl/NativeAffinityImpTest.java | 2 +- .../java/net/openhft/affinity/impl/PosixJNAAffinityTest.java | 2 +- .../java/net/openhft/affinity/impl/VanillaCpuLayoutTest.java | 2 +- .../java/net/openhft/affinity/impl/VersionHelperTest.java | 2 +- .../affinity/testimpl/TestFileLockBasedLockChecker.java | 4 +--- .../src/test/java/net/openhft/ticker/impl/JNIClockTest.java | 2 +- .../chronicle/enterprise/internals/JnaAffinityTest.java | 2 +- .../chronicle/enterprise/internals/NativeAffinityTest.java | 2 +- affinity/src/test/resources/i7.properties | 2 +- pom.xml | 2 +- 63 files changed, 63 insertions(+), 81 deletions(-) diff --git a/LICENSE b/LICENSE index a1993e4de..f7f8b7f7d 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2014-2018 Chronicle Software Ltd + Copyright 2014-2025 chronicle.software Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/affinity-test/pom.xml b/affinity-test/pom.xml index 97b6857dc..e90b2d811 100644 --- a/affinity-test/pom.xml +++ b/affinity-test/pom.xml @@ -1,6 +1,6 @@ - sonatype-nexus-staging - https://oss.sonatype.org/content/repositories/staging + + true + + chronicle-enterprise-snapshots + Snapshot Repository + https://nexus.chronicle.software/content/repositories/snapshots + + true + chronicle-enterprise-release + https://nexus.chronicle.software/content/repositories/releases @@ -269,7 +276,7 @@ scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git scm:git:git@github.com:OpenHFT/Java-Thread-Affinity.git - Java-Thread-Affinity-3.26ea4 + ea From c7e60bb74ca99a5cc2eea78a0a3f1630a4921dd5 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 11:29:12 +0100 Subject: [PATCH 169/226] Add requirements document for Java Thread Affinity library and update README with OS support details --- README.adoc | 129 +++++++- affinity/src/main/adoc/requirements.adoc | 297 ++++++++++++++++++ .../openhft/affinity/impl/LinuxHelper.java | 6 +- 3 files changed, 425 insertions(+), 7 deletions(-) create mode 100644 affinity/src/main/adoc/requirements.adoc diff --git a/README.adoc b/README.adoc index 773c4ffa7..91b0eeb06 100644 --- a/README.adoc +++ b/README.adoc @@ -17,6 +17,20 @@ OpenHFT Java Thread Affinity library See https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java[affinity/src/test/java] for working examples of how to use this library. +=== Supported operating systems + +The library detects the running platform in `Affinity.java` and selects an +implementation for that OS. Features differ between systems: + +* *Linux* - full affinity control via JNA. The implementation can get and set + thread affinity, query the current CPU, and obtain process and thread IDs. +* *Windows* - thread affinity is managed through the kernel API. Process and + thread IDs are available, while `getCpu()` returns `-1`. +* *macOS* - provides process and thread IDs but does not modify affinity and + reports the CPU id as `-1`. +* *Solaris* - mirrors the macOS implementation: only process and thread IDs are + returned with no affinity or CPU querying support. + === Changes * V3.2.0 - Add support for text configuration @@ -47,6 +61,12 @@ for the artifacts `jna` and `jna-platform` in the project's `pom` file. sudo yum install jna +=== Installing JNA on Windows + + choco install jna + +Or download jna.jar and jna-platform.jar from the JNA project and add them to your classpath. + === How does CPU allocation work? The library will read your `/proc/cpuinfo` if you have one or provide one and it will determine your CPU layout. If you don't have one it will assume every CPU is on one CPU socket. @@ -54,7 +74,20 @@ The library looks for isolated CPUs determined by looking at the CPUs you are no i.e. if you have 16 CPUs but 8 of them are not available for general use (as determined by the affinity of the process on startup) it will start assigning to those CPUs. Note: if you have more than one process using this library you need to specify which CPUs the process can use otherwise it will assign the same CPUs to both processes. -To control which CPUs a process can use, add -Daffinity.reserved={cpu-mask-in-hex} to the command line of the process. + +To control which CPUs a process can use, add `-Daffinity.reserved={cpu-mask-in-hex}` +to the command line of the process. The mask is a hexadecimal bit mask without +the `0x` prefix where bit `0` represents CPU `0`, bit `1` represents CPU `1` and +so on. Multiple CPUs can be specified by setting more than one bit. + +For example: + +* `-Daffinity.reserved=2` reserves only CPU `1`. +* `-Daffinity.reserved=6` reserves CPUs `1` and `2`. +* `-Daffinity.reserved=10` reserves CPUs `1` and `3` (hexadecimal `a`). + +Use an appropriate mask when starting each process to avoid reserving the same +cores for multiple JVMs. Note: the CPU 0 is reserved for the Operating System, it has to run somewhere. @@ -76,6 +109,21 @@ To isolate the 1st and 3rd CPU cores (CPU numbers start from 0) on your system, isolcpus=1,3 +Using GRUB +[source] +---- +sudo sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="isolcpus=1,3 /' /etc/default/grub +sudo update-grub +sudo reboot +---- + +Using systemd-boot +[source] +---- +sudo sed -i 's/^options \(.*\)/options \1 isolcpus=1,3/' /boot/loader/entries/*.conf +sudo reboot +---- + == Using AffinityLock === Acquiring a CPU lock for a thread @@ -127,7 +175,21 @@ try (final AffinityLock al = AffinityLock.acquireLock()) { t.start(); } ---- -In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. +In this example, the library will prefer a free CPU on the same Socket as the first thread, otherwise it will pick any free CPU. + +=== Affinity strategies +The `AffinityStrategies` enum defines hints for selecting a CPU relative to an existing lock. + +[options="header",cols="1,3"] +|=== +| Strategy | Meaning + +|`ANY`|Use any available CPU. +|`SAME_CORE`|Select a CPU on the same core. +|`SAME_SOCKET`|Select a CPU on the same socket but a different core. +|`DIFFERENT_CORE`|Select a CPU on another core (possibly another socket). +|`DIFFERENT_SOCKET`|Select a CPU on a different socket. +|=== === Getting the thread id You can get the current thread id using @@ -157,10 +219,50 @@ long reservedAffinity = AffinityLock.RESERVED_AFFINITY; ---- If you want to get/set the affinity directly you can do [source, java] ----- +---- long currentAffinity = AffinitySupport.getAffinity(); AffinitySupport.setAffinity(1L << 5); // lock to CPU 5. ----- +---- + +=== Understanding dumpLocks() output + +Several examples print the current CPU assignments using `AffinityLock.dumpLocks()`. +Each line of the output begins with the zero based CPU id followed by the status +of that CPU. Example output might look like: + +[source] +---- +0: Reserved for this application +1: Thread[reader,5,main] alive=true +2: General use CPU +3: CPU not available +---- + +The number on each line is the logical CPU index as recognised by the library. +The text after the colon describes whether that CPU is free, reserved or already +bound to a thread. Use these indices when calling `AffinityLock.acquireLock(n)` +or when constructing explicit affinity masks. + +=== Lock file directory + +AffinityLock stores a small lock file for each CPU. These files are placed in +the directory specified by the `java.io.tmpdir` system property, which by +default points to your system's temporary directory (usually `/tmp` on Linux). + +If you want to keep the lock files elsewhere, set this property before using any +affinity APIs: + +[source, bash] +---- +java -Djava.io.tmpdir=/path/to/dir ... +---- + +or in code + +[source, java] +---- +System.setProperty("java.io.tmpdir", "/path/to/dir"); +---- === Debugging affinity state @@ -185,6 +287,25 @@ $ for i in "$(ls cpu-*)"; ---- +== Using AffinityThreadFactory + +`AffinityThreadFactory` binds each thread it creates according to a set of +`AffinityStrategy` rules. This allows executors to automatically run tasks on +cores selected by the library. + +[source, java] +---- +ExecutorService es = Executors.newFixedThreadPool(4, + new AffinityThreadFactory("worker", + AffinityStrategies.SAME_CORE, + AffinityStrategies.DIFFERENT_SOCKET, + AffinityStrategies.ANY)); +es.submit(() -> { + // your task here +}); +System.out.println("\nThe assignment of CPUs is\n" + AffinityLock.dumpLocks()); +---- + == Support Material https://groups.google.com/forum/?hl=en-GB#!forum/java-thread-affinity[Java Thread Affinity support group] diff --git a/affinity/src/main/adoc/requirements.adoc b/affinity/src/main/adoc/requirements.adoc new file mode 100644 index 000000000..f15cf0ed4 --- /dev/null +++ b/affinity/src/main/adoc/requirements.adoc @@ -0,0 +1,297 @@ += Requirements Document: Java Thread Affinity +Author: Gemini AI +Date: 23 May 2025 +Version: 1.0 +:toc: left +:toclevels: 3 +:sectnums: + +== 1. Introduction + +This document outlines the requirements for the *Java Thread Affinity* library. The primary purpose of this library is to provide Java applications with the capability to control Central Processing Unit (CPU) affinity for their threads. This allows developers to bind specific threads to designated CPU cores, which can lead to performance improvements, especially in latency-sensitive applications, by reducing context switching and improving cache utilisation. + +The library aims to offer a cross-platform API, with the most comprehensive support for Linux systems, leveraging Java Native Access (JNA) and, where applicable, Java Native Interface (JNI) for low-level system interactions. + +== 2. Scope + +The scope of the Java Thread Affinity project includes: + +* Providing mechanisms to get and set thread affinity on supported operating systems. +* Offering a CPU locking mechanism (`AffinityLock`) to manage core reservations for threads or entire cores. +* Detecting or allowing specification of the CPU layout (sockets, cores, threads per core). +* Providing a high-resolution timer. +* Supporting inter-process lock checking for CPU core reservations. +* Delivering a thread factory that assigns affinity to newly created threads. +* Packaging the core library and an OSGi-compatible test bundle. + +== 3. Definitions, Acronyms, and Abbreviations + +* *CPU*: Central Processing Unit +* *JNA*: Java Native Access +* *JNI*: Java Native Interface +* *OS*: Operating System +* *PID*: Process Identifier +* *OSGi*: Open Service Gateway initiative +* *POM*: Project Object Model (Maven) +* *API*: Application Programming Interface + +== 4. References + +* Project Repository: https://github.com/OpenHFT/Java-Thread-Affinity +* JNA: https://github.com/java-native-access/jna + +== 5. Project Overview + +The *Java Thread Affinity* library enables fine-grained control over which CPU cores Java threads execute on. This is particularly beneficial for high-performance computing and low-latency applications where minimising jitter and maximising cache efficiency is critical. The library abstracts OS-specific details, providing a unified Java API. + +=== 5.1. Purpose + +* To allow Java threads to be bound to specific CPU cores. +* To provide tools for understanding and managing CPU topology from within a Java application. +* To offer a high-resolution timing mechanism. + +=== 5.2. Benefits + +* _Performance Improvement_: Reduced thread migration and context switching. +* _Cache Efficiency_: Better utilisation of CPU caches (L1, L2, L3). +* _Jitter Reduction_: More predictable thread execution times. + +== 6. Functional Requirements + +=== 6.1. Core Affinity Control (net.openhft.affinity.Affinity) + +* *FR1*: The system _shall_ allow setting the affinity of the current thread to a specific CPU core or a set of cores (BitSet). +** `Affinity.setAffinity(BitSet affinity)` +** `Affinity.setAffinity(int cpu)` +* *FR2*: The system _shall_ allow retrieving the current affinity mask of the current thread. +** `Affinity.getAffinity()` +* *FR3*: The system _shall_ allow querying the logical CPU ID the current thread is running on. +** `Affinity.getCpu()` +* *FR4*: The system _shall_ allow retrieving the native process ID of the current Java process. +** `IAffinity.getProcessId()` +* *FR5*: The system _shall_ allow retrieving the native thread ID of the current Java thread. +** `IAffinity.getThreadId()` +** `Affinity.setThreadId()` (to update `Thread.tid` via reflection if available) + +=== 6.2. CPU Lock Management (net.openhft.affinity.AffinityLock) + +* *FR6.1*: The system _shall_ provide a mechanism to acquire an exclusive lock on an available CPU core for the current thread. +** `AffinityLock.acquireLock()` +** `AffinityLock.acquireLock(boolean bind)` +** `AffinityLock.acquireLock(int cpuId)` +** `AffinityLock.acquireLock(String desc)` (e.g., "last", "last-N", "N", "any", "none", "csv:1,2,3") +* *FR6.2*: The system _shall_ provide a mechanism to acquire an exclusive lock on an entire physical core (including all its logical CPUs/hyper-threads). +** `AffinityLock.acquireCore()` +** `AffinityLock.acquireCore(boolean bind)` +* *FR6.3*: Acquired locks _shall_ be releasable, restoring the thread's affinity to a base state or a defined default. +** `AffinityLock.release()` +** `AffinityLock.close()` (for try-with-resources) +* *FR6.4*: The system _shall_ support affinity strategies for acquiring new locks relative to existing locks (e.g., same core, same socket, different core, different socket). +** `AffinityLock.acquireLock(AffinityStrategy... strategies)` +** `AffinityStrategies` enum: `ANY`, `SAME_CORE`, `SAME_SOCKET`, `DIFFERENT_CORE`, `DIFFERENT_SOCKET`. +* *FR6.5*: The system _shall_ provide a method to dump the current status of all CPU locks managed by the library. +** `AffinityLock.dumpLocks()` +* *FR6.6*: The system _shall_ allow querying if a lock is allocated and bound. +** `AffinityLock.isAllocated()` +** `AffinityLock.isBound()` + +=== 6.3. CPU Layout Detection (net.openhft.affinity.CpuLayout) + +* *FR7.1*: On Linux, the system _shall_ attempt to automatically detect the CPU layout (sockets, cores per socket, threads per core) by parsing `/proc/cpuinfo`. +** `VanillaCpuLayout.fromCpuInfo()` +* *FR7.2*: The system _shall_ allow applications to programmatically define the CPU layout. +** `AffinityLock.cpuLayout(CpuLayout cpuLayout)` +* *FR7.3*: The CPU layout _shall_ provide information about: +** Total number of logical CPUs: `CpuLayout.cpus()` +** Number of sockets: `CpuLayout.sockets()` +** Cores per socket: `CpuLayout.coresPerSocket()` +** Threads per core: `CpuLayout.threadsPerCore()` +** Mapping a logical CPU ID to its socket, core, and thread ID: `socketId(int)`, `coreId(int)`, `threadId(int)`. +** Hyper-threaded pair for a CPU: `pair(int)`. + +=== 6.4. High-Resolution Timer (net.openhft.ticker.Ticker) + +* *FR8.1*: The system _shall_ provide a high-resolution time source. +** `Ticker.ticks()` (raw timer ticks) +** `Ticker.nanoTime()` (ticks converted to nanoseconds) +* *FR8.2*: If native JNI components are available and loaded (specifically `libCEInternals.so`), the timer _shall_ attempt to use `rdtsc` (Read Time-Stamp Counter). +** `JNIClock.rdtsc0()` +* *FR8.3*: If JNI-based `rdtsc` is not available, the timer _shall_ fall back to `System.nanoTime()`. +** `SystemClock.INSTANCE` +* *FR8.4*: The timer _shall_ provide methods to convert ticks to nanoseconds and microseconds. +** `ITicker.toNanos(long ticks)` +** `ITicker.toMicros(double ticks)` + +=== 6.5. OS-Specific Implementations (net.openhft.affinity.impl) + +* *FR9.1*: The system _shall_ provide tailored implementations of `IAffinity` for different operating systems: +** *Linux*: Full affinity control, CPU ID, Process ID, Thread ID via JNA (`LinuxJNAAffinity`, `PosixJNAAffinity`) or JNI (`NativeAffinity`). +** *Windows*: Thread affinity control, Process ID, Thread ID via JNA (`WindowsJNAAffinity`). `getCpu()` returns -1. +** *macOS*: Process ID, Thread ID via JNA (`OSXJNAAffinity`). No affinity modification; `getCpu()` returns -1. +** *Solaris*: Process ID, Thread ID via JNA (`SolarisJNAAffinity`). No affinity modification; `getCpu()` returns -1. +* *FR9.2*: A `NullAffinity` implementation _shall_ be used as a fallback if no suitable native implementation can be loaded or for unsupported OS. + +=== 6.6. Affinity Thread Factory (net.openhft.affinity.AffinityThreadFactory) + +* *FR10.1*: The system _shall_ provide a `ThreadFactory` that assigns affinity to newly created threads based on specified `AffinityStrategy` rules. +** `new AffinityThreadFactory(String name, AffinityStrategy... strategies)` +* *FR10.2*: If no strategies are provided, `AffinityStrategies.ANY` _shall_ be used by default. + +=== 6.7. Inter-Process Lock Checking (net.openhft.affinity.lockchecker) + +* *FR11.1*: On Linux, the system _shall_ provide a mechanism to check if a specific CPU core is free or already locked by another process. +** `LockCheck.isCpuFree(int cpu)` +* *FR11.2*: This mechanism _shall_ use file-based locks located in the directory specified by the `java.io.tmpdir` system property. +** `FileLockBasedLockChecker` +* *FR11.3*: The system _shall_ allow obtaining and releasing these inter-process locks for specified CPU IDs. +** `LockChecker.obtainLock(int id, int id2, String metaInfo)` +** `LockChecker.releaseLock(int id)` +* *FR11.4*: The system _shall_ store meta-information (e.g., PID of the locking process) within the lock file and allow its retrieval. +** `LockChecker.getMetaInfo(int id)` + +=== 6.8. Native Code Compilation (C/C++) + +* *FR12.1*: The system _shall_ include C/C++ source code for native functions required for affinity and timer operations on Linux and macOS. + ** `software_chronicle_enterprise_internals_impl_NativeAffinity.cpp` (Linux) + ** `software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c` (macOS) + ** `net_openhft_ticker_impl_JNIClock.cpp` (for `rdtsc`) +* *FR12.2*: A Makefile _shall_ be provided to compile the native C/C++ code into a shared library (`libCEInternals.so`). +* *FR12.3*: The Java code _shall_ load this native library if available. +** `software.chronicle.enterprise.internals.impl.NativeAffinity.loadAffinityNativeLibrary()` + +== 7. Non-Functional Requirements + +* *NFR1. Platform Support*: +** *Primary Support*: Linux (full functionality). +** *Partial Support*: Windows (affinity setting, PID/TID, no `getCpu()`). +** *Limited Support*: macOS, Solaris (PID/TID only, no affinity setting or `getCpu()`). +* *NFR2. Dependencies*: +** *JNA*: `net.java.dev.jna:jna`, `net.java.dev.jna:jna-platform`. Version 5.x or higher is recommended for full functionality. The project currently uses version 4.4.0 (as per README, though POMs might show updates). +** *SLF4J API*: `org.slf4j:slf4j-api` for logging. +** *JetBrains Annotations*: `org.jetbrains:annotations` for code quality. +* *NFR3. Performance*: The library _should_ introduce minimal overhead. Native calls _should_ be efficient. The primary goal is to enable performance improvements in the client application. +* *NFR4. Licensing*: The project _shall_ be licensed under the Apache License, Version 2.0. +* *NFR5. Build System*: The project _shall_ use Apache Maven for building and dependency management. +* *NFR6. Language*: +** Core library _shall_ be implemented in Java (1.8+ as per POM). +** Native components _shall_ be implemented in C/C++. +* *NFR7. Usability*: +** The API _should_ be clear and relatively simple to use. +** Javadoc _shall_ be provided for public APIs. +** Example usage _shall_ be available (e.g., in test sources and README). +* *NFR8. Error Handling and Resilience*: +** The library _shall_ degrade gracefully if JNA or native libraries are not available or if an OS does not support certain features (e.g., falling back to `NullAffinity`). +** Errors during native calls _should_ be appropriately logged and/or propagated as exceptions. +* *NFR9. Configuration*: +** Reserved CPUs for the application _shall_ be configurable via the system property `affinity.reserved={hex-mask}`. +** The lock file directory _shall_ default to `java.io.tmpdir` and be overridable by setting this system property. +* *NFR10. OSGi Support*: The `affinity-test` module _shall_ be packaged as an OSGi bundle, demonstrating OSGi compatibility. +* *NFR11. Language Style*: Code and documentation _shall_ use British English, except for established technical US spellings (e.g., `synchronized`). + +== 8. System Architecture + +=== 8.1. High-Level Architecture + +The Java Thread Affinity library is a Java-based system that interfaces with the underlying operating system through JNA (primarily) and JNI (for specific `libCEInternals.so` functionalities). It abstracts OS-specific system calls related to thread affinity, CPU information, and timing. + +=== 8.2. Key Components + +* *`net.openhft.affinity.Affinity`*: Main public API facade for basic affinity operations. +* *`net.openhft.affinity.IAffinity`*: Interface defining the contract for OS-specific implementations. +** Concrete Implementations: `LinuxJNAAffinity`, `WindowsJNAAffinity`, `OSXJNAAffinity`, `SolarisJNAAffinity`, `PosixJNAAffinity`, `NativeAffinity` (JNI), `NullAffinity`. +* *`net.openhft.affinity.AffinityLock`*: Manages CPU reservations and bindings. +* *`net.openhft.affinity.LockInventory`*: Tracks the state of CPU locks based on `CpuLayout`. +* *`net.openhft.affinity.CpuLayout`*: Interface for CPU topology information. +** `VanillaCpuLayout`: Parses `/proc/cpuinfo` or properties files. +** `NoCpuLayout`: Default layout if detection fails. +* *`net.openhft.affinity.AffinityStrategies`*: Enum defining strategies for selecting CPUs. +* *`net.openhft.affinity.AffinityThreadFactory`*: A `java.util.concurrent.ThreadFactory` that sets affinity for new threads. +* *`net.openhft.ticker.Ticker`*: Provides high-resolution time. +** `JNIClock`: Uses `rdtsc` via JNI. +** `SystemClock`: Uses `System.nanoTime()`. +* *`net.openhft.affinity.lockchecker.LockChecker`*: Interface for inter-process lock management. +** `FileLockBasedLockChecker`: Implementation using file system locks. +* *Native Code (`src/main/c`)*: C/C++ sources for `libCEInternals.so` providing functions like `getAffinity0`, `setAffinity0` (Linux JNI), `rdtsc0`. + +=== 8.3. Maven Modules + +* *`Java-Thread-Affinity` (Parent POM)*: Aggregates sub-modules. +** Group ID: `net.openhft` +** Artifact ID: `Java-Thread-Affinity` +* *`affinity` (Core Library)*: Contains the main library code, JNA/JNI integrations, and native sources. +** Artifact ID: `affinity` +** Packaging: `bundle` (OSGi compatible) +* *`affinity-test` (Test Module)*: Contains OSGi integration tests and example usage. +** Artifact ID: `affinity-test` +** Packaging: `bundle` + +== 9. Native Components (libCEInternals.so) + +The library can utilise an optional native shared library, `libCEInternals.so`, for certain operations, primarily on Linux. + +* *Purpose*: Provides direct JNI implementations for thread affinity and the `rdtsc` timer. +* *Source Location*: `Java-Thread-Affinity/affinity/src/main/c/` +* *Build*: Compiled using the `Makefile` in the source directory (typically invoked by Maven's `exec-maven-plugin`). +* *Key Native Functions Implemented*: +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getAffinity0` +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_setAffinity0` +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getCpu0` +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getProcessId0` +** `Java_software_chronicle_enterprise_internals_impl_NativeAffinity_getThreadId0` +** `Java_net_openhft_ticker_impl_JNIClock_rdtsc0` +* *Platform Specifics*: +** *Linux*: Uses `sched_getaffinity`, `sched_setaffinity`, `sched_getcpu`, `getpid`, `syscall(SYS_gettid)`. +** *macOS*: (Separate C file `software_chronicle_enterprise_internals_impl_NativeAffinity_MacOSX.c`) Uses `pthread_mach_thread_np`, `thread_policy_get`, `thread_policy_set`. Note: JNA implementations are generally preferred on macOS. +* *Loading*: The `NativeAffinity.java` class attempts to load `System.loadLibrary("CEInternals")`. + +== 10. API Overview + +A brief overview of the primary public classes and interfaces: + +* *`net.openhft.affinity.Affinity`*: +** Static utility methods for basic affinity operations: `getAffinity()`, `setAffinity(BitSet)`, `setAffinity(int cpu)`, `getCpu()`, `getThreadId()`. +** Manages selection of the appropriate `IAffinity` implementation. +* *`net.openhft.affinity.AffinityLock`*: +** Manages acquisition and release of CPU locks: `acquireLock()`, `acquireCore()`, `release()`, `close()`. +** Configures CPU layout: `cpuLayout(CpuLayout)`. +** Provides information about reserved CPUs: `BASE_AFFINITY`, `RESERVED_AFFINITY`. +* *`net.openhft.affinity.AffinityStrategies`*: +** Enum defining CPU selection strategies for `AffinityLock`. +* *`net.openhft.affinity.CpuLayout`*: +** Interface to describe the machine's CPU topology. +* *`net.openhft.affinity.IAffinity`*: +** Core interface implemented by OS-specific providers. +* *`net.openhft.ticker.Ticker`*: +** Static utility for accessing high-resolution time: `ticks()`, `nanoTime()`. +* *`net.openhft.affinity.AffinityThreadFactory`*: +** Implements `java.util.concurrent.ThreadFactory` to create threads with specific affinity settings. + +== 11. Build and Deployment + +* The project is built using Apache Maven. +* The main artifact `net.openhft:affinity` is an OSGi bundle. +* Dependencies are managed via `pom.xml` files, including a `third-party-bom` and `chronicle-bom`. +* The `make-c` profile in `affinity/pom.xml` triggers the compilation of native C code using `make`. +* The `maven-bundle-plugin` is used to generate OSGi manifest information. +* The `maven-scm-publish-plugin` is configured for publishing Javadoc to `gh-pages`. + +== 12. Testing + +The project includes a comprehensive suite of tests: + +* *Unit Tests*: Located in `affinity/src/test/java/`. +** `NativeAffinityTest`, `JnaAffinityTest`: Test core JNI/JNA functionalities. +** `AffinityLockTest`: Tests `AffinityLock` logic, including descriptions and inter-thread lock acquisition. +** `VanillaCpuLayoutTest`, `VanillaCpuLayoutPropertiesParseTest`: Test parsing of `cpuinfo` files and properties files for CPU layout. +** `TickerTest`, `JNIClockTest`: Test timer implementations. +** `LockCheckTest`, `FileLockLockCheckTest`: Test inter-process lock checking. +** `MultiProcessAffinityTest`: Tests affinity locking behavior across multiple Java processes. +* *OSGi Bundle Tests*: Located in `affinity-test/src/test/java/net/openhft/affinity/osgi/`. +** `OSGiBundleTest`: Verifies bundle activation and package exports in an OSGi environment using Pax Exam. +* *Test Resources*: Includes sample `cpuinfo` files for various architectures and corresponding properties files to test layout parsing. +** `affinity/src/test/resources/` +* *Test Infrastructure*: +** `BaseAffinityTest`: Provides common setup for tests, including temporary folder management for lock files. +** `chronicle-test-framework`: Used for some test utilities, like `JavaProcessBuilder` for multi-process tests. + +The tests cover various aspects including basic affinity setting, CPU layout parsing, lock management, multi-threading scenarios, multi-process contention, and OSGi integration. diff --git a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java index efde99972..df5cbbc3d 100644 --- a/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java +++ b/affinity/src/main/java/net/openhft/affinity/impl/LinuxHelper.java @@ -66,9 +66,9 @@ cpu_set_t sched_getaffinity() { return cpuset; } - public static void sched_setaffinity(final BitSet affinity) { - sched_setaffinity(0, affinity); - } + public static void sched_setaffinity(final BitSet affinity) { + sched_setaffinity(0, affinity); + } public static void sched_setaffinity(final int pid, final BitSet affinity) { final CLibrary lib = CLibrary.INSTANCE; From e6f2812ba24d880ca0afdc538d8162b907ba02bb Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 11:35:11 +0100 Subject: [PATCH 170/226] Enhance documentation for ITicker interface with detailed description of high resolution time source and utility methods --- .../main/java/net/openhft/ticker/ITicker.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/affinity/src/main/java/net/openhft/ticker/ITicker.java b/affinity/src/main/java/net/openhft/ticker/ITicker.java index 5438e51d8..0763f0871 100644 --- a/affinity/src/main/java/net/openhft/ticker/ITicker.java +++ b/affinity/src/main/java/net/openhft/ticker/ITicker.java @@ -17,8 +17,23 @@ package net.openhft.ticker; -/* - * Created by Peter Lawrey on 13/07/15. +/** + * Abstraction of a high resolution time source used throughout the library. + *

+ * Implementations may be based on {@link System#nanoTime()} or platform + * specific timers such as the processor's time stamp counter accessed via + * JNI. The {@linkplain #ticks() tick values} returned are therefore + * implementation dependent. They always increase monotonically but the unit + * they represent can vary from nanoseconds to CPU cycles. + *

+ * Utility methods are provided to convert these raw ticks into conventional + * time units. For example {@link #toNanos(long)} converts the supplied number + * of ticks to nanoseconds and {@link #toMicros(double)} converts them to + * microseconds. + *

+ * This interface is typically accessed via the {@link net.openhft.ticker.Ticker} + * helper class which selects the best available implementation for the + * running platform. */ public interface ITicker { long nanoTime(); From 32f317ae3a8ae1df8278056adb189f3bf64ceb59 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 23 May 2025 12:01:03 +0100 Subject: [PATCH 171/226] Code analysis fixes: Refactor code for consistency and readability, including assertion simplifications and formatting improvements --- .../openhft/affinity/osgi/OSGiBundleTest.java | 2 +- .../openhft/affinity/osgi/OSGiTestBase.java | 2 +- .../java/net/openhft/affinity/Affinity.java | 5 ++-- .../net/openhft/affinity/AffinityLock.java | 26 ++++++++++++------- .../affinity/AffinityThreadFactory.java | 12 ++++----- .../net/openhft/affinity/BootClassPath.java | 5 ++-- .../net/openhft/affinity/LockInventory.java | 12 ++++----- .../openhft/affinity/MicroJitterSampler.java | 1 + .../affinity/impl/LinuxJNAAffinity.java | 2 +- .../openhft/affinity/impl/NullAffinity.java | 2 +- .../openhft/affinity/impl/OSXJNAAffinity.java | 2 +- .../affinity/impl/PosixJNAAffinity.java | 2 +- .../affinity/impl/SolarisJNAAffinity.java | 2 +- .../affinity/impl/VanillaCpuLayout.java | 3 ++- .../openhft/affinity/impl/VersionHelper.java | 4 +-- .../lockchecker/FileLockBasedLockChecker.java | 10 +++---- .../affinity/main/AffinityTestMain.java | 7 ++--- .../net/openhft/ticker/impl/JNIClock.java | 5 ++-- .../openhft/affinity/AffinityLockTest.java | 15 ++++------- .../affinity/AffinityThreadFactoryMain.java | 10 +++---- .../affinity/MultiProcessAffinityTest.java | 19 ++++++++------ .../impl/AbstractAffinityImplTest.java | 8 ++---- .../enterprise/internals/JnaAffinityTest.java | 11 +++----- .../internals/NativeAffinityTest.java | 11 +++----- 24 files changed, 84 insertions(+), 94 deletions(-) diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java index 9d1cfee02..80949898f 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiBundleTest.java @@ -64,7 +64,7 @@ public void checkInject() { public void checkBundleState() { final Bundle bundle = findBundle(context, "net.openhft.affinity"); assertNotNull(bundle); - assertEquals(bundle.getState(), Bundle.ACTIVE); + assertEquals(Bundle.ACTIVE, bundle.getState()); } @Test diff --git a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java index b50b0a8ce..a1e9fcc96 100644 --- a/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java +++ b/affinity-test/src/test/java/net/openhft/affinity/osgi/OSGiTestBase.java @@ -29,7 +29,7 @@ public class OSGiTestBase { public static Option workspaceBundle(String projectName) { String baseDir = System.getProperty("main.basedir"); - String bundleDir = null; + String bundleDir; bundleDir = String.format("%s/%s/target/classes", baseDir, projectName); if (new File(bundleDir).exists()) { diff --git a/affinity/src/main/java/net/openhft/affinity/Affinity.java b/affinity/src/main/java/net/openhft/affinity/Affinity.java index 034602821..d4654749a 100644 --- a/affinity/src/main/java/net/openhft/affinity/Affinity.java +++ b/affinity/src/main/java/net/openhft/affinity/Affinity.java @@ -190,11 +190,10 @@ public static void setThreadId() { public static boolean isJNAAvailable() { if (JNAAvailable == null) { int majorVersion = Integer.parseInt(Native.VERSION.split("\\.")[0]); - if(majorVersion < 5) { + if (majorVersion < 5) { LOGGER.warn("Affinity library requires JNA version >= 5"); JNAAvailable = false; - } - else { + } else { try { Class.forName("com.sun.jna.Platform"); JNAAvailable = true; diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index 5954efcb4..2fcdb4d95 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -131,7 +131,7 @@ private static BitSet getReservedAffinity0() { reservedAffinity = reservedAffinity.trim(); long[] longs = new long[1 + (reservedAffinity.length() - 1) / 16]; int end = reservedAffinity.length(); - for(int i = 0; i < longs.length ; i++) { + for (int i = 0; i < longs.length; i++) { int begin = Math.max(0, end - 16); longs[i] = Long.parseLong(reservedAffinity.substring(begin, end), 16); end = begin; @@ -186,6 +186,9 @@ public static AffinityLock acquireLock(boolean bind) { * @return A handle for an affinity lock. */ public static AffinityLock acquireLock(int cpuId) { + if (cpuId < 0 || cpuId >= PROCESSORS) { + throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpuId); + } return acquireLock(true, cpuId, AffinityStrategies.ANY); } @@ -199,17 +202,18 @@ public static AffinityLock acquireLock(int cpuId) { * @return A handle for an affinity lock, or nolock if no available CPU in the array */ public static AffinityLock acquireLock(int[] cpus) { - for( int cpu : cpus ) - { + for (int cpu : cpus) { + if (cpu < 0 || cpu >= PROCESSORS) { + throw new IllegalArgumentException("cpuId must be between 0 and " + (PROCESSORS - 1) + ": " + cpu); + } AffinityLock lock = tryAcquireLock(true, cpu); - if(lock != null) - { + if (lock != null) { LOGGER.info("Acquired lock on CPU {}", cpu); return lock; } } - LOGGER.warn("Failed to lock any CPU in explicit list " + Arrays.toString(cpus)); + LOGGER.warn("Failed to lock any CPU in explicit list {}", Arrays.toString(cpus)); return LOCK_INVENTORY.noLock(); } @@ -228,7 +232,7 @@ public static AffinityLock acquireLockLastMinus(int n) { *