mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8318422: Allow poller threads be virtual threads
Reviewed-by: michaelm
This commit is contained in:
parent
29cf2c471b
commit
c099cf53f2
13 changed files with 368 additions and 399 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2023, 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
|
||||
|
@ -25,6 +25,7 @@
|
|||
package sun.nio.ch;
|
||||
|
||||
import java.io.IOException;
|
||||
import jdk.internal.vm.ContinuationSupport;
|
||||
|
||||
/**
|
||||
* Default PollerProvider for Linux.
|
||||
|
@ -33,12 +34,31 @@ class DefaultPollerProvider extends PollerProvider {
|
|||
DefaultPollerProvider() { }
|
||||
|
||||
@Override
|
||||
Poller readPoller() throws IOException {
|
||||
return new EPollPoller(true);
|
||||
Poller.Mode defaultPollerMode() {
|
||||
if (ContinuationSupport.isSupported()) {
|
||||
return Poller.Mode.VTHREAD_POLLERS;
|
||||
} else {
|
||||
return Poller.Mode.SYSTEM_THREADS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Poller writePoller() throws IOException {
|
||||
return new EPollPoller(false);
|
||||
int defaultReadPollers(Poller.Mode mode) {
|
||||
int ncpus = Runtime.getRuntime().availableProcessors();
|
||||
if (mode == Poller.Mode.VTHREAD_POLLERS) {
|
||||
return Math.min(Integer.highestOneBit(ncpus), 32);
|
||||
} else {
|
||||
return Math.max(Integer.highestOneBit(ncpus / 4), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Poller readPoller(boolean subPoller) throws IOException {
|
||||
return new EPollPoller(subPoller, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
Poller writePoller(boolean subPoller) throws IOException {
|
||||
return new EPollPoller(subPoller, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,18 +32,18 @@ import static sun.nio.ch.EPoll.*;
|
|||
*/
|
||||
|
||||
class EPollPoller extends Poller {
|
||||
private static final int MAX_EVENTS_TO_POLL = 512;
|
||||
private static final int ENOENT = 2;
|
||||
|
||||
private final int epfd;
|
||||
private final int event;
|
||||
private final int maxEvents;
|
||||
private final long address;
|
||||
|
||||
EPollPoller(boolean read) throws IOException {
|
||||
super(read);
|
||||
EPollPoller(boolean subPoller, boolean read) throws IOException {
|
||||
this.epfd = EPoll.create();
|
||||
this.event = (read) ? EPOLLIN : EPOLLOUT;
|
||||
this.address = EPoll.allocatePollArray(MAX_EVENTS_TO_POLL);
|
||||
this.maxEvents = (subPoller) ? 64 : 512;
|
||||
this.address = EPoll.allocatePollArray(maxEvents);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,7 @@ class EPollPoller extends Poller {
|
|||
|
||||
@Override
|
||||
int poll(int timeout) throws IOException {
|
||||
int n = EPoll.wait(epfd, address, MAX_EVENTS_TO_POLL, timeout);
|
||||
int n = EPoll.wait(epfd, address, maxEvents, timeout);
|
||||
int i = 0;
|
||||
while (i < n) {
|
||||
long eventAddress = EPoll.getEvent(address, i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue