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:
Alan Bateman 2022-05-07 08:06:16 +00:00
parent 5212535a27
commit 9583e3657e
1133 changed files with 95935 additions and 8335 deletions

View file

@ -46,6 +46,7 @@ import java.util.Objects;
import jdk.internal.access.JavaIOFileDescriptorAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.Blocker;
import jdk.internal.misc.ExtendedMapMode;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
@ -229,7 +230,12 @@ public class FileChannelImpl
if (!isOpen())
return 0;
do {
n = IOUtil.read(fd, dst, -1, direct, alignment, nd);
long comp = Blocker.begin();
try {
n = IOUtil.read(fd, dst, -1, direct, alignment, nd);
} finally {
Blocker.end(comp);
}
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
@ -258,8 +264,13 @@ public class FileChannelImpl
if (!isOpen())
return 0;
do {
n = IOUtil.read(fd, dsts, offset, length,
direct, alignment, nd);
long comp = Blocker.begin();
try {
n = IOUtil.read(fd, dsts, offset, length, direct, alignment, nd);
} finally {
Blocker.end(comp);
}
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
@ -285,7 +296,13 @@ public class FileChannelImpl
if (!isOpen())
return 0;
do {
n = IOUtil.write(fd, src, -1, direct, alignment, nd);
long comp = Blocker.begin();
try {
n = IOUtil.write(fd, src, -1, direct, alignment, nd);
} finally {
Blocker.end(comp);
}
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
@ -314,8 +331,12 @@ public class FileChannelImpl
if (!isOpen())
return 0;
do {
n = IOUtil.write(fd, srcs, offset, length,
direct, alignment, nd);
long comp = Blocker.begin();
try {
n = IOUtil.write(fd, srcs, offset, length, direct, alignment, nd);
} finally {
Blocker.end(comp);
}
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
@ -340,8 +361,13 @@ public class FileChannelImpl
return 0;
boolean append = fdAccess.getAppend(fd);
do {
// in append-mode then position is advanced to end before writing
p = (append) ? nd.size(fd) : nd.seek(fd, -1);
long comp = Blocker.begin();
try {
// in append-mode then position is advanced to end before writing
p = (append) ? nd.size(fd) : nd.seek(fd, -1);
} finally {
Blocker.end(comp);
}
} while ((p == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(p);
} finally {
@ -365,7 +391,12 @@ public class FileChannelImpl
if (!isOpen())
return null;
do {
p = nd.seek(fd, newPosition);
long comp = Blocker.begin();
try {
p = nd.seek(fd, newPosition);
} finally {
Blocker.end(comp);
}
} while ((p == IOStatus.INTERRUPTED) && isOpen());
return this;
} finally {
@ -387,7 +418,12 @@ public class FileChannelImpl
if (!isOpen())
return -1;
do {
s = nd.size(fd);
long comp = Blocker.begin();
try {
s = nd.size(fd);
} finally {
Blocker.end(comp);
}
} while ((s == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(s);
} finally {
@ -418,14 +454,24 @@ public class FileChannelImpl
// get current size
long size;
do {
size = nd.size(fd);
long comp = Blocker.begin();
try {
size = nd.size(fd);
} finally {
Blocker.end(comp);
}
} while ((size == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
// get current position
do {
p = nd.seek(fd, -1);
long comp = Blocker.begin();
try {
p = nd.seek(fd, -1);
} finally {
Blocker.end(comp);
}
} while ((p == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
@ -434,7 +480,12 @@ public class FileChannelImpl
// truncate file if given size is less than the current size
if (newSize < size) {
do {
rv = nd.truncate(fd, newSize);
long comp = Blocker.begin();
try {
rv = nd.truncate(fd, newSize);
} finally {
Blocker.end(comp);
}
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
@ -444,7 +495,12 @@ public class FileChannelImpl
if (p > newSize)
p = newSize;
do {
rp = nd.seek(fd, p);
long comp = Blocker.begin();
try {
rp = nd.seek(fd, p);
} finally {
Blocker.end(comp);
}
} while ((rp == IOStatus.INTERRUPTED) && isOpen());
return this;
} finally {
@ -465,7 +521,12 @@ public class FileChannelImpl
if (!isOpen())
return;
do {
rv = nd.force(fd, metaData);
long comp = Blocker.begin();
try {
rv = nd.force(fd, metaData);
} finally {
Blocker.end(comp);
}
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
} finally {
threads.remove(ti);
@ -505,7 +566,12 @@ public class FileChannelImpl
if (!isOpen())
return -1;
do {
n = transferTo0(fd, position, icount, targetFD);
long comp = Blocker.begin();
try {
n = transferTo0(fd, position, icount, targetFD);
} finally {
Blocker.end(comp);
}
} while ((n == IOStatus.INTERRUPTED) && isOpen());
if (n == IOStatus.UNSUPPORTED_CASE) {
if (target instanceof SinkChannelImpl)
@ -843,7 +909,12 @@ public class FileChannelImpl
if (!isOpen())
return -1;
do {
n = IOUtil.read(fd, dst, position, direct, alignment, nd);
long comp = Blocker.begin();
try {
n = IOUtil.read(fd, dst, position, direct, alignment, nd);
} finally {
Blocker.end(comp);
}
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
@ -882,7 +953,12 @@ public class FileChannelImpl
if (!isOpen())
return -1;
do {
n = IOUtil.write(fd, src, position, direct, alignment, nd);
long comp = Blocker.begin();
try {
n = IOUtil.write(fd, src, position, direct, alignment, nd);
} finally {
Blocker.end(comp);
}
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
@ -1090,7 +1166,12 @@ public class FileChannelImpl
synchronized (positionLock) {
long filesize;
do {
filesize = nd.size(fd);
long comp = Blocker.begin();
try {
filesize = nd.size(fd);
} finally {
Blocker.end(comp);
}
} while ((filesize == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
@ -1102,7 +1183,12 @@ public class FileChannelImpl
}
int rv;
do {
rv = nd.truncate(fd, position + size);
long comp = Blocker.begin();
try {
rv = nd.truncate(fd, position + size);
} finally {
Blocker.end(comp);
}
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
@ -1292,7 +1378,12 @@ public class FileChannelImpl
return null;
int n;
do {
n = nd.lock(fd, true, position, size, shared);
long comp = Blocker.begin();
try {
n = nd.lock(fd, true, position, size, shared);
} finally {
Blocker.end(comp);
}
} while ((n == FileDispatcher.INTERRUPTED) && isOpen());
if (isOpen()) {
if (n == FileDispatcher.RET_EX_LOCK) {