mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8338383: Implement JEP 491: Synchronize Virtual Threads without Pinning
Co-authored-by: Patricio Chilano Mateo <pchilanomate@openjdk.org> Co-authored-by: Alan Bateman <alanb@openjdk.org> Co-authored-by: Andrew Haley <aph@openjdk.org> Co-authored-by: Fei Yang <fyang@openjdk.org> Co-authored-by: Coleen Phillimore <coleenp@openjdk.org> Co-authored-by: Richard Reingruber <rrich@openjdk.org> Co-authored-by: Martin Doerr <mdoerr@openjdk.org> Reviewed-by: aboldtch, dholmes, coleenp, fbredberg, dlong, sspitsyn
This commit is contained in:
parent
8a2a75e56d
commit
78b80150e0
246 changed files with 8295 additions and 2755 deletions
|
@ -26,7 +26,9 @@ package sun.nio.ch;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -40,7 +42,7 @@ import sun.security.action.GetPropertyAction;
|
|||
* Polls file descriptors. Virtual threads invoke the poll method to park
|
||||
* until a given file descriptor is ready for I/O.
|
||||
*/
|
||||
abstract class Poller {
|
||||
public abstract class Poller {
|
||||
private static final Pollers POLLERS;
|
||||
static {
|
||||
try {
|
||||
|
@ -142,6 +144,20 @@ abstract class Poller {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parks the current thread until a Selector's file descriptor is ready.
|
||||
* @param fdVal the Selector's file descriptor
|
||||
* @param nanos the waiting time or 0 to wait indefinitely
|
||||
*/
|
||||
static void pollSelector(int fdVal, long nanos) throws IOException {
|
||||
assert nanos >= 0L;
|
||||
Poller poller = POLLERS.masterPoller();
|
||||
if (poller == null) {
|
||||
poller = POLLERS.readPoller(fdVal);
|
||||
}
|
||||
poller.poll(fdVal, nanos, () -> true);
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is a thread polling the given file descriptor for the given event then
|
||||
* the thread is unparked.
|
||||
|
@ -258,6 +274,18 @@ abstract class Poller {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number I/O operations currently registered with this poller.
|
||||
*/
|
||||
public int registered() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toIdentityString(this) + " [registered = " + registered() + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* The Pollers used for read and write events.
|
||||
*/
|
||||
|
@ -344,6 +372,13 @@ abstract class Poller {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the master poller, or null if there is no master poller.
|
||||
*/
|
||||
Poller masterPoller() {
|
||||
return masterPoller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the read poller for the given file descriptor.
|
||||
*/
|
||||
|
@ -360,6 +395,21 @@ abstract class Poller {
|
|||
return writePollers[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of read pollers.
|
||||
*/
|
||||
List<Poller> readPollers() {
|
||||
return List.of(readPollers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of write pollers.
|
||||
*/
|
||||
List<Poller> writePollers() {
|
||||
return List.of(writePollers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the given property name to get the poller count. If the property is
|
||||
* set then the value must be a power of 2. Returns 1 if the property is not
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue