From 813ee038da4a31e4c7e539550d56ccd095946192 Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Mon, 10 Jun 2024 20:14:08 -0700 Subject: [PATCH] Acquire interruptLock for interruptImpl and isInterruptedImpl interruptImpl and isInterruptedImpl use the eetop/threadRef value. Acquiring interruptLock assures that the eetop/threadRef value won't change during interruptImpl and isInterruptedImpl. This will prevent crashes which happen when a stale eetop/threadRef value is used to invoke OMR thread library functions. Related: https://github.com/eclipse-openj9/openj9/issues/19544 Related: https://github.com/eclipse-openj9/openj9/issues/19598 Backport of https://github.com/ibmruntimes/openj9-openjdk-jdk/pull/803 Signed-off-by: Babneet Singh --- src/java.base/share/classes/java/lang/Thread.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/java.base/share/classes/java/lang/Thread.java b/src/java.base/share/classes/java/lang/Thread.java index 19c3cda11c6..044ecb666d0 100644 --- a/src/java.base/share/classes/java/lang/Thread.java +++ b/src/java.base/share/classes/java/lang/Thread.java @@ -25,7 +25,7 @@ /* * =========================================================================== - * (c) Copyright IBM Corp. 2021, 2023 All Rights Reserved + * (c) Copyright IBM Corp. 2021, 2024 All Rights Reserved * =========================================================================== */ @@ -1774,7 +1774,9 @@ public static boolean interrupted() { public boolean isInterrupted() { // use fully qualified name to avoid ambiguous class error if (com.ibm.oti.vm.VM.isJVMInSingleThreadedMode()) { - return isInterruptedImpl(); + synchronized (interruptLock) { + return isInterruptedImpl(); + } } return interrupted; } @@ -3031,7 +3033,9 @@ private void setPriority0(int newPriority) { } private void interrupt0() { - interruptImpl(); + synchronized (interruptLock) { + interruptImpl(); + } } private static void clearInterruptEvent() {