diff --git a/src/share/classes/jdk/jfr/internal/JVMSupport.java b/src/share/classes/jdk/jfr/internal/JVMSupport.java index 8203fc0c2797e3c61292e80c3d96502e6a3d7970..f509690050394f65f95c20bc562ffdc7e23a2ef1 100644 --- a/src/share/classes/jdk/jfr/internal/JVMSupport.java +++ b/src/share/classes/jdk/jfr/internal/JVMSupport.java @@ -80,4 +80,7 @@ public final class JVMSupport { public static boolean isNotAvailable() { return notAvailable; } + + public static void tryToInitializeJVM() { + } } diff --git a/src/share/classes/jdk/jfr/internal/LogTag.java b/src/share/classes/jdk/jfr/internal/LogTag.java index f6de8864af4e0438bdb6e6dde7ff06f330ce6cbd..195d6b06adc83abc4ec0ec4630c12df55a6a8871 100644 --- a/src/share/classes/jdk/jfr/internal/LogTag.java +++ b/src/share/classes/jdk/jfr/internal/LogTag.java @@ -80,19 +80,11 @@ public enum LogTag { 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 true;// XXX level >= tagSetLevel; - } - - public boolean shouldLog(LogLevel logLevel) { - return shouldLog(logLevel.level); - } } diff --git a/src/share/classes/jdk/jfr/internal/Logger.java b/src/share/classes/jdk/jfr/internal/Logger.java index ab4bf421705a3c0a673d96d8c7e3cb6350262e9a..7ac595dc31b26b0514b8d58c32a9d05979c6e2b4 100644 --- a/src/share/classes/jdk/jfr/internal/Logger.java +++ b/src/share/classes/jdk/jfr/internal/Logger.java @@ -35,15 +35,20 @@ import java.util.function.Supplier; 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 messageSupplier) { - if (logTag.shouldLog(logLevel.level)) { + if (shouldLog(logTag, logLevel)) { logInternal(logTag, logLevel, messageSupplier.get()); } } @@ -55,4 +60,10 @@ public final class Logger { JVM.log(logTag.id, logLevel.level, message.substring(0, MAX_SIZE)); } } + + public static boolean shouldLog(LogTag tag, LogLevel level) { + // Logging level is not initialized because of lack of Xlog support in jdk8, + // so this method returns true directly now. + return true; // TODO: level.level >= tag.tagSetLevel; + } } diff --git a/src/share/classes/jdk/jfr/internal/MetadataReader.java b/src/share/classes/jdk/jfr/internal/MetadataReader.java index 79b9709e64546c9b359f76c4892fd4e5ba42d205..481e3700dc63338b95f74e1829d2c0d5024bb29c 100644 --- a/src/share/classes/jdk/jfr/internal/MetadataReader.java +++ b/src/share/classes/jdk/jfr/internal/MetadataReader.java @@ -79,7 +79,7 @@ final class MetadataReader { 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 ts = new ArrayList<>(types.values()); Collections.sort(ts, (x,y) -> x.getName().compareTo(y.getName())); for (Type t : ts) { diff --git a/src/share/classes/jdk/jfr/internal/PlatformRecording.java b/src/share/classes/jdk/jfr/internal/PlatformRecording.java index 2d908d73c771fdcd9c5a15c038a51cdfc9b3913b..74707121d37ca09b691c2c5b742d236686eb4081 100644 --- a/src/share/classes/jdk/jfr/internal/PlatformRecording.java +++ b/src/share/classes/jdk/jfr/internal/PlatformRecording.java @@ -453,7 +453,7 @@ public final class PlatformRecording implements AutoCloseable { } private void setSettings(Map settings, boolean update) { - if (LogTag.JFR_SETTING.shouldLog(LogLevel.INFO.level) && update) { + if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO) && update) { TreeMap ordered = new TreeMap<>(settings); Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "New settings for recording \"" + getName() + "\" (" + getId() + ")"); for (Map.Entry entry : ordered.entrySet()) { diff --git a/src/share/classes/jdk/jfr/internal/SettingsManager.java b/src/share/classes/jdk/jfr/internal/SettingsManager.java index af27561b31fca8d1f29c8d1c436611481a42f850..592f216c1865ab0aff283680b3399fff6d666a09 100644 --- a/src/share/classes/jdk/jfr/internal/SettingsManager.java +++ b/src/share/classes/jdk/jfr/internal/SettingsManager.java @@ -140,7 +140,7 @@ final class SettingsManager { 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) { @@ -225,7 +225,7 @@ final class SettingsManager { 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(", ", "{", "}"); @@ -242,7 +242,7 @@ final class SettingsManager { } } 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); } diff --git a/src/share/classes/jdk/jfr/internal/Type.java b/src/share/classes/jdk/jfr/internal/Type.java index 06833f29910fadadce3c940ea5e605f7a14c1411..aff93a5c4a0ff4db39dcb52d2b6c3f426f2b5921 100644 --- a/src/share/classes/jdk/jfr/internal/Type.java +++ b/src/share/classes/jdk/jfr/internal/Type.java @@ -275,7 +275,7 @@ public class Type implements Comparable { } 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() ? "[]" : ""; @@ -283,7 +283,7 @@ public class Type implements Comparable { } 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()); } } diff --git a/src/share/classes/jdk/jfr/internal/TypeLibrary.java b/src/share/classes/jdk/jfr/internal/TypeLibrary.java index 825f9d508e4fca845c9b247f9c4fe4c9183be4a0..40544e944b4a06e5d25415c90b25fccf100159f3 100644 --- a/src/share/classes/jdk/jfr/internal/TypeLibrary.java +++ b/src/share/classes/jdk/jfr/internal/TypeLibrary.java @@ -69,7 +69,7 @@ public final class TypeLibrary { private TypeLibrary(List 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 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)); } @@ -423,7 +423,7 @@ public final class TypeLibrary { 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()); } } diff --git a/src/share/classes/jdk/jfr/internal/dcmd/DCmdCheck.java b/src/share/classes/jdk/jfr/internal/dcmd/DCmdCheck.java index 20c43fd70a6d4eb3467b52928cdf3b196d268f34..0cffba6a67bda5ec1de989f681f373f5ef4eafca 100644 --- a/src/share/classes/jdk/jfr/internal/dcmd/DCmdCheck.java +++ b/src/share/classes/jdk/jfr/internal/dcmd/DCmdCheck.java @@ -64,7 +64,7 @@ final class DCmdCheck extends AbstractDCmd { } 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); } diff --git a/src/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java b/src/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java index 557128f63dec0ceab0bcc8a8c8a45141a3b75c98..f15053a7caafd02106fd65f288589c68d068da43 100644 --- a/src/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java +++ b/src/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java @@ -70,7 +70,7 @@ final class DCmdConfigure extends AbstractDCmd { 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 + diff --git a/src/share/classes/jdk/jfr/internal/dcmd/DCmdDump.java b/src/share/classes/jdk/jfr/internal/dcmd/DCmdDump.java index 28593e7aa4d58208ae42019c250968c41cab3001..0fad0c5b8c1067736d7093a8da3645ed200fea2a 100644 --- a/src/share/classes/jdk/jfr/internal/dcmd/DCmdDump.java +++ b/src/share/classes/jdk/jfr/internal/dcmd/DCmdDump.java @@ -70,7 +70,7 @@ final class DCmdDump extends AbstractDCmd { * @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 + diff --git a/src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java b/src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java index f18a68f6004b2c3d00d9e3d6d36fa073290c9e4f..c198e9b03eac1d9fc2e687be7d180557bc16c29d 100644 --- a/src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java +++ b/src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java @@ -82,7 +82,7 @@ final class DCmdStart extends AbstractDCmd { */ @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=" + (settings != null ? Arrays.asList(settings) : "(none)") + ", delay=" + delay + @@ -110,11 +110,6 @@ final class DCmdStart extends AbstractDCmd { throw new DCmdException("No settings specified. Use settings=none to start without any settings"); } Map s = new HashMap<>(); - - if (settings == null || settings.length == 0) { - settings = new String[] { "default" }; - } - for (String configName : settings) { try { s.putAll(JFC.createKnown(configName).getSettings()); diff --git a/src/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java b/src/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java index 361447861f52bed03d7c00e2df82adbf7bf1395f..71490b1915a4e6f3023e9e1fdaefd730cce96fef 100644 --- a/src/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java +++ b/src/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java @@ -56,7 +56,7 @@ final class DCmdStop extends AbstractDCmd { * @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); }