8195818: JFR.start should increase autogenerated name by one
authoregahlin
Mon, 21 May 2018 18:19:11 +0200
changeset 50197 f4735ff8d17d
parent 50196 85e3ac4fa57b
child 50198 db3c6bb7f856
8195818: JFR.start should increase autogenerated name by one Reviewed-by: mgronlun
src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java
src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java	Mon May 21 11:09:58 2018 -0500
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java	Mon May 21 18:19:11 2018 +0200
@@ -108,7 +108,11 @@
     }
 
     public synchronized PlatformRecording newRecording(Map<String, String> settings) {
-        PlatformRecording recording = new PlatformRecording(this, ++recordingCounter);
+        return newRecording(settings, ++recordingCounter);
+    }
+
+    public synchronized PlatformRecording newRecording(Map<String, String> settings, long id) {
+        PlatformRecording recording = new PlatformRecording(this, id);
         if (!settings.isEmpty()) {
             recording.setSettings(settings);
         }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java	Mon May 21 11:09:58 2018 -0500
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java	Mon May 21 18:19:11 2018 +0200
@@ -101,7 +101,7 @@
         RecordingState oldState;
         RecordingState newState;
         synchronized (recorder) {
-            oldState = recording.getState();
+            oldState = getState();
             if (!Utils.isBefore(state, RecordingState.RUNNING)) {
                 throw new IllegalStateException("Recording can only be started once.");
             }
@@ -139,7 +139,7 @@
                     }
                     return "Started recording \"" + getName() + "\" (" + getId() + ") " + optionText;
                 });
-            newState = recording.getState();
+            newState = getState();
         }
         notifyIfStateChanged(oldState, newState);
     }
@@ -156,16 +156,16 @@
         RecordingState oldState;
         RecordingState newState;
         synchronized (recorder) {
-            oldState = recording.getState();
+            oldState = getState();
             if (stopTask != null) {
                 stopTask.cancel();
                 stopTask = null;
             }
             recorder.stop(this, alternativePath);
-            String endTExt = reason == null ? "" : ". Reason \"" + reason + "\".";
-            Logger.log(LogTag.JFR, LogLevel.INFO, "Stopped recording \"" + recording.getName() + "\" (" + recording.getId()+ ")" + endTExt);
+            String endText = reason == null ? "" : ". Reason \"" + reason + "\".";
+            Logger.log(LogTag.JFR, LogLevel.INFO, "Stopped recording \"" + getName() + "\" (" + getId()+ ")" + endText);
             this.stopTime = Instant.now();
-            newState = recording.getState();
+            newState = getState();
         }
         WriteableUserPath dest = getDestination();
         if (dest == null && alternativePath != null) {
@@ -174,7 +174,7 @@
         if (dest != null) {
             try {
                 copyTo(dest, reason, overlaySettings);
-                Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + recording.getName() + "\" (" + recording.getId()+ ") to " + dest.getText());
+                Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + getName() + "\" (" + getId()+ ") to " + dest.getText());
                 notifyIfStateChanged(newState, oldState);
                 close(); // remove if copied out
             } catch (IOException e) {
@@ -195,7 +195,7 @@
             setState(RecordingState.DELAYED);
             startTask = createStartTask();
             recorder.getTimer().schedule(startTask, delay.toMillis());
-            Logger.log(LogTag.JFR, LogLevel.INFO, "Scheduled recording \"" + recording.getName() + "\" (" + recording.getId()+ ") to start at " + now);
+            Logger.log(LogTag.JFR, LogLevel.INFO, "Scheduled recording \"" + getName() + "\" (" + getId()+ ") to start at " + now);
         }
     }
 
@@ -319,8 +319,7 @@
             }
 
             // Recording is RUNNING, create a clone
-            try(Recording r = new Recording()) {
-                PlatformRecording clone = PrivateAccess.getInstance().getPlatformRecording(r);
+            try(PlatformRecording clone = recorder.newRecording(Collections.emptyMap(), 0)) {
                 clone.setShouldWriteActiveRecordingEvent(false);
                 clone.setName(getName());
                 clone.setDestination(path);