changeset 21141:2b1228d97525

Cache computation of timer and metric objects for phases
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 28 Apr 2015 10:14:40 -0700
parents 7d2f6dd603b0
children 0b221b4ad707
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/LIRPhase.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java
diffstat 2 files changed, 77 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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<LIRPhaseStatistics> statisticsClassValue = new ClassValue<LIRPhaseStatistics>() {
+        @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 <B extends AbstractBlockBase<B>> void apply(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, C context) {
--- 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<BasePhaseStatistics> statisticsClassValue = new ClassValue<BasePhaseStatistics>() {
+        @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() {