From 328a149d786f228892f806147798d2f110e31647 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 Signed-off-by: Babneet Singh --- src/java.base/share/classes/java/lang/Thread.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/lang/Thread.java b/src/java.base/share/classes/java/lang/Thread.java index 2297095b30d..4c7cf3019b6 100644 --- a/src/java.base/share/classes/java/lang/Thread.java +++ b/src/java.base/share/classes/java/lang/Thread.java @@ -1769,7 +1769,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; } @@ -3013,7 +3015,9 @@ private void setPriority0(int newPriority) { } private void interrupt0() { - interruptImpl(); + synchronized (interruptLock) { + interruptImpl(); + } } private static void clearInterruptEvent() {