<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof"><span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);">Hi Carter,</span></div>
<div style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);"><br>
</span></div>
<div style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);">t's not possible to guarantee that events will be available unless a RecordingStream
 is used, the period is everyChunk and the stop() method is used.</span></div>
<div style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);"><br>
</span></div>
<div style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);">That said, it looks strange. You could try running with -Xlog:jfr+system+parser=info,jfr+periodic=debug and
 only enable the ThreadStatistics event:</span></div>
<div style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);"><br>
</span></div>
<div class="elementToProof" style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);">recording.enable("jdk.JavaThreadStatistics").with("period", "1000 ms"); </span></div>
<div style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);"><br>
</span></div>
<div style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);">It might make it easier to diagnose.</span></div>
<div style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);"><br>
</span></div>
<div class="elementToProof" style="text-align: left; margin: 0px; background-color: rgb(255, 255, 255);">
<span style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; font-weight: 400; color: rgb(0, 0, 0);">Erik</span></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> hotspot-jfr-dev <hotspot-jfr-dev-retn@openjdk.org> on behalf of Carter Kozak <ckozak@ckozak.net><br>
<b>Sent:</b> Thursday, December 14, 2023 11:06 PM<br>
<b>To:</b> hotspot-jfr-dev@openjdk.java.net <hotspot-jfr-dev@openjdk.java.net><br>
<b>Subject:</b> Re: JFR Recordings Missing Periodic Events</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">This behavior appears to be a bug introduced by <a href="https://github.com/openjdk/jdk/pull/12668">
https://github.com/openjdk/jdk/pull/12668</a><br>
More specifically, I believe that the first recording completes as expected, however in subsequent recordings, this snippet makes an incorrect assumption:<br>
<a href="https://github.com/egahlin/jdk/blob/11ae47e75e907d5ce2c9491cf789767d207614a2/src/jdk.jfr/share/classes/jdk/jfr/internal/periodic/BatchManager.java#L65-L70">https://github.com/egahlin/jdk/blob/11ae47e75e907d5ce2c9491cf789767d207614a2/src/jdk.jfr/share/classes/jdk/jfr/internal/periodic/BatchManager.java#L65-L70</a><br>
> Batch batch = task.getBatch();<br>
> // If new task, or period has changed, find new batch<br>
> if (batch == null) {<br>
>     batch = findBatch(task.getPeriod());<br>
> }<br>
> batch.add(task);<br>
<br>
task.getBatch() may return a non-null batch which has been removed from the BatchManager between recordings, when all events are disabled. The periodic task is then added to this orphaned batch, not to be scheduled again.<br>
This also results in a memory leak as the initial iteration over batches which clears periodic tasks doesn't execute on orphaned batches, so each update will write additional duplicate elements into the batch.<br>
Assuming this exists to avoid iteration over batches within refresh, I think we should add a boolean flag to the Batch type to describe whether or not it is active, allowing us to retain the optimization without orphaning events or leaking memory.<br>
Feedback on this proposed fix would be appreciated!<br>
<br>
I'd be happy to take a shot at fixing this, I'd appreciate if someone could create a ticket that I might work against.<br>
<br>
Thanks,<br>
Carter Kozak<br>
</div>
</span></font></div>
</body>
</html>