Make stream more responsive JEP-349-branch
authoregahlin
Mon, 08 Jul 2019 18:11:26 +0200
branchJEP-349-branch
changeset 57459 df39f8d8f4d6
parent 57454 703fb247dc4e
child 57460 bcbc53560c77
Make stream more responsive
src/jdk.jfr/share/classes/jdk/jfr/consumer/ChunkParser.java
src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataRepository.java
src/jdk.jfr/share/classes/jdk/jfr/internal/RequestEngine.java
src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java
src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/ChunkParser.java	Fri Jul 05 17:11:55 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/ChunkParser.java	Mon Jul 08 18:11:26 2019 +0200
@@ -67,19 +67,19 @@
     private long firstNanos;
 
     public ChunkParser(RecordingInput input, boolean reuse) throws IOException {
-       this(new ChunkHeader(input), null, 100);
+       this(new ChunkHeader(input), null, 1000);
        this.reuse = reuse;
     }
 
     public ChunkParser(ChunkParser previous) throws IOException {
-        this(new ChunkHeader(previous.input), previous, 100);
+        this(new ChunkHeader(previous.input), previous, 1000);
      }
 
     private ChunkParser(ChunkHeader header, ChunkParser previous, long pollInterval) throws IOException {
         this.input = header.getInput();
         this.chunkHeader = header;
         if (previous == null) {
-            this.pollInterval = 500;
+            this.pollInterval = 1000;
             this.constantLookups = new LongMap<>();
             this.previousMetadata = null;
         } else {
@@ -201,7 +201,7 @@
             if (chunkHeader.isFinished()) {
                 return true;
             }
-            Utils.takeNap(pollInterval);
+            Utils.waitFlush(pollInterval);
         }
     }
 
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataRepository.java	Fri Jul 05 17:11:55 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataRepository.java	Mon Jul 08 18:11:26 2019 +0200
@@ -263,6 +263,7 @@
     // to storeDescriptorInJVM
     synchronized void setOutput(String filename) {
         jvm.setOutput(filename);
+        Utils.notifyFlush();
         flushMetadata = false;
         unregisterUnloaded();
         if (unregistered) {
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/RequestEngine.java	Fri Jul 05 17:11:55 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/RequestEngine.java	Mon Jul 08 18:11:26 2019 +0200
@@ -263,6 +263,7 @@
             if (r_delta >= r_period) {
                 r_delta = 0;
                 MetadataRepository.getInstance().flush();
+                Utils.notifyFlush();
             }
             long left = (r_period - r_delta);
             if (left < 0) {
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java	Fri Jul 05 17:11:55 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java	Mon Jul 08 18:11:26 2019 +0200
@@ -65,17 +65,17 @@
 
 public final class Utils {
 
+    private static final Object flushObject = new Object();
     private static final String INFINITY = "infinity";
-
-    private static Boolean SAVE_GENERATED;
-
     public static final String EVENTS_PACKAGE_NAME = "jdk.jfr.events";
     public static final String INSTRUMENT_PACKAGE_NAME = "jdk.jfr.internal.instrument";
     public static final String HANDLERS_PACKAGE_NAME = "jdk.jfr.internal.handlers";
     public static final String REGISTER_EVENT = "registerEvent";
     public static final String ACCESS_FLIGHT_RECORDER = "accessFlightRecorder";
+    private final static String LEGACY_EVENT_NAME_PREFIX = "com.oracle.jdk.";
 
-    private final static String LEGACY_EVENT_NAME_PREFIX = "com.oracle.jdk.";
+    private static Boolean SAVE_GENERATED;
+
 
     public static void checkAccessFlightRecorder() throws SecurityException {
         SecurityManager sm = System.getSecurityManager();
@@ -595,10 +595,28 @@
         String idText = recording == null ? "" :  "-id-" + Long.toString(recording.getId());
         return "hotspot-" + "pid-" + pid + idText + "-" + date + ".jfr";
     }
+
     public static void takeNap(long millis) {
         try {
             Thread.sleep(millis);
         } catch (InterruptedException e) {
         }
     }
+
+    public static void notifyFlush() {
+        synchronized (flushObject) {
+            flushObject.notifyAll();
+        }
+    }
+
+    public static void waitFlush(long timeOut) {
+        synchronized (flushObject) {
+            try {
+                flushObject.wait(timeOut);
+            } catch (InterruptedException e) {
+                // OK
+            }
+        }
+
+    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java	Fri Jul 05 17:11:55 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java	Mon Jul 08 18:11:26 2019 +0200
@@ -112,7 +112,7 @@
             byte fileState1;
             input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
             while ((fileState1 = input.readPhysicalByte()) == UPDATING_CHUNK_HEADER) {
-                Utils.takeNap(3);
+                Utils.takeNap(1);
                 input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
             }
             input.positionPhysical(absoluteChunkStart + CHUNK_SIZE_POSITION);
@@ -166,11 +166,11 @@
             input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
             while (true) {
                 byte filestate = input.readPhysicalByte();
-                if (filestate ==0) {
+                if (filestate == 0) {
                     finished = true;
                     return;
                 }
-                Utils.takeNap(3);
+                Utils.takeNap(1);
             }
         } finally {
             input.position(pos);