JDK 10 RFR of 8147615: (fc) FileChannelImpl has no finalizer
Brian Burkhalter
brian.burkhalter at oracle.com
Fri Oct 6 23:06:21 UTC 2017
Hi Roger,
On Oct 6, 2017, at 6:34 AM, Roger Riggs <Roger.Riggs at oracle.com> wrote:
> Sorry for the delay.
Likewise.
> FileChannelImpl:
>
> - line 117: A lambda could be used instead of the explicit Closer class.
>
> () -> fdAccess.close(fd)
> // Note: fd is the argument (not the field) to prevent the lambda
> from capturing this.
>
> In the test:
> - Perhaps a bit more descriptive name than just "Cleaner" perhaps CleanerTest or...
>
> - Add @modules java.management - so the test will not be run unless the runtime includes management
I made the foregoing changes but now the test times out. I imagine there is a problem with how I set up the lambda. Please see the diff below.
Thanks,
Brian
--- a/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java
+++ b/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java
@@ -90,18 +90,6 @@
// Cleanable with an action which closes this channel's file descriptor
private final Cleanable cleanable;
- private static class Closer implements Runnable {
- private final FileDescriptor fd;
-
- Closer(FileDescriptor fd) {
- this.fd = fd;
- }
-
- public void run() {
- fdAccess.close(fd);
- }
- }
-
private FileChannelImpl(FileDescriptor fd, String path, boolean readable,
boolean writable, Object parent)
{
@@ -113,8 +101,7 @@
this.nd = new FileDispatcherImpl();
// Register a cleaning action if and only if there is no parent
// as the parent will take care of closing the file descriptor.
- this.cleanable = parent != null ? null :
- CleanerFactory.cleaner().register(this, new Closer(fd));
+ this.cleanable = parent != null ? null : () -> fdAccess.close(fd);
}
// Used by FileInputStream.getChannel(), FileOutputStream.getChannel
rename from test/jdk/java/nio/channels/FileChannel/Cleaner.java
rename to test/jdk/java/nio/channels/FileChannel/CleanerTest.java
--- a/test/jdk/java/nio/channels/FileChannel/Cleaner.java
+++ b/test/jdk/java/nio/channels/FileChannel/CleanerTest.java
@@ -25,7 +25,8 @@
* @bug 8147615
* @summary Test whether an unreferenced FileChannel is actually cleaned
* @requires (os.family == "linux") | (os.family == "mac") | (os.family == "solaris") | (os.family == "aix")
- * @run main/othervm Cleaner
+ * @modules java.management
+ * @run main/othervm CleanerTest
*/
import com.sun.management.UnixOperatingSystemMXBean;
@@ -40,7 +41,7 @@
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
-public class Cleaner {
+public class CleanerTest {
public static void main(String[] args) throws Throwable {
OperatingSystemMXBean mxBean =
ManagementFactory.getOperatingSystemMXBean();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20171006/8408310d/attachment-0001.html>
More information about the nio-dev
mailing list