changeset 4348:d49c90e641cb

Remove GraalMetrics, replace with new syntax for metrics.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 11 Jan 2012 15:46:58 +0100
parents c8e5635f2bdd
children 7e974a026889
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalContext.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalMetrics.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/Interval.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GlobalValueNumberingPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java
diffstat 11 files changed, 43 insertions(+), 197 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java	Wed Jan 11 15:46:58 2012 +0100
@@ -42,6 +42,7 @@
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.phases.PhasePlan.PhasePosition;
 import com.oracle.max.graal.compiler.schedule.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.virtual.*;
@@ -146,9 +147,7 @@
                 emitLIR(compiler.xir);
                 targetMethod = emitCode();
 
-                if (GraalOptions.Meter) {
-                    context().metrics.BytecodesCompiled += method.codeSize();
-                }
+                Debug.metric("BytecodesCompiled").add(method.codeSize());
             } catch (CiBailout bailout) {
                 throw bailout;
             } catch (GraalInternalError e) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalContext.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalContext.java	Wed Jan 11 15:46:58 2012 +0100
@@ -35,7 +35,6 @@
 
     public final ObservableContext observable = new ObservableContext();
     public final GraalTimers timers = new GraalTimers();
-    public final GraalMetrics metrics = new GraalMetrics();
 
     private final String name;
 
@@ -57,9 +56,6 @@
                 TTY.print('=');
             }
             TTY.println("\n========== " + name + " ==========");
-            if (GraalOptions.Meter) {
-                metrics.print();
-            }
             if (GraalOptions.Time) {
                 timers.print();
             }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalMetrics.java	Wed Jan 11 15:03:55 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, 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.max.graal.compiler;
-
-import java.lang.reflect.*;
-import java.util.*;
-import java.util.Map.Entry;
-
-import com.oracle.max.criutils.*;
-
-
-/**
- * This class contains a number of fields that collect metrics about compilation, particularly
- * the number of times certain optimizations are performed.
- */
-public final class GraalMetrics {
-    // Checkstyle: stop
-    public int CompiledMethods;
-    public int TargetMethods;
-    public int LocalValueNumberHits;
-    public int ValueMapResizes;
-    public int InlinedFinalizerChecks;
-    public int InlineForcedMethods;
-    public int InlineForbiddenMethods;
-    public int InlineConsidered;
-    public int InlinePerformed;
-    public int InlineUncompiledConsidered;
-    public int InlineUncompiledPerformed;
-    public int BlocksDeleted;
-    public int BytecodesCompiled;
-    public int CodeBytesEmitted;
-    public int SafepointsEmitted;
-    public int ExceptionHandlersEmitted;
-    public int DataPatches;
-    public int DirectCallSitesEmitted;
-    public int IndirectCallSitesEmitted;
-    public int LiveHIRInstructions;
-    public int LIRInstructions;
-    public int LIRVariables;
-    public int LIRXIRInstructions;
-    public int LIRMoveInstructions;
-    public int LSRAIntervalsCreated;
-    public int LSRASpills;
-    public int LoadConstantIterations;
-    public int CodeBufferCopies;
-    public int UniqueValueIdsAssigned;
-    public int FrameStatesCreated;
-    public int FrameStateValuesCreated;
-    public int LoopsPeeled;
-    public int LoopsInverted;
-    public int PartialUsageProbability;
-    public int FullUsageProbability;
-    public int Rematerializations;
-    public int GlobalValueNumberingHits;
-    public int ExplicitExceptions;
-    public int GuardsHoisted;
-    // Checkstyle: resume
-
-    public void print() {
-        for (Entry<String, MetricsEntry> m : map.entrySet()) {
-            printField(m.getKey(), m.getValue().value);
-        }
-        printFields(GraalMetrics.class);
-    }
-
-    public static class MetricsEntry {
-        public int value;
-
-        public void increment() {
-            increment(1);
-        }
-
-        public void increment(int val) {
-            value += val;
-        }
-    }
-
-    private LinkedHashMap<String, MetricsEntry> map = new LinkedHashMap<>();
-
-    public MetricsEntry get(String name) {
-        if (!map.containsKey(name)) {
-            map.put(name, new MetricsEntry());
-        }
-        return map.get(name);
-    }
-
-    public void printFields(Class<?> javaClass) {
-        final String className = javaClass.getSimpleName();
-        TTY.println(className + " {");
-        for (final Field field : javaClass.getFields()) {
-            printField(field, false);
-        }
-        TTY.println("}");
-    }
-
-    public void printField(final Field field, boolean tabbed) {
-        final String fieldName = String.format("%35s", field.getName());
-        try {
-            String prefix = tabbed ? "" : "    " + fieldName + " = ";
-            String postfix = tabbed ? "\t" : "\n";
-            if (field.getType() == int.class) {
-                TTY.print(prefix + field.getInt(this) + postfix);
-            } else if (field.getType() == boolean.class) {
-                TTY.print(prefix + field.getBoolean(this) + postfix);
-            } else if (field.getType() == float.class) {
-                TTY.print(prefix + field.getFloat(this) + postfix);
-            } else if (field.getType() == String.class) {
-                TTY.print(prefix + field.get(this) + postfix);
-            } else if (field.getType() == Map.class) {
-                Map<?, ?> m = (Map<?, ?>) field.get(this);
-                TTY.print(prefix + printMap(m) + postfix);
-            } else {
-                TTY.print(prefix + field.get(this) + postfix);
-            }
-        } catch (IllegalAccessException e) {
-            // do nothing.
-        }
-    }
-
-    private static String printMap(Map<?, ?> m) {
-        StringBuilder sb = new StringBuilder();
-
-        List<String> keys = new ArrayList<>();
-        for (Object key : m.keySet()) {
-            keys.add((String) key);
-        }
-        Collections.sort(keys);
-
-        for (String key : keys) {
-            sb.append(key);
-            sb.append("\t");
-            sb.append(m.get(key));
-            sb.append("\n");
-        }
-
-        return sb.toString();
-    }
-
-    private static void printField(String fieldName, long value) {
-        TTY.print("    " + fieldName + " = " + value + "\n");
-    }
-}
-
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java	Wed Jan 11 15:46:58 2012 +0100
@@ -28,6 +28,7 @@
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 
 /**
  * This class performs basic optimizations on the control flow graph after LIR generation.
@@ -123,7 +124,7 @@
             if (canDeleteBlock(block)) {
                 // adjust successor and predecessor lists
                 block.replaceWith(block.suxAt(0));
-                context.metrics.BlocksDeleted++;
+                Debug.metric("BlocksDeleted").increment();
             } else {
                 // adjust position of this block in the block list if blocks before
                 // have been deleted
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/Interval.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/Interval.java	Wed Jan 11 15:46:58 2012 +0100
@@ -31,6 +31,7 @@
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 
 /**
  * Represents an interval in the {@linkplain LinearScan linear scan register allocator}.
@@ -659,10 +660,10 @@
      */
     static final Interval EndMarker = new Interval(null, CiValue.IllegalValue, -1);
 
+    private static final Debug.Metric instanceMetric = Debug.metric("LSRAIntervalsCreated");
+
     Interval(GraalContext context, CiValue operand, int operandNumber) {
-        if (GraalOptions.Meter && context != null) {
-            context.metrics.LSRAIntervalsCreated++;
-        }
+        instanceMetric.increment();
         assert operand != null;
         this.operand = operand;
         this.operandNumber = operandNumber;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java	Wed Jan 11 15:46:58 2012 +0100
@@ -33,6 +33,7 @@
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 
 public class TargetMethodAssembler {
     public final GraalCompilation compilation;
@@ -75,13 +76,11 @@
             }
         }
 
-        if (GraalOptions.Meter) {
-            compilation.compiler.context.metrics.TargetMethods++;
-            compilation.compiler.context.metrics.CodeBytesEmitted += targetMethod.targetCodeSize();
-            compilation.compiler.context.metrics.SafepointsEmitted += targetMethod.safepoints.size();
-            compilation.compiler.context.metrics.DataPatches += targetMethod.dataReferences.size();
-            compilation.compiler.context.metrics.ExceptionHandlersEmitted += targetMethod.exceptionHandlers.size();
-        }
+        Debug.metric("TargetMethods").increment();
+        Debug.metric("CodeBytesEmitted").add(targetMethod.targetCodeSize());
+        Debug.metric("SafepointsEmitted").add(targetMethod.safepoints.size());
+        Debug.metric("DataPatches").add(targetMethod.dataReferences.size());
+        Debug.metric("ExceptionHandlersEmitted").add(targetMethod.exceptionHandlers.size());
 
         if (GraalOptions.PrintAssembly && !TTY.isSuppressed() && !isStub) {
             Util.printSection("Target Method", Util.SECTION_CHARACTER);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Wed Jan 11 15:46:58 2012 +0100
@@ -50,6 +50,7 @@
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.stub.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.DeoptimizeNode.DeoptAction;
@@ -1314,9 +1315,7 @@
                     inputOperandArray, tempOperandArray, inputOperandIndicesArray, tempOperandIndicesArray,
                     (allocatedResultOperand == IllegalValue) ? -1 : resultOperand.index,
                     info, infoAfter, method));
-            if (GraalOptions.Meter) {
-                context.metrics.LIRXIRInstructions++;
-            }
+            Debug.metric("LIRXIRInstructions").increment();
         }
 
         return operandsArray[resultOperand.index];
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GlobalValueNumberingPhase.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GlobalValueNumberingPhase.java	Wed Jan 11 15:46:58 2012 +0100
@@ -24,11 +24,14 @@
 
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
 public class GlobalValueNumberingPhase extends Phase {
 
+    public static final Debug.Metric metricGlobalValueNumberingHits = Debug.metric("GlobalValueNumberingHits");
+
     @Override
     protected void run(StructuredGraph graph) {
         NodeBitMap visited = graph.createNodeBitMap();
@@ -47,9 +50,7 @@
                 Node newNode = compilerGraph.findDuplicate(n);
                 if (newNode != null) {
                     n.replaceAndDelete(newNode);
-                    if (GraalOptions.Meter) {
-                        currentContext.metrics.GlobalValueNumberingHits++;
-                    }
+                    metricGlobalValueNumberingHits.increment();
                     if (GraalOptions.TraceGVN) {
                         TTY.println("GVN applied and new node is " + newNode);
                     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Wed Jan 11 15:46:58 2012 +0100
@@ -33,6 +33,7 @@
 import com.oracle.max.graal.compiler.util.InliningUtil.InlineInfo;
 import com.oracle.max.graal.compiler.util.InliningUtil.InliningCallback;
 import com.oracle.max.graal.cri.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
@@ -54,6 +55,10 @@
 
     private final PhasePlan plan;
 
+    // Metrics
+    private static final Debug.Metric metricInliningPerformed = Debug.metric("InliningPerformed");
+    private static final Debug.Metric metricInliningConsidered = Debug.metric("InliningConsidered");
+
     public InliningPhase(CiTarget target, GraalRuntime runtime, Collection<Invoke> hints, CiAssumptions assumptions, PhasePlan plan) {
         this.target = target;
         this.runtime = runtime;
@@ -105,9 +110,7 @@
                     if (GraalOptions.Intrinsify) {
                         new IntrinsificationPhase(runtime).apply(graph, currentContext);
                     }
-                    if (GraalOptions.Meter) {
-                        currentContext.metrics.InlinePerformed++;
-                    }
+                    metricInliningPerformed.increment();
                 } catch (CiBailout bailout) {
                     // TODO determine if we should really bail out of the whole compilation.
                     throw bailout;
@@ -146,10 +149,7 @@
     private void scanInvoke(Invoke invoke, int level) {
         InlineInfo info = InliningUtil.getInlineInfo(invoke, level, runtime, assumptions, this);
         if (info != null) {
-            if (GraalOptions.Meter) {
-                currentContext.metrics.InlineConsidered++;
-            }
-
+            metricInliningConsidered.increment();
             inlineCandidates.add(info);
         }
     }
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Wed Jan 11 15:46:58 2012 +0100
@@ -70,6 +70,16 @@
             super(name);
         }
 
+        public void increment() {
+            // TODO Auto-generated method stub
+
+        }
+
+        public void add(int targetCodeSize) {
+            // TODO Auto-generated method stub
+
+        }
+
     }
 
     public static final class Timer extends ScopeChild {
@@ -77,4 +87,8 @@
             super(name);
         }
     }
+
+    public static Metric metric(String string) {
+        return new Metric(string);
+    }
 }
--- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java	Wed Jan 11 15:03:55 2012 +0100
+++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java	Wed Jan 11 15:46:58 2012 +0100
@@ -36,6 +36,7 @@
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.java.BlockMap.*;
 import com.oracle.max.graal.nodes.*;
@@ -866,9 +867,7 @@
             } else {
                 exception.exceptionEdge.setNext(createTarget(unwindBlock(bci()), frameState.duplicateWithException(bci(), exception.exception)));
             }
-            if (GraalOptions.Meter) {
-                currentContext.metrics.ExplicitExceptions++;
-            }
+            Debug.metric("ExplicitExceptions").increment();
         }
     }