changeset 52435:6372f5af9612

8209960: -Xlog:jfr* doesn't work with the JFR Reviewed-by: mgronlun
author egahlin
date Mon, 05 Nov 2018 14:40:16 +0100
parents df84c02f4780
children 6d42c07ba238
files src/hotspot/share/jfr/dcmd/jfrDcmds.cpp src/jdk.jfr/share/classes/jdk/jfr/internal/JVMSupport.java src/jdk.jfr/share/classes/jdk/jfr/internal/LogTag.java src/jdk.jfr/share/classes/jdk/jfr/internal/Logger.java src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataReader.java src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java src/jdk.jfr/share/classes/jdk/jfr/internal/Type.java src/jdk.jfr/share/classes/jdk/jfr/internal/TypeLibrary.java src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdCheck.java src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdDump.java src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java
diffstat 14 files changed, 35 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp	Mon Nov 05 14:40:16 2018 +0100
@@ -446,6 +446,12 @@
       assert(element != NULL, "invariant");
       JfrJavaSupport::set_array_element(settings, element, i, CHECK);
     }
+  } else {
+    settings = JfrJavaSupport::new_string_array(1, CHECK);
+    assert(settings != NULL, "invariant");
+    jobject element = JfrJavaSupport::new_string("default", CHECK);
+    assert(element != NULL, "invariant");
+    JfrJavaSupport::set_array_element(settings, element, 0, CHECK);
   }
 
   static const char klass[] = "jdk/jfr/internal/dcmd/DCmdStart";
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/JVMSupport.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/JVMSupport.java	Mon Nov 05 14:40:16 2018 +0100
@@ -81,4 +81,7 @@
     public static boolean isNotAvailable() {
         return notAvailable;
     }
