8212232: Wrong metadata for the configuration of the cutoff for old object sample events
authoregahlin
Fri, 07 Dec 2018 17:11:17 +0100
changeset 52901 3ba9ff4d4aaf
parent 52900 2998e6d76879
child 52902 e3398b2e1ab0
8212232: Wrong metadata for the configuration of the cutoff for old object sample events Reviewed-by: mgronlun
src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java
src/jdk.jfr/share/classes/jdk/jfr/internal/settings/CutoffSetting.java
src/jdk.jfr/share/classes/jdk/jfr/internal/settings/PeriodSetting.java
src/jdk.jfr/share/classes/jdk/jfr/internal/settings/ThresholdSetting.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java	Fri Dec 07 17:52:37 2018 +0300
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java	Fri Dec 07 17:11:17 2018 +0100
@@ -65,6 +65,8 @@
 
 public final class Utils {
 
+    private static final String INFINITY = "infinity";
+
     private static Boolean SAVE_GENERATED;
 
     public static final String EVENTS_PACKAGE_NAME = "jdk.jfr.events";
@@ -117,7 +119,6 @@
         if (dValue == null) {
             return "0";
         }
-
         long value = dValue.toNanos();
         TimespanUnit result = TimespanUnit.NANOSECONDS;
         for (TimespanUnit unit : TimespanUnit.values()) {
@@ -131,6 +132,13 @@
         return String.format("%d%s%s", value, separation, result.text);
     }
 
+    public static long parseTimespanWithInfinity(String s) {
+        if (INFINITY.equals(s)) {
+            return Long.MAX_VALUE;
+        }
+        return parseTimespan(s);
+    }
+
     public static long parseTimespan(String s) {
         if (s.endsWith("ns")) {
             return Long.parseLong(s.substring(0, s.length() - 2).trim());
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/settings/CutoffSetting.java	Fri Dec 07 17:52:37 2018 +0300
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/settings/CutoffSetting.java	Fri Dec 07 17:11:17 2018 +0100
@@ -28,11 +28,11 @@
 import java.util.Objects;
 import java.util.Set;
 
-import jdk.jfr.BooleanFlag;
 import jdk.jfr.Description;
 import jdk.jfr.Label;
 import jdk.jfr.MetadataDefinition;
 import jdk.jfr.Name;
+import jdk.jfr.Timespan;
 import jdk.jfr.internal.Control;
 import jdk.jfr.internal.PlatformEventType;
 import jdk.jfr.internal.Type;
@@ -42,7 +42,7 @@
 @Label("Cutoff")
 @Description("Limit running time of event")
 @Name(Type.SETTINGS_PREFIX + "Cutoff")
-@BooleanFlag
+@Timespan
 public final class CutoffSetting extends Control {
     private final static long typeId = Type.getTypeId(CutoffSetting.class);
 
@@ -59,7 +59,7 @@
         long max = 0;
         String text = "0 ns";
         for (String value : values) {
-            long l = parseValue(value);
+            long l =  Utils.parseTimespanWithInfinity(value);
             if (l > max) {
                 text = value;
                 max = l;
@@ -70,15 +70,11 @@
 
     @Override
     public void setValue(String value) {
-        long l = parseValue(value);
+        long l =  Utils.parseTimespanWithInfinity(value);
         this.value = value;
         eventType.setCutoff(l);
     }
 
-    private long parseValue(String value) {
-        return isInfinity(value) ? Long.MAX_VALUE : Utils.parseTimespan(value);
-    }
-
     @Override
     public String getValue() {
         return value;
@@ -88,16 +84,12 @@
         return CutoffSetting.typeId == typeId;
     }
 
-    private static boolean isInfinity(String s) {
-        return s.equals("infinity");
-    }
-
     public static long parseValueSafe(String value) {
         if (value == null) {
             return 0L;
         }
         try {
-            return isInfinity(value) ? Long.MAX_VALUE : Utils.parseTimespan(value);
+            return Utils.parseTimespanWithInfinity(value);
         } catch (NumberFormatException nfe) {
             return 0L;
         }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/settings/PeriodSetting.java	Fri Dec 07 17:52:37 2018 +0300
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/settings/PeriodSetting.java	Fri Dec 07 17:11:17 2018 +0100
@@ -58,10 +58,11 @@
 
     @Override
     public String combine(Set<String> values) {
-        long min = Long.MAX_VALUE;
+
         boolean beginChunk = false;
         boolean endChunk = false;
-        String text = EVERY_CHUNK;
+        Long min = null;
+        String text = null;
         for (String value : values) {
             switch (value) {
             case EVERY_CHUNK:
@@ -75,14 +76,21 @@
                 endChunk = true;
                 break;
             default:
-                long l = Utils.parseTimespan(value);
-                if (l < min) {
+                long l = Utils.parseTimespanWithInfinity(value);
+                // Always accept first specified value
+                if (min == null) {
                     text = value;
                     min = l;
+                } else {
+                    if (l < min) {
+                        text = value;
+                        min = l;
+                    }
                 }
             }
         }
-        if (min != Long.MAX_VALUE) {
+        // A specified interval trumps *_CHUNK
+        if (min != null) {
             return text;
         }
         if (beginChunk && !endChunk) {
@@ -91,7 +99,7 @@
         if (!beginChunk && endChunk) {
             return END_CHUNK;
         }
-        return text;
+        return EVERY_CHUNK; // also default
     }
 
     @Override
@@ -107,7 +115,12 @@
             eventType.setPeriod(0, false, true);
             break;
         default:
-            eventType.setPeriod(Utils.parseTimespan(value) / 1_000_000, false, false);
+            long nanos = Utils.parseTimespanWithInfinity(value);
+            if (nanos != Long.MAX_VALUE) {
+                eventType.setPeriod(nanos / 1_000_000, false, false);
+            } else {
+                eventType.setPeriod(Long.MAX_VALUE, false, false);
+            }
         }
         this.value = value;
     }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/settings/ThresholdSetting.java	Fri Dec 07 17:52:37 2018 +0300
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/settings/ThresholdSetting.java	Fri Dec 07 17:11:17 2018 +0100
@@ -54,21 +54,27 @@
 
     @Override
     public String combine(Set<String> values) {
-        long min = Long.MAX_VALUE;
-        String text = "0 ns";
+        Long min = null;
+        String text = null;
         for (String value : values) {
-            long l = Utils.parseTimespan(value);
-            if (l < min) {
+            long l = Utils.parseTimespanWithInfinity(value);
+            // always accept first value
+            if (min == null) {
+                min = l;
                 text = value;
-                min = l;
+            } else {
+                if (l < min) {
+                    text = value;
+                    min = l;
+                }
             }
         }
-        return text;
+        return text == null ? "0 ns" : text;
     }
 
     @Override
     public void setValue(String value) {
-        long l = Utils.parseTimespan(value);
+        long l = Utils.parseTimespanWithInfinity(value);
         this.value = value;
         eventType.setThreshold(l);
     }