# HG changeset patch # User Tom Rodriguez # Date 1430241280 25200 # Node ID 2b1228d975256b23b802467842acaa5d34ea7942 # Parent 7d2f6dd603b0004d219c5441ea142aee2b7f92d2 Cache computation of timer and metric objects for phases diff -r 7d2f6dd603b0 -r 2b1228d97525 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java Tue Apr 28 09:44:39 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java Tue Apr 28 10:14:40 2015 -0700 @@ -60,6 +60,30 @@ */ private final DebugMemUseTracker memUseTracker; + private static class LIRPhaseStatistics { + /** + * Records time spent within {@link #apply}. + */ + private final DebugTimer timer; + + /** + * Records memory usage within {@link #apply}. + */ + private final DebugMemUseTracker memUseTracker; + + LIRPhaseStatistics(Class clazz) { + timer = Debug.timer("LIRPhaseTime_%s", clazz); + memUseTracker = Debug.memUseTracker("LIRPhaseMemUse_%s", clazz); + } + } + + private static final ClassValue statisticsClassValue = new ClassValue() { + @Override + protected LIRPhaseStatistics computeValue(Class c) { + return new LIRPhaseStatistics(c); + } + }; + private static final Pattern NAME_PATTERN = Pattern.compile("[A-Z][A-Za-z0-9]+"); private static boolean checkName(String name) { @@ -68,15 +92,17 @@ } public LIRPhase() { - timer = Debug.timer("LIRPhaseTime_%s", getClass()); - memUseTracker = Debug.memUseTracker("LIRPhaseMemUse_%s", getClass()); + LIRPhaseStatistics statistics = statisticsClassValue.get(getClass()); + timer = statistics.timer; + memUseTracker = statistics.memUseTracker; } protected LIRPhase(String name) { assert checkName(name); this.name = name; - timer = Debug.timer("LIRPhaseTime_%s", getClass()); - memUseTracker = Debug.memUseTracker("LIRPhaseMemUse_%s", getClass()); + LIRPhaseStatistics statistics = statisticsClassValue.get(getClass()); + timer = statistics.timer; + memUseTracker = statistics.memUseTracker; } public final > void apply(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, C context) { diff -r 7d2f6dd603b0 -r 2b1228d97525 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java Tue Apr 28 09:44:39 2015 -0700 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java Tue Apr 28 10:14:40 2015 -0700 @@ -69,20 +69,59 @@ return true; } + private static class BasePhaseStatistics { + /** + * Records time spent in {@link #apply(StructuredGraph, Object, boolean)}. + */ + private final DebugTimer timer; + + /** + * Counts calls to {@link #apply(StructuredGraph, Object, boolean)}. + */ + private final DebugMetric executionCount; + + /** + * Accumulates the {@linkplain Graph#getNodeCount() live node count} of all graphs sent to + * {@link #apply(StructuredGraph, Object, boolean)}. + */ + private final DebugMetric inputNodesCount; + + /** + * Records memory usage within {@link #apply(StructuredGraph, Object, boolean)}. + */ + private final DebugMemUseTracker memUseTracker; + + BasePhaseStatistics(Class clazz) { + timer = Debug.timer("PhaseTime_%s", clazz); + executionCount = Debug.metric("PhaseCount_%s", clazz); + memUseTracker = Debug.memUseTracker("PhaseMemUse_%s", clazz); + inputNodesCount = Debug.metric("PhaseNodes_%s", clazz); + } + } + + private static final ClassValue statisticsClassValue = new ClassValue() { + @Override + protected BasePhaseStatistics computeValue(Class c) { + return new BasePhaseStatistics(c); + } + }; + protected BasePhase() { - timer = Debug.timer("PhaseTime_%s", getClass()); - executionCount = Debug.metric("PhaseCount_%s", getClass()); - memUseTracker = Debug.memUseTracker("PhaseMemUse_%s", getClass()); - inputNodesCount = Debug.metric("PhaseNodes_%s", getClass()); + BasePhaseStatistics statistics = statisticsClassValue.get(getClass()); + timer = statistics.timer; + executionCount = statistics.executionCount; + memUseTracker = statistics.memUseTracker; + inputNodesCount = statistics.inputNodesCount; } protected BasePhase(String name) { assert checkName(name); this.name = name; - timer = Debug.timer("PhaseTime_%s", getClass()); - executionCount = Debug.metric("PhaseCount_%s", getClass()); - memUseTracker = Debug.memUseTracker("PhaseMemUse_%s", getClass()); - inputNodesCount = Debug.metric("PhaseNodes_%s", getClass()); + BasePhaseStatistics statistics = statisticsClassValue.get(getClass()); + timer = statistics.timer; + executionCount = statistics.executionCount; + memUseTracker = statistics.memUseTracker; + inputNodesCount = statistics.inputNodesCount; } protected CharSequence getDetailedName() {