Skip to content
Permalink
Browse files
8240778: JFR: Create timer task lazily
Reviewed-by: mgronlun, mseledtsov
  • Loading branch information
egahlin committed Mar 10, 2020
1 parent 42ff13a commit 8208b9ce32c04e544572beaddcdec71215731674
Showing with 19 additions and 8 deletions.
  1. +10 −5 src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java
  2. +9 −3 src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -64,12 +64,12 @@
private final List<PlatformRecording> recordings = new ArrayList<>();
private final static List<SecureRecorderListener> changeListeners = new ArrayList<>();
private final Repository repository;
private final Timer timer;
private final static JVM jvm = JVM.getJVM();
private final EventType activeRecordingEvent;
private final EventType activeSettingEvent;
private final Thread shutdownHook;

private Timer timer;
private long recordingCounter = 0;
private RepositoryChunk currentChunk;
private boolean inShutdown;
@@ -89,7 +89,7 @@ public PlatformRecorder() throws Exception {
shutdownHook = SecuritySupport.createThreadWitNoPermissions("JFR: Shutdown Hook", new ShutdownHook(this));
SecuritySupport.setUncaughtExceptionHandler(shutdownHook, new ShutdownHook.ExceptionHandler());
SecuritySupport.registerShutdownHook(shutdownHook);
timer = createTimer();

}


@@ -168,7 +168,10 @@ public synchronized static boolean removeListener(FlightRecorderListener changeL
return new ArrayList<>(changeListeners);
}

Timer getTimer() {
synchronized Timer getTimer() {
if (timer == null) {
timer = createTimer();
}
return timer;
}

@@ -186,7 +189,9 @@ synchronized void setInShutDown() {
// called by shutdown hook
synchronized void destroy() {
try {
timer.cancel();
if (timer != null) {
timer.cancel();
}
} catch (Exception ex) {
Logger.log(JFR_SYSTEM, WARN, "Shutdown hook could not cancel timer");
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -190,8 +190,14 @@ public void scheduleStart(Duration delay) {
LocalDateTime now = LocalDateTime.now().plus(delay);
setState(RecordingState.DELAYED);
startTask = createStartTask();
recorder.getTimer().schedule(startTask, delay.toMillis());
Logger.log(LogTag.JFR, LogLevel.INFO, "Scheduled recording \"" + getName() + "\" (" + getId() + ") to start at " + now);
try {
recorder.getTimer().schedule(startTask, delay.toMillis());
Logger.log(LogTag.JFR, LogLevel.INFO, "Scheduled recording \"" + getName() + "\" (" + getId() + ") to start at " + now);
} catch (IllegalStateException ise) {
// This can happen in the unlikely case that a recording
// is scheduled after the Timer has been cancelled in
// the shutdown hook. Just ignore.
}
}
}

0 comments on commit 8208b9c

Please sign in to comment.