mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8329593: Drop adjustments to target parallelism when virtual threads do I/O on files opened for buffered I/O
Reviewed-by: bpb, jpai
This commit is contained in:
parent
b07e1531b3
commit
412e306d81
28 changed files with 461 additions and 870 deletions
|
@ -78,6 +78,7 @@ public class FileChannelImpl
|
|||
// File access mode (immutable)
|
||||
private final boolean writable;
|
||||
private final boolean readable;
|
||||
private final boolean sync; // O_SYNC or O_DSYNC
|
||||
|
||||
// Required to prevent finalization of creating stream (immutable)
|
||||
private final Closeable parent;
|
||||
|
@ -122,12 +123,14 @@ public class FileChannelImpl
|
|||
}
|
||||
|
||||
private FileChannelImpl(FileDescriptor fd, String path, boolean readable,
|
||||
boolean writable, boolean direct, Closeable parent)
|
||||
boolean writable, boolean sync, boolean direct,
|
||||
Closeable parent)
|
||||
{
|
||||
this.fd = fd;
|
||||
this.path = path;
|
||||
this.readable = readable;
|
||||
this.writable = writable;
|
||||
this.sync = sync;
|
||||
this.direct = direct;
|
||||
this.parent = parent;
|
||||
if (direct) {
|
||||
|
@ -150,9 +153,9 @@ public class FileChannelImpl
|
|||
// and RandomAccessFile::getChannel
|
||||
public static FileChannel open(FileDescriptor fd, String path,
|
||||
boolean readable, boolean writable,
|
||||
boolean direct, Closeable parent)
|
||||
boolean sync, boolean direct, Closeable parent)
|
||||
{
|
||||
return new FileChannelImpl(fd, path, readable, writable, direct, parent);
|
||||
return new FileChannelImpl(fd, path, readable, writable, sync, direct, parent);
|
||||
}
|
||||
|
||||
private void ensureOpen() throws IOException {
|
||||
|
@ -230,11 +233,11 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return 0;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
boolean attempted = Blocker.begin(direct);
|
||||
try {
|
||||
n = IOUtil.read(fd, dst, -1, direct, alignment, nd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
Blocker.end(attempted);
|
||||
}
|
||||
} while ((n == IOStatus.INTERRUPTED) && isOpen());
|
||||
return IOStatus.normalize(n);
|
||||
|
@ -265,11 +268,11 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return 0;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
boolean attempted = Blocker.begin(direct);
|
||||
try {
|
||||
n = IOUtil.read(fd, dsts, offset, length, direct, alignment, nd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
Blocker.end(attempted);
|
||||
}
|
||||
|
||||
} while ((n == IOStatus.INTERRUPTED) && isOpen());
|
||||
|
@ -298,11 +301,11 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return 0;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
boolean attempted = Blocker.begin(sync || direct);
|
||||
try {
|
||||
n = IOUtil.write(fd, src, -1, direct, alignment, nd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
Blocker.end(attempted);
|
||||
}
|
||||
|
||||
} while ((n == IOStatus.INTERRUPTED) && isOpen());
|
||||
|
@ -334,11 +337,11 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return 0;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
boolean attempted = Blocker.begin(sync || direct);
|
||||
try {
|
||||
n = IOUtil.write(fd, srcs, offset, length, direct, alignment, nd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
Blocker.end(attempted);
|
||||
}
|
||||
} while ((n == IOStatus.INTERRUPTED) && isOpen());
|
||||
return IOStatus.normalize(n);
|
||||
|
@ -365,13 +368,8 @@ public class FileChannelImpl
|
|||
return 0;
|
||||
boolean append = fdAccess.getAppend(fd);
|
||||
do {
|
||||
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);
|
||||
}
|
||||
// in append-mode then position is advanced to end before writing
|
||||
p = (append) ? nd.size(fd) : nd.seek(fd, -1);
|
||||
} while ((p == IOStatus.INTERRUPTED) && isOpen());
|
||||
return IOStatus.normalize(p);
|
||||
} finally {
|
||||
|
@ -396,12 +394,7 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return null;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
p = nd.seek(fd, newPosition);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
p = nd.seek(fd, newPosition);
|
||||
} while ((p == IOStatus.INTERRUPTED) && isOpen());
|
||||
return this;
|
||||
} finally {
|
||||
|
@ -424,12 +417,7 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return -1;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
s = nd.size(fd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
s = nd.size(fd);
|
||||
} while ((s == IOStatus.INTERRUPTED) && isOpen());
|
||||
return IOStatus.normalize(s);
|
||||
} finally {
|
||||
|
@ -461,24 +449,14 @@ public class FileChannelImpl
|
|||
// get current size
|
||||
long size;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
size = nd.size(fd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
size = nd.size(fd);
|
||||
} while ((size == IOStatus.INTERRUPTED) && isOpen());
|
||||
if (!isOpen())
|
||||
return null;
|
||||
|
||||
// get current position
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
p = nd.seek(fd, -1);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
p = nd.seek(fd, -1);
|
||||
} while ((p == IOStatus.INTERRUPTED) && isOpen());
|
||||
if (!isOpen())
|
||||
return null;
|
||||
|
@ -487,12 +465,7 @@ public class FileChannelImpl
|
|||
// truncate file if given size is less than the current size
|
||||
if (newSize < size) {
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
rv = nd.truncate(fd, newSize);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
rv = nd.truncate(fd, newSize);
|
||||
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
|
||||
if (!isOpen())
|
||||
return null;
|
||||
|
@ -502,12 +475,7 @@ public class FileChannelImpl
|
|||
if (p > newSize)
|
||||
p = newSize;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
rp = nd.seek(fd, p);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
rp = nd.seek(fd, p);
|
||||
} while ((rp == IOStatus.INTERRUPTED) && isOpen());
|
||||
return this;
|
||||
} finally {
|
||||
|
@ -529,11 +497,11 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
boolean attempted = Blocker.begin();
|
||||
try {
|
||||
rv = nd.force(fd, metaData);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
Blocker.end(attempted);
|
||||
}
|
||||
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
|
||||
} finally {
|
||||
|
@ -624,12 +592,7 @@ public class FileChannelImpl
|
|||
long n;
|
||||
boolean append = fdAccess.getAppend(targetFD);
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
n = nd.transferTo(fd, position, count, targetFD, append);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
n = nd.transferTo(fd, position, count, targetFD, append);
|
||||
} while ((n == IOStatus.INTERRUPTED) && isOpen());
|
||||
return n;
|
||||
}
|
||||
|
@ -895,12 +858,7 @@ public class FileChannelImpl
|
|||
long n;
|
||||
boolean append = fdAccess.getAppend(fd);
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
n = nd.transferFrom(srcFD, fd, position, count, append);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
n = nd.transferFrom(srcFD, fd, position, count, append);
|
||||
} while ((n == IOStatus.INTERRUPTED) && isOpen());
|
||||
return n;
|
||||
}
|
||||
|
@ -1088,11 +1046,11 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return -1;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
boolean attempted = Blocker.begin(direct);
|
||||
try {
|
||||
n = IOUtil.read(fd, dst, position, direct, alignment, nd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
Blocker.end(attempted);
|
||||
}
|
||||
} while ((n == IOStatus.INTERRUPTED) && isOpen());
|
||||
return IOStatus.normalize(n);
|
||||
|
@ -1133,11 +1091,11 @@ public class FileChannelImpl
|
|||
if (!isOpen())
|
||||
return -1;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
boolean attempted = Blocker.begin(sync || direct);
|
||||
try {
|
||||
n = IOUtil.write(fd, src, position, direct, alignment, nd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
Blocker.end(attempted);
|
||||
}
|
||||
} while ((n == IOStatus.INTERRUPTED) && isOpen());
|
||||
return IOStatus.normalize(n);
|
||||
|
@ -1362,12 +1320,7 @@ public class FileChannelImpl
|
|||
synchronized (positionLock) {
|
||||
long filesize;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
filesize = nd.size(fd);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
filesize = nd.size(fd);
|
||||
} while ((filesize == IOStatus.INTERRUPTED) && isOpen());
|
||||
if (!isOpen())
|
||||
return null;
|
||||
|
@ -1379,12 +1332,7 @@ public class FileChannelImpl
|
|||
}
|
||||
int rv;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
try {
|
||||
rv = nd.truncate(fd, position + size);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
}
|
||||
rv = nd.truncate(fd, position + size);
|
||||
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
|
||||
if (!isOpen())
|
||||
return null;
|
||||
|
@ -1575,11 +1523,11 @@ public class FileChannelImpl
|
|||
return null;
|
||||
int n;
|
||||
do {
|
||||
long comp = Blocker.begin();
|
||||
boolean attempted = Blocker.begin();
|
||||
try {
|
||||
n = nd.lock(fd, true, position, size, shared);
|
||||
} finally {
|
||||
Blocker.end(comp);
|
||||
Blocker.end(attempted);
|
||||
}
|
||||
} while ((n == FileDispatcher.INTERRUPTED) && isOpen());
|
||||
if (isOpen()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue