mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8343039: Remove jdk.internal.misc.InternalLock and usages from java.io
Reviewed-by: liach, alanb
This commit is contained in:
parent
3c38ed4128
commit
0b9b82af03
19 changed files with 548 additions and 1789 deletions
|
@ -26,7 +26,6 @@
|
|||
package java.io;
|
||||
|
||||
import java.util.Objects;
|
||||
import jdk.internal.misc.InternalLock;
|
||||
|
||||
/**
|
||||
* Abstract class for writing to character streams. The only methods that a
|
||||
|
@ -162,21 +161,6 @@ public abstract class Writer implements Appendable, Closeable, Flushable {
|
|||
this.lock = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* For use by BufferedWriter to create a character-stream writer that uses an
|
||||
* internal lock when BufferedWriter is not extended and the given writer is
|
||||
* trusted, otherwise critical sections will synchronize on the given writer.
|
||||
*/
|
||||
Writer(Writer writer) {
|
||||
Class<?> clazz = writer.getClass();
|
||||
if (getClass() == BufferedWriter.class &&
|
||||
(clazz == OutputStreamWriter.class || clazz == FileWriter.class)) {
|
||||
this.lock = InternalLock.newLockOr(writer);
|
||||
} else {
|
||||
this.lock = writer;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new character-stream writer whose critical sections will
|
||||
* synchronize on the given object.
|
||||
|
@ -206,29 +190,15 @@ public abstract class Writer implements Appendable, Closeable, Flushable {
|
|||
* If an I/O error occurs
|
||||
*/
|
||||
public void write(int c) throws IOException {
|
||||
Object lock = this.lock;
|
||||
if (lock instanceof InternalLock locker) {
|
||||
locker.lock();
|
||||
try {
|
||||
implWrite(c);
|
||||
} finally {
|
||||
locker.unlock();
|
||||
}
|
||||
} else {
|
||||
synchronized (lock) {
|
||||
implWrite(c);
|
||||
synchronized (lock) {
|
||||
if (writeBuffer == null){
|
||||
writeBuffer = new char[WRITE_BUFFER_SIZE];
|
||||
}
|
||||
writeBuffer[0] = (char) c;
|
||||
write(writeBuffer, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void implWrite(int c) throws IOException {
|
||||
if (writeBuffer == null){
|
||||
writeBuffer = new char[WRITE_BUFFER_SIZE];
|
||||
}
|
||||
writeBuffer[0] = (char) c;
|
||||
write(writeBuffer, 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an array of characters.
|
||||
*
|
||||
|
@ -305,35 +275,21 @@ public abstract class Writer implements Appendable, Closeable, Flushable {
|
|||
* If an I/O error occurs
|
||||
*/
|
||||
public void write(String str, int off, int len) throws IOException {
|
||||
Object lock = this.lock;
|
||||
if (lock instanceof InternalLock locker) {
|
||||
locker.lock();
|
||||
try {
|
||||
implWrite(str, off, len);
|
||||
} finally {
|
||||
locker.unlock();
|
||||
}
|
||||
} else {
|
||||
synchronized (lock) {
|
||||
implWrite(str, off, len);
|
||||
synchronized (lock) {
|
||||
char cbuf[];
|
||||
if (len <= WRITE_BUFFER_SIZE) {
|
||||
if (writeBuffer == null) {
|
||||
writeBuffer = new char[WRITE_BUFFER_SIZE];
|
||||
}
|
||||
cbuf = writeBuffer;
|
||||
} else { // Don't permanently allocate very large buffers.
|
||||
cbuf = new char[len];
|
||||
}
|
||||
str.getChars(off, (off + len), cbuf, 0);
|
||||
write(cbuf, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
private void implWrite(String str, int off, int len) throws IOException {
|
||||
char cbuf[];
|
||||
if (len <= WRITE_BUFFER_SIZE) {
|
||||
if (writeBuffer == null) {
|
||||
writeBuffer = new char[WRITE_BUFFER_SIZE];
|
||||
}
|
||||
cbuf = writeBuffer;
|
||||
} else { // Don't permanently allocate very large buffers.
|
||||
cbuf = new char[len];
|
||||
}
|
||||
str.getChars(off, (off + len), cbuf, 0);
|
||||
write(cbuf, 0, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the specified character sequence to this writer.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue