Skip to content

Commit

Permalink
Acquire interruptLock for interruptImpl and isInterruptedImpl
Browse files Browse the repository at this point in the history
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: eclipse-openj9/openj9#19544
Related: eclipse-openj9/openj9#19598

Backport of ibmruntimes/openj9-openjdk-jdk#803

Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
  • Loading branch information
babsingh committed Jun 18, 2024
1 parent e4d7f3c commit 813ee03
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2023 All Rights Reserved
* (c) Copyright IBM Corp. 2021, 2024 All Rights Reserved
* ===========================================================================
*/

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -3031,7 +3033,9 @@ private void setPriority0(int newPriority) {
}

private void interrupt0() {
interruptImpl();
synchronized (interruptLock) {
interruptImpl();
}
}

private static void clearInterruptEvent() {
Expand Down

0 comments on commit 813ee03

Please sign in to comment.