8322829: Refactor nioBlocker to avoid blocking while holding Thread's interrupt lock

Reviewed-by: jpai
This commit is contained in:
Alan Bateman 2024-01-09 07:05:27 +00:00
parent 07fce8eff2
commit 7286f5291d
6 changed files with 118 additions and 54 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -345,15 +345,20 @@ public class Thread implements Runnable {
* operation, if any. The blocker's interrupt method should be invoked
* after setting this thread's interrupt status.
*/
volatile Interruptible nioBlocker;
private Interruptible nioBlocker;
Interruptible nioBlocker() {
//assert Thread.holdsLock(interruptLock);
return nioBlocker;
}
/* Set the blocker field; invoked via jdk.internal.access.SharedSecrets
* from java.nio code
*/
static void blockedOn(Interruptible b) {
Thread me = Thread.currentThread();
synchronized (me.interruptLock) {
me.nioBlocker = b;
void blockedOn(Interruptible b) {
//assert Thread.currentThread() == this;
synchronized (interruptLock) {
nioBlocker = b;
}
}
@ -1699,15 +1704,19 @@ public class Thread implements Runnable {
checkAccess();
// thread may be blocked in an I/O operation
Interruptible blocker;
synchronized (interruptLock) {
Interruptible b = nioBlocker;
if (b != null) {
blocker = nioBlocker;
if (blocker != null) {
interrupted = true;
interrupt0(); // inform VM of interrupt
b.interrupt(this);
return;
blocker.interrupt(this);
}
}
if (blocker != null) {
blocker.postInterrupt();
return;
}
}
interrupted = true;
interrupt0(); // inform VM of interrupt