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:
Alan Bateman 2024-04-23 16:10:13 +00:00
parent b07e1531b3
commit 412e306d81
28 changed files with 461 additions and 870 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, 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
@ -207,11 +207,11 @@ public final class FileDescriptor {
* @since 1.1
*/
public void sync() throws SyncFailedException {
long comp = Blocker.begin();
boolean attempted = Blocker.begin();
try {
sync0();
} finally {
Blocker.end(comp);
Blocker.end(attempted);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2024, 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
@ -27,7 +27,6 @@ package java.io;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import jdk.internal.misc.Blocker;
import jdk.internal.util.ArraysSupport;
import sun.nio.ch.FileChannelImpl;
@ -210,12 +209,7 @@ public class FileInputStream extends InputStream
* @param name the name of the file
*/
private void open(String name) throws FileNotFoundException {
long comp = Blocker.begin();
try {
open0(name);
} finally {
Blocker.end(comp);
}
open0(name);
}
/**
@ -228,12 +222,7 @@ public class FileInputStream extends InputStream
*/
@Override
public int read() throws IOException {
long comp = Blocker.begin();
try {
return read0();
} finally {
Blocker.end(comp);
}
return read0();
}
private native int read0() throws IOException;
@ -260,12 +249,7 @@ public class FileInputStream extends InputStream
*/
@Override
public int read(byte[] b) throws IOException {
long comp = Blocker.begin();
try {
return readBytes(b, 0, b.length);
} finally {
Blocker.end(comp);
}
return readBytes(b, 0, b.length);
}
/**
@ -284,12 +268,7 @@ public class FileInputStream extends InputStream
*/
@Override
public int read(byte[] b, int off, int len) throws IOException {
long comp = Blocker.begin();
try {
return readBytes(b, off, len);
} finally {
Blocker.end(comp);
}
return readBytes(b, off, len);
}
@Override
@ -396,22 +375,12 @@ public class FileInputStream extends InputStream
}
private long length() throws IOException {
long comp = Blocker.begin();
try {
return length0();
} finally {
Blocker.end(comp);
}
return length0();
}
private native long length0() throws IOException;
private long position() throws IOException {
long comp = Blocker.begin();
try {
return position0();
} finally {
Blocker.end(comp);
}
return position0();
}
private native long position0() throws IOException;
@ -441,12 +410,7 @@ public class FileInputStream extends InputStream
*/
@Override
public long skip(long n) throws IOException {
long comp = Blocker.begin();
try {
return skip0(n);
} finally {
Blocker.end(comp);
}
return skip0(n);
}
private native long skip0(long n) throws IOException;
@ -470,12 +434,7 @@ public class FileInputStream extends InputStream
*/
@Override
public int available() throws IOException {
long comp = Blocker.begin();
try {
return available0();
} finally {
Blocker.end(comp);
}
return available0();
}
private native int available0() throws IOException;
@ -566,8 +525,8 @@ public class FileInputStream extends InputStream
synchronized (this) {
fc = this.channel;
if (fc == null) {
this.channel = fc = FileChannelImpl.open(fd, path, true,
false, false, this);
fc = FileChannelImpl.open(fd, path, true, false, false, false, this);
this.channel = fc;
if (closed) {
try {
// possible race with close(), benign since

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2024, 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
@ -28,7 +28,6 @@ package java.io;
import java.nio.channels.FileChannel;
import jdk.internal.access.SharedSecrets;
import jdk.internal.access.JavaIOFileDescriptorAccess;
import jdk.internal.misc.Blocker;
import sun.nio.ch.FileChannelImpl;
@ -286,12 +285,7 @@ public class FileOutputStream extends OutputStream
* @param append whether the file is to be opened in append mode
*/
private void open(String name, boolean append) throws FileNotFoundException {
long comp = Blocker.begin();
try {
open0(name, append);
} finally {
Blocker.end(comp);
}
open0(name, append);
}
/**
@ -313,12 +307,7 @@ public class FileOutputStream extends OutputStream
@Override
public void write(int b) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
long comp = Blocker.begin();
try {
write(b, append);
} finally {
Blocker.end(comp);
}
write(b, append);
}
/**
@ -343,12 +332,7 @@ public class FileOutputStream extends OutputStream
@Override
public void write(byte[] b) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
long comp = Blocker.begin();
try {
writeBytes(b, 0, b.length, append);
} finally {
Blocker.end(comp);
}
writeBytes(b, 0, b.length, append);
}
/**
@ -364,12 +348,7 @@ public class FileOutputStream extends OutputStream
@Override
public void write(byte[] b, int off, int len) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
long comp = Blocker.begin();
try {
writeBytes(b, off, len, append);
} finally {
Blocker.end(comp);
}
writeBytes(b, off, len, append);
}
/**
@ -460,8 +439,8 @@ public class FileOutputStream extends OutputStream
synchronized (this) {
fc = this.channel;
if (fc == null) {
this.channel = fc = FileChannelImpl.open(fd, path, false,
true, false, this);
fc = FileChannelImpl.open(fd, path, false, true, false, false, this);
this.channel = fc;
if (closed) {
try {
// possible race with close(), benign since

View file

@ -71,6 +71,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
private final FileDescriptor fd;
private final boolean rw;
private final boolean sync; // O_SYNC or O_DSYNC
/**
* The path of the referenced file
@ -229,21 +230,25 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
int imode = -1;
boolean rw = false;
boolean sync = false;
if (mode.equals("r"))
imode = O_RDONLY;
else if (mode.startsWith("rw")) {
imode = O_RDWR;
rw = true;
if (mode.length() > 2) {
if (mode.equals("rws"))
if (mode.equals("rws")) {
imode |= O_SYNC;
else if (mode.equals("rwd"))
sync = true;
} else if (mode.equals("rwd")) {
imode |= O_DSYNC;
else
sync = true;
} else
imode = -1;
}
}
this.rw = rw;
this.sync = sync;
if (openAndDelete)
imode |= O_TEMPORARY;
@ -308,8 +313,8 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
synchronized (this) {
fc = this.channel;
if (fc == null) {
this.channel = fc = FileChannelImpl.open(fd, path, true,
rw, false, this);
fc = FileChannelImpl.open(fd, path, true, rw, sync, false, this);
this.channel = fc;
if (closed) {
try {
fc.close();
@ -350,12 +355,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* defined above
*/
private void open(String name, int mode) throws FileNotFoundException {
long comp = Blocker.begin();
try {
open0(name, mode);
} finally {
Blocker.end(comp);
}
open0(name, mode);
}
// 'Read' primitives
@ -376,12 +376,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* end-of-file has been reached.
*/
public int read() throws IOException {
long comp = Blocker.begin();
try {
return read0();
} finally {
Blocker.end(comp);
}
return read0();
}
private native int read0() throws IOException;
@ -394,12 +389,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @throws IOException If an I/O error has occurred.
*/
private int readBytes(byte[] b, int off, int len) throws IOException {
long comp = Blocker.begin();
try {
return readBytes0(b, off, len);
} finally {
Blocker.end(comp);
}
return readBytes0(b, off, len);
}
private native int readBytes0(byte[] b, int off, int len) throws IOException;
@ -547,11 +537,11 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @throws IOException if an I/O error occurs.
*/
public void write(int b) throws IOException {
long comp = Blocker.begin();
boolean attempted = Blocker.begin(sync);
try {
write0(b);
} finally {
Blocker.end(comp);
Blocker.end(attempted);
}
}
@ -566,11 +556,11 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @throws IOException If an I/O error has occurred.
*/
private void writeBytes(byte[] b, int off, int len) throws IOException {
long comp = Blocker.begin();
boolean attempted = Blocker.begin(sync);
try {
writeBytes0(b, off, len);
} finally {
Blocker.end(comp);
Blocker.end(attempted);
}
}
@ -630,12 +620,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
if (pos < 0) {
throw new IOException("Negative seek offset");
}
long comp = Blocker.begin();
try {
seek0(pos);
} finally {
Blocker.end(comp);
}
seek0(pos);
}
private native void seek0(long pos) throws IOException;
@ -647,12 +632,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @throws IOException if an I/O error occurs.
*/
public long length() throws IOException {
long comp = Blocker.begin();
try {
return length0();
} finally {
Blocker.end(comp);
}
return length0();
}
private native long length0() throws IOException;
@ -684,12 +664,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @since 1.2
*/
public void setLength(long newLength) throws IOException {
long comp = Blocker.begin();
try {
setLength0(newLength);
} finally {
Blocker.end(comp);
}
setLength0(newLength);
}
private native void setLength0(long newLength) throws IOException;