Skip to content

Commit

Permalink
[Backport] 8233870: JFR TestSetEndTime.java times out - onClose() is …
Browse files Browse the repository at this point in the history
…never called

Summary:

Test Plan: jdk/jfr

Reviewed-by: yuleil

Issue: dragonwell-project/dragonwell8#112
  • Loading branch information
D-D-H committed Jul 31, 2020
1 parent 64e12c6 commit 235b51f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,8 @@ public long getEventStart() {
static long headerSize() {
return HEADER_SIZE;
}

public long getLastNanos() {
return getStartNanos() + getDurationNanos();
}
}
7 changes: 5 additions & 2 deletions src/share/classes/jdk/jfr/internal/consumer/ChunkParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ RecordedEvent readStreamingEvent(boolean awaitNewEvents) throws IOException {
long lastValid = absoluteChunkEnd;
long metadataPoistion = chunkHeader.getMetataPosition();
long contantPosition = chunkHeader.getConstantPoolPosition();
chunkFinished = awaitUpdatedHeader(absoluteChunkEnd);
chunkFinished = awaitUpdatedHeader(absoluteChunkEnd, configuration.filterEnd);
if (chunkFinished) {
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "At chunk end");
return null;
Expand Down Expand Up @@ -279,11 +279,14 @@ private void parseCheckpoint() throws IOException {
}
}

private boolean awaitUpdatedHeader(long absoluteChunkEnd) throws IOException {
private boolean awaitUpdatedHeader(long absoluteChunkEnd, long filterEnd) throws IOException {
if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO)) {
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Waiting for more data (streaming). Read so far: " + chunkHeader.getChunkSize() + " bytes");
}
while (true) {
if (chunkHeader.getLastNanos() > filterEnd) {
return true;
}
chunkHeader.refresh();
if (absoluteChunkEnd != chunkHeader.getEnd()) {
return false;
Expand Down
12 changes: 10 additions & 2 deletions test/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public final static class Mark extends Event {
public static void main(String... args) throws Exception {
testEventStream();
testRecordingStream();
testEmptyStream();
}

private static void testEmptyStream() {
try (RecordingStream rs = new RecordingStream()) {
rs.setEndTime(Instant.now().plusMillis(1100));
rs.start();
}
}

private static void testRecordingStream() throws Exception {
Expand All @@ -88,10 +96,10 @@ private static void testRecordingStream() throws Exception {
}
closed.await();
System.out.println("Found events: " + count.get());
if (count.get() < 50) {
if (count.get() > 0 && count.get() < 50) {
return;
}
System.out.println("Found 50 events. Retrying");
System.out.println("Retrying");
System.out.println();
}
}
Expand Down

0 comments on commit 235b51f

Please sign in to comment.