changeset 59252:dd0caf00b05c

8244661: JFR: Remove use of thread-locals for java.base events Reviewed-by: jbachorik, mgronlun
author egahlin
date Tue, 12 May 2020 15:20:15 +0200
parents 4f8be70ec25d
children e62705474229
files src/jdk.jfr/share/classes/jdk/jfr/events/ErrorThrownEvent.java src/jdk.jfr/share/classes/jdk/jfr/events/ExceptionThrownEvent.java src/jdk.jfr/share/classes/jdk/jfr/events/FileForceEvent.java src/jdk.jfr/share/classes/jdk/jfr/events/FileReadEvent.java src/jdk.jfr/share/classes/jdk/jfr/events/FileWriteEvent.java src/jdk.jfr/share/classes/jdk/jfr/events/Handlers.java src/jdk.jfr/share/classes/jdk/jfr/events/SocketReadEvent.java src/jdk.jfr/share/classes/jdk/jfr/events/SocketWriteEvent.java src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java src/jdk.jfr/share/classes/jdk/jfr/internal/handlers/EventHandler.java src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileChannelImplInstrumentor.java src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileInputStreamInstrumentor.java src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileOutputStreamInstrumentor.java src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/RandomAccessFileInstrumentor.java src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketChannelImplInstrumentor.java src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketInputStreamInstrumentor.java src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketOutputStreamInstrumentor.java src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/ThrowableTracer.java
diffstat 18 files changed, 394 insertions(+), 342 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/ErrorThrownEvent.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/ErrorThrownEvent.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -36,6 +36,9 @@
 @Description("An object derived from java.lang.Error has been created. OutOfMemoryErrors are ignored")
 public final class ErrorThrownEvent extends AbstractJDKEvent {
 
+    // The order of these fields must be the same as the parameters in
+    // EventHandler::write(..., String, Class)
+
     @Label("Message")
     public String message;
 
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/ExceptionThrownEvent.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/ExceptionThrownEvent.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -37,6 +37,9 @@
 @Description("An object derived from java.lang.Exception has been created")
 public final class ExceptionThrownEvent extends AbstractJDKEvent {
 
+    // The order of these fields must be the same as the parameters in
+    // EventHandler::write(..., String, Class)
+
     @Label("Message")
     public String message;
 
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/FileForceEvent.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/FileForceEvent.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 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
@@ -37,12 +37,8 @@
 @Description("Force updates to be written to file")
 public final class FileForceEvent extends AbstractJDKEvent {
 
-    public static final ThreadLocal<FileForceEvent> EVENT =
-        new ThreadLocal<>() {
-            @Override protected FileForceEvent initialValue() {
-                return new FileForceEvent();
-            }
-        };
+    // The order of these fields must be the same as the parameters in
+    // EventHandler::write(..., String, boolean)
 
     @Label("Path")
     @Description("Full path of the file")
@@ -51,9 +47,4 @@
     @Label("Update Metadata")
     @Description("Whether the file metadata is updated")
     public boolean metaData;
-
-    public void reset() {
-        path = null;
-        metaData = false;
-    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/FileReadEvent.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/FileReadEvent.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -38,12 +38,8 @@
 @Description("Reading data from a file")
 public final class FileReadEvent extends AbstractJDKEvent {
 
-    public static final ThreadLocal<FileReadEvent> EVENT =
-        new ThreadLocal<>() {
-            @Override protected FileReadEvent initialValue() {
-                return new FileReadEvent();
-            }
-        };
+    // The order of these fields must be the same as the parameters in
+    // EventHandler::write(..., String, long, boolean)
 
     @Label("Path")
     @Description("Full path of the file")
@@ -57,10 +53,4 @@
     @Label("End of File")
     @Description("If end of file was reached")
     public boolean endOfFile;
-
-    public void reset() {
-        path = null;
-        endOfFile = false;
-        bytesRead = 0;
-    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/FileWriteEvent.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/FileWriteEvent.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -38,12 +38,8 @@
 @Description("Writing data to a file")
 public final class FileWriteEvent extends AbstractJDKEvent {
 
-    public static final ThreadLocal<FileWriteEvent> EVENT =
-        new ThreadLocal<>() {
-            @Override protected FileWriteEvent initialValue() {
-                return new FileWriteEvent();
-            }
-        };
+    // The order of these fields must be the same as the parameters in
+    // EventHandler::write(..., String, long)
 
     @Label("Path")
     @Description("Full path of the file")
@@ -53,9 +49,4 @@
     @Description("Number of bytes written to the file")
     @DataAmount
     public long bytesWritten;
-
-    public void reset() {
-        path = null;
-        bytesWritten = 0;
-    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/Handlers.java	Tue May 12 15:20:15 2020 +0200
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.jfr.events;
+import jdk.jfr.internal.handlers.EventHandler;
+import jdk.jfr.internal.Utils;
+
+public final class Handlers {
+    public final static EventHandler SOCKET_READ = Utils.getHandler(SocketReadEvent.class);
+    public final static EventHandler SOCKET_WRITE = Utils.getHandler(SocketWriteEvent.class);
+    public final static EventHandler FILE_READ = Utils.getHandler(FileReadEvent.class);
+    public final static EventHandler FILE_WRITE = Utils.getHandler(FileWriteEvent.class);
+    public final static EventHandler FILE_FORCE = Utils.getHandler(FileForceEvent.class);
+    public final static EventHandler ERROR_THROWN = Utils.getHandler(ErrorThrownEvent.class);
+    public final static EventHandler EXCEPTION_THROWN = Utils.getHandler(ExceptionThrownEvent.class);
+}
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/SocketReadEvent.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/SocketReadEvent.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -39,12 +39,8 @@
 @Description("Reading data from a socket")
 public final class SocketReadEvent extends AbstractJDKEvent {
 
-    public static final ThreadLocal<SocketReadEvent> EVENT =
-        new ThreadLocal<>() {
-            @Override protected SocketReadEvent initialValue() {
-                return new SocketReadEvent();
-            }
-        };
+    // The order of these fields must be the same as the parameters in
+    // EventHandler::write(..., String, String, int, long, long, boolean)
 
     @Label("Remote Host")
     public String host;
@@ -67,13 +63,4 @@
     @Label("End of Stream")
     @Description("If end of stream was reached")
     public boolean endOfStream;
-
-    public void reset() {
-        host = null;
-        address = null;
-        port = 0;
-        timeout = 0;
-        bytesRead = 0L;
-        endOfStream = false;
-    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/events/SocketWriteEvent.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/events/SocketWriteEvent.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -38,12 +38,8 @@
 @Description("Writing data to a socket")
 public final class SocketWriteEvent extends AbstractJDKEvent {
 
-    public static final ThreadLocal<SocketWriteEvent> EVENT =
-        new ThreadLocal<>() {
-            @Override protected SocketWriteEvent initialValue() {
-                return new SocketWriteEvent();
-            }
-        };
+    // The order of these fields must be the same as the parameters in
+    // EventHandler::write(..., String, String, int, long)
 
     @Label("Remote Host")
     public String host;
@@ -58,11 +54,4 @@
     @Description("Number of bytes written to the socket")
     @DataAmount
     public long bytesWritten;
-
-    public void reset() {
-        host = null;
-        address = null;
-        port = 0;
-        bytesWritten = 0;
-    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java	Tue May 12 15:20:15 2020 +0200
@@ -350,7 +350,7 @@
         return (long) (nanos * JVM.getJVM().getTimeConversionFactor());
     }
 
-    static synchronized EventHandler getHandler(Class<? extends jdk.internal.event.Event> eventClass) {
+    public static synchronized EventHandler getHandler(Class<? extends jdk.internal.event.Event> eventClass) {
         Utils.ensureValidEventSubclass(eventClass);
         try {
             Field f = eventClass.getDeclaredField(EventInstrumentation.FIELD_EVENT_HANDLER);
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/handlers/EventHandler.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/handlers/EventHandler.java	Tue May 12 15:20:15 2020 +0200
@@ -114,4 +114,32 @@
     public boolean setRegistered(boolean registered) {
        return platformEventType.setRegistered(registered);
     }
+
+    public void write(long start, long duration, String host, String address, int port, long timeout, long bytesRead, boolean endOfSTream) {
+        throwError("SocketReadEvent");
+    }
+
+    public void write(long start, long duration, String host, String address, int port, long bytesWritten) {
+        throwError("SocketWriteEvent");
+    }
+
+    public void write(long start, long duration, String path, boolean metadata) {
+        throwError("FileForceEvent");
+    }
+
+    public void write(long start, long duration, String path, long bytesRead, boolean endOfFile) {
+        throwError("FileReadEvent");
+    }
+
+    public void write(long start, long duration, String path, long bytesWritten) {
+        throwError("FileWriteEvent");
+    }
+
+    public void write(long start, long duration, String path, Class<?> exceptionClass)  {
+        throwError("ExceptionThrownEvent or ErrorThrownEvent");
+    }
+
+    private void throwError(String classes) {
+        throw new InternalError("Method parameters don't match fields in class " + classes);
+    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileChannelImplInstrumentor.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileChannelImplInstrumentor.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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,9 +28,8 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
-import jdk.jfr.events.FileForceEvent;
-import jdk.jfr.events.FileReadEvent;
-import jdk.jfr.events.FileWriteEvent;
+import jdk.jfr.events.Handlers;
+import jdk.jfr.internal.handlers.EventHandler;
 
 /**
  * See {@link JITracer} for an explanation of this code.
@@ -46,42 +45,44 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public void force(boolean metaData) throws IOException {
-        FileForceEvent event = FileForceEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_FORCE;
+        if (!handler.isEnabled()) {
             force(metaData);
             return;
         }
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             force(metaData);
         } finally {
-            event.path = path;
-            event.metaData = metaData;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, metaData);
+            }
         }
     }
 
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read(ByteBuffer dst) throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read(dst);
         }
         int bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(dst);
         } finally {
-            if (bytesRead < 0) {
-                event.endOfFile = true;
-            } else {
-                event.bytesRead = bytesRead;
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                if (bytesRead < 0) {
+                    handler.write(start, duration, path, 0L, true);
+                } else {
+                    handler.write(start, duration, path, bytesRead, false);
+                }
             }
-            event.path = path;
-            event.commit();
-            event.reset();
         }
         return bytesRead;
     }
@@ -89,23 +90,24 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read(ByteBuffer dst, long position) throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read(dst, position);
         }
         int bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(dst, position);
         } finally {
-            if (bytesRead < 0) {
-                event.endOfFile = true;
-            } else {
-                event.bytesRead = bytesRead;
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                if (bytesRead < 0) {
+                    handler.write(start, duration, path, 0L, true);
+                } else {
+                    handler.write(start, duration, path, bytesRead, false);
+                }
             }
-            event.path = path;
-            event.commit();
-            event.reset();
         }
         return bytesRead;
     }
@@ -113,23 +115,24 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read(dsts, offset, length);
         }
         long bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(dsts, offset, length);
         } finally {
-            if (bytesRead < 0) {
-                event.endOfFile = true;
-            } else {
-                event.bytesRead = bytesRead;
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                if (bytesRead < 0) {
+                    handler.write(start, duration, path, 0L, true);
+                } else {
+                    handler.write(start, duration, path, bytesRead, false);
+                }
             }
-            event.path = path;
-            event.commit();
-            event.reset();
         }
         return bytesRead;
     }
@@ -137,19 +140,21 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int write(ByteBuffer src) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             return write(src);
         }
         int bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesWritten = write(src);
         } finally {
-            event.bytesWritten = bytesWritten > 0 ? bytesWritten : 0;
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                long bytes = bytesWritten > 0 ? bytesWritten : 0;
+                handler.write(start, duration, path, bytes);
+            }
         }
         return bytesWritten;
     }
@@ -157,20 +162,22 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int write(ByteBuffer src, long position) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             return write(src, position);
         }
 
         int bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesWritten = write(src, position);
         } finally {
-            event.bytesWritten = bytesWritten > 0 ? bytesWritten : 0;
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                long bytes = bytesWritten > 0 ? bytesWritten : 0;
+                handler.write(start, duration, path, bytes);
+            }
         }
         return bytesWritten;
     }
@@ -178,19 +185,21 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public long write(ByteBuffer[] srcs, int offset, int length) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             return write(srcs, offset, length);
         }
         long bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesWritten = write(srcs, offset, length);
         } finally {
-            event.bytesWritten = bytesWritten > 0 ? bytesWritten : 0;
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                long bytes = bytesWritten > 0 ? bytesWritten : 0;
+                handler.write(start, duration, path, bytes);
+            }
         }
         return bytesWritten;
     }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileInputStreamInstrumentor.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileInputStreamInstrumentor.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -27,7 +27,8 @@
 
 import java.io.IOException;
 
-import jdk.jfr.events.FileReadEvent;
+import jdk.jfr.events.Handlers;
+import jdk.jfr.internal.handlers.EventHandler;
 
 /**
  * See {@link JITracer} for an explanation of this code.
@@ -43,23 +44,27 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read() throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read();
         }
         int result = 0;
+        boolean endOfFile = false;
+        long bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             result = read();
             if (result < 0) {
-                event.endOfFile = true;
+                endOfFile = true;
             } else {
-                event.bytesRead = 1;
+                bytesRead = 1;
             }
         } finally {
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, bytesRead, endOfFile);
+            }
         }
         return result;
     }
@@ -67,23 +72,24 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read(byte b[]) throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read(b);
         }
         int bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(b);
         } finally {
-            if (bytesRead < 0) {
-                event.endOfFile = true;
-            } else {
-                event.bytesRead = bytesRead;
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                if (bytesRead < 0) {
+                    handler.write(start, duration, path, 0L, true);
+                } else {
+                    handler.write(start, duration, path, bytesRead, false);
+                }
             }
-            event.path = path;
-            event.commit();
-            event.reset();
         }
         return bytesRead;
     }
@@ -91,25 +97,25 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read(byte b[], int off, int len) throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read(b, off, len);
         }
         int bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(b, off, len);
         } finally {
-            if (bytesRead < 0) {
-                event.endOfFile = true;
-            } else {
-                event.bytesRead = bytesRead;
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                if (bytesRead < 0) {
+                    handler.write(start, duration, path, 0L, true);
+                } else {
+                    handler.write(start, duration, path, bytesRead, false);
+                }
             }
-            event.path = path;
-            event.commit();
-            event.reset();
         }
         return bytesRead;
     }
-
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileOutputStreamInstrumentor.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileOutputStreamInstrumentor.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -27,7 +27,8 @@
 
 import java.io.IOException;
 
-import jdk.jfr.events.FileWriteEvent;
+import jdk.jfr.events.Handlers;
+import jdk.jfr.internal.handlers.EventHandler;
 
 /**
  * See {@link JITracer} for an explanation of this code.
@@ -43,57 +44,66 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public void write(int b) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             write(b);
             return;
         }
+        long bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             write(b);
-            event.bytesWritten = 1;
+            bytesWritten = 1;
         } finally {
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, bytesWritten);
+            }
         }
     }
 
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public void write(byte b[]) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             write(b);
             return;
         }
+        long bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             write(b);
-            event.bytesWritten = b.length;
+            bytesWritten = b.length;
         } finally {
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, bytesWritten);
+            }
         }
     }
 
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public void write(byte b[], int off, int len) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             write(b, off, len);
             return;
         }
+        long bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             write(b, off, len);
-            event.bytesWritten = len;
+            bytesWritten = len;
         } finally {
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, bytesWritten);
+            }
         }
     }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/RandomAccessFileInstrumentor.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/RandomAccessFileInstrumentor.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -27,8 +27,8 @@
 
 import java.io.IOException;
 
-import jdk.jfr.events.FileReadEvent;
-import jdk.jfr.events.FileWriteEvent;
+import jdk.jfr.events.Handlers;
+import jdk.jfr.internal.handlers.EventHandler;
 
 /**
  * See {@link JITracer} for an explanation of this code.
@@ -44,23 +44,27 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read() throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read();
         }
         int result = 0;
+        long bytesRead = 0;
+        boolean endOfFile = false;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             result = read();
             if (result < 0) {
-                event.endOfFile = true;
+                endOfFile = true;
             } else {
-                event.bytesRead = 1;
+                bytesRead = 1;
             }
         } finally {
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, bytesRead, endOfFile);
+            }
         }
         return result;
     }
@@ -68,23 +72,24 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read(byte b[]) throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read(b);
         }
         int bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(b);
         } finally {
-            if (bytesRead < 0) {
-                event.endOfFile = true;
-            } else {
-                event.bytesRead = bytesRead;
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                if (bytesRead < 0) {
+                    handler.write(start, duration, path, 0L, true);
+                } else {
+                    handler.write(start, duration, path, bytesRead, false);
+                }
             }
-            event.path = path;
-            event.commit();
-            event.reset();
         }
         return bytesRead;
     }
@@ -92,23 +97,24 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read(byte b[], int off, int len) throws IOException {
-        FileReadEvent event = FileReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_READ;
+        if (!handler.isEnabled()) {
             return read(b, off, len);
         }
         int bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(b, off, len);
         } finally {
-            if (bytesRead < 0) {
-                event.endOfFile = true;
-            } else {
-                event.bytesRead = bytesRead;
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                if (bytesRead < 0) {
+                    handler.write(start, duration, path, 0L, true);
+                } else {
+                    handler.write(start, duration, path, bytesRead, false);
+                }
             }
-            event.path = path;
-            event.commit();
-            event.reset();
         }
         return bytesRead;
     }
@@ -116,58 +122,66 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public void write(int b) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             write(b);
             return;
         }
+        long bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             write(b);
-            event.bytesWritten = 1;
+            bytesWritten = 1;
         } finally {
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, bytesWritten);
+            }
         }
     }
 
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public void write(byte b[]) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             write(b);
             return;
         }
+        long bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             write(b);
-            event.bytesWritten = b.length;
+            bytesWritten = b.length;
         } finally {
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp();
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, bytesWritten);
+            }
         }
     }
 
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public void write(byte b[], int off, int len) throws IOException {
-        FileWriteEvent event = FileWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.FILE_WRITE;
+        if (!handler.isEnabled()) {
             write(b, off, len);
             return;
         }
+        long bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             write(b, off, len);
-            event.bytesWritten = len;
+            bytesWritten = len;
         } finally {
-            event.path = path;
-            event.commit();
-            event.reset();
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
+                handler.write(start, duration, path, bytesWritten);
+            }
         }
     }
-
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketChannelImplInstrumentor.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketChannelImplInstrumentor.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -29,8 +29,8 @@
 import java.net.InetSocketAddress;
 import java.nio.ByteBuffer;
 
-import jdk.jfr.events.SocketReadEvent;
-import jdk.jfr.events.SocketWriteEvent;
+import jdk.jfr.events.Handlers;
+import jdk.jfr.internal.handlers.EventHandler;
 
 /**
  * See {@link JITracer} for an explanation of this code.
@@ -46,32 +46,29 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read(ByteBuffer dst) throws IOException {
-        SocketReadEvent event = SocketReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.SOCKET_READ;
+        if (!handler.isEnabled()) {
             return read(dst);
         }
         int bytesRead = 0;
+        long start  = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();;
             bytesRead = read(dst);
         } finally {
-            event.end();
-            if (event.shouldCommit())  {
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration))  {
                 String hostString  = remoteAddress.getAddress().toString();
                 int delimiterIndex = hostString.lastIndexOf('/');
 
-                event.host      = hostString.substring(0, delimiterIndex);
-                event.address   = hostString.substring(delimiterIndex + 1);
-                event.port      = remoteAddress.getPort();
+                String host = hostString.substring(0, delimiterIndex);
+                String address = hostString.substring(delimiterIndex + 1);
+                int port = remoteAddress.getPort();
                 if (bytesRead < 0) {
-                    event.endOfStream = true;
+                    handler.write(start, duration, host, address, port, 0, 0L, true);
                 } else {
-                    event.bytesRead = bytesRead;
+                    handler.write(start, duration, host, address, port, 0, bytesRead, false);
                 }
-                event.timeout   = 0;
-
-                event.commit();
-                event.reset();
             }
         }
         return bytesRead;
@@ -80,33 +77,30 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
-        SocketReadEvent event = SocketReadEvent.EVENT.get();
-        if(!event.isEnabled()) {
+        EventHandler handler = Handlers.SOCKET_READ;
+        if (!handler.isEnabled()) {
             return read(dsts, offset, length);
         }
 
         long bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(dsts, offset, length);
         } finally {
-            event.end();
-            if (event.shouldCommit()) {
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
                 String hostString  = remoteAddress.getAddress().toString();
                 int delimiterIndex = hostString.lastIndexOf('/');
 
-                event.host      = hostString.substring(0, delimiterIndex);
-                event.address   = hostString.substring(delimiterIndex + 1);
-                event.port      = remoteAddress.getPort();
+                String host = hostString.substring(0, delimiterIndex);
+                String address = hostString.substring(delimiterIndex + 1);
+                int port = remoteAddress.getPort();
                 if (bytesRead < 0) {
-                    event.endOfStream = true;
+                    handler.write(start, duration, host, address, port, 0, 0L, true);
                 } else {
-                    event.bytesRead = bytesRead;
+                    handler.write(start, duration, host, address, port, 0, bytesRead, false);
                 }
-                event.timeout   = 0;
-
-                event.commit();
-                event.reset();
             }
         }
         return bytesRead;
@@ -115,28 +109,26 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int write(ByteBuffer buf) throws IOException {
-        SocketWriteEvent event = SocketWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.SOCKET_WRITE;
+        if (!handler.isEnabled()) {
             return write(buf);
         }
-
         int bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesWritten = write(buf);
         } finally {
-            event.end();
-            if (event.shouldCommit()) {
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
                 String hostString  = remoteAddress.getAddress().toString();
                 int delimiterIndex = hostString.lastIndexOf('/');
 
-                event.host         = hostString.substring(0, delimiterIndex);
-                event.address      = hostString.substring(delimiterIndex + 1);
-                event.port         = remoteAddress.getPort();
-                event.bytesWritten = bytesWritten < 0 ? 0 : bytesWritten;
-
-                event.commit();
-                event.reset();
+                String host = hostString.substring(0, delimiterIndex);
+                String address = hostString.substring(delimiterIndex + 1);
+                int port = remoteAddress.getPort();
+                long bytes = bytesWritten < 0 ? 0 : bytesWritten;
+                handler.write(start, duration, host, address, port, bytes);
             }
         }
         return bytesWritten;
@@ -145,30 +137,28 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public long write(ByteBuffer[] srcs, int offset, int length) throws IOException {
-        SocketWriteEvent event = SocketWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.SOCKET_WRITE;
+        if (!handler.isEnabled()) {
             return write(srcs, offset, length);
         }
         long bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesWritten = write(srcs, offset, length);
         } finally {
-            event.end();
-            if (event.shouldCommit()) {
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
                 String hostString  = remoteAddress.getAddress().toString();
                 int delimiterIndex = hostString.lastIndexOf('/');
 
-                event.host         = hostString.substring(0, delimiterIndex);
-                event.address      = hostString.substring(delimiterIndex + 1);
-                event.port         = remoteAddress.getPort();
-                event.bytesWritten = bytesWritten < 0 ? 0 : bytesWritten;
-
-                event.commit();
-                event.reset();
+                String host = hostString.substring(0, delimiterIndex);
+                String address = hostString.substring(delimiterIndex + 1);
+                int port = remoteAddress.getPort();
+                long bytes = bytesWritten < 0 ? 0 : bytesWritten;
+                handler.write(start, duration, host, address, port, bytes);
             }
         }
         return bytesWritten;
     }
-
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketInputStreamInstrumentor.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketInputStreamInstrumentor.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -29,7 +29,8 @@
 import java.net.InetAddress;
 import java.net.Socket;
 
-import jdk.jfr.events.SocketReadEvent;
+import jdk.jfr.events.Handlers;
+import jdk.jfr.internal.handlers.EventHandler;
 
 /**
  * See {@link JITracer} for an explanation of this code.
@@ -43,30 +44,28 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public int read(byte b[], int off, int length) throws IOException {
-        SocketReadEvent event = SocketReadEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.SOCKET_READ;
+        if (!handler.isEnabled()) {
             return read(b, off, length);
         }
         int bytesRead = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             bytesRead = read(b, off, length);
         } finally {
-            event.end();
-            if (event.shouldCommit()) {
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
                 InetAddress remote = parent.getInetAddress();
-                event.host = remote.getHostName();
-                event.address = remote.getHostAddress();
-                event.port = parent.getPort();
+                String host = remote.getHostName();
+                String address = remote.getHostAddress();
+                int port = parent.getPort();
+                int timeout = parent.getSoTimeout();
                 if (bytesRead < 0) {
-                    event.endOfStream = true;
+                    handler.write(start, duration, host, address, port, timeout, 0L, true);
                 } else {
-                    event.bytesRead = bytesRead;
+                    handler.write(start, duration, host, address, port, timeout, bytesRead, false);
                 }
-                event.timeout = parent.getSoTimeout();
-
-                event.commit();
-                event.reset();
             }
         }
         return bytesRead;
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketOutputStreamInstrumentor.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketOutputStreamInstrumentor.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -29,7 +29,8 @@
 import java.net.InetAddress;
 import java.net.Socket;
 
-import jdk.jfr.events.SocketWriteEvent;
+import jdk.jfr.events.Handlers;
+import jdk.jfr.internal.handlers.EventHandler;
 
 /**
  * See {@link JITracer} for an explanation of this code.
@@ -43,27 +44,28 @@
     @SuppressWarnings("deprecation")
     @JIInstrumentationMethod
     public void write(byte b[], int off, int len) throws IOException {
-        SocketWriteEvent event = SocketWriteEvent.EVENT.get();
-        if (!event.isEnabled()) {
+        EventHandler handler = Handlers.SOCKET_WRITE;
+        if (!handler.isEnabled()) {
             write(b, off, len);
             return;
         }
         int bytesWritten = 0;
+        long start = 0;
         try {
-            event.begin();
+            start = EventHandler.timestamp();
             write(b, off, len);
             bytesWritten = len;
         } finally {
-            event.end() ;
-            if (event.shouldCommit()) {
+            long duration = EventHandler.timestamp() - start;
+            if (handler.shouldCommit(duration)) {
                 InetAddress remote = parent.getInetAddress();
-                event.host = remote.getHostName();
-                event.address = remote.getHostAddress();
-                event.port = parent.getPort();
-                event.bytesWritten = bytesWritten;
-
-                event.commit();
-                event.reset();
+                handler.write(
+                        start,
+                        duration,
+                        remote.getHostName(),
+                        remote.getHostAddress(),
+                        parent.getPort(),
+                        bytesWritten);
             }
         }
     }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/ThrowableTracer.java	Tue May 12 11:11:02 2020 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/ThrowableTracer.java	Tue May 12 15:20:15 2020 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -27,34 +27,36 @@
 
 import java.util.concurrent.atomic.AtomicLong;
 
-import jdk.jfr.events.ErrorThrownEvent;
-import jdk.jfr.events.ExceptionThrownEvent;
+import jdk.jfr.events.Handlers;
+import jdk.jfr.internal.handlers.EventHandler;
 
 public final class ThrowableTracer {
 
-    private static AtomicLong numThrowables = new AtomicLong(0);
+    private static final AtomicLong numThrowables = new AtomicLong(0);
 
     public static void traceError(Error e, String message) {
         if (e instanceof OutOfMemoryError) {
             return;
         }
-        ErrorThrownEvent errorEvent = new ErrorThrownEvent();
-        errorEvent.message = message;
-        errorEvent.thrownClass = e.getClass();
-        errorEvent.commit();
+        long timestamp = EventHandler.timestamp();
 
-        ExceptionThrownEvent exceptionEvent = new ExceptionThrownEvent();
-        exceptionEvent.message = message;
-        exceptionEvent.thrownClass = e.getClass();
-        exceptionEvent.commit();
+        EventHandler h1 = Handlers.ERROR_THROWN;
+        if (h1.isEnabled()) {
+            h1.write(timestamp, 0L, message, e.getClass());
+        }
+        EventHandler h2 = Handlers.EXCEPTION_THROWN;
+        if (h2.isEnabled()) {
+            h2.write(timestamp, 0L, message, e.getClass());
+        }
         numThrowables.incrementAndGet();
     }
 
     public static void traceThrowable(Throwable t, String message) {
-        ExceptionThrownEvent event = new ExceptionThrownEvent();
-        event.message = message;
-        event.thrownClass = t.getClass();
-        event.commit();
+        EventHandler h = Handlers.EXCEPTION_THROWN;
+        if (h.isEnabled()) {
+            long timestamp = EventHandler.timestamp();
+            h.write(timestamp, 0L, message, t.getClass());
+        }
         numThrowables.incrementAndGet();
     }