changeset 4369:efc430d943c0

Drafted regexp filters. Rewrote logging statements of floating read phase.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 26 Jan 2012 18:33:58 +0100
parents d8d6b3de346b
children 44e2e5cb37f3
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/FloatingReadPhase.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java
diffstat 6 files changed, 71 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Thu Jan 26 17:26:42 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Thu Jan 26 18:33:58 2012 +0100
@@ -81,7 +81,7 @@
         if (osrBCI != -1) {
             throw new CiBailout("No OSR supported");
         }
-        return Debug.scope("CompileMethod", method, new Callable<CiTargetMethod>() {
+        return Debug.scope(createScopeName(method), method, new Callable<CiTargetMethod>() {
             public CiTargetMethod call() {
                 final CiAssumptions assumptions = GraalOptions.OptAssumptions ? new CiAssumptions() : null;
                 final LIR lir = Debug.scope("FrontEnd", graph, new Callable<LIR>() {
@@ -103,6 +103,23 @@
         });
     }
 
+    private static String createScopeName(RiResolvedMethod method) {
+        if (Debug.isEnabled()) {
+            return String.format("[%s::%s]", createSimpleName(method.holder()), method.name());
+        } else {
+            return null;
+        }
+    }
+
+    private static String createSimpleName(RiResolvedType holder) {
+        String base = holder.name();
+        int slashIndex = base.lastIndexOf('/');
+        if (slashIndex == -1) {
+            slashIndex = 0;
+        }
+        return base.substring(slashIndex + 1, base.length() - 1);
+    }
+
     /**
      * Builds the graph, optimizes it.
      */
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Thu Jan 26 17:26:42 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Thu Jan 26 18:33:58 2012 +0100
@@ -117,7 +117,6 @@
     public static boolean TraceDeadCodeElimination           = ____;
     public static boolean TraceEscapeAnalysis                = ____;
     public static boolean TraceCanonicalizer                 = ____;
-    public static boolean TraceMemoryMaps                    = ____;
     public static boolean TraceProbability                   = ____;
     public static boolean TraceReadElimination               = ____;
     public static boolean TraceGVN                           = ____;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/FloatingReadPhase.java	Thu Jan 26 17:26:42 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/FloatingReadPhase.java	Thu Jan 26 18:33:58 2012 +0100
@@ -25,10 +25,9 @@
 import java.util.*;
 
 import com.oracle.max.cri.ci.*;
-import com.oracle.max.criutils.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.loop.*;
 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.PhiNode.*;
@@ -74,9 +73,7 @@
         }
 
         public void mergeWith(MemoryMap otherMemoryMap, Block b) {
-            if (GraalOptions.TraceMemoryMaps) {
-                TTY.println("merging block " + otherMemoryMap.block + " into block " + block);
-            }
+            Debug.log("Merging block %s into block %s.", otherMemoryMap.block, block);
             IdentityHashMap<Object, Node> otherMap = otherMemoryMap.map;
 
             for (Map.Entry<Object, Node> entry : map.entrySet()) {
@@ -109,19 +106,14 @@
 
         private void mergeNodes(Object location, Node original, Node newValue, Block mergeBlock) {
             if (original == newValue) {
-                // Nothing to merge.
-                if (GraalOptions.TraceMemoryMaps) {
-                    TTY.println("Nothing to merge both nodes are " + original);
-                }
+                Debug.log("Nothing to merge both nodes are %s.", original);
                 return;
             }
             MergeNode m = (MergeNode) mergeBlock.firstNode();
             if (m.isPhiAtMerge(original)) {
                 PhiNode phi = (PhiNode) original;
                 phi.addInput((ValueNode) newValue);
-                if (GraalOptions.TraceMemoryMaps) {
-                    TTY.println("Add new input to " + original + ": " + newValue);
-                }
+                Debug.log("Add new input to %s: %s.", original, newValue);
                 assert phi.valueCount() <= phi.merge().endCount() : phi.merge();
             } else {
                 PhiNode phi = m.graph().unique(new PhiNode(CiKind.Illegal, m, PhiType.Memory));
@@ -129,9 +121,7 @@
                     phi.addInput((ValueNode) original);
                 }
                 phi.addInput((ValueNode) newValue);
-                if (GraalOptions.TraceMemoryMaps) {
-                    TTY.println("Creating new " + phi + " merge=" + phi.merge() + ", mergeOperationCount=" + mergeOperationCount + ", newValue=" + newValue + ", location=" + location);
-                }
+                Debug.log("Creating new %s merge=%s newValue=%s location=%s.", phi, phi.merge(), newValue, location);
                 assert phi.valueCount() <= phi.merge().endCount() + ((phi.merge() instanceof LoopBeginNode) ? 1 : 0) : phi.merge() + "/" + phi.valueCount() + "/" + phi.merge().endCount() + "/" + mergeOperationCount;
                 assert m.usages().contains(phi);
                 assert phi.merge().usages().contains(phi);
@@ -155,10 +145,7 @@
             StructuredGraph graph = (StructuredGraph) readNode.graph();
             assert readNode.getNullCheck() == false;
 
-            if (GraalOptions.TraceMemoryMaps) {
-                TTY.println("Register read to node " + readNode);
-            }
-
+            Debug.log("Register read to node %s.", readNode);
             FloatingReadNode floatingRead;
             if (readNode.location().locationIdentity() == LocationNode.FINAL_LOCATION) {
                 floatingRead = graph.unique(new FloatingReadNode(readNode.kind(), readNode.object(), readNode.guard(), readNode.location()));
@@ -245,9 +232,7 @@
             propagateFromChildren(loop, modifiedValues);
         }
 
-        if (GraalOptions.TraceMemoryMaps) {
-            print(loopInfo, modifiedValues);
-        }
+        Debug.log("Modified values: %s.", modifiedValues);
 
         // Identify blocks.
         final IdentifyBlocksPhase s = new IdentifyBlocksPhase(false);
@@ -343,15 +328,6 @@
         modifiedValues.get(loop).add(locationIdentity);
     }
 
-    private static void print(LoopInfo loopInfo, HashMap<Loop, Set<Object>> modifiedValues) {
-        TTY.println();
-        TTY.println("Loops:");
-        for (Loop loop : loopInfo.loops()) {
-            TTY.print(loop + " modified values: " + modifiedValues.get(loop));
-            TTY.println();
-        }
-    }
-
     private void mark(LoopBeginNode begin, LoopBeginNode outer, NodeMap<LoopBeginNode> nodeToLoop) {
 
         if (nodeToLoop.get(begin) != null) {
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Thu Jan 26 17:26:42 2012 +0100
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Thu Jan 26 18:33:58 2012 +0100
@@ -37,6 +37,10 @@
         DebugScope.initialize();
     }
 
+    public static boolean isEnabled() {
+        return ENABLED;
+    }
+
     public static void sandbox(String name, Runnable runnable) {
         if (ENABLED) {
             DebugScope.getInstance().scope(name, runnable, null, true, new Object[0]);
@@ -126,7 +130,7 @@
         }
     }
 
-    public static DebugConfig fixedConfix(final boolean isLogEnabled, final boolean isDumpEnabled, final boolean isMeterEnabled, final boolean isTimerEnabled) {
+    public static DebugConfig fixedConfig(final boolean isLogEnabled, final boolean isDumpEnabled, final boolean isMeterEnabled, final boolean isTimerEnabled) {
         return new DebugConfig() {
 
             @Override
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java	Thu Jan 26 17:26:42 2012 +0100
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/internal/DebugScope.java	Thu Jan 26 18:33:58 2012 +0100
@@ -44,7 +44,6 @@
     private DebugValueMap valueMap;
     private String qualifiedName;
 
-    public static final DebugScope DEFAULT_CONTEXT = new DebugScope("DEFAULT", "DEFAULT", null);
     private static final char SCOPE_SEP = '.';
 
     private boolean logEnabled;
@@ -55,7 +54,7 @@
     public static DebugScope getInstance() {
         DebugScope result = instanceTL.get();
         if (result == null) {
-            instanceTL.set(new DebugScope("DEFAULT", "DEFAULT", null));
+            instanceTL.set(new DebugScope("", "", null));
             return instanceTL.get();
         } else {
             return result;
@@ -107,6 +106,8 @@
         }
     }
 
+    private static Object lock = new Object();
+
     public <T> T scope(String newName, Runnable runnable, Callable<T> callable, boolean sandbox, Object[] newContext) {
         DebugScope oldContext = getInstance();
         DebugConfig oldConfig = getConfig();
@@ -118,15 +119,30 @@
             newChild = oldContext.createChild(newName, newContext);
         }
         instanceTL.set(newChild);
-        T result = null;
         newChild.updateFlags();
-        newChild.log("Starting scope %s", newChild.getQualifiedName());
         try {
+            if (logEnabled || dumpEnabled) {
+                synchronized (lock) {
+                    return executeScope(runnable, callable);
+                }
+            } else {
+                return executeScope(runnable, callable);
+            }
+        } finally {
+            newChild.deactivate();
+            instanceTL.set(oldContext);
+            setConfig(oldConfig);
+        }
+    }
+
+    private <T> T executeScope(Runnable runnable, Callable<T> callable) {
+        try {
+            instanceTL.get().log("Starting scope %s", instanceTL.get().getQualifiedName());
             if (runnable != null) {
                 runnable.run();
             }
             if (callable != null) {
-                result = call(callable);
+                return call(callable);
             }
         } catch (RuntimeException e) {
             if (e == lastExceptionThrownTL.get()) {
@@ -136,12 +152,8 @@
                 lastExceptionThrownTL.set(newException);
                 throw newException;
             }
-        } finally {
-            newChild.deactivate();
-            instanceTL.set(oldContext);
-            setConfig(oldConfig);
         }
-        return result;
+        return null;
     }
 
     private void updateFlags() {
@@ -195,7 +207,10 @@
     }
 
     private DebugScope createChild(String newName, Object[] newContext) {
-        String newQualifiedName = this.qualifiedName + SCOPE_SEP + newName;
+        String newQualifiedName = newName;
+        if (this.qualifiedName.length() > 0) {
+            newQualifiedName = this.qualifiedName + SCOPE_SEP + newName;
+        }
         DebugScope result = new DebugScope(newName, newQualifiedName, this, newContext);
         if (children == null) {
             children = new ArrayList<>(4);
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java	Thu Jan 26 17:26:42 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java	Thu Jan 26 18:33:58 2012 +0100
@@ -23,6 +23,7 @@
 package com.oracle.max.graal.hotspot;
 
 import java.util.*;
+import java.util.regex.*;
 
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.graal.debug.*;
@@ -65,7 +66,19 @@
     }
 
     private boolean isEnabled(String filter) {
-        return filter != null && Debug.currentScope().contains(filter) && checkMethodFilter();
+        return filter != null && checkContains(Debug.currentScope(), filter) && checkMethodFilter();
+    }
+
+    private static boolean checkContains(String currentScope, String filter) {
+        if (filter.contains("*")) {
+            /*filter = filter.replace("*", ".*");
+            filter = filter.replace("[", "\\[");
+            filter = filter.replace("]", "\\]");
+            filter = filter.replace(":", "\\:");*/
+            System.out.println("regexp: " + filter + " string=" + currentScope + ", " + Pattern.matches(filter, currentScope));
+            return Pattern.matches(filter, currentScope);
+        }
+        return currentScope.contains(filter);
     }
 
     private boolean checkMethodFilter() {
@@ -107,7 +120,7 @@
 
     @Override
     public RuntimeException interceptException(RuntimeException e) {
-        Debug.setConfig(Debug.fixedConfix(true, true, false, false));
+        Debug.setConfig(Debug.fixedConfig(true, true, false, false));
         Debug.log(String.format("Exception occured in scope: %s", Debug.currentScope()));
         for (Object o : Debug.context()) {
             Debug.log("Context obj %s", o);