mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8284161: Implementation of Virtual Threads (Preview)
Co-authored-by: Ron Pressler <rpressler@openjdk.org> Co-authored-by: Alan Bateman <alanb@openjdk.org> Co-authored-by: Erik Österlund <eosterlund@openjdk.org> Co-authored-by: Andrew Haley <aph@openjdk.org> Co-authored-by: Rickard Bäckman <rbackman@openjdk.org> Co-authored-by: Markus Grönlund <mgronlun@openjdk.org> Co-authored-by: Leonid Mesnik <lmesnik@openjdk.org> Co-authored-by: Serguei Spitsyn <sspitsyn@openjdk.org> Co-authored-by: Chris Plummer <cjplummer@openjdk.org> Co-authored-by: Coleen Phillimore <coleenp@openjdk.org> Co-authored-by: Robbin Ehn <rehn@openjdk.org> Co-authored-by: Stefan Karlsson <stefank@openjdk.org> Co-authored-by: Thomas Schatzl <tschatzl@openjdk.org> Co-authored-by: Sergey Kuksenko <skuksenko@openjdk.org> Reviewed-by: lancea, eosterlund, rehn, sspitsyn, stefank, tschatzl, dfuchs, lmesnik, dcubed, kevinw, amenkov, dlong, mchung, psandoz, bpb, coleenp, smarks, egahlin, mseledtsov, coffeys, darcy
This commit is contained in:
parent
5212535a27
commit
9583e3657e
1133 changed files with 95935 additions and 8335 deletions
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2022, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.nio.ch;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Default PollerProvider for Linux.
|
||||
*/
|
||||
class DefaultPollerProvider extends PollerProvider {
|
||||
DefaultPollerProvider() { }
|
||||
|
||||
@Override
|
||||
Poller readPoller() throws IOException {
|
||||
return new EPollPoller(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
Poller writePoller() throws IOException {
|
||||
return new EPollPoller(false);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2022, 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
|
||||
|
@ -50,6 +50,9 @@ class EPoll {
|
|||
* epoll_data_t data;
|
||||
* }
|
||||
*/
|
||||
static {
|
||||
IOUtil.load();
|
||||
}
|
||||
private static final int SIZEOF_EPOLLEVENT = eventSize();
|
||||
private static final int OFFSETOF_EVENTS = eventsOffset();
|
||||
private static final int OFFSETOF_FD = dataOffset();
|
||||
|
@ -115,8 +118,4 @@ class EPoll {
|
|||
|
||||
static native int wait(int epfd, long pollAddress, int numfds, int timeout)
|
||||
throws IOException;
|
||||
|
||||
static {
|
||||
IOUtil.load();
|
||||
}
|
||||
}
|
||||
|
|
82
src/java.base/linux/classes/sun/nio/ch/EPollPoller.java
Normal file
82
src/java.base/linux/classes/sun/nio/ch/EPollPoller.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2022, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package sun.nio.ch;
|
||||
|
||||
import java.io.IOException;
|
||||
import static sun.nio.ch.EPoll.*;
|
||||
|
||||
/**
|
||||
* Poller implementation based on the epoll facility.
|
||||
*/
|
||||
|
||||
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 long address;
|
||||
|
||||
EPollPoller(boolean read) throws IOException {
|
||||
super(read);
|
||||
this.epfd = EPoll.create();
|
||||
this.event = (read) ? EPOLLIN : EPOLLOUT;
|
||||
this.address = EPoll.allocatePollArray(MAX_EVENTS_TO_POLL);
|
||||
}
|
||||
|
||||
@Override
|
||||
int fdVal() {
|
||||
return epfd;
|
||||
}
|
||||
|
||||
@Override
|
||||
void implRegister(int fdVal) throws IOException {
|
||||
// re-arm
|
||||
int err = EPoll.ctl(epfd, EPOLL_CTL_MOD, fdVal, (event | EPOLLONESHOT));
|
||||
if (err == ENOENT)
|
||||
err = EPoll.ctl(epfd, EPOLL_CTL_ADD, fdVal, (event | EPOLLONESHOT));
|
||||
if (err != 0)
|
||||
throw new IOException("epoll_ctl failed: " + err);
|
||||
}
|
||||
|
||||
@Override
|
||||
void implDeregister(int fdVal) {
|
||||
EPoll.ctl(epfd, EPOLL_CTL_DEL, fdVal, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
int poll(int timeout) throws IOException {
|
||||
int n = EPoll.wait(epfd, address, MAX_EVENTS_TO_POLL, timeout);
|
||||
int i = 0;
|
||||
while (i < n) {
|
||||
long eventAddress = EPoll.getEvent(address, i);
|
||||
int fdVal = EPoll.getDescriptor(eventAddress);
|
||||
polled(fdVal);
|
||||
i++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2022, 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
|
||||
|
@ -36,6 +36,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import jdk.internal.misc.Blocker;
|
||||
|
||||
import static sun.nio.ch.EPoll.EPOLLIN;
|
||||
import static sun.nio.ch.EPoll.EPOLL_CTL_ADD;
|
||||
|
@ -115,7 +116,12 @@ class EPollSelectorImpl extends SelectorImpl {
|
|||
|
||||
do {
|
||||
long startTime = timedPoll ? System.nanoTime() : 0;
|
||||
numEntries = EPoll.wait(epfd, pollArrayAddress, NUM_EPOLLEVENTS, to);
|
||||
long comp = Blocker.begin(blocking);
|
||||
try {
|
||||
numEntries = EPoll.wait(epfd, pollArrayAddress, NUM_EPOLLEVENTS, to);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
if (numEntries == IOStatus.INTERRUPTED && timedPoll) {
|
||||
// timed poll interrupted so need to adjust timeout
|
||||
long adjust = System.nanoTime() - startTime;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue