# HG changeset patch # User Doug Simon # Date 1427146361 -3600 # Node ID e7e868a42b3f0547425af7761cfe48c587d9c33f # Parent ae0e4453df73ffcbeac1f59f463da0b8cf30f73e avoid creation of scopes if -G:Time, -G:Meter and -G:TrackMemUse all have null or empty values and no other debug scope based options are given (e.g., -G:Log, -G:Dump, etc) diff -r ae0e4453df73 -r e7e868a42b3f graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java Mon Mar 23 13:33:18 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java Mon Mar 23 22:32:41 2015 +0100 @@ -40,13 +40,16 @@ // @formatter:off @Option(help = "Pattern for scope(s) in which dumping is enabled (see DebugFilter and Debug.dump)", type = OptionType.Debug) public static final OptionValue Dump = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which metering is enabled (see DebugFilter and Debug.metric)", type = OptionType.Debug) + @Option(help = "Pattern for scope(s) in which metering is enabled (see DebugFilter and Debug.metric). " + + "An empty value enables all metrics unconditionally.", type = OptionType.Debug) public static final OptionValue Meter = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which verification is enabled (see DebugFilter and Debug.verify)", type = OptionType.Debug) + @Option(help = "Pattern for scope(s) in which verification is enabled (see DebugFilter and Debug.verify).", type = OptionType.Debug) public static final OptionValue Verify = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which memory use tracking is enabled (see DebugFilter and Debug.metric)", type = OptionType.Debug) + @Option(help = "Pattern for scope(s) in which memory use tracking is enabled (see DebugFilter and Debug.metric). " + + "An empty value enables all memory use trackers unconditionally.", type = OptionType.Debug) public static final OptionValue TrackMemUse = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which timing is enabled (see DebugFilter and Debug.timer)", type = OptionType.Debug) + @Option(help = "Pattern for scope(s) in which timing is enabled (see DebugFilter and Debug.timer). " + + "An empty value enables all timers unconditionally.", type = OptionType.Debug) public static final OptionValue Time = new OptionValue<>(null); @Option(help = "Pattern for scope(s) in which logging is enabled (see DebugFilter and Debug.log)", type = OptionType.Debug) public static final OptionValue Log = new OptionValue<>(null); @@ -71,12 +74,20 @@ public static final OptionValue LogVerbose = new OptionValue<>(false); // @formatter:on - public static boolean areDebugScopePatternsEnabled() { - return DumpOnError.getValue() || Dump.getValue() != null || Log.getValue() != null || areMetricsOrTimersEnabled(); + public static boolean isNotEmpty(OptionValue option) { + return option.getValue() != null && !option.getValue().isEmpty(); } - public static boolean areMetricsOrTimersEnabled() { - return Meter.getValue() != null || Time.getValue() != null || TrackMemUse.getValue() != null; + public static boolean areDebugScopePatternsEnabled() { + return DumpOnError.getValue() || Dump.getValue() != null || Log.getValue() != null || areScopedMetricsOrTimersEnabled(); + } + + /** + * Determines if any of {@link #Meter}, {@link #Time} or {@link #TrackMemUse} has a non-null, + * non-empty value. + */ + public static boolean areScopedMetricsOrTimersEnabled() { + return isNotEmpty(Meter) || isNotEmpty(Time) || isNotEmpty(TrackMemUse); } private final DebugFilter logFilter; diff -r ae0e4453df73 -r e7e868a42b3f graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Mar 23 13:33:18 2015 -0700 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Mar 23 22:32:41 2015 +0100 @@ -853,7 +853,7 @@ * A disabled tracker has virtually no overhead. */ public static DebugMemUseTracker memUseTracker(CharSequence name) { - if (!ENABLED) { + if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { return VOID_MEM_USE_TRACKER; } return createMemUseTracker("%s", name, null); @@ -871,7 +871,7 @@ * @see #metric(String, Object, Object) */ public static DebugMemUseTracker memUseTracker(String format, Object arg) { - if (!ENABLED) { + if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { return VOID_MEM_USE_TRACKER; } return createMemUseTracker(format, arg, null); @@ -898,7 +898,7 @@ * @see #memUseTracker(CharSequence) */ public static DebugMemUseTracker memUseTracker(String format, Object arg1, Object arg2) { - if (!ENABLED) { + if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { return VOID_MEM_USE_TRACKER; } return createMemUseTracker(format, arg1, arg2); @@ -906,7 +906,7 @@ private static DebugMemUseTracker createMemUseTracker(String format, Object arg1, Object arg2) { String name = formatDebugName(format, arg1, arg2); - return new MemUseTrackerImpl(name); + return new MemUseTrackerImpl(name, !isUnconditionalMemUseTrackingEnabled); } /** @@ -920,7 +920,7 @@ * A disabled metric has virtually no overhead. */ public static DebugMetric metric(CharSequence name) { - if (enabledMetrics == null && !ENABLED) { + if (!areUnconditionalMetricsEnabled() && !ENABLED) { return VOID_METRIC; } return createMetric("%s", name, null); @@ -963,7 +963,7 @@ * @see #metric(String, Object, Object) */ public static DebugMetric metric(String format, Object arg) { - if (enabledMetrics == null && !ENABLED) { + if (!areUnconditionalMetricsEnabled() && !ENABLED) { return VOID_METRIC; } return createMetric(format, arg, null); @@ -990,7 +990,7 @@ * @see #metric(CharSequence) */ public static DebugMetric metric(String format, Object arg1, Object arg2) { - if (enabledMetrics == null && !ENABLED) { + if (!areUnconditionalMetricsEnabled() && !ENABLED) { return VOID_METRIC; } return createMetric(format, arg1, arg2); @@ -1140,6 +1140,10 @@ } }; + public static final String ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME = "graal.debug.unscopedTimers"; + public static final String ENABLE_UNSCOPED_METRICS_PROPERTY_NAME = "graal.debug.unscopedMetrics"; + public static final String ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME = "graal.debug.unscopedMemUseTrackers"; + /** * @see #timer(CharSequence) */ @@ -1150,20 +1154,53 @@ */ public static final String ENABLE_METRIC_PROPERTY_NAME_PREFIX = "graal.debug.metric."; + /** + * Set of unconditionally enabled metrics. Possible values and their meanings: + *
    + *
  • {@code null}: no unconditionally enabled metrics
  • + *
  • {@code isEmpty()}: all metrics are unconditionally enabled
  • + *
  • {@code !isEmpty()}: use {@link #findMatch(Set, Set, String)} on this set and + * {@link #enabledMetricsSubstrings} to determine which metrics are unconditionally enabled
  • + *
+ */ private static final Set enabledMetrics; + + /** + * Set of unconditionally enabled timers. Same interpretation of values as for + * {@link #enabledMetrics}. + */ private static final Set enabledTimers; + private static final Set enabledMetricsSubstrings = new HashSet<>(); private static final Set enabledTimersSubstrings = new HashSet<>(); + /** + * Specifies if all mem use trackers are unconditionally enabled. + */ + private static final boolean isUnconditionalMemUseTrackingEnabled; + static { Set metrics = new HashSet<>(); Set timers = new HashSet<>(); parseMetricAndTimerSystemProperties(metrics, timers, enabledMetricsSubstrings, enabledTimersSubstrings); - enabledMetrics = metrics.isEmpty() && enabledMetricsSubstrings.isEmpty() ? null : metrics; - enabledTimers = timers.isEmpty() && enabledTimersSubstrings.isEmpty() ? null : timers; + metrics = metrics.isEmpty() && enabledMetricsSubstrings.isEmpty() ? null : metrics; + timers = timers.isEmpty() && enabledTimersSubstrings.isEmpty() ? null : timers; + if (metrics == null && Boolean.getBoolean(ENABLE_UNSCOPED_METRICS_PROPERTY_NAME)) { + metrics = Collections.emptySet(); + } + if (timers == null && Boolean.getBoolean(ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME)) { + timers = Collections.emptySet(); + } + enabledMetrics = metrics; + enabledTimers = timers; + isUnconditionalMemUseTrackingEnabled = Boolean.getBoolean(ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME); } private static boolean findMatch(Set haystack, Set haystackSubstrings, String needle) { + if (haystack.isEmpty()) { + // Empty haystack means match all + return true; + } if (haystack.contains(needle)) { return true; } @@ -1224,7 +1261,7 @@ * A disabled timer has virtually no overhead. */ public static DebugTimer timer(CharSequence name) { - if (enabledTimers == null && !ENABLED) { + if (!areUnconditionalTimersEnabled() && !ENABLED) { return VOID_TIMER; } return createTimer("%s", name, null); @@ -1242,7 +1279,7 @@ * @see #timer(String, Object, Object) */ public static DebugTimer timer(String format, Object arg) { - if (enabledTimers == null && !ENABLED) { + if (!areUnconditionalTimersEnabled() && !ENABLED) { return VOID_TIMER; } return createTimer(format, arg, null); @@ -1269,7 +1306,7 @@ * @see #timer(CharSequence) */ public static DebugTimer timer(String format, Object arg1, Object arg2) { - if (enabledTimers == null && !ENABLED) { + if (!areUnconditionalTimersEnabled() && !ENABLED) { return VOID_TIMER; } return createTimer(format, arg1, arg2); diff -r ae0e4453df73 -r e7e868a42b3f graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MemUseTrackerImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MemUseTrackerImpl.java Mon Mar 23 13:33:18 2015 -0700 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MemUseTrackerImpl.java Mon Mar 23 22:32:41 2015 +0100 @@ -48,8 +48,8 @@ */ private static final ThreadLocal currentTracker = new ThreadLocal<>(); - public MemUseTrackerImpl(String name) { - super(name, true, new DebugValue(name + "_Flat", true) { + public MemUseTrackerImpl(String name, boolean conditional) { + super(name, conditional, new DebugValue(name + "_Flat", conditional) { @Override public String toString(long value) { diff -r ae0e4453df73 -r e7e868a42b3f graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Mar 23 13:33:18 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Mar 23 22:32:41 2015 +0100 @@ -110,9 +110,9 @@ this.compilerToVm = toVM; - if (Log.getValue() == null && Meter.getValue() == null && Time.getValue() == null && Dump.getValue() == null && Verify.getValue() == null) { + if (Log.getValue() == null && !areScopedMetricsOrTimersEnabled() && Dump.getValue() == null && Verify.getValue() == null) { if (MethodFilter.getValue() != null) { - TTY.println("WARNING: Ignoring MethodFilter option since Log, Meter, Time, Dump and Verify options are all null"); + TTY.println("WARNING: Ignoring MethodFilter option since Log, Meter, Time, TrackMemUse, Dump and Verify options are all null"); } } @@ -133,7 +133,7 @@ } } - if (Debug.areUnconditionalMetricsEnabled() || Debug.areUnconditionalTimersEnabled() || (Debug.isEnabled() && areMetricsOrTimersEnabled())) { + if (Debug.areUnconditionalMetricsEnabled() || Debug.areUnconditionalTimersEnabled() || (Debug.isEnabled() && areScopedMetricsOrTimersEnabled())) { // This must be created here to avoid loading the DebugValuesPrinter class // during shutdown() which in turn can cause a deadlock debugValuesPrinter = new DebugValuesPrinter(); diff -r ae0e4453df73 -r e7e868a42b3f graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java Mon Mar 23 13:33:18 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java Mon Mar 23 22:32:41 2015 +0100 @@ -63,6 +63,15 @@ if (areDebugScopePatternsEnabled()) { System.setProperty(Debug.Initialization.INITIALIZER_PROPERTY_NAME, "true"); } + if ("".equals(Meter.getValue())) { + System.setProperty(Debug.ENABLE_UNSCOPED_METRICS_PROPERTY_NAME, "true"); + } + if ("".equals(Time.getValue())) { + System.setProperty(Debug.ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME, "true"); + } + if ("".equals(TrackMemUse.getValue())) { + System.setProperty(Debug.ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME, "true"); + } } /**