# HG changeset patch # User Doug Simon # Date 1395159306 -3600 # Node ID d2fe05d5cc96b20db734def00116cf00a8b93fec # Parent 7e9409cb656fcec4fec1dfcd248d90f86b2e3b34 added support for lazy computation of names for use with Debug diff -r 7e9409cb656f -r d2fe05d5cc96 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 Tue Mar 18 16:35:49 2014 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Tue Mar 18 17:15:06 2014 +0100 @@ -167,7 +167,7 @@ * @return the scope entered by this method which will be exited when its {@link Scope#close()} * method is called */ - public static Scope scope(String name, Object... context) { + public static Scope scope(CharSequence name, Object... context) { if (ENABLED) { return DebugScope.getInstance().scope(name, null, context); } else { @@ -195,7 +195,7 @@ * @return the scope entered by this method which will be exited when its {@link Scope#close()} * method is called */ - public static Scope sandbox(String name, DebugConfig config, Object... context) { + public static Scope sandbox(CharSequence name, DebugConfig config, Object... context) { if (ENABLED) { DebugConfig sandboxConfig = config == null ? silentConfig() : config; return DebugScope.getInstance().scope(name, sandboxConfig, context); @@ -379,11 +379,11 @@ *

* A disabled metric has virtually no overhead. */ - public static DebugMetric metric(String name) { - if (enabledMetrics != null && enabledMetrics.contains(name)) { - return new MetricImpl(name, false); + public static DebugMetric metric(CharSequence name) { + if (enabledMetrics != null && enabledMetrics.contains(name.toString())) { + return new MetricImpl(name.toString(), false); } else if (ENABLED) { - return new MetricImpl(name, true); + return new MetricImpl(name.toString(), true); } else { return VOID_METRIC; } @@ -495,12 +495,12 @@ }; /** - * @see #timer(String) + * @see #timer(CharSequence) */ public static final String ENABLE_TIMER_PROPERTY_NAME_PREFIX = "graal.debug.timer."; /** - * @see #metric(String) + * @see #metric(CharSequence) */ public static final String ENABLE_METRIC_PROPERTY_NAME_PREFIX = "graal.debug.metric."; @@ -532,11 +532,11 @@ *

* A disabled timer has virtually no overhead. */ - public static DebugTimer timer(String name) { - if (enabledTimers != null && enabledTimers.contains(name)) { - return new TimerImpl(name, false); + public static DebugTimer timer(CharSequence name) { + if (enabledTimers != null && enabledTimers.contains(name.toString())) { + return new TimerImpl(name.toString(), false); } else if (ENABLED) { - return new TimerImpl(name, true); + return new TimerImpl(name.toString(), true); } else { return VOID_TIMER; } diff -r 7e9409cb656f -r d2fe05d5cc96 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java Tue Mar 18 16:35:49 2014 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java Tue Mar 18 17:15:06 2014 +0100 @@ -45,7 +45,7 @@ * Determines if metering is enabled in the {@linkplain Debug#currentScope() current debug * scope}. * - * @see Debug#metric(String) + * @see Debug#metric(CharSequence) */ boolean isMeterEnabled(); @@ -76,7 +76,7 @@ void removeFromContext(Object o); /** - * @see Debug#timer(String) + * @see Debug#timer(CharSequence) */ boolean isTimeEnabled(); diff -r 7e9409cb656f -r d2fe05d5cc96 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugHistogram.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugHistogram.java Tue Mar 18 16:35:49 2014 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugHistogram.java Tue Mar 18 17:15:06 2014 +0100 @@ -72,6 +72,10 @@ count++; } + public void add(int n) { + count += n; + } + public int getCount() { return count; } diff -r 7e9409cb656f -r d2fe05d5cc96 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java Tue Mar 18 16:35:49 2014 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java Tue Mar 18 17:15:06 2014 +0100 @@ -231,13 +231,13 @@ * @param newContextObjects objects to be appended to the debug context * @return the new scope which will be exited when its {@link #close()} method is called */ - public DebugScope scope(String name, DebugConfig sandboxConfig, Object... newContextObjects) { + public DebugScope scope(CharSequence name, DebugConfig sandboxConfig, Object... newContextObjects) { DebugScope newScope = null; if (sandboxConfig != null) { - newScope = new DebugScope(name, name, this, true, newContextObjects); + newScope = new DebugScope(name.toString(), name.toString(), this, true, newContextObjects); configTL.set(sandboxConfig); } else { - newScope = this.createChild(name, newContextObjects); + newScope = this.createChild(name.toString(), newContextObjects); } instanceTL.set(newScope); newScope.updateFlags(); diff -r 7e9409cb656f -r d2fe05d5cc96 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/LazyName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/LazyName.java Tue Mar 18 17:15:06 2014 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.phases; + +import com.oracle.graal.debug.*; + +/** + * A name whose {@link String} value is computed only when it is needed. This is useful in + * combination with debugging facilities such as {@link Debug#scope(CharSequence, Object...)} where + * the {@link String} value of a name is only needed if debugging is enabled. + */ +public abstract class LazyName implements CharSequence { + + private String value; + + public int length() { + return toString().length(); + } + + public char charAt(int index) { + return toString().charAt(index); + } + + public CharSequence subSequence(int start, int end) { + return toString().subSequence(start, end); + } + + @Override + public final String toString() { + if (value == null) { + value = createString(); + } + return value; + } + + /** + * Creates the {@link String} value of this name. + */ + protected abstract String createString(); +}