Skip to content
Permalink
Browse files
8244661: JFR: Remove use of thread-locals for java.base events
Reviewed-by: jbachorik, mgronlun
  • Loading branch information
egahlin committed May 12, 2020
1 parent b29d982 commit a6cdce140450a9d6750df560ce179428380e4733
Showing with 394 additions and 342 deletions.
  1. +4 −1 src/jdk.jfr/share/classes/jdk/jfr/events/ErrorThrownEvent.java
  2. +4 −1 src/jdk.jfr/share/classes/jdk/jfr/events/ExceptionThrownEvent.java
  3. +3 −12 src/jdk.jfr/share/classes/jdk/jfr/events/FileForceEvent.java
  4. +3 −13 src/jdk.jfr/share/classes/jdk/jfr/events/FileReadEvent.java
  5. +3 −12 src/jdk.jfr/share/classes/jdk/jfr/events/FileWriteEvent.java
  6. +38 −0 src/jdk.jfr/share/classes/jdk/jfr/events/Handlers.java
  7. +3 −16 src/jdk.jfr/share/classes/jdk/jfr/events/SocketReadEvent.java
  8. +3 −14 src/jdk.jfr/share/classes/jdk/jfr/events/SocketWriteEvent.java
  9. +1 −1 src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java
  10. +28 −0 src/jdk.jfr/share/classes/jdk/jfr/internal/handlers/EventHandler.java
  11. +71 −62 src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileChannelImplInstrumentor.java
  12. +37 −31 src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileInputStreamInstrumentor.java
  13. +33 −23 src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/FileOutputStreamInstrumentor.java
  14. +67 −53 src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/RandomAccessFileInstrumentor.java
  15. +47 −57 src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketChannelImplInstrumentor.java
  16. +15 −16 src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketInputStreamInstrumentor.java
  17. +16 −14 src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketOutputStreamInstrumentor.java
  18. +18 −16 src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/ThrowableTracer.java
@@ -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;

@@ -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;

@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
@@ -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;
}
}
@@ -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;
}
}
@@ -350,7 +350,7 @@ static long nanosToTicks(long nanos) {
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);
@@ -114,4 +114,32 @@ public boolean isRegistered() {
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);
}
}

0 comments on commit a6cdce1

Please sign in to comment.