--- old/test/jdk/java/io/FileInputStream/UnreferencedFISClosesFd.java 2018-10-11 12:56:42.070345857 -0400 +++ new/test/jdk/java/io/FileInputStream/UnreferencedFISClosesFd.java 2018-10-11 12:56:41.630343675 -0400 @@ -62,15 +62,11 @@ */ public class UnreferencedFISClosesFd { - enum CleanupType { - CLOSE, // Cleanup is handled via calling close - CLEANER} // Cleanup is handled via Cleaner - static final String FILE_NAME = "empty.txt"; /** * Subclass w/ no overrides; not finalize or close. - * Cleanup should be via the Cleaner (not close). + * Cleanup should be via the Cleaner. */ public static class StreamOverrides extends FileInputStream { @@ -88,7 +84,7 @@ /** * Subclass overrides close. - * Cleanup should be via AltFinalizer calling close(). + * Cleanup should be via the Cleaner. */ public static class StreamOverridesClose extends StreamOverrides { @@ -104,7 +100,7 @@ /** * Subclass overrides finalize. - * Cleanup should be via the Cleaner (not close). + * Cleanup should be via the Cleaner. */ public static class StreamOverridesFinalize extends StreamOverrides { @@ -113,7 +109,7 @@ } @SuppressWarnings({"deprecation","removal"}) - protected void finalize() throws IOException { + protected void finalize() throws IOException, Throwable { super.finalize(); } } @@ -129,7 +125,7 @@ } @SuppressWarnings({"deprecation","removal"}) - protected void finalize() throws IOException { + protected void finalize() throws IOException, Throwable { super.finalize(); } } @@ -149,15 +145,15 @@ long fdCount0 = getFdCount(); int failCount = 0; - failCount += test(new FileInputStream(name), CleanupType.CLEANER); + failCount += test(new FileInputStream(name)); - failCount += test(new StreamOverrides(name), CleanupType.CLEANER); + failCount += test(new StreamOverrides(name)); - failCount += test(new StreamOverridesClose(name), CleanupType.CLOSE); + failCount += test(new StreamOverridesClose(name)); - failCount += test(new StreamOverridesFinalize(name), CleanupType.CLEANER); + failCount += test(new StreamOverridesFinalize(name)); - failCount += test(new StreamOverridesFinalizeClose(name), CleanupType.CLOSE); + failCount += test(new StreamOverridesFinalizeClose(name)); if (failCount > 0) { throw new AssertionError("Failed test count: " + failCount); @@ -180,7 +176,7 @@ : -1L; } - private static int test(FileInputStream fis, CleanupType cleanType) throws Exception { + private static int test(FileInputStream fis) throws Exception { try { System.out.printf("%nTesting %s%n", fis.getClass().getName()); @@ -199,36 +195,19 @@ fdField.setAccessible(true); int ffd = fdField.getInt(fd); - Field altFinalizerField = FileInputStream.class.getDeclaredField("altFinalizer"); - altFinalizerField.setAccessible(true); - Object altFinalizer = altFinalizerField.get(fis); - if ((altFinalizer != null) ^ (cleanType == CleanupType.CLOSE)) { - throw new RuntimeException("Unexpected AltFinalizer: " + altFinalizer - + ", for " + cleanType); - } - Field cleanupField = FileDescriptor.class.getDeclaredField("cleanup"); cleanupField.setAccessible(true); Object cleanup = cleanupField.get(fd); - System.out.printf(" cleanup: %s, alt: %s, ffd: %d, cf: %s%n", - cleanup, altFinalizer, ffd, cleanupField); - if ((cleanup != null) ^ (cleanType == CleanupType.CLEANER)) { - throw new Exception("unexpected cleanup: " - + cleanup + ", for " + cleanType); - } - if (cleanup != null) { - WeakReference cleanupWeak = new WeakReference<>(cleanup, queue); - pending.add(cleanupWeak); - System.out.printf(" fdWeak: %s%n msWeak: %s%n cleanupWeak: %s%n", - fdWeak, msWeak, cleanupWeak); - } - if (altFinalizer != null) { - WeakReference altFinalizerWeak = new WeakReference<>(altFinalizer, queue); - pending.add(altFinalizerWeak); - System.out.printf(" fdWeak: %s%n msWeak: %s%n altFinalizerWeak: %s%n", - fdWeak, msWeak, altFinalizerWeak); + System.out.printf(" cleanup: %s, ffd: %d, cf: %s%n", cleanup, ffd, cleanupField); + if (cleanup == null) { + throw new RuntimeException("cleanup should not be null"); } + WeakReference cleanupWeak = new WeakReference<>(cleanup, queue); + pending.add(cleanupWeak); + System.out.printf(" fdWeak: %s%n msWeak: %s%n cleanupWeak: %s%n", + fdWeak, msWeak, cleanupWeak); + AtomicInteger closeCounter = fis instanceof StreamOverrides ? ((StreamOverrides)fis).closeCounter() : null; @@ -243,28 +222,16 @@ fis = null; fd = null; cleanup = null; - altFinalizer = null; System.gc(); // attempt to reclaim them } } Reference.reachabilityFence(fd); Reference.reachabilityFence(fis); Reference.reachabilityFence(cleanup); - Reference.reachabilityFence(altFinalizer); // Confirm the correct number of calls to close depending on the cleanup type - switch (cleanType) { - case CLEANER: - if (closeCounter != null && closeCounter.get() > 0) { - throw new RuntimeException("Close should not have been called: count: " - + closeCounter); - } - break; - case CLOSE: - if (closeCounter == null || closeCounter.get() == 0) { - throw new RuntimeException("Close should have been called: count: 0"); - } - break; + if (closeCounter != null && closeCounter.get() > 0) { + throw new RuntimeException("Close should not have been called: count: " + closeCounter); } } catch (Exception ex) { ex.printStackTrace(System.out);