8202324: Avoid loading FileInput-/OutputStream$AltFinalizer

Reviewed-by: alanb
This commit is contained in:
Claes Redestad 2018-04-26 17:14:04 +02:00
parent a7b8407fbc
commit dce2872700
2 changed files with 41 additions and 42 deletions

View File

@ -79,7 +79,7 @@ class FileInputStream extends InputStream
private volatile boolean closed;
private final AltFinalizer altFinalizer;
private final Object altFinalizer;
/**
* Creates a <code>FileInputStream</code> by
@ -155,7 +155,7 @@ class FileInputStream extends InputStream
fd.attach(this);
path = name;
open(name);
altFinalizer = AltFinalizer.get(this);
altFinalizer = getFinalizer(this);
if (altFinalizer == null) {
FileCleanable.register(fd); // open set the fd, register the cleanup
}
@ -471,21 +471,11 @@ class FileInputStream extends InputStream
protected void finalize() throws IOException {
}
/**
* Class to call {@code FileInputStream.close} when finalized.
* If finalization of the stream is needed, an instance is created
* in its constructor(s). When the set of instances
* related to the stream is unreachable, the AltFinalizer performs
* the needed call to the stream's {@code close} method.
*/
static class AltFinalizer {
private final FileInputStream fis;
/*
* Returns a finalizer object if the FIS needs a finalizer; otherwise null.
* If the FIS has a close method; it needs an AltFinalizer.
*/
static AltFinalizer get(FileInputStream fis) {
private static Object getFinalizer(FileInputStream fis) {
Class<?> clazz = fis.getClass();
while (clazz != FileInputStream.class) {
try {
@ -498,8 +488,17 @@ class FileInputStream extends InputStream
}
return null;
}
/**
* Class to call {@code FileInputStream.close} when finalized.
* If finalization of the stream is needed, an instance is created
* in its constructor(s). When the set of instances
* related to the stream is unreachable, the AltFinalizer performs
* the needed call to the stream's {@code close} method.
*/
static class AltFinalizer {
private final FileInputStream fis;
private AltFinalizer(FileInputStream fis) {
AltFinalizer(FileInputStream fis) {
this.fis = fis;
}

View File

@ -95,7 +95,7 @@ class FileOutputStream extends OutputStream
private volatile boolean closed;
private final AltFinalizer altFinalizer;
private final Object altFinalizer;
/**
* Creates a file output stream to write to the file with the
@ -235,7 +235,7 @@ class FileOutputStream extends OutputStream
this.path = name;
open(name, append);
altFinalizer = AltFinalizer.get(this);
altFinalizer = getFinalizer(this);
if (altFinalizer == null) {
FileCleanable.register(fd); // open sets the fd, register the cleanup
}
@ -496,21 +496,11 @@ class FileOutputStream extends OutputStream
initIDs();
}
/**
* Class to call {@code FileOutputStream.close} when finalized.
* If finalization of the stream is needed, an instance is created
* in its constructor(s). When the set of instances
* related to the stream is unreachable, the AltFinalizer performs
* the needed call to the stream's {@code close} method.
*/
static class AltFinalizer {
private final FileOutputStream fos;
/*
* Returns a finalizer object if the FOS needs a finalizer; otherwise null.
* If the FOS has a close method; it needs an AltFinalizer.
*/
static AltFinalizer get(FileOutputStream fos) {
private static Object getFinalizer(FileOutputStream fos) {
Class<?> clazz = fos.getClass();
while (clazz != FileOutputStream.class) {
try {
@ -524,7 +514,17 @@ class FileOutputStream extends OutputStream
return null;
}
private AltFinalizer(FileOutputStream fos) {
/**
* Class to call {@code FileOutputStream.close} when finalized.
* If finalization of the stream is needed, an instance is created
* in its constructor(s). When the set of instances
* related to the stream is unreachable, the AltFinalizer performs
* the needed call to the stream's {@code close} method.
*/
static class AltFinalizer {
private final FileOutputStream fos;
AltFinalizer(FileOutputStream fos) {
this.fos = fos;
}