Skip to content
13 changes: 8 additions & 5 deletions src/java.base/share/classes/java/io/FileInputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2025, 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
Expand Down Expand Up @@ -217,10 +217,12 @@ private int traceRead0() throws IOException {
bytesRead = 1;
}
} finally {
long duration = FileReadEvent.timestamp() - start;
if (FileReadEvent.shouldCommit(duration)) {
long end = FileReadEvent.timestamp();
long duration = end - start;
if (FileReadEvent.shouldThrottleCommit(duration, end)) {
FileReadEvent.commit(start, duration, path, bytesRead, endOfFile);
}

}
return result;
}
Expand All @@ -241,8 +243,9 @@ private int traceReadBytes(byte b[], int off, int len) throws IOException {
start = FileReadEvent.timestamp();
bytesRead = readBytes(b, off, len);
} finally {
long duration = FileReadEvent.timestamp() - start;
if (FileReadEvent.shouldCommit(duration)) {
long end = FileReadEvent.timestamp();
long duration = end - start;
if (FileReadEvent.shouldThrottleCommit(duration, end)) {
if (bytesRead < 0) {
FileReadEvent.commit(start, duration, path, 0L, true);
} else {
Expand Down
12 changes: 7 additions & 5 deletions src/java.base/share/classes/java/io/FileOutputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2025, 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
Expand Down Expand Up @@ -272,8 +272,9 @@ private void traceWrite(int b, boolean append) throws IOException {
write(b, append);
bytesWritten = 1;
} finally {
long duration = FileWriteEvent.timestamp() - start;
if (FileWriteEvent.shouldCommit(duration)) {
long end = FileWriteEvent.timestamp();
long duration = end - start;
if (FileWriteEvent.shouldThrottleCommit(duration, end)) {
FileWriteEvent.commit(start, duration, path, bytesWritten);
}
}
Expand Down Expand Up @@ -316,8 +317,9 @@ private void traceWriteBytes(byte b[], int off, int len, boolean append) throws
writeBytes(b, off, len, append);
bytesWritten = len;
} finally {
long duration = FileWriteEvent.timestamp() - start;
if (FileWriteEvent.shouldCommit(duration)) {
long end = FileWriteEvent.timestamp();
long duration = end - start;
if (FileWriteEvent.shouldThrottleCommit(duration, end)) {
FileWriteEvent.commit(start, duration, path, bytesWritten);
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/java.base/share/classes/java/io/RandomAccessFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2025, 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
Expand Down Expand Up @@ -378,8 +378,9 @@ private int traceRead0() throws IOException {
bytesRead = 1;
}
} finally {
long duration = FileReadEvent.timestamp() - start;
if (FileReadEvent.shouldCommit(duration)) {
long end = FileReadEvent.timestamp();
long duration = end - start;
if (FileReadEvent.shouldThrottleCommit(duration, end)) {
FileReadEvent.commit(start, duration, path, bytesRead, endOfFile);
}
}
Expand Down Expand Up @@ -409,8 +410,9 @@ private int traceReadBytes0(byte b[], int off, int len) throws IOException {
start = FileReadEvent.timestamp();
bytesRead = readBytes0(b, off, len);
} finally {
long duration = FileReadEvent.timestamp() - start;
if (FileReadEvent.shouldCommit(duration)) {
long end = FileReadEvent.timestamp();
long duration = end - start;
if (FileReadEvent.shouldThrottleCommit(duration, end)) {
if (bytesRead < 0) {
FileReadEvent.commit(start, duration, path, 0L, true);
} else {
Expand Down Expand Up @@ -588,8 +590,9 @@ private void traceImplWrite(int b) throws IOException {
implWrite(b);
bytesWritten = 1;
} finally {
long duration = FileWriteEvent.timestamp() - start;
if (FileWriteEvent.shouldCommit(duration)) {
long end = FileWriteEvent.timestamp();
long duration = end - start;
if (FileWriteEvent.shouldThrottleCommit(duration, end)) {
FileWriteEvent.commit(start, duration, path, bytesWritten);
}
}
Expand Down Expand Up @@ -630,8 +633,9 @@ private void traceImplWriteBytes(byte b[], int off, int len) throws IOException
implWriteBytes(b, off, len);
bytesWritten = len;
} finally {
long duration = FileWriteEvent.timestamp() - start;
if (FileWriteEvent.shouldCommit(duration)) {
long end = FileWriteEvent.timestamp();
long duration = end - start;
if (FileWriteEvent.shouldThrottleCommit(duration, end)) {
FileWriteEvent.commit(start, duration, path, bytesWritten);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/lang/Throwable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2025, 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
Expand Down Expand Up @@ -121,7 +121,7 @@ public class Throwable implements Serializable {
* Flag set by jdk.internal.event.JFRTracing to indicate if
* exceptions should be traced by JFR.
*/
static volatile boolean jfrTracing;
static boolean jfrTracing;

/**
* The JVM saves some indication of the stack backtrace in this slot.
Expand Down
10 changes: 6 additions & 4 deletions src/java.base/share/classes/java/net/Socket.java
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,9 @@ public int read(byte[] b, int off, int len) throws IOException {
}
long start = SocketReadEvent.timestamp();
int nbytes = implRead(b, off, len);
long duration = SocketReadEvent.timestamp() - start;
if (SocketReadEvent.shouldCommit(duration)) {
long end = SocketReadEvent.timestamp();
long duration = end - start;
if (SocketReadEvent.shouldThrottleCommit(duration, end)) {
SocketReadEvent.emit(start, duration, nbytes, parent.getRemoteSocketAddress(), getSoTimeout());
}
return nbytes;
Expand Down Expand Up @@ -1081,8 +1082,9 @@ public void write(byte[] b, int off, int len) throws IOException {
}
long start = SocketWriteEvent.timestamp();
implWrite(b, off, len);
long duration = SocketWriteEvent.timestamp() - start;
if (SocketWriteEvent.shouldCommit(duration)) {
long end = SocketWriteEvent.timestamp();
long duration = end - start;
if (SocketWriteEvent.shouldThrottleCommit(duration, end)) {
SocketWriteEvent.emit(start, duration, len, parent.getRemoteSocketAddress());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, 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
Expand Down Expand Up @@ -31,6 +31,11 @@ public final class ExceptionThrownEvent extends Event {
public String message;
public Class<?> thrownClass;

public static boolean shouldThrottleCommit(long timestamp) {
// Generated by JFR
return false;
}

public static void commit(long start, String message, Class<?> thrownClass) {
// Generated by JFR
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, 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
Expand Down Expand Up @@ -45,7 +45,7 @@ public static long timestamp() {
return 0L;
}

public static boolean shouldCommit(long duration) {
public static boolean shouldThrottleCommit(long duration, long timestamp) {
// Generated by JFR
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, 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
Expand Down Expand Up @@ -44,7 +44,7 @@ public static long timestamp() {
return 0L;
}

public static boolean shouldCommit(long duration) {
public static boolean shouldThrottleCommit(long duration, long timestamp) {
// Generated by JFR
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, 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
Expand Down Expand Up @@ -76,7 +76,7 @@ public static void commit(long start, long duration, String host, String address
* @param duration time in nanoseconds to complete the operation
* @return true if the event should be commited
*/
public static boolean shouldCommit(long duration) {
public static boolean shouldThrottleCommit(long duration, long timestamp) {
// Generated by JFR
return false;
}
Expand Down Expand Up @@ -118,8 +118,9 @@ public static long timestamp() {
* @param timeout maximum time to wait
*/
public static void offer(long start, long nbytes, SocketAddress remote, long timeout) {
long duration = timestamp() - start;
if (shouldCommit(duration)) {
long end = timestamp();
long duration = end - start;
if (shouldThrottleCommit(duration, end)) {
emit(start, duration, nbytes, remote, timeout);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, 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
Expand Down Expand Up @@ -71,7 +71,7 @@ public static void commit(long start, long duration, String host, String address
* @param duration time in nanoseconds to complete the operation
* @return true if the event should be commited
*/
public static boolean shouldCommit(long duration) {
public static boolean shouldThrottleCommit(long duration, long timestamp) {
// Generated by JFR
return false;
}
Expand Down Expand Up @@ -104,16 +104,17 @@ public static long timestamp() {
* The duration of the operation is computed using the current
* timestamp and the given start time. If the duration is meets
* or exceeds the configured value (determined by calling the generated method
* {@link #shouldCommit(long)}), an event will be emitted by calling
* {@link #shouldThrottleCommit(long)}), an event will be emitted by calling
* {@link #emit(long, long, long, SocketAddress)}.
*
* @param start the start time
* @param bytesWritten how many bytes were sent
* @param remote the address of the remote socket being written to
*/
public static void offer(long start, long bytesWritten, SocketAddress remote) {
long duration = timestamp() - start;
if (shouldCommit(duration)) {
long end = timestamp();
long duration = end - start;
if (shouldThrottleCommit(duration, end)) {
emit(start, duration, bytesWritten, remote);
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/java.base/share/classes/jdk/internal/event/ThrowableTracer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2025, 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
Expand Down Expand Up @@ -37,22 +37,24 @@ public static void traceError(Class<?> clazz, String message) {
if (OutOfMemoryError.class.isAssignableFrom(clazz)) {
return;
}

if (ErrorThrownEvent.enabled()) {
if (ErrorThrownEvent.enabled() || ExceptionThrownEvent.enabled()) {
long timestamp = ErrorThrownEvent.timestamp();
ErrorThrownEvent.commit(timestamp, message, clazz);
}
if (ExceptionThrownEvent.enabled()) {
long timestamp = ExceptionThrownEvent.timestamp();
ExceptionThrownEvent.commit(timestamp, message, clazz);
if (ErrorThrownEvent.enabled()) {
ErrorThrownEvent.commit(timestamp, message, clazz);
}
if (ExceptionThrownEvent.shouldThrottleCommit(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);
long timestamp = ErrorThrownEvent.timestamp();
if (ExceptionThrownEvent.shouldThrottleCommit(timestamp)) {
ExceptionThrownEvent.commit(timestamp, message, clazz);
}
}
numThrowables.incrementAndGet();
}
Expand Down
32 changes: 19 additions & 13 deletions src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2025, 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
Expand Down Expand Up @@ -269,8 +269,9 @@ private int traceImplRead(ByteBuffer dst) throws IOException {
start = FileReadEvent.timestamp();
bytesRead = implRead(dst);
} finally {
long duration = FileReadEvent.timestamp() - start;
if (FileReadEvent.shouldCommit(duration)) {
long end = FileReadEvent.timestamp();
long duration = end - start;
if (FileReadEvent.shouldThrottleCommit(duration, end)) {
if (bytesRead < 0) {
FileReadEvent.commit(start, duration, path, 0L, true);
} else {
Expand Down Expand Up @@ -331,8 +332,9 @@ private long traceImplRead(ByteBuffer[] dsts, int offset, int length) throws IOE
start = FileReadEvent.timestamp();
bytesRead = implRead(dsts, offset, length);
} finally {
long duration = FileReadEvent.timestamp() - start;
if (FileReadEvent.shouldCommit(duration)) {
long end = FileReadEvent.timestamp();
long duration = end - start;
if (FileReadEvent.shouldThrottleCommit(duration, end)) {
if (bytesRead < 0) {
FileReadEvent.commit(start, duration, path, 0L, true);
} else {
Expand Down Expand Up @@ -390,8 +392,9 @@ private int traceImplWrite(ByteBuffer src) throws IOException {
start = FileWriteEvent.timestamp();
bytesWritten = implWrite(src);
} finally {
long duration = FileWriteEvent.timestamp() - start;
if (FileWriteEvent.shouldCommit(duration)) {
long end = FileWriteEvent.timestamp();
long duration = end - start;
if (FileWriteEvent.shouldThrottleCommit(duration, end)) {
long bytes = bytesWritten > 0 ? bytesWritten : 0;
FileWriteEvent.commit(start, duration, path, bytes);
}
Expand Down Expand Up @@ -446,8 +449,9 @@ private long traceImplWrite(ByteBuffer[] srcs, int offset, int length) throws IO
start = FileWriteEvent.timestamp();
bytesWritten = implWrite(srcs, offset, length);
} finally {
long duration = FileWriteEvent.timestamp() - start;
if (FileWriteEvent.shouldCommit(duration)) {
long end = FileWriteEvent.timestamp();
long duration = end - start;
if (FileWriteEvent.shouldThrottleCommit(duration, end)) {
long bytes = bytesWritten > 0 ? bytesWritten : 0;
FileWriteEvent.commit(start, duration, path, bytes);
}
Expand Down Expand Up @@ -1204,8 +1208,9 @@ private int traceImplRead(ByteBuffer dst, long position) throws IOException {
start = FileReadEvent.timestamp();
bytesRead = implRead(dst, position);
} finally {
long duration = FileReadEvent.timestamp() - start;
if (FileReadEvent.shouldCommit(duration)) {
long end = FileReadEvent.timestamp();
long duration = end - start;
if (FileReadEvent.shouldThrottleCommit(duration, end)) {
if (bytesRead < 0) {
FileReadEvent.commit(start, duration, path, 0L, true);
} else {
Expand Down Expand Up @@ -1276,8 +1281,9 @@ private int traceImplWrite(ByteBuffer src, long position) throws IOException {
start = FileWriteEvent.timestamp();
bytesWritten = implWrite(src, position);
} finally {
long duration = FileWriteEvent.timestamp() - start;
if (FileWriteEvent.shouldCommit(duration)) {
long end = FileWriteEvent.timestamp();
long duration = end - start;
if (FileWriteEvent.shouldThrottleCommit(duration, end)) {
long bytes = bytesWritten > 0 ? bytesWritten : 0;
FileWriteEvent.commit(start, duration, path, bytes);
}
Expand Down
Loading