8319374: JFR: Remove instrumentation for exception events

Reviewed-by: mgronlun, alanb
This commit is contained in:
Erik Gahlin 2023-11-08 13:22:33 +00:00
parent cd9719bc1d
commit e841897247
18 changed files with 234 additions and 247 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2023, 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
@ -25,6 +25,8 @@
package java.lang;
import jdk.internal.event.ThrowableTracer;
/**
* An {@code Error} is a subclass of {@code Throwable}
* that indicates serious problems that a reasonable application
@ -53,6 +55,9 @@ public class Error extends Throwable {
*/
public Error() {
super();
if (Throwable.jfrTracing) {
ThrowableTracer.traceError(getClass(), null);
}
}
/**
@ -65,6 +70,9 @@ public class Error extends Throwable {
*/
public Error(String message) {
super(message);
if (Throwable.jfrTracing) {
ThrowableTracer.traceError(getClass(), message);
}
}
/**
@ -83,6 +91,9 @@ public class Error extends Throwable {
*/
public Error(String message, Throwable cause) {
super(message, cause);
if (Throwable.jfrTracing) {
ThrowableTracer.traceError(getClass(), message);
}
}
/**
@ -100,6 +111,9 @@ public class Error extends Throwable {
*/
public Error(Throwable cause) {
super(cause);
if (Throwable.jfrTracing) {
ThrowableTracer.traceError(getClass(), null);
}
}
/**
@ -121,5 +135,8 @@ public class Error extends Throwable {
boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
if (Throwable.jfrTracing) {
ThrowableTracer.traceError(getClass(), message);
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2023, 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,7 @@ package java.lang;
import java.io.*;
import java.util.*;
import jdk.internal.access.SharedSecrets;
import jdk.internal.event.ThrowableTracer;
import jdk.internal.misc.InternalLock;
/**
@ -118,6 +119,11 @@ public class Throwable implements Serializable {
@java.io.Serial
private static final long serialVersionUID = -3042686055658047285L;
/**
* Flag that determines if exceptions should be traced by JFR
*/
static volatile boolean jfrTracing;
/**
* The JVM saves some indication of the stack backtrace in this slot.
*/
@ -256,6 +262,9 @@ public class Throwable implements Serializable {
*/
public Throwable() {
fillInStackTrace();
if (jfrTracing) {
ThrowableTracer.traceThrowable(getClass(), null);
}
}
/**
@ -272,6 +281,9 @@ public class Throwable implements Serializable {
public Throwable(String message) {
fillInStackTrace();
detailMessage = message;
if (jfrTracing) {
ThrowableTracer.traceThrowable(getClass(), message);
}
}
/**
@ -295,6 +307,9 @@ public class Throwable implements Serializable {
fillInStackTrace();
detailMessage = message;
this.cause = cause;
if (jfrTracing) {
ThrowableTracer.traceThrowable(getClass(), message);
}
}
/**
@ -318,6 +333,9 @@ public class Throwable implements Serializable {
fillInStackTrace();
detailMessage = (cause==null ? null : cause.toString());
this.cause = cause;
if (jfrTracing) {
ThrowableTracer.traceThrowable(getClass(), null);
}
}
/**
@ -370,8 +388,12 @@ public class Throwable implements Serializable {
}
detailMessage = message;
this.cause = cause;
if (!enableSuppression)
if (!enableSuppression) {
suppressedExceptions = null;
}
if (jfrTracing) {
ThrowableTracer.traceThrowable(getClass(), message);
}
}
/**

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2023, 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.internal.event;
/**
* Event recording error exceptions.
*/
public final class ErrorThrownEvent extends Event {
public String message;
public Class<?> thrownClass;
public static void commit(long start, String message, Class<?> thrownClass) {
// Generated by JFR
}
public static boolean enabled() {
// Generated by JFR
return false;
}
public static long timestamp() {
// Generated by JFR
return 0;
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2023, 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.internal.event;
/**
* Event recording number of exceptions that has been created.
*/
public class ExceptionStatisticsEvent extends Event {
public long throwables;
public static void commit(long timestamp, long throwables) {
// Generated by JFR
}
public static boolean enabled() {
// Generated by JFR
return false;
}
public static long timestamp() {
// Generated by JFR
return 0;
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2023, 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.internal.event;
/**
* Event recording all exception.
*/
public final class ExceptionThrownEvent extends Event {
public String message;
public Class<?> thrownClass;
public static void commit(long start, String message, Class<?> thrownClass) {
// Generated by JFR
}
public static boolean enabled() {
// Generated by JFR
return false;
}
public static long timestamp() {
// Generated by JFR
return 0;
}
}

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2012, 2023, 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.internal.event;
import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicLong;
/**
* Helper class for exception events.
*/
public final class ThrowableTracer {
private static final AtomicLong numThrowables = new AtomicLong();
public static void enable() throws NoSuchFieldException, IllegalAccessException {
Field field = Throwable.class.getDeclaredField("jfrTracing");
field.setAccessible(true);
field.setBoolean(null, true);
}
public static void traceError(Class<?> clazz, String message) {
if (OutOfMemoryError.class.isAssignableFrom(clazz)) {
return;
}
if (ErrorThrownEvent.enabled()) {
long timestamp = ErrorThrownEvent.timestamp();
ErrorThrownEvent.commit(timestamp, message, clazz);
}
if (ExceptionThrownEvent.enabled()) {
long timestamp = ExceptionThrownEvent.timestamp();
ExceptionThrownEvent.commit(timestamp, message, clazz);
}
numThrowables.incrementAndGet();
}
public static void traceThrowable(Class<?> clazz, String message) {
if (ExceptionThrownEvent.enabled()) {
long timestamp = ExceptionThrownEvent.timestamp();
ExceptionThrownEvent.commit(timestamp, message, clazz);
}
numThrowables.incrementAndGet();
}
public static void emitStatistics() {
long timestamp = ExceptionStatisticsEvent.timestamp();
ExceptionStatisticsEvent.commit(timestamp, numThrowables.get());
}
}