Skip to content

Commit 93260d6

Browse files
committed
8361640: JFR: RandomAccessFile::readLine emits events for each character
Reviewed-by: mgronlun, alanb Backport-of: 9bef2d1
1 parent b67fb82 commit 93260d6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/java.base/share/classes/java/io/RandomAccessFile.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,17 +1030,32 @@ public final double readDouble() throws IOException {
10301030
*/
10311031

10321032
public final String readLine() throws IOException {
1033+
if (jfrTracing && FileReadEvent.enabled()) {
1034+
long bytesRead = 0;
1035+
long start = FileReadEvent.timestamp();
1036+
try {
1037+
String result = implReadLine();
1038+
bytesRead = result == null ? 0 : result.length();
1039+
return result;
1040+
} finally {
1041+
FileReadEvent.offer(start, path, bytesRead);
1042+
}
1043+
}
1044+
return implReadLine();
1045+
}
1046+
1047+
private final String implReadLine() throws IOException {
10331048
StringBuilder input = new StringBuilder();
10341049
int c = -1;
10351050
boolean eol = false;
10361051

10371052
while (!eol) {
1038-
switch (c = read()) {
1053+
switch (c = read0()) {
10391054
case -1, '\n' -> eol = true;
10401055
case '\r' -> {
10411056
eol = true;
10421057
long cur = getFilePointer();
1043-
if ((read()) != '\n') {
1058+
if ((read0()) != '\n') {
10441059
seek(cur);
10451060
}
10461061
}

0 commit comments

Comments
 (0)