changeset 58823:d7994062de41

8202142: jfr/event/io/TestInstrumentation is unstable Reviewed-by: mgronlun, mseledtsov
author egahlin
date Thu, 30 Jan 2020 09:01:58 +0100
parents 68181ac4ce7d
children 99f7916541e0
files test/jdk/ProblemList.txt test/jdk/jdk/jfr/event/io/IOEvent.java test/jdk/jdk/jfr/event/io/IOHelper.java test/jdk/jdk/jfr/event/io/TestDisabledEvents.java test/jdk/jdk/jfr/event/io/TestFileChannelEvents.java test/jdk/jdk/jfr/event/io/TestFileReadOnly.java test/jdk/jdk/jfr/event/io/TestFileStreamEvents.java test/jdk/jdk/jfr/event/io/TestInstrumentation.java test/jdk/jdk/jfr/event/io/TestRandomAccessFileEvents.java test/jdk/jdk/jfr/event/io/TestRandomAccessFileThread.java test/jdk/jdk/jfr/event/io/TestSocketChannelEvents.java test/jdk/jdk/jfr/event/io/TestSocketEvents.java
diffstat 12 files changed, 333 insertions(+), 326 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/ProblemList.txt	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/ProblemList.txt	Thu Jan 30 09:01:58 2020 +0100
@@ -932,7 +932,6 @@
 
 # jdk_jfr
 
-jdk/jfr/event/io/TestInstrumentation.java                       8202142    generic-all
 jdk/jfr/event/io/EvilInstrument.java                            8221331    generic-all
 jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java          8228990,8229370    generic-all
 jdk/jfr/event/compiler/TestCodeSweeper.java                     8225209    generic-all
--- a/test/jdk/jdk/jfr/event/io/IOEvent.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/IOEvent.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -197,14 +197,11 @@
             }
             return canonical_path;
         } else {
-            return String.format("%s/%s:%d",
-                                event.getValue("host"),
-                                event.getValue("address"),
-                                event.getValue("port"));
+            return event.getValue("address") + ":"  + event.getValue("port");
         }
     }
 
     private static String getAddress(Socket s) {
-        return s.getInetAddress().toString() + ":" + s.getPort();
+        return s.getInetAddress().getHostAddress() + ":" + s.getPort();
     }
 }
--- a/test/jdk/jdk/jfr/event/io/IOHelper.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/IOHelper.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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,6 +28,8 @@
 import static jdk.test.lib.Asserts.assertEquals;
 import static jdk.test.lib.Asserts.assertTrue;
 
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -41,6 +43,7 @@
 public class IOHelper {
 
     public static void verifyEqualsInOrder(List<RecordedEvent> events, List<IOEvent> expectedEvents) throws Throwable {
+        Collections.sort(events, Comparator.comparing(RecordedEvent::getStartTime));
         List<IOEvent> actualEvents = getTestEvents(events, expectedEvents);
         try {
             assertEquals(actualEvents.size(), expectedEvents.size(), "Wrong number of events.");
@@ -48,6 +51,9 @@
                 assertEquals(actualEvents.get(i), expectedEvents.get(i), "Wrong event at pos " + i);
             }
         } catch (Throwable t) {
+            for (RecordedEvent e: events) {
+                System.out.println(e);
+            }
             logEvents(actualEvents, expectedEvents);
             throw t;
         }
--- a/test/jdk/jdk/jfr/event/io/TestDisabledEvents.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestDisabledEvents.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -57,21 +57,22 @@
 
     public static void main(String[] args) throws Throwable {
         File tmp = Utils.createTempFile("TestDisabledEvents", ".tmp").toFile();
-        Recording recording = new Recording();
-        recording.disable(IOEvent.EVENT_FILE_READ);
-        recording.disable(IOEvent.EVENT_FILE_WRITE);
-        recording.start();
+        try (Recording recording = new Recording()) {
+            recording.disable(IOEvent.EVENT_FILE_READ);
+            recording.disable(IOEvent.EVENT_FILE_WRITE);
+            recording.start();
 
-        useRandomAccessFile(tmp);
-        useFileStreams(tmp);
-        useFileChannel(tmp);
+            useRandomAccessFile(tmp);
+            useFileStreams(tmp);
+            useFileChannel(tmp);
 
-        recording.stop();
-        for (RecordedEvent event : Events.fromRecording(recording)) {
-            final String eventName = event.getEventType().getName();
-            System.out.println("Got eventName:" + eventName);
-            assertNotEquals(eventName, IOEvent.EVENT_FILE_READ, "Got disabled read event");
-            assertNotEquals(eventName, IOEvent.EVENT_FILE_WRITE, "Got disabled write event");
+            recording.stop();
+            for (RecordedEvent event : Events.fromRecording(recording)) {
+                final String eventName = event.getEventType().getName();
+                System.out.println("Got eventName:" + eventName);
+                assertNotEquals(eventName, IOEvent.EVENT_FILE_READ, "Got disabled read event");
+                assertNotEquals(eventName, IOEvent.EVENT_FILE_WRITE, "Got disabled write event");
+            }
         }
     }
 
--- a/test/jdk/jdk/jfr/event/io/TestFileChannelEvents.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestFileChannelEvents.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -50,74 +50,74 @@
 public class TestFileChannelEvents {
     public static void main(String[] args) throws Throwable {
         File tmp = Utils.createTempFile("TestFileChannelEvents", ".tmp").toFile();
-        Recording recording = new Recording();
-        List<IOEvent> expectedEvents = new ArrayList<>();
+        try (Recording recording = new Recording()) {
+            List<IOEvent> expectedEvents = new ArrayList<>();
+            try (RandomAccessFile rf = new RandomAccessFile(tmp, "rw"); FileChannel ch = rf.getChannel();) {
+                recording.enable(IOEvent.EVENT_FILE_FORCE).withThreshold(Duration.ofMillis(0));
+                recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
+                recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
+                recording.start();
 
-        try (RandomAccessFile rf = new RandomAccessFile(tmp, "rw"); FileChannel ch = rf.getChannel();) {
-            recording.enable(IOEvent.EVENT_FILE_FORCE).withThreshold(Duration.ofMillis(0));
-            recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
-            recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
-            recording.start();
+                ByteBuffer bufA = ByteBuffer.allocateDirect(10);
+                ByteBuffer bufB = ByteBuffer.allocateDirect(20);
+                bufA.put("1234567890".getBytes());
+                bufB.put("1234567890".getBytes());
 
-            ByteBuffer bufA = ByteBuffer.allocateDirect(10);
-            ByteBuffer bufB = ByteBuffer.allocateDirect(20);
-            bufA.put("1234567890".getBytes());
-            bufB.put("1234567890".getBytes());
+                // test write(ByteBuffer)
+                bufA.flip();
+                long size = ch.write(bufA);
+                expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));
 
-            // test write(ByteBuffer)
-            bufA.flip();
-            long size = ch.write(bufA);
-            expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));
+                // test write(ByteBuffer, long)
+                bufA.flip();
+                size = ch.write(bufA, bufA.capacity() / 2);
+                expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));
 
-            // test write(ByteBuffer, long)
-            bufA.flip();
-            size = ch.write(bufA, bufA.capacity() / 2);
-            expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));
+                // test write(ByteBuffer[])
+                bufA.flip();
+                bufA.limit(5);
+                bufB.flip();
+                bufB.limit(5);
+                size = ch.write(new ByteBuffer[] { bufA, bufB });
+                expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));
 
-            // test write(ByteBuffer[])
-            bufA.flip();
-            bufA.limit(5);
-            bufB.flip();
-            bufB.limit(5);
-            size = ch.write(new ByteBuffer[] { bufA, bufB });
-            expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));
+                // test force(boolean)
+                ch.force(true);
+                expectedEvents.add(IOEvent.createFileForceEvent(tmp));
 
-            // test force(boolean)
-            ch.force(true);
-            expectedEvents.add(IOEvent.createFileForceEvent(tmp));
+                // reset file
+                ch.position(0);
 
-            // reset file
-            ch.position(0);
+                // test read(ByteBuffer)
+                bufA.clear();
+                size = ch.read(bufA);
+                expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
 
-            // test read(ByteBuffer)
-            bufA.clear();
-            size = ch.read(bufA);
-            expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
+                // test read(ByteBuffer, long)
+                bufA.clear();
+                size = ch.read(bufA, bufA.capacity() / 2);
+                expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
 
-            // test read(ByteBuffer, long)
-            bufA.clear();
-            size = ch.read(bufA, bufA.capacity() / 2);
-            expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
+                // test read(ByteBuffer[])
+                bufA.clear();
+                bufA.limit(5);
+                bufB.clear();
+                bufB.limit(5);
+                size = ch.read(new ByteBuffer[] { bufA, bufB });
+                expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
 
-            // test read(ByteBuffer[])
-            bufA.clear();
-            bufA.limit(5);
-            bufB.clear();
-            bufB.limit(5);
-            size = ch.read(new ByteBuffer[] { bufA, bufB });
-            expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
+                // Read at EOF. Should get size -1 in event.
+                ch.position(ch.size());
+                bufA.clear();
+                size = ch.read(bufA);
+                assertEquals(size, -1L, "Expected size -1 when read at EOF");
+                expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
 
-            // Read at EOF. Should get size -1 in event.
-            ch.position(ch.size());
-            bufA.clear();
-            size = ch.read(bufA);
-            assertEquals(size, -1L, "Expected size -1 when read at EOF");
-            expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
-
-            ch.close();
-            recording.stop();
-            List<RecordedEvent> events = Events.fromRecording(recording);
-            IOHelper.verifyEqualsInOrder(events, expectedEvents);
+                ch.close();
+                recording.stop();
+                List<RecordedEvent> events = Events.fromRecording(recording);
+                IOHelper.verifyEqualsInOrder(events, expectedEvents);
+            }
         }
     }
 }
--- a/test/jdk/jdk/jfr/event/io/TestFileReadOnly.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestFileReadOnly.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -52,50 +52,51 @@
 
     public static void main(String[] args) throws Throwable {
         File tmp = Utils.createTempFile("TestFileReadOnly", ".tmp").toFile();
-        Recording recording = new Recording();
-        List<IOEvent> expectedEvents = new ArrayList<>();
+        try (Recording recording = new Recording()) {
+            List<IOEvent> expectedEvents = new ArrayList<>();
 
-        recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
-        recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
-        recording.start();
+            recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
+            recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
+            recording.start();
 
-        final byte[] buf = { 1, 2, 3 };
+            final byte[] buf = { 1, 2, 3 };
 
-        // Create the file.
-        try (RandomAccessFile f = new RandomAccessFile(tmp, "rw")) {
-            f.write(buf);
-            expectedEvents.add(IOEvent.createFileWriteEvent(buf.length, tmp));
+            // Create the file.
+            try (RandomAccessFile f = new RandomAccessFile(tmp, "rw")) {
+                f.write(buf);
+                expectedEvents.add(IOEvent.createFileWriteEvent(buf.length, tmp));
+            }
+
+            // Reopen the file as ReadOnly and try to write to it.
+            // Should generate an event with bytesWritten = -1.
+            try (RandomAccessFile f = new RandomAccessFile(tmp, "r")) {
+                try {
+                    f.write(buf);
+                    fail("No exception for ReadOnly File");
+                } catch (IOException e) {
+                    // Expected exception
+                    expectedEvents.add(IOEvent.createFileWriteEvent(-1, tmp));
+                }
+            }
+
+            // Try to write to read-only FileChannel.
+            try (RandomAccessFile f = new RandomAccessFile(tmp, "r"); FileChannel ch = f.getChannel()) {
+                ByteBuffer writeBuf = ByteBuffer.allocateDirect(buf.length);
+                writeBuf.put(buf);
+                writeBuf.flip();
+                ch.position(0);
+                try {
+                    ch.write(writeBuf);
+                    fail("No exception for ReadOnly FileChannel");
+                } catch (java.nio.channels.NonWritableChannelException e) {
+                    // Expected exception
+                    expectedEvents.add(IOEvent.createFileWriteEvent(-1, tmp));
+                }
+            }
+
+            recording.stop();
+            List<RecordedEvent> events = Events.fromRecording(recording);
+            IOHelper.verifyEqualsInOrder(events, expectedEvents);
         }
-
-        // Reopen the file as ReadOnly and try to write to it.
-        // Should generate an event with bytesWritten = -1.
-        try (RandomAccessFile f = new RandomAccessFile(tmp, "r")) {
-            try {
-                f.write(buf);
-                fail("No exception for ReadOnly File");
-            } catch (IOException e) {
-                // Expected exception
-                expectedEvents.add(IOEvent.createFileWriteEvent(-1, tmp));
-            }
-        }
-
-        // Try to write to read-only FileChannel.
-        try (RandomAccessFile f = new RandomAccessFile(tmp, "r"); FileChannel ch = f.getChannel()) {
-            ByteBuffer writeBuf = ByteBuffer.allocateDirect(buf.length);
-            writeBuf.put(buf);
-            writeBuf.flip();
-            ch.position(0);
-            try {
-                ch.write(writeBuf);
-                fail("No exception for ReadOnly FileChannel");
-            } catch (java.nio.channels.NonWritableChannelException e) {
-                // Expected exception
-                expectedEvents.add(IOEvent.createFileWriteEvent(-1, tmp));
-            }
-        }
-
-        recording.stop();
-        List<RecordedEvent> events = Events.fromRecording(recording);
-        IOHelper.verifyEqualsInOrder(events, expectedEvents);
     }
 }
--- a/test/jdk/jdk/jfr/event/io/TestFileStreamEvents.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestFileStreamEvents.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -50,47 +50,47 @@
 public class TestFileStreamEvents {
     public static void main(String[] args) throws Throwable {
         File tmp = Utils.createTempFile("TestFileStreamEvents", ".tmp").toFile();
-        Recording recording = new Recording();
-        List<IOEvent> expectedEvents = new ArrayList<>();
+        try (Recording recording = new Recording()) {
+            List<IOEvent> expectedEvents = new ArrayList<>();
+            try(FileOutputStream fos = new FileOutputStream(tmp); FileInputStream fis = new FileInputStream(tmp);) {
+                recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
+                recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
+                recording.start();
 
-        try(FileOutputStream fos = new FileOutputStream(tmp); FileInputStream fis = new FileInputStream(tmp);) {
-            recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
-            recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
-            recording.start();
+                int writeByte = 47;
+                byte[] writeBuf = {11, 12, 13, 14};
 
-            int writeByte = 47;
-            byte[] writeBuf = {11, 12, 13, 14};
+                // Write
+                fos.write(writeByte);
+                expectedEvents.add(IOEvent.createFileWriteEvent(1, tmp));
+                fos.write(writeBuf);
+                expectedEvents.add(IOEvent.createFileWriteEvent(writeBuf.length, tmp));
+                fos.write(writeBuf, 0, 2);
+                expectedEvents.add(IOEvent.createFileWriteEvent(2, tmp));
 
-            // Write
-            fos.write(writeByte);
-            expectedEvents.add(IOEvent.createFileWriteEvent(1, tmp));
-            fos.write(writeBuf);
-            expectedEvents.add(IOEvent.createFileWriteEvent(writeBuf.length, tmp));
-            fos.write(writeBuf, 0, 2);
-            expectedEvents.add(IOEvent.createFileWriteEvent(2, tmp));
+                // Read
+                int readByte = fis.read();
+                assertEquals(readByte, writeByte, "Wrong byte read");
+                expectedEvents.add(IOEvent.createFileReadEvent(1, tmp));
 
-            // Read
-            int readByte = fis.read();
-            assertEquals(readByte, writeByte, "Wrong byte read");
-            expectedEvents.add(IOEvent.createFileReadEvent(1, tmp));
+                byte[] readBuf = new byte[writeBuf.length];
+                long size = fis.read(readBuf);
+                assertEquals(size, (long)writeBuf.length, "Wrong size when reading byte[]");
+                expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
 
-            byte[] readBuf = new byte[writeBuf.length];
-            long size = fis.read(readBuf);
-            assertEquals(size, (long)writeBuf.length, "Wrong size when reading byte[]");
-            expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
+                size = fis.read(readBuf, 0, 2);
+                assertEquals(size, 2L, "Wrong size when reading 2 bytes");
+                expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
 
-            size = fis.read(readBuf, 0, 2);
-            assertEquals(size, 2L, "Wrong size when reading 2 bytes");
-            expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
+                // We are at EOF. Read more and verify we get size -1.
+                size = fis.read(readBuf);
+                assertEquals(size, -1L, "Size should be -1 at EOF");
+                expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
 
-            // We are at EOF. Read more and verify we get size -1.
-            size = fis.read(readBuf);
-            assertEquals(size, -1L, "Size should be -1 at EOF");
-            expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
-
-            recording.stop();
-            List<RecordedEvent> events = Events.fromRecording(recording);
-            IOHelper.verifyEqualsInOrder(events, expectedEvents);
+                recording.stop();
+                List<RecordedEvent> events = Events.fromRecording(recording);
+                IOHelper.verifyEqualsInOrder(events, expectedEvents);
+            }
         }
     }
 }
--- a/test/jdk/jdk/jfr/event/io/TestInstrumentation.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestInstrumentation.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -106,11 +106,9 @@
         "java/io/FileOutputStream::write::([B)V",
         "java/io/FileOutputStream::write::([BII)V",
         "java/net/Socket$SocketInputStream::read::()I",
-        "java/net/Socket$SocketInputStream::read::([B)I",
         "java/net/Socket$SocketInputStream::read::([BII)I",
         "java/net/Socket$SocketInputStream::close::()V",
         "java/net/Socket$SocketOutputStream::write::(I)V",
-        "java/net/Socket$SocketOutputStream::write::([B)V",
         "java/net/Socket$SocketOutputStream::write::([BII)V",
         "java/net/Socket$SocketOutputStream::close::()V",
         "java/nio/channels/FileChannel::read::([Ljava/nio/ByteBuffer;)J",
--- a/test/jdk/jdk/jfr/event/io/TestRandomAccessFileEvents.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestRandomAccessFileEvents.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -49,62 +49,63 @@
 
     public static void main(String[] args) throws Throwable {
         File tmp = Utils.createTempFile("TestRandomAccessFileEvents", ".tmp").toFile();
-        Recording recording = new Recording();
-        List<IOEvent> expectedEvents = new ArrayList<>();
+        try (Recording recording = new Recording()) {
+            List<IOEvent> expectedEvents = new ArrayList<>();
 
-        recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
-        recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
-        recording.start();
+            recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
+            recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
+            recording.start();
 
-        RandomAccessFile ras = new RandomAccessFile(tmp, "rw");
-        int writeInt = 47;
-        byte[] writeBuffer = {10,11,12,13};
+            RandomAccessFile ras = new RandomAccessFile(tmp, "rw");
+            int writeInt = 47;
+            byte[] writeBuffer = {10,11,12,13};
 
-        // Write an int and a buffer.
-        ras.write(writeInt);
-        expectedEvents.add(IOEvent.createFileWriteEvent(1, tmp));
-        ras.write(writeBuffer);
-        expectedEvents.add(IOEvent.createFileWriteEvent(writeBuffer.length, tmp));
+            // Write an int and a buffer.
+            ras.write(writeInt);
+            expectedEvents.add(IOEvent.createFileWriteEvent(1, tmp));
+            ras.write(writeBuffer);
+            expectedEvents.add(IOEvent.createFileWriteEvent(writeBuffer.length, tmp));
 
-        ras.seek(0);
+            ras.seek(0);
 
-        // Read int and buffer
-        int readInt = ras.read();
-        assertEquals(readInt, writeInt, "wrong int read");
-        expectedEvents.add(IOEvent.createFileReadEvent(1, tmp));
-        byte[] readBuffer = new byte [writeBuffer.length];
-        int size = ras.read(readBuffer);
-        verifyBufferEquals(readBuffer, writeBuffer);
-        expectedEvents.add(IOEvent.createFileReadEvent(readBuffer.length, tmp));
+            // Read int and buffer
+            int readInt = ras.read();
+            assertEquals(readInt, writeInt, "wrong int read");
+            expectedEvents.add(IOEvent.createFileReadEvent(1, tmp));
+            byte[] readBuffer = new byte [writeBuffer.length];
+            int size = ras.read(readBuffer);
+            verifyBufferEquals(readBuffer, writeBuffer);
+            expectedEvents.add(IOEvent.createFileReadEvent(readBuffer.length, tmp));
 
-        // Read beyond EOF
-        readInt = ras.read();
-        assertEquals(-1, readInt, "wrong read after EOF");
-        expectedEvents.add(IOEvent.createFileReadEvent(-1, tmp));
+            // Read beyond EOF
+            readInt = ras.read();
+            assertEquals(-1, readInt, "wrong read after EOF");
+            expectedEvents.add(IOEvent.createFileReadEvent(-1, tmp));
 
-        // Seek to beginning and verify we can read after EOF.
-        ras.seek(0);
-        readInt = ras.read();
-        assertEquals(readInt, writeInt, "wrong int read after seek(0)");
-        expectedEvents.add(IOEvent.createFileReadEvent(1, tmp));
+            // Seek to beginning and verify we can read after EOF.
+            ras.seek(0);
+            readInt = ras.read();
+            assertEquals(readInt, writeInt, "wrong int read after seek(0)");
+            expectedEvents.add(IOEvent.createFileReadEvent(1, tmp));
 
-        // seek beyond EOF and verify we get EOF when reading.
-        ras.seek(10);
-        readInt = ras.read();
-        assertEquals(-1, readInt, "wrong read after seek beyond EOF");
-        expectedEvents.add(IOEvent.createFileReadEvent(-1, tmp));
+            // seek beyond EOF and verify we get EOF when reading.
+            ras.seek(10);
+            readInt = ras.read();
+            assertEquals(-1, readInt, "wrong read after seek beyond EOF");
+            expectedEvents.add(IOEvent.createFileReadEvent(-1, tmp));
 
-        // Read partial buffer.
-        int partialSize = writeBuffer.length - 2;
-        ras.seek(ras.length()-partialSize);
-        size = ras.read(readBuffer);
-        assertEquals(size, partialSize, "Wrong size partial buffer read");
-        expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
+            // Read partial buffer.
+            int partialSize = writeBuffer.length - 2;
+            ras.seek(ras.length()-partialSize);
+            size = ras.read(readBuffer);
+            assertEquals(size, partialSize, "Wrong size partial buffer read");
+            expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));
 
-        ras.close();
-        recording.stop();
-        List<RecordedEvent> events = Events.fromRecording(recording);
-        IOHelper.verifyEqualsInOrder(events, expectedEvents);
+            ras.close();
+            recording.stop();
+            List<RecordedEvent> events = Events.fromRecording(recording);
+            IOHelper.verifyEqualsInOrder(events, expectedEvents);
+        }
     }
 
     private static void verifyBufferEquals(byte[] a, byte[] b) {
--- a/test/jdk/jdk/jfr/event/io/TestRandomAccessFileThread.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestRandomAccessFileThread.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -64,26 +64,25 @@
 
     public static void main(String[] args) throws Throwable {
         File tmp = Utils.createTempFile("TestRandomAccessFileThread", ".tmp").toFile();
+        try (Recording recording = new Recording()) {
+            recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
+            recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
+            recording.start();
 
-        Recording recording = new Recording();
-        recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
-        recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
-        recording.start();
-
-        TestThread writerThread = new TestThread(new XRun() {
-            @Override
-            public void xrun() throws IOException {
-                final byte[] buf = new byte[OP_COUNT];
-                for (int i = 0; i < buf.length; ++i) {
-                    buf[i] = (byte)((i + 'a') % 255);
-                }
-                try (RandomAccessFile raf = new RandomAccessFile(tmp, "rwd")) {
-                    for(int i = 0; i < OP_COUNT; ++i) {
-                        raf.write(buf, 0, i + 1);
-                        writeCount++;
+            TestThread writerThread = new TestThread(new XRun() {
+                @Override
+                public void xrun() throws IOException {
+                    final byte[] buf = new byte[OP_COUNT];
+                    for (int i = 0; i < buf.length; ++i) {
+                        buf[i] = (byte)((i + 'a') % 255);
                     }
-                }
-            }}, "TestWriterThread");
+                    try (RandomAccessFile raf = new RandomAccessFile(tmp, "rwd")) {
+                        for(int i = 0; i < OP_COUNT; ++i) {
+                            raf.write(buf, 0, i + 1);
+                            writeCount++;
+                        }
+                    }
+                }}, "TestWriterThread");
 
             TestThread readerThread = new TestThread(new XRun() {
             @Override
@@ -118,7 +117,7 @@
                     continue;
                 }
                 logEventSummary(event);
-                if (Events.isEventType(event,IOEvent.EVENT_FILE_READ)) {
+                if (Events.isEventType(event, IOEvent.EVENT_FILE_READ)) {
                     readEvents.add(event);
                 } else {
                     writeEvents.add(event);
@@ -136,6 +135,7 @@
             Asserts.assertEquals(readEvents.size(), OP_COUNT, "Wrong number of read events");
             Asserts.assertEquals(writeEvents.size(), OP_COUNT, "Wrong number of write events");
         }
+    }
 
         private static void logEventSummary(RecordedEvent event) {
             boolean isRead = Events.isEventType(event, IOEvent.EVENT_FILE_READ);
--- a/test/jdk/jdk/jfr/event/io/TestSocketChannelEvents.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestSocketChannelEvents.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -53,6 +53,7 @@
     private static final int bufSizeB = 20;
 
     private List<IOEvent> expectedEvents = new ArrayList<>();
+
     private synchronized void addExpectedEvent(IOEvent event) {
         expectedEvents.add(event);
     }
@@ -62,69 +63,70 @@
     }
 
     public void test() throws Throwable {
-        Recording recording = new Recording();
+        try (Recording recording = new Recording()) {
+            try (ServerSocketChannel ss = ServerSocketChannel.open()) {
+                recording.enable(IOEvent.EVENT_SOCKET_READ).withThreshold(Duration.ofMillis(0));
+                recording.enable(IOEvent.EVENT_SOCKET_WRITE).withThreshold(Duration.ofMillis(0));
+                recording.start();
 
-        try (ServerSocketChannel ss = ServerSocketChannel.open()) {
-            recording.enable(IOEvent.EVENT_SOCKET_READ).withThreshold(Duration.ofMillis(0));
-            recording.enable(IOEvent.EVENT_SOCKET_WRITE).withThreshold(Duration.ofMillis(0));
-            recording.start();
+                ss.socket().setReuseAddress(true);
+                ss.socket().bind(null);
 
-            ss.socket().setReuseAddress(true);
-            ss.socket().bind(null);
+                TestThread readerThread = new TestThread(new XRun() {
+                    @Override
+                    public void xrun() throws IOException {
+                        ByteBuffer bufA = ByteBuffer.allocate(bufSizeA);
+                        ByteBuffer bufB = ByteBuffer.allocate(bufSizeB);
+                        try (SocketChannel sc = ss.accept()) {
+                            int readSize = sc.read(bufA);
+                            assertEquals(readSize, bufSizeA, "Wrong readSize bufA");
+                            addExpectedEvent(IOEvent.createSocketReadEvent(bufSizeA, sc.socket()));
 
-            TestThread readerThread = new TestThread(new XRun() {
-                @Override
-                public void xrun() throws IOException {
-                    ByteBuffer bufA = ByteBuffer.allocate(bufSizeA);
-                    ByteBuffer bufB = ByteBuffer.allocate(bufSizeB);
-                    try (SocketChannel sc = ss.accept()) {
-                        int readSize = sc.read(bufA);
-                        assertEquals(readSize, bufSizeA, "Wrong readSize bufA");
-                        addExpectedEvent(IOEvent.createSocketReadEvent(bufSizeA, sc.socket()));
+                            bufA.clear();
+                            bufA.limit(1);
+                            readSize = (int) sc.read(new ByteBuffer[] { bufA, bufB });
+                            assertEquals(readSize, 1 + bufSizeB, "Wrong readSize 1+bufB");
+                            addExpectedEvent(IOEvent.createSocketReadEvent(readSize, sc.socket()));
 
-                        bufA.clear();
-                        bufA.limit(1);
-                        readSize = (int)sc.read(new ByteBuffer[] { bufA, bufB });
-                        assertEquals(readSize, 1 + bufSizeB, "Wrong readSize 1+bufB");
-                        addExpectedEvent(IOEvent.createSocketReadEvent(readSize, sc.socket()));
+                            // We try to read, but client have closed. Should
+                            // get EOF.
+                            bufA.clear();
+                            bufA.limit(1);
+                            readSize = sc.read(bufA);
+                            assertEquals(readSize, -1, "Wrong readSize at EOF");
+                            addExpectedEvent(IOEvent.createSocketReadEvent(-1, sc.socket()));
+                        }
+                    }
+                });
+                readerThread.start();
 
-                        // We try to read, but client have closed. Should get EOF.
-                        bufA.clear();
-                        bufA.limit(1);
-                        readSize = sc.read(bufA);
-                        assertEquals(readSize, -1, "Wrong readSize at EOF");
-                        addExpectedEvent(IOEvent.createSocketReadEvent(-1, sc.socket()));
+                try (SocketChannel sc = SocketChannel.open(ss.socket().getLocalSocketAddress())) {
+                    ByteBuffer bufA = ByteBuffer.allocateDirect(bufSizeA);
+                    ByteBuffer bufB = ByteBuffer.allocateDirect(bufSizeB);
+                    for (int i = 0; i < bufSizeA; ++i) {
+                        bufA.put((byte) ('a' + (i % 20)));
                     }
+                    for (int i = 0; i < bufSizeB; ++i) {
+                        bufB.put((byte) ('A' + (i % 20)));
+                    }
+                    bufA.flip();
+                    bufB.flip();
+
+                    sc.write(bufA);
+                    addExpectedEvent(IOEvent.createSocketWriteEvent(bufSizeA, sc.socket()));
+
+                    bufA.clear();
+                    bufA.limit(1);
+                    int bytesWritten = (int) sc.write(new ByteBuffer[] { bufA, bufB });
+                    assertEquals(bytesWritten, 1 + bufSizeB, "Wrong bytesWritten 1+bufB");
+                    addExpectedEvent(IOEvent.createSocketWriteEvent(bytesWritten, sc.socket()));
                 }
-            });
-            readerThread.start();
 
-            try (SocketChannel sc = SocketChannel.open(ss.socket().getLocalSocketAddress())) {
-                ByteBuffer bufA = ByteBuffer.allocateDirect(bufSizeA);
-                ByteBuffer bufB = ByteBuffer.allocateDirect(bufSizeB);
-                for (int i = 0; i < bufSizeA; ++i) {
-                    bufA.put((byte)('a' + (i % 20)));
-                }
-                for (int i = 0; i < bufSizeB; ++i) {
-                    bufB.put((byte)('A' + (i % 20)));
-                }
-                bufA.flip();
-                bufB.flip();
-
-                sc.write(bufA);
-                addExpectedEvent(IOEvent.createSocketWriteEvent(bufSizeA, sc.socket()));
-
-                bufA.clear();
-                bufA.limit(1);
-                int bytesWritten = (int)sc.write(new ByteBuffer[] { bufA, bufB });
-                assertEquals(bytesWritten, 1 + bufSizeB, "Wrong bytesWritten 1+bufB");
-                addExpectedEvent(IOEvent.createSocketWriteEvent(bytesWritten, sc.socket()));
+                readerThread.joinAndThrow();
+                recording.stop();
+                List<RecordedEvent> events = Events.fromRecording(recording);
+                IOHelper.verifyEquals(events, expectedEvents);
             }
-
-            readerThread.joinAndThrow();
-            recording.stop();
-            List<RecordedEvent> events= Events.fromRecording(recording);
-            IOHelper.verifyEquals(events, expectedEvents);
         }
     }
 }
--- a/test/jdk/jdk/jfr/event/io/TestSocketEvents.java	Thu Jan 30 10:26:56 2020 +0300
+++ b/test/jdk/jdk/jfr/event/io/TestSocketEvents.java	Thu Jan 30 09:01:58 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -55,6 +55,7 @@
     private static final byte[] writeBuf = { 'B', 'C', 'D', 'E' };
 
     private List<IOEvent> expectedEvents = new ArrayList<>();
+
     private synchronized void addExpectedEvent(IOEvent event) {
         expectedEvents.add(event);
     }
@@ -64,58 +65,59 @@
     }
 
     private void test() throws Throwable {
-        Recording recording = new Recording();
+        try (Recording recording = new Recording()) {
+            try (ServerSocket ss = new ServerSocket()) {
+                recording.enable(IOEvent.EVENT_SOCKET_READ).withThreshold(Duration.ofMillis(0));
+                recording.enable(IOEvent.EVENT_SOCKET_WRITE).withThreshold(Duration.ofMillis(0));
+                recording.start();
 
-        try (ServerSocket ss = new ServerSocket()) {
-            recording.enable(IOEvent.EVENT_SOCKET_READ).withThreshold(Duration.ofMillis(0));
-            recording.enable(IOEvent.EVENT_SOCKET_WRITE).withThreshold(Duration.ofMillis(0));
-            recording.start();
+                ss.setReuseAddress(true);
+                ss.bind(null);
 
-            ss.setReuseAddress(true);
-            ss.bind(null);
+                TestThread readerThread = new TestThread(new XRun() {
+                    @Override
+                    public void xrun() throws IOException {
+                        byte[] bs = new byte[4];
+                        try (Socket s = ss.accept(); InputStream is = s.getInputStream()) {
+                            int readInt = is.read();
+                            assertEquals(readInt, writeInt, "Wrong readInt");
+                            addExpectedEvent(IOEvent.createSocketReadEvent(1, s));
 
-            TestThread readerThread = new TestThread(new XRun() {
-                @Override
-                public void xrun() throws IOException {
-                    byte[] bs = new byte[4];
-                    try (Socket s = ss.accept(); InputStream is = s.getInputStream()) {
-                        int readInt = is.read();
-                        assertEquals(readInt, writeInt, "Wrong readInt");
-                        addExpectedEvent(IOEvent.createSocketReadEvent(1, s));
+                            int bytesRead = is.read(bs, 0, 3);
+                            assertEquals(bytesRead, 3, "Wrong bytesRead partial buffer");
+                            addExpectedEvent(IOEvent.createSocketReadEvent(bytesRead, s));
 
-                        int bytesRead = is.read(bs, 0, 3);
-                        assertEquals(bytesRead, 3, "Wrong bytesRead partial buffer");
-                        addExpectedEvent(IOEvent.createSocketReadEvent(bytesRead, s));
+                            bytesRead = is.read(bs);
+                            assertEquals(bytesRead, writeBuf.length, "Wrong bytesRead full buffer");
+                            addExpectedEvent(IOEvent.createSocketReadEvent(bytesRead, s));
 
-                        bytesRead = is.read(bs);
-                        assertEquals(bytesRead, writeBuf.length, "Wrong bytesRead full buffer");
-                        addExpectedEvent(IOEvent.createSocketReadEvent(bytesRead, s));
+                            // Try to read more, but writer have closed. Should
+                            // get EOF.
+                            readInt = is.read();
+                            assertEquals(readInt, -1, "Wrong readInt at EOF");
+                            addExpectedEvent(IOEvent.createSocketReadEvent(-1, s));
+                        }
+                    }
+                });
+                readerThread.start();
 
-                        // Try to read more, but writer have closed. Should get EOF.
-                        readInt = is.read();
-                        assertEquals(readInt, -1, "Wrong readInt at EOF");
-                        addExpectedEvent(IOEvent.createSocketReadEvent(-1, s));
-                   }
+                try (Socket s = new Socket()) {
+                    s.connect(ss.getLocalSocketAddress());
+                    try (OutputStream os = s.getOutputStream()) {
+                        os.write(writeInt);
+                        addExpectedEvent(IOEvent.createSocketWriteEvent(1, s));
+                        os.write(writeBuf, 0, 3);
+                        addExpectedEvent(IOEvent.createSocketWriteEvent(3, s));
+                        os.write(writeBuf);
+                        addExpectedEvent(IOEvent.createSocketWriteEvent(writeBuf.length, s));
+                    }
                 }
-            });
-            readerThread.start();
 
-            try (Socket s = new Socket()) {
-                s.connect(ss.getLocalSocketAddress());
-                try (OutputStream os = s.getOutputStream()) {
-                    os.write(writeInt);
-                    addExpectedEvent(IOEvent.createSocketWriteEvent(1, s));
-                    os.write(writeBuf, 0, 3);
-                    addExpectedEvent(IOEvent.createSocketWriteEvent(3, s));
-                    os.write(writeBuf);
-                    addExpectedEvent(IOEvent.createSocketWriteEvent(writeBuf.length, s));
-                }
+                readerThread.joinAndThrow();
+                recording.stop();
+                List<RecordedEvent> events = Events.fromRecording(recording);
+                IOHelper.verifyEquals(events, expectedEvents);
             }
-
-            readerThread.joinAndThrow();
-            recording.stop();
-            List<RecordedEvent> events = Events.fromRecording(recording);
-            IOHelper.verifyEquals(events, expectedEvents);
         }
     }
 }