mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8331876: JFR: Move file read and write events to java.base
Reviewed-by: mgronlun, alanb
This commit is contained in:
parent
f608918df3
commit
4a20691e9b
20 changed files with 551 additions and 662 deletions
|
@ -28,6 +28,7 @@ package java.io;
|
|||
import java.nio.channels.FileChannel;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.access.JavaIOFileDescriptorAccess;
|
||||
import jdk.internal.event.FileWriteEvent;
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
|
||||
|
||||
|
@ -68,6 +69,12 @@ public class FileOutputStream extends OutputStream
|
|||
private static final JavaIOFileDescriptorAccess FD_ACCESS =
|
||||
SharedSecrets.getJavaIOFileDescriptorAccess();
|
||||
|
||||
/**
|
||||
* Flag set by jdk.internal.event.JFRTracing to indicate if
|
||||
* file writes should be traced by JFR.
|
||||
*/
|
||||
private static boolean jfrTracing;
|
||||
|
||||
/**
|
||||
* The system dependent file descriptor.
|
||||
*/
|
||||
|
@ -297,6 +304,21 @@ public class FileOutputStream extends OutputStream
|
|||
*/
|
||||
private native void write(int b, boolean append) throws IOException;
|
||||
|
||||
private void traceWrite(int b, boolean append) throws IOException {
|
||||
long bytesWritten = 0;
|
||||
long start = 0;
|
||||
try {
|
||||
start = FileWriteEvent.timestamp();
|
||||
write(b, append);
|
||||
bytesWritten = 1;
|
||||
} finally {
|
||||
long duration = FileWriteEvent.timestamp() - start;
|
||||
if (FileWriteEvent.shouldCommit(duration)) {
|
||||
FileWriteEvent.commit(start, duration, path, bytesWritten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the specified byte to this file output stream. Implements
|
||||
* the {@code write} method of {@code OutputStream}.
|
||||
|
@ -307,6 +329,10 @@ public class FileOutputStream extends OutputStream
|
|||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
boolean append = FD_ACCESS.getAppend(fd);
|
||||
if (jfrTracing && FileWriteEvent.enabled()) {
|
||||
traceWrite(b, append);
|
||||
return;
|
||||
}
|
||||
write(b, append);
|
||||
}
|
||||
|
||||
|
@ -322,6 +348,21 @@ public class FileOutputStream extends OutputStream
|
|||
private native void writeBytes(byte[] b, int off, int len, boolean append)
|
||||
throws IOException;
|
||||
|
||||
private void traceWriteBytes(byte b[], int off, int len, boolean append) throws IOException {
|
||||
long bytesWritten = 0;
|
||||
long start = 0;
|
||||
try {
|
||||
start = FileWriteEvent.timestamp();
|
||||
writeBytes(b, off, len, append);
|
||||
bytesWritten = len;
|
||||
} finally {
|
||||
long duration = FileWriteEvent.timestamp() - start;
|
||||
if (FileWriteEvent.shouldCommit(duration)) {
|
||||
FileWriteEvent.commit(start, duration, path, bytesWritten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes {@code b.length} bytes from the specified byte array
|
||||
* to this file output stream.
|
||||
|
@ -332,6 +373,10 @@ public class FileOutputStream extends OutputStream
|
|||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
boolean append = FD_ACCESS.getAppend(fd);
|
||||
if (jfrTracing && FileWriteEvent.enabled()) {
|
||||
traceWriteBytes(b, 0, b.length, append);
|
||||
return;
|
||||
}
|
||||
writeBytes(b, 0, b.length, append);
|
||||
}
|
||||
|
||||
|
@ -348,6 +393,10 @@ public class FileOutputStream extends OutputStream
|
|||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
boolean append = FD_ACCESS.getAppend(fd);
|
||||
if (jfrTracing && FileWriteEvent.enabled()) {
|
||||
traceWriteBytes(b, off, len, append);
|
||||
return;
|
||||
}
|
||||
writeBytes(b, off, len, append);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue