From 9bef2d1610647dec18f9e81cbac3dddbbf99dd6d Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Tue, 15 Jul 2025 20:33:24 +0000 Subject: [PATCH] 8361640: JFR: RandomAccessFile::readLine emits events for each character Reviewed-by: rriggs, alanb, mgronlun --- .../classes/java/io/RandomAccessFile.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/io/RandomAccessFile.java b/src/java.base/share/classes/java/io/RandomAccessFile.java index 339030e022c..a7aa3ea358b 100644 --- a/src/java.base/share/classes/java/io/RandomAccessFile.java +++ b/src/java.base/share/classes/java/io/RandomAccessFile.java @@ -1030,17 +1030,32 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { */ public final String readLine() throws IOException { + if (jfrTracing && FileReadEvent.enabled()) { + long bytesRead = 0; + long start = FileReadEvent.timestamp(); + try { + String result = implReadLine(); + bytesRead = result == null ? 0 : result.length(); + return result; + } finally { + FileReadEvent.offer(start, path, bytesRead); + } + } + return implReadLine(); + } + + private final String implReadLine() throws IOException { StringBuilder input = new StringBuilder(); int c = -1; boolean eol = false; while (!eol) { - switch (c = read()) { + switch (c = read0()) { case -1, '\n' -> eol = true; case '\r' -> { eol = true; long cur = getFilePointer(); - if ((read()) != '\n') { + if ((read0()) != '\n') { seek(cur); } }