Mercurial > hg > graal-compiler
diff graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java @ 14587:8a6612e8e1e1
use lazy names in BasePhase
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 18 Mar 2014 17:15:35 +0100 |
parents | 8569b9e047cd |
children | a378e5922932 |
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java Tue Mar 18 17:15:06 2014 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java Tue Mar 18 17:15:35 2014 +0100 @@ -36,7 +36,35 @@ */ public abstract class BasePhase<C> { - private final String name; + /** + * Phase name lazily computed from the phase class. + */ + class Name extends LazyName { + + @Override + public String createString() { + String s = BasePhase.this.getClass().getSimpleName(); + return s.substring(0, s.length() - "Phase".length()); + } + } + + /** + * Lazily computed debug value name composed of a prefix and a phase's name. + */ + class DebugValueName extends LazyName { + final String prefix; + + public DebugValueName(String prefix) { + this.prefix = prefix; + } + + @Override + public String createString() { + return prefix + name; + } + } + + private final CharSequence name; private final DebugTimer phaseTimer; private final DebugMetric phaseMetric; @@ -49,25 +77,20 @@ } protected BasePhase() { - String nm = this.getClass().getSimpleName(); - if (nm.endsWith("Phase")) { - name = nm.substring(0, nm.length() - "Phase".length()); - } else { - name = nm; - } - assert checkName(name); - phaseTimer = Debug.timer("PhaseTime_" + name); - phaseMetric = Debug.metric("PhaseCount_" + name); + name = new Name(); + assert checkName(name.toString()); + phaseTimer = Debug.timer(new DebugValueName("PhaseTime_")); + phaseMetric = Debug.metric(new DebugValueName("PhaseCount_")); } protected BasePhase(String name) { assert checkName(name); this.name = name; - phaseTimer = Debug.timer("PhaseTime_" + name); - phaseMetric = Debug.metric("PhaseCount_" + name); + phaseTimer = Debug.timer(new DebugValueName("PhaseTime_")); + phaseMetric = Debug.metric(new DebugValueName("PhaseCount_")); } - protected String getDetailedName() { + protected CharSequence getDetailedName() { return getName(); } @@ -88,7 +111,7 @@ } } - public final String getName() { + public final CharSequence getName() { return name; }