mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8322829: Refactor nioBlocker to avoid blocking while holding Thread's interrupt lock
Reviewed-by: jpai
This commit is contained in:
parent
07fce8eff2
commit
7286f5291d
6 changed files with 118 additions and 54 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -852,18 +852,32 @@ final class VirtualThread extends BaseVirtualThread {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
void blockedOn(Interruptible b) {
|
||||
notifyJvmtiDisableSuspend(true);
|
||||
try {
|
||||
super.blockedOn(b);
|
||||
} finally {
|
||||
notifyJvmtiDisableSuspend(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public void interrupt() {
|
||||
if (Thread.currentThread() != this) {
|
||||
checkAccess();
|
||||
|
||||
// if current thread is a virtual thread then prevent it from being
|
||||
// suspended when entering or holding interruptLock
|
||||
Interruptible blocker;
|
||||
notifyJvmtiDisableSuspend(true);
|
||||
try {
|
||||
synchronized (interruptLock) {
|
||||
interrupted = true;
|
||||
Interruptible b = nioBlocker;
|
||||
if (b != null) {
|
||||
b.interrupt(this);
|
||||
blocker = nioBlocker();
|
||||
if (blocker != null) {
|
||||
blocker.interrupt(this);
|
||||
}
|
||||
|
||||
// interrupt carrier thread if mounted
|
||||
|
@ -873,6 +887,11 @@ final class VirtualThread extends BaseVirtualThread {
|
|||
} finally {
|
||||
notifyJvmtiDisableSuspend(false);
|
||||
}
|
||||
|
||||
// notify blocker after releasing interruptLock
|
||||
if (blocker != null) {
|
||||
blocker.postInterrupt();
|
||||
}
|
||||
} else {
|
||||
interrupted = true;
|
||||
carrierThread.setInterrupt();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue