DataDog / dd-trace-java

Datadog APM client for Java
https://docs.datadoghq.com/tracing/languages/java
Apache License 2.0
573 stars 284 forks source link

Corrupted/malformed main.jfr generated on OpenJDK 21 #7559

Closed sivachandran closed 3 weeks ago

sivachandran commented 3 weeks ago

Hi,

I'm using dd-trace-java outside DataDog eco-system.

I'm profiling(using dd-java-agent-1.39.0.jar) a simple Java application(serves pages using com.sun.net.httpserver.HttpHandler) on OpenJDK 21. The generated profile(main.jfr) seems to be corrupted or malformed. I tried viewing the JFR with jfr command-line and it is returning the following error

❯ jfr view gc jfr-profile-openjdk-21.jfr
jfr view: unexpected internal error, Pool java.lang.String must contain at least one element
java.lang.InternalError: Pool java.lang.String must contain at least one element
        at jdk.jfr/jdk.jfr.internal.consumer.ChunkParser.fillConstantPools(ChunkParser.java:357)
        at jdk.jfr/jdk.jfr.internal.consumer.ChunkParser.<init>(ChunkParser.java:141)
        at jdk.jfr/jdk.jfr.internal.consumer.ChunkParser.nextChunkParser(ChunkParser.java:150)
        at jdk.jfr/jdk.jfr.internal.consumer.EventFileStream.process(EventFileStream.java:111)
        at jdk.jfr/jdk.jfr.internal.consumer.AbstractEventStream.execute(AbstractEventStream.java:261)
        at jdk.jfr/jdk.jfr.internal.consumer.AbstractEventStream$1.run(AbstractEventStream.java:284)
        at jdk.jfr/jdk.jfr.internal.consumer.AbstractEventStream$1.run(AbstractEventStream.java:281)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
        at jdk.jfr/jdk.jfr.internal.consumer.AbstractEventStream.run(AbstractEventStream.java:281)
        at jdk.jfr/jdk.jfr.internal.consumer.AbstractEventStream.start(AbstractEventStream.java:232)
        at jdk.jfr/jdk.jfr.internal.consumer.EventFileStream.start(EventFileStream.java:56)
        at jdk.jfr/jdk.jfr.internal.query.QueryExecutor.run(QueryExecutor.java:59)
        at jdk.jfr/jdk.jfr.internal.query.ViewPrinter.showViews(ViewPrinter.java:167)
        at jdk.jfr/jdk.jfr.internal.query.ViewPrinter.execute(ViewPrinter.java:87)
        at jdk.jfr/jdk.jfr.internal.tool.View.execute(View.java:145)
        at jdk.jfr/jdk.jfr.internal.tool.Main.main(Main.java:92)

but the same application profiled on OpenJDK 17 produces valid JFR. jfr command-line is able to open and process the JFR

❯ jfr view gc jfr-profile-openjdk-17.jfr

                                Garbage Collections

Start    GC ID Type                     Heap Before GC Heap After GC Longest Pause
-------- ----- ------------------------ -------------- ------------- -------------
11:45:34   349 Young Garbage Collection       135.7 MB       19.8 MB       1.38 ms
11:45:34   350 Young Garbage Collection       135.8 MB       19.6 MB      0.668 ms
11:45:35   351 Young Garbage Collection       135.6 MB       19.8 MB       1.05 ms
11:45:36   352 Young Garbage Collection       135.8 MB       19.8 MB       1.02 ms
11:45:36   353 Young Garbage Collection       135.8 MB       19.7 MB      0.961 ms
11:45:37   354 Young Garbage Collection       135.7 MB       19.6 MB      0.756 ms
11:45:37   355 Young Garbage Collection       135.6 MB       19.5 MB      0.616 ms
11:45:38   356 Young Garbage Collection       135.5 MB       19.8 MB       1.00 ms
11:45:38   357 Young Garbage Collection       135.8 MB       19.7 MB      0.875 ms

Attached the JFR for your reference jfr-profile-openjdk-21.jfr.gz

I also tried profiling on Azul Zulu OpenJDK. The profiles generated from Azul Zulu OpenJDK 17 and 18 both failed with jfr command-line with the same error.

jbachorik commented 3 weeks ago

Hello @sivachandran , thanks for your report.

The recording is not really corrupted - it is a valid JFR file, according to all available information about the JFR format. Unfortunately, the jfr tool is rather picky - when you use eg. JMC to open the recording it will work just fine.

We will look into how to make the jfr tool happy as well, but it is not the top priority.

sivachandran commented 3 weeks ago

I'm able to parse the JFR with another tool.

Thanks for the information.