+
+    public static void tryToInitializeJVM() {
+    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/LogTag.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/LogTag.java	Mon Nov 05 14:40:16 2018 +0100
@@ -80,19 +80,11 @@
     JFR_DCMD(10);
 
     /* set from native side */
-    private volatile int tagSetLevel = 100; // prevent logging if JVM log system has not been initialized
+    volatile int tagSetLevel = 100; // prevent logging if JVM log system has not been initialized
 
     final int id;
 
     LogTag(int tagId) {
         id = tagId;
     }
-
-    public boolean shouldLog(int level) {
-        return level >= tagSetLevel;
-    }
-
-    public boolean shouldLog(LogLevel logLevel) {
-        return shouldLog(logLevel.level);
-    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/Logger.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/Logger.java	Mon Nov 05 14:40:16 2018 +0100
@@ -35,15 +35,20 @@
 public final class Logger {
 
     private final static int MAX_SIZE = 10000;
+    static {
+        // This will try to initialize the JVM logging system
+        JVMSupport.tryToInitializeJVM();
+    }
+
 
     public static void log(LogTag logTag, LogLevel logLevel, String message) {
-        if (logTag.shouldLog(logLevel.level)) {
+        if (shouldLog(logTag, logLevel)) {
             logInternal(logTag, logLevel, message);
         }
     }
 
     public static void log(LogTag logTag, LogLevel logLevel, Supplier<String> messageSupplier) {
-        if (logTag.shouldLog(logLevel.level)) {
+        if (shouldLog(logTag, logLevel)) {
             logInternal(logTag, logLevel, messageSupplier.get());
         }
     }
@@ -55,4 +60,8 @@
             JVM.log(logTag.id, logLevel.level, message.substring(0, MAX_SIZE));
         }
     }
+
+    public static boolean shouldLog(LogTag tag, LogLevel level) {
+        return level.level >= tag.tagSetLevel;
+    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataReader.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataReader.java	Mon Nov 05 14:40:16 2018 +0100
@@ -79,7 +79,7 @@
         descriptor.gmtOffset = time.attribute(MetadataDescriptor.ATTRIBUTE_GMT_OFFSET, 1);
         descriptor.locale = time.attribute(MetadataDescriptor.ATTRIBUTE_LOCALE, "");
         descriptor.root = root;
-        if (LogTag.JFR_SYSTEM_PARSER.shouldLog(LogLevel.TRACE.level)) {
+        if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE)) {
              List<Type> ts = new ArrayList<>(types.values());
              Collections.sort(ts, (x,y) -> x.getName().compareTo(y.getName()));
              for (Type t : ts) {
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java	Mon Nov 05 14:40:16 2018 +0100
@@ -453,7 +453,7 @@
     }
 
     private void setSettings(Map<String, String> settings, boolean update) {
-        if (LogTag.JFR_SETTING.shouldLog(LogLevel.INFO.level) && update) {
+        if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO) && update) {
             TreeMap<String, String> ordered = new TreeMap<>(settings);
             Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "New settings for recording \"" + getName() + "\" (" + getId() + ")");
             for (Map.Entry<String, String> entry : ordered.entrySet()) {
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java	Mon Nov 05 14:40:16 2018 +0100
@@ -139,7 +139,7 @@
                 ec.disable();
             }
         } else {
-            if (LogTag.JFR_SETTING.shouldLog(LogLevel.INFO.level)) {
+            if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO)) {
                 Collections.sort(eventControls, (x,y) -> x.getEventType().getName().compareTo(y.getEventType().getName()));
             }
             for (EventControl ec : eventControls) {
@@ -224,7 +224,7 @@
             if (values != null) {
                 control.apply(values);
                 String after = control.getLastValue();
-                if (LogTag.JFR_SETTING.shouldLog(LogLevel.INFO.level)) {
+                if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO)) {
                     if (Utils.isSettingVisible(control, ec.getEventType().hasEventHook())) {
                         if (values.size() > 1) {
                             StringJoiner sj = new StringJoiner(", ", "{", "}");
@@ -241,7 +241,7 @@
                 }
             } else {
                 control.setDefault();
-                if (LogTag.JFR_SETTING.shouldLog(LogLevel.INFO.level)) {
+                if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO)) {
                     String message = "  " + settingName + "=\"" + control.getLastValue() + "\"";
                     Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, message);
                 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/Type.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/Type.java	Mon Nov 05 14:40:16 2018 +0100
@@ -271,7 +271,7 @@
     }
 
     void log(String action, LogTag logTag, LogLevel level) {
-        if (logTag.shouldLog(level.level) && !isSimpleType()) {
+        if (Logger.shouldLog(logTag, level) && !isSimpleType()) {
             Logger.log(logTag, LogLevel.TRACE, action + " " + typeText() + " " + getLogName() + " {");
             for (ValueDescriptor v : getFields()) {
                 String array = v.isArray() ? "[]" : "";
@@ -279,7 +279,7 @@
             }
             Logger.log(logTag, LogLevel.TRACE, "}");
         } else {
-            if (logTag.shouldLog(LogLevel.INFO.level) && !isSimpleType()) {
+            if (Logger.shouldLog(logTag, LogLevel.INFO) && !isSimpleType()) {
                 Logger.log(logTag, LogLevel.INFO, action + " " + typeText() + " " + getLogName());
             }
         }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/TypeLibrary.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/TypeLibrary.java	Mon Nov 05 14:40:16 2018 +0100
@@ -68,7 +68,7 @@
 
     private TypeLibrary(List<Type> jvmTypes) {
         visitReachable(jvmTypes, t -> !types.containsKey(t.getId()), t -> types.put(t.getId(), t));
-        if (LogTag.JFR_SYSTEM_METADATA.shouldLog(LogLevel.INFO.level)) {
+        if (Logger.shouldLog(LogTag.JFR_SYSTEM_METADATA, LogLevel.INFO)) {
             Stream<Type> s = types.values().stream().sorted((x, y) -> Long.compare(x.getId(), y.getId()));
             s.forEach(t -> t.log("Added", LogTag.JFR_SYSTEM_METADATA, LogLevel.INFO));
         }
@@ -422,7 +422,7 @@
         for (Type type :  types.values()) {
             if (type.getRemove() && !Type.isDefinedByJVM(type.getId())) {
                 removeIds.add(type.getId());
-                if (LogTag.JFR_METADATA.shouldLog(LogLevel.TRACE.level)) {
+                if (Logger.shouldLog(LogTag.JFR_METADATA, LogLevel.TRACE)) {
                     Logger.log(LogTag.JFR_METADATA, LogLevel.TRACE, "Removed obsolete metadata " + type.getName());
                 }
             }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdCheck.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdCheck.java	Mon Nov 05 14:40:16 2018 +0100
@@ -63,7 +63,7 @@
     }
 
     private void executeInternal(String name, Boolean verbose) throws DCmdException {
-        if (LogTag.JFR_DCMD.shouldLog(LogLevel.DEBUG)) {
+        if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
             Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdCheck: name=" + name + ", verbose=" + verbose);
         }
 
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java	Mon Nov 05 14:40:16 2018 +0100
@@ -70,7 +70,7 @@
             Boolean sampleThreads
 
     ) throws DCmdException {
-        if (LogTag.JFR_DCMD.shouldLog(LogLevel.DEBUG)) {
+        if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
             Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdConfigure: repositorypath=" + repositoryPath +
                     ", dumppath=" + dumpPath +
                     ", stackdepth=" + stackDepth +
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdDump.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdDump.java	Mon Nov 05 14:40:16 2018 +0100
@@ -70,7 +70,7 @@
      * @throws DCmdException if the dump could not be completed
      */
     public String execute(String name, String filename, Long maxAge, Long maxSize, String begin, String end, Boolean pathToGcRoots) throws DCmdException {
-        if (LogTag.JFR_DCMD.shouldLog(LogLevel.DEBUG)) {
+        if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
             Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG,
                     "Executing DCmdDump: name=" + name +
                     ", filename=" + filename +
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java	Mon Nov 05 14:40:16 2018 +0100
@@ -81,7 +81,7 @@
      */
     @SuppressWarnings("resource")
     public String execute(String name, String[] settings, Long delay, Long duration, Boolean disk, String path, Long maxAge, Long maxSize, Boolean dumpOnExit, Boolean pathToGcRoots) throws DCmdException {
-        if (LogTag.JFR_DCMD.shouldLog(LogLevel.DEBUG)) {
+        if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
             Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdStart: name=" + name +
                     ", settings=" + Arrays.asList(settings) +
                     ", delay=" + delay +
@@ -106,13 +106,7 @@
             throw new DCmdException("Filename can only be set for a time bound recording or if dumponexit=true. Set duration/dumponexit or omit filename.");
         }
 
-
         Map<String, String> s = new HashMap<>();
-
-        if (settings == null || settings.length == 0) {
-            settings = new String[] { "default" };
-        }
-
         for (String configName : settings) {
             try {
                 s.putAll(JFC.createKnown(configName).getSettings());
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java	Mon Nov 05 14:02:04 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java	Mon Nov 05 14:40:16 2018 +0100
@@ -56,7 +56,7 @@
      * @throws DCmdException if recording could not be stopped
      */
     public String execute(String name, String filename) throws DCmdException {
-        if (LogTag.JFR_DCMD.shouldLog(LogLevel.DEBUG)) {
+        if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
             Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdStart: name=" + name + ", filename=" + filename);
         }