From d10467e27b9898a75d7df8c31ee14a33edf7b848 Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Wed, 24 May 2023 16:38:50 +0000 Subject: [PATCH] 8307738: JFR: EventStream.openRepository() drops events Reviewed-by: mgronlun --- .../jfr/internal/consumer/ChunkParser.java | 19 ++++++++++++++----- .../consumer/EventDirectoryStream.java | 6 ++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkParser.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkParser.java index e0a55bf26eb..1ab375ada0c 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkParser.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, 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 @@ -98,6 +98,7 @@ public final class ChunkParser { private ParserConfiguration configuration; private MetadataDescriptor previousMetadata; private MetadataDescriptor metadata; + private long lastFlush; private boolean staleMetadata = true; public ChunkParser(RecordingInput input, ParserState ps) throws IOException { @@ -254,7 +255,7 @@ public final class ChunkParser { // Not accepted by filter } else { if (typeId == 1) { // checkpoint event - if (CheckpointType.FLUSH.is(parseCheckpointType())) { + if ((parseFlushCheckpoint())) { input.position(pos + size); return FLUSH_MARKER; } @@ -269,11 +270,15 @@ public final class ChunkParser { return null; } - private byte parseCheckpointType() throws IOException { - input.readLong(); // timestamp + private boolean parseFlushCheckpoint() throws IOException { + long timestamp = input.readLong(); input.readLong(); // duration input.readLong(); // delta - return input.readByte(); + if (CheckpointType.FLUSH.is(input.readByte())) { + lastFlush = timeConverter.convertTimestamp(timestamp); + return true; + } + return false; } private boolean awaitUpdatedHeader(long absoluteChunkEnd, long filterEnd) throws IOException { @@ -482,6 +487,10 @@ public final class ChunkParser { return getStartNanos() + getChunkDuration(); } + public long getLastFlush() { + return lastFlush; + } + public void setStaleMetadata(boolean stale) { this.staleMetadata = stale; } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java index f0ed752cefd..4d4df7541b1 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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 @@ -166,9 +166,7 @@ public final class EventDirectoryStream extends AbstractEventStream { processUnordered(disp); } currentParser.resetCache(); - long endNanos = currentParser.getStartNanos() + currentParser.getChunkDuration(); - // same conversion as in RecordingInfo - if (endNanos > filterEnd) { + if (currentParser.getLastFlush() > filterEnd) { return; } }