Skip to content

Commit 4b6acad

Browse files
committed
8302883: JFR: Improve periodic events
Reviewed-by: mgronlun
1 parent a2471b3 commit 4b6acad

20 files changed

+1125
-351
lines changed

src/jdk.jfr/share/classes/jdk/jfr/FlightRecorder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
import jdk.jfr.internal.PlatformRecorder;
4545
import jdk.jfr.internal.PlatformRecording;
4646
import jdk.jfr.internal.Repository;
47-
import jdk.jfr.internal.RequestEngine;
4847
import jdk.jfr.internal.Utils;
48+
import jdk.jfr.internal.periodic.PeriodicEvents;
4949

5050
/**
5151
* Class for accessing, controlling, and managing Flight Recorder.
@@ -225,7 +225,7 @@ public static void addPeriodicEvent(Class<? extends Event> eventClass, Runnable
225225
Utils.checkRegisterPermission();
226226
@SuppressWarnings("removal")
227227
AccessControlContext acc = AccessController.getContext();
228-
RequestEngine.addHook(acc, EventType.getEventType(eventClass).getPlatformEventType(), hook);
228+
PeriodicEvents.addUserEvent(acc, eventClass, hook);
229229
}
230230

231231
/**
@@ -242,7 +242,7 @@ public static boolean removePeriodicEvent(Runnable hook) throws SecurityExceptio
242242
if (JVMSupport.isNotAvailable()) {
243243
return false;
244244
}
245-
return RequestEngine.removeHook(hook);
245+
return PeriodicEvents.removeEvent(hook);
246246
}
247247

248248
/**

src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static class ChunkRotationMonitor {}
4848
* The monitor type is used to exclude jdk.JavaMonitorWait events from being generated
4949
* when Object.wait() is called on this monitor.
5050
*/
51-
static final Object CHUNK_ROTATION_MONITOR = new ChunkRotationMonitor();
51+
public static final Object CHUNK_ROTATION_MONITOR = new ChunkRotationMonitor();
5252

5353
private volatile boolean nativeOK;
5454

src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataRepository.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
import jdk.jfr.StackTrace;
4747
import jdk.jfr.Threshold;
4848
import jdk.jfr.ValueDescriptor;
49-
import jdk.jfr.internal.RequestEngine.RequestHook;
5049
import jdk.jfr.internal.consumer.RepositoryFiles;
5150
import jdk.jfr.internal.event.EventConfiguration;
51+
import jdk.jfr.internal.periodic.PeriodicEvents;
5252

5353
public final class MetadataRepository {
5454

@@ -70,7 +70,6 @@ public MetadataRepository() {
7070
}
7171

7272
private void initializeJVMEventTypes() {
73-
List<RequestHook> requestHooks = new ArrayList<>();
7473
for (Type type : new ArrayList<>(typeLibrary.getTypes())) {
7574
if (type instanceof PlatformEventType pEventType) {
7675
EventType eventType = PrivateAccess.getInstance().newEventType(pEventType);
@@ -84,14 +83,13 @@ private void initializeJVMEventTypes() {
8483
if (pEventType.hasPeriod()) {
8584
pEventType.setEventHook(true);
8685
if (!pEventType.isMethodSampling()) {
87-
requestHooks.add(new RequestHook(pEventType));
86+
PeriodicEvents.addJVMEvent(pEventType);
8887
}
8988
}
9089
nativeControls.add(new EventControl(pEventType));
9190
nativeEventTypes.add(eventType);
9291
}
9392
}
94-
RequestEngine.addHooks(requestHooks);
9593
}
9694

9795
public static MetadataRepository getInstance() {

src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformEventType.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Objects;
3131

3232
import jdk.jfr.SettingDescriptor;
33-
33+
import jdk.jfr.internal.periodic.PeriodicEvents;
3434
/**
3535
* Implementation of event type.
3636
*
@@ -65,7 +65,6 @@ public final class PlatformEventType extends Type {
6565
private boolean registered = true;
6666
private boolean committable = enabled && registered;
6767

68-
6968
// package private
7069
PlatformEventType(String name, long id, boolean isJDK, boolean dynamicSettings) {
7170
super(name, Type.SUPER_TYPE_EVENT, id);
@@ -201,6 +200,7 @@ public boolean isJDK() {
201200
}
202201

203202
public void setEnabled(boolean enabled) {
203+
boolean changed = enabled != this.enabled;
204204
this.enabled = enabled;
205205
updateCommittable();
206206
if (isJVM) {
@@ -211,6 +211,9 @@ public void setEnabled(boolean enabled) {
211211
JVM.getJVM().setEnabled(getId(), enabled);
212212
}
213213
}
214+
if (changed) {
215+
PeriodicEvents.setChanged();
216+
}
214217
}
215218

216219
public void setPeriod(long periodMillis, boolean beginChunk, boolean endChunk) {
@@ -220,7 +223,11 @@ public void setPeriod(long periodMillis, boolean beginChunk, boolean endChunk) {
220223
}
221224
this.beginChunk = beginChunk;
222225
this.endChunk = endChunk;
226+
boolean changed = period != periodMillis;
223227
this.period = periodMillis;
228+
if (changed) {
229+
PeriodicEvents.setChanged();
230+
}
224231
}
225232

226233
public void setStackTraceEnabled(boolean stackTraceEnabled) {
@@ -263,6 +270,7 @@ public boolean hasEventHook() {
263270

264271
public void setEventHook(boolean hasHook) {
265272
this.hasHook = hasHook;
273+
PeriodicEvents.setChanged();
266274
}
267275

268276
public boolean isBeginChunk() {

src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import jdk.jfr.internal.SecuritySupport.SecureRecorderListener;
5858
import jdk.jfr.internal.consumer.EventLog;
5959
import jdk.jfr.internal.instrument.JDKEvents;
60+
import jdk.jfr.internal.periodic.PeriodicEvents;
6061

6162
public final class PlatformRecorder {
6263

@@ -258,7 +259,7 @@ synchronized long start(PlatformRecording recording) {
258259
if (EventLog.shouldLog()) {
259260
EventLog.start();
260261
}
261-
RequestEngine.doChunkEnd();
262+
PeriodicEvents.doChunkEnd();
262263
String p = newChunk.getFile().toString();
263264
startTime = MetadataRepository.getInstance().setOutput(p);
264265
newChunk.setStartTime(startTime);
@@ -275,9 +276,9 @@ synchronized long start(PlatformRecording recording) {
275276
currentChunk = newChunk;
276277
}
277278
if (toDisk) {
278-
RequestEngine.setFlushInterval(streamInterval);
279+
PeriodicEvents.setFlushInterval(streamInterval);
279280
}
280-
RequestEngine.doChunkBegin();
281+
PeriodicEvents.doChunkBegin();
281282
Duration duration = recording.getDuration();
282283
if (duration != null) {
283284
recording.setStopTime(startTime.plus(duration));
@@ -313,7 +314,7 @@ synchronized void stop(PlatformRecording recording) {
313314
recording.setFinalStartnanos(Utils.getChunkStartNanos());
314315

315316
if (endPhysical) {
316-
RequestEngine.doChunkEnd();
317+
PeriodicEvents.doChunkEnd();
317318
if (recording.isToDisk()) {
318319
if (inShutdown) {
319320
jvm.markChunkFinal();
@@ -330,7 +331,7 @@ synchronized void stop(PlatformRecording recording) {
330331
disableEvents();
331332
} else {
332333
RepositoryChunk newChunk = null;
333-
RequestEngine.doChunkEnd();
334+
PeriodicEvents.doChunkEnd();
334335
updateSettingsButIgnoreRecording(recording, false);
335336

336337
String path = null;
@@ -348,13 +349,13 @@ synchronized void stop(PlatformRecording recording) {
348349
finishChunk(currentChunk, stopTime, null);
349350
}
350351
currentChunk = newChunk;
351-
RequestEngine.doChunkBegin();
352+
PeriodicEvents.doChunkBegin();
352353
}
353354

354355
if (toDisk) {
355-
RequestEngine.setFlushInterval(streamInterval);
356+
PeriodicEvents.setFlushInterval(streamInterval);
356357
} else {
357-
RequestEngine.setFlushInterval(Long.MAX_VALUE);
358+
PeriodicEvents.setFlushInterval(Long.MAX_VALUE);
358359
}
359360
recording.setState(RecordingState.STOPPED);
360361
if (!isToDisk()) {
@@ -394,7 +395,7 @@ void updateSettingsButIgnoreRecording(PlatformRecording ignoreMe, boolean writeS
394395

395396
synchronized void rotateDisk() {
396397
RepositoryChunk newChunk = repository.newChunk();
397-
RequestEngine.doChunkEnd();
398+
PeriodicEvents.doChunkEnd();
398399
String path = newChunk.getFile().toString();
399400
Instant timestamp = MetadataRepository.getInstance().setOutput(path);
400401
newChunk.setStartTime(timestamp);
@@ -403,7 +404,7 @@ synchronized void rotateDisk() {
403404
finishChunk(currentChunk, timestamp, null);
404405
}
405406
currentChunk = newChunk;
406-
RequestEngine.doChunkBegin();
407+
PeriodicEvents.doChunkBegin();
407408
}
408409

409410
private List<PlatformRecording> getRunningRecordings() {
@@ -499,7 +500,7 @@ private void periodicTask() {
499500
EventLog.update();
500501
}
501502
}
502-
long minDelta = RequestEngine.doPeriodic();
503+
long minDelta = PeriodicEvents.doPeriodic();
503504
long wait = Math.min(minDelta, Options.getWaitInterval());
504505
takeNap(wait);
505506
}

0 commit comments

Comments
 (0)