RFR: 8289688: jfr command hangs when it processes invalid file [v2]

Erik Gahlin egahlin at openjdk.org
Mon Jul 25 13:32:17 UTC 2022


On Sun, 24 Jul 2022 09:52:42 GMT, Yasumasa Suenaga <ysuenaga at openjdk.org> wrote:

> diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java
> index 8c8ec55f0da..8648c030f06 100644
> --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java
> +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java
> @@ -162,6 +162,8 @@ public final class ChunkHeader {
>                      Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: finalChunk=" + finalChunk);
>                      absoluteChunkEnd = absoluteChunkStart + chunkSize;
>                      return;
> +                } else if (finished) {
> +                    throw new IOException("metadataPosition is 0 but chunk header is valid.");
>                  }
>              }
>          }
> ```
> 

This may work, values are read reliably and when a chunk is finished, it should always have metadata section, or something is wrong with the file. 

That said, when the file format was designed the metadata pointer in the header was meant as a hint (not a mandatory thing) to prevent a parser for reading the file twice. Neither JMC or JDK parser supports reading recordings without the metadata pointer hint AFAIK, so that ship may have sailed. If the use case should arrive, the ChunkHeader class must be modified anyway (and the above check replaced with an iteration over all the events to find the offset). 

Have you looked at the HotSpot implementation to make sure fileState is never 0, unless the metadata pointer hint has been written? If I remember correctly, the initial value is 1, but I haven't checked. I looked at the RemoteRecordingStream class and it looks like it can't happen there, if the output from the JVM is OK.

I think the message could be "No metadata event found in finished chunk".

-------------

PR: https://git.openjdk.org/jdk/pull/9363


More information about the hotspot-jfr-dev mailing list