From 6b24b4a70fac9ef1e9554fbbb2c7e1aa991ccc33 Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Thu, 23 Feb 2023 19:53:21 +0000 Subject: [PATCH] 8302821: JFR: Periodic task thread spins after recording has stopped Reviewed-by: mgronlun --- .../jdk/jfr/internal/PlatformRecorder.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java index c15fa69705a..832a0bd7eac 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java @@ -72,6 +72,7 @@ public final class PlatformRecorder { private long recordingCounter = 0; private RepositoryChunk currentChunk; private boolean inShutdown; + private boolean runPeriodicTask; public PlatformRecorder() throws Exception { repository = Repository.getRepository(); @@ -252,6 +253,7 @@ public final class PlatformRecorder { updateSettings(false); recording.setStartTime(startTime); writeMetaEvents(); + setRunPeriodicTask(true); } else { RepositoryChunk newChunk = null; if (toDisk) { @@ -329,6 +331,7 @@ public final class PlatformRecorder { jvm.endRecording(); recording.setStopTime(stopTime); disableEvents(); + setRunPeriodicTask(false); } else { RepositoryChunk newChunk = null; PeriodicEvents.doChunkEnd(); @@ -518,9 +521,21 @@ public final class PlatformRecorder { return false; } + private void setRunPeriodicTask(boolean runPeriodicTask) { + synchronized (JVM.CHUNK_ROTATION_MONITOR) { + this.runPeriodicTask = runPeriodicTask; + if (runPeriodicTask) { + JVM.CHUNK_ROTATION_MONITOR.notifyAll(); + } + } + } + private void takeNap(long duration) { try { synchronized (JVM.CHUNK_ROTATION_MONITOR) { + if (!runPeriodicTask) { + duration = Long.MAX_VALUE; + } JVM.CHUNK_ROTATION_MONITOR.wait(duration < 10 ? 10 : duration); } } catch (InterruptedException e) {