changeset 10082:665e95c28965

DynamicCounterNode: counter without lowering, output tweaks
author Lukas Stadler <lukas.stadler@jku.at>
date Tue, 18 Jun 2013 16:39:17 +0200
parents 20fd8760cb34
children 8dc4cdde75fb 72eafe3a1c34
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java
diffstat 2 files changed, 86 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java	Tue Jun 18 16:38:18 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java	Tue Jun 18 16:39:17 2013 +0200
@@ -25,10 +25,14 @@
 import java.io.*;
 import java.util.*;
 
+import sun.misc.*;
+
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.HeapAccess.WriteBarrierType;
 import com.oracle.graal.nodes.calc.*;
+import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.nodes.java.*;
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.nodes.type.*;
@@ -44,7 +48,7 @@
 public class DynamicCounterNode extends FixedWithNextNode implements Lowerable {
 
     private static final int MAX_COUNTERS = 10 * 1024;
-    private static final long[] COUNTERS = new long[MAX_COUNTERS];
+    public static final long[] COUNTERS = new long[MAX_COUNTERS];
     private static final long[] STATIC_COUNTERS = new long[MAX_COUNTERS];
     private static final String[] GROUPS = new String[MAX_COUNTERS];
     private static final HashMap<String, Integer> INDEXES = new HashMap<>();
@@ -95,8 +99,10 @@
 
     public static synchronized void dump(PrintStream out, double seconds) {
         for (String group : new HashSet<>(Arrays.asList(GROUPS))) {
-            dumpCounters(out, seconds, true, group);
-            dumpCounters(out, seconds, false, group);
+            if (group != null) {
+                dumpCounters(out, seconds, true, group);
+                dumpCounters(out, seconds, false, group);
+            }
         }
         out.println("============================");
 
@@ -116,28 +122,42 @@
             }
         }
 
-        long cutoff = sum / 1000;
-        long sum2 = 0;
-        if (staticCounter) {
-            out.println("=========== " + group + " static counters: ");
-            for (Map.Entry<Long, String> entry : sorted.entrySet()) {
-                long counter = entry.getKey() / MAX_COUNTERS;
-                sum2 += counter;
-                if (sum2 >= cutoff) {
-                    out.println(counter + " \t" + ((counter * 200 + 1) / sum / 2) + "% \t" + entry.getValue());
+        if (sum > 0) {
+            long cutoff = sum / 1000;
+            long sum2 = 0;
+            if (staticCounter) {
+                out.println("=========== " + group + " static counters: ");
+                for (Map.Entry<Long, String> entry : sorted.entrySet()) {
+                    long counter = entry.getKey() / MAX_COUNTERS;
+                    sum2 += counter;
+                    if (sum2 >= cutoff) {
+                        out.println(counter + " \t" + ((counter * 200 + 1) / sum / 2) + "% \t" + entry.getValue());
+                    }
+                }
+                out.println(sum + ": total");
+            } else {
+                if (group.startsWith("~")) {
+                    out.println("=========== " + group + " dynamic counters");
+                    for (Map.Entry<Long, String> entry : sorted.entrySet()) {
+                        long counter = entry.getKey() / MAX_COUNTERS;
+                        sum2 += counter;
+                        if (sum2 >= cutoff) {
+                            out.println(counter + " \t" + ((counter * 200 + 1) / sum / 2) + "% \t" + entry.getValue());
+                        }
+                    }
+                    out.println(sum + "/s: total");
+                } else {
+                    out.println("=========== " + group + " dynamic counters, time = " + seconds + " s");
+                    for (Map.Entry<Long, String> entry : sorted.entrySet()) {
+                        long counter = entry.getKey() / MAX_COUNTERS;
+                        sum2 += counter;
+                        if (sum2 >= cutoff) {
+                            out.println((long) (counter / seconds) + "/s \t" + ((counter * 200 + 1) / sum / 2) + "% \t" + entry.getValue());
+                        }
+                    }
+                    out.println((long) (sum / seconds) + "/s: total");
                 }
             }
-            out.println(sum + ": total");
-        } else {
-            out.println("=========== " + group + " dynamic counters, time = " + seconds + " s");
-            for (Map.Entry<Long, String> entry : sorted.entrySet()) {
-                long counter = entry.getKey() / MAX_COUNTERS;
-                sum2 += counter;
-                if (sum2 >= cutoff) {
-                    out.println((int) (counter / seconds) + "/s \t" + ((counter * 200 + 1) / sum / 2) + "% \t" + entry.getValue());
-                }
-            }
-            out.println((int) (sum / seconds) + "/s: total");
         }
     }
 
@@ -167,6 +187,28 @@
         graph().removeFixed(this);
     }
 
+    public static void addLowLevel(String group, String name, long increment, boolean addContext, FixedNode position, MetaAccessProvider runtime) {
+        if (!enabled) {
+            throw new GraalInternalError("counter nodes shouldn't exist when not enabled");
+        }
+        StructuredGraph graph = position.graph();
+        if (excludedClassPrefix == null || !graph.method().getDeclaringClass().getName().startsWith(excludedClassPrefix)) {
+            int index = addContext ? getIndex(name + " @ " + MetaUtil.format("%h.%n", graph.method())) : getIndex(name);
+            STATIC_COUNTERS[index] += increment;
+            GROUPS[index] = group;
+
+            ConstantNode arrayConstant = ConstantNode.forObject(COUNTERS, runtime, graph);
+            ConstantLocationNode location = ConstantLocationNode.create(NamedLocationIdentity.getArrayLocation(Kind.Long), Kind.Long, Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE *
+                            index, graph);
+            ReadNode read = graph.add(new ReadNode(arrayConstant, location, StampFactory.forKind(Kind.Long), WriteBarrierType.NONE, false));
+            IntegerAddNode add = graph.add(new IntegerAddNode(Kind.Long, read, ConstantNode.forLong(increment, graph)));
+            WriteNode write = graph.add(new WriteNode(arrayConstant, add, location, WriteBarrierType.NONE, false));
+
+            graph.addBeforeFixed(position, read);
+            graph.addBeforeFixed(position, write);
+        }
+    }
+
     public static void addCounterBefore(String group, String name, long increment, boolean addContext, FixedNode position) {
         if (enabled) {
             StructuredGraph graph = position.graph();
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java	Tue Jun 18 16:38:18 2013 +0200
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java	Tue Jun 18 16:39:17 2013 +0200
@@ -24,6 +24,7 @@
 
 import java.util.*;
 
+import com.oracle.graal.api.meta.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.calc.*;
@@ -367,4 +368,24 @@
             }
         });
     }
+
+    public void addLowLevelCounterBefore(final String group, final String name, final int increment, final boolean addContext, final FixedNode position, final MetaAccessProvider runtime) {
+        add(new Effect() {
+
+            @Override
+            public String name() {
+                return "addLowLevelCounterBefore";
+            }
+
+            @Override
+            public void apply(StructuredGraph graph, ArrayList<Node> obsoleteNodes) {
+                DynamicCounterNode.addLowLevel(group, name, increment, addContext, position, runtime);
+            }
+
+            @Override
+            public boolean isVisible() {
+                return true;
+            }
+        });
+    }
 }