changeset 5494:64b1fceb4570

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 01 Jun 2012 19:27:46 +0200
parents 5134cd2f25ed (current diff) af838558e9e5 (diff)
children c78cf0abfdff
files
diffstat 11 files changed, 126 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Fri Jun 01 19:27:46 2012 +0200
@@ -520,10 +520,44 @@
      * @param replacements the replacement map (can be null if no replacement is to be performed)
      * @return a map which associates the original nodes from {@code nodes} to their duplicates
      */
+    public Map<Node, Node> addDuplicates(Iterable<Node> newNodes, Map<Node, Node> replacementsMap) {
+        DuplicationReplacement replacements;
+        if (replacementsMap == null) {
+            replacements = null;
+        } else {
+            replacements = new MapReplacement(replacementsMap);
+        }
+        return addDuplicates(newNodes, replacements);
+    }
+
+    public interface DuplicationReplacement {
+        Node replacement(Node original);
+    }
+
+    private static final class MapReplacement implements DuplicationReplacement {
+        private final Map<Node, Node> map;
+        public MapReplacement(Map<Node, Node> map) {
+            this.map = map;
+        }
+        @Override
+        public Node replacement(Node original) {
+            Node replacement = map.get(original);
+            return replacement != null ? replacement : original;
+        }
+
+    }
+
+    private static final DuplicationReplacement NO_REPLACEMENT = new DuplicationReplacement() {
+        @Override
+        public Node replacement(Node original) {
+            return original;
+        }
+    };
+
     @SuppressWarnings("all")
-    public Map<Node, Node> addDuplicates(Iterable<Node> newNodes, Map<Node, Node> replacements) {
+    public Map<Node, Node> addDuplicates(Iterable<Node> newNodes, DuplicationReplacement replacements) {
         if (replacements == null) {
-            replacements = Collections.emptyMap();
+            replacements = NO_REPLACEMENT;
         }
         return NodeClass.addGraphDuplicate(this, newNodes, replacements);
     }
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Fri Jun 01 19:27:46 2012 +0200
@@ -27,6 +27,8 @@
 import java.util.Map.*;
 import java.util.concurrent.ConcurrentHashMap;
 
+import com.oracle.graal.graph.Graph.DuplicationReplacement;
+
 import sun.misc.Unsafe;
 
 public class NodeClass {
@@ -910,15 +912,21 @@
         return directSuccessorCount;
     }
 
-    static Map<Node, Node> addGraphDuplicate(Graph graph, Iterable<Node> nodes, Map<Node, Node> replacements) {
+    static Map<Node, Node> addGraphDuplicate(Graph graph, Iterable<Node> nodes, DuplicationReplacement replacements) {
         Map<Node, Node> newNodes = new IdentityHashMap<>();
+        Map<Node, Node> replacementsMap = new IdentityHashMap<>();
         // create node duplicates
         for (Node node : nodes) {
-            if (node != null && !replacements.containsKey(node)) {
+            if (node != null) {
                 assert !node.isDeleted() : "trying to duplicate deleted node";
-                Node newNode = node.clone(graph);
-                assert newNode.getClass() == node.getClass();
-                newNodes.put(node, newNode);
+                Node replacement = replacements.replacement(node);
+                if (replacement != node) {
+                    replacementsMap.put(node, replacement);
+                } else {
+                    Node newNode = node.clone(graph);
+                    assert newNode.getClass() == node.getClass();
+                    newNodes.put(node, newNode);
+                }
             }
         }
         // re-wire inputs
@@ -928,24 +936,29 @@
             for (NodeClassIterator iter = oldNode.inputs().iterator(); iter.hasNext();) {
                 Position pos = iter.nextPosition();
                 Node input = oldNode.getNodeClass().get(oldNode, pos);
-                Node target = replacements.get(input);
+                Node target = replacementsMap.get(input);
                 if (target == null) {
-                    target = newNodes.get(input);
+                    Node replacement = replacements.replacement(input);
+                    if (replacement != input) {
+                        replacementsMap.put(input, replacement);
+                        target = replacement;
+                    } else {
+                        target = newNodes.get(input);
+                    }
                 }
                 node.getNodeClass().set(node, pos, target);
             }
         }
-        for (Entry<Node, Node> entry : replacements.entrySet()) {
+        for (Entry<Node, Node> entry : replacementsMap.entrySet()) {
             Node oldNode = entry.getKey();
             Node node = entry.getValue();
-            if (oldNode == node) {
-                continue;
-            }
             for (NodeClassIterator iter = oldNode.inputs().iterator(); iter.hasNext();) {
                 Position pos = iter.nextPosition();
-                Node input = oldNode.getNodeClass().get(oldNode, pos);
-                if (newNodes.containsKey(input)) {
-                    node.getNodeClass().set(node, pos, newNodes.get(input));
+                if (pos.isValidFor(node, oldNode)) {
+                    Node input = oldNode.getNodeClass().get(oldNode, pos);
+                    if (newNodes.containsKey(input)) {
+                        node.getNodeClass().set(node, pos, newNodes.get(input));
+                    }
                 }
             }
         }
@@ -957,24 +970,27 @@
             for (NodeClassIterator iter = oldNode.successors().iterator(); iter.hasNext();) {
                 Position pos = iter.nextPosition();
                 Node succ = oldNode.getNodeClass().get(oldNode, pos);
-                Node target = replacements.get(succ);
-                if (target == null) {
+                Node target = replacementsMap.get(succ);
+                Node replacement = replacements.replacement(succ);
+                if (replacement != succ) {
+                    replacementsMap.put(succ, replacement);
+                    target = replacement;
+                } else {
                     target = newNodes.get(succ);
                 }
                 node.getNodeClass().set(node, pos, target);
             }
         }
-        for (Entry<Node, Node> entry : replacements.entrySet()) {
+        for (Entry<Node, Node> entry : replacementsMap.entrySet()) {
             Node oldNode = entry.getKey();
             Node node = entry.getValue();
-            if (oldNode == node) {
-                continue;
-            }
             for (NodeClassIterator iter = oldNode.successors().iterator(); iter.hasNext();) {
                 Position pos = iter.nextPosition();
-                Node succ = oldNode.getNodeClass().get(oldNode, pos);
-                if (newNodes.containsKey(succ)) {
-                    node.getNodeClass().set(node, pos, newNodes.get(succ));
+                if (pos.isValidFor(node, oldNode)) {
+                    Node succ = oldNode.getNodeClass().get(oldNode, pos);
+                    if (newNodes.containsKey(succ)) {
+                        node.getNodeClass().set(node, pos, newNodes.get(succ));
+                    }
                 }
             }
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ControlSplitNode.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ControlSplitNode.java	Fri Jun 01 19:27:46 2012 +0200
@@ -105,4 +105,12 @@
         properties.put("branchProbability", str.toString());
         return properties;
     }
+
+    public int blockSuccessorIndex(BeginNode successor) {
+        int idx = blockSuccessors.indexOf(successor);
+        if (idx < 0) {
+            throw new IllegalArgumentException();
+        }
+        return idx;
+    }
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingReadNode.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingReadNode.java	Fri Jun 01 19:27:46 2012 +0200
@@ -60,12 +60,12 @@
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        if (object() != null && object().isConstant() && object().kind() == CiKind.Object) {
+        RiRuntime runtime = tool.runtime();
+        if (runtime != null && object() != null && object().isConstant() && object().kind() == CiKind.Object) {
             if (this.location() == LocationNode.FINAL_LOCATION && location().getClass() == LocationNode.class) {
                 Object value = object().asConstant().asObject();
                 long displacement = location().displacement();
                 CiKind kind = location().kind();
-                RiRuntime runtime = tool.runtime();
                 CiConstant constant = kind.readUnsafeConstant(value, displacement);
                 if (constant != null) {
                     return ConstantNode.forCiConstant(constant, runtime, graph());
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadHubNode.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadHubNode.java	Fri Jun 01 19:27:46 2012 +0200
@@ -49,22 +49,25 @@
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        ObjectStamp stamp = object.objectStamp();
+        RiRuntime runtime = tool.runtime();
+        if (runtime != null) {
+            ObjectStamp stamp = object.objectStamp();
 
-        RiResolvedType exactType;
-        if (stamp.isExactType()) {
-            exactType = stamp.type();
-        } else if (stamp.type() != null && tool.assumptions() != null) {
-            exactType = stamp.type().uniqueConcreteSubtype();
+            RiResolvedType exactType;
+            if (stamp.isExactType()) {
+                exactType = stamp.type();
+            } else if (stamp.type() != null && tool.assumptions() != null) {
+                exactType = stamp.type().uniqueConcreteSubtype();
+                if (exactType != null) {
+                    tool.assumptions().recordConcreteSubtype(stamp.type(), exactType);
+                }
+            } else {
+                exactType = null;
+            }
+
             if (exactType != null) {
-                tool.assumptions().recordConcreteSubtype(stamp.type(), exactType);
+                return ConstantNode.forCiConstant(exactType.getEncoding(Representation.ObjectHub), runtime, graph());
             }
-        } else {
-            exactType = null;
-        }
-
-        if (exactType != null) {
-            return ConstantNode.forCiConstant(exactType.getEncoding(Representation.ObjectHub), tool.runtime(), graph());
         }
         return this;
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Fri Jun 01 19:27:46 2012 +0200
@@ -43,12 +43,12 @@
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        if (object() != null && object().isConstant() && object().kind() == CiKind.Object) {
+        RiRuntime runtime = tool.runtime();
+        if (runtime != null && object() != null && object().isConstant() && object().kind() == CiKind.Object) {
             if (location() == LocationNode.FINAL_LOCATION && location().getClass() == LocationNode.class) {
                 Object value = object().asConstant().asObject();
                 long displacement = location().displacement();
                 CiKind kind = location().kind();
-                RiRuntime runtime = tool.runtime();
                 CiConstant constant = kind.readUnsafeConstant(value, displacement);
                 if (constant != null) {
                     return ConstantNode.forCiConstant(constant, runtime, graph());
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java	Fri Jun 01 19:27:46 2012 +0200
@@ -52,11 +52,10 @@
             assert length != null;
             return length;
         }
-        CiConstant constantValue = null;
-        if (array().isConstant() && !array().isNullConstant()) {
-            constantValue = array().asConstant();
+        RiRuntime runtime = tool.runtime();
+        if (runtime != null && array().isConstant() && !array().isNullConstant()) {
+            CiConstant constantValue = array().asConstant();
             if (constantValue != null && constantValue.isNonNull()) {
-                RiRuntime runtime = tool.runtime();
                 return ConstantNode.forInt(runtime.getArrayLength(constantValue), graph());
             }
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java	Fri Jun 01 19:27:46 2012 +0200
@@ -55,14 +55,17 @@
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        CiConstant constant = null;
-        if (isStatic()) {
-            constant = field().constantValue(null);
-        } else if (object().isConstant() && !object().isNullConstant()) {
-            constant = field().constantValue(object().asConstant());
-        }
-        if (constant != null) {
-            return ConstantNode.forCiConstant(constant, tool.runtime(), graph());
+        RiRuntime runtime = tool.runtime();
+        if (runtime != null) {
+            CiConstant constant = null;
+            if (isStatic()) {
+                constant = field().constantValue(null);
+            } else if (object().isConstant() && !object().isNullConstant()) {
+                constant = field().constantValue(object().asConstant());
+            }
+            if (constant != null) {
+                return ConstantNode.forCiConstant(constant, runtime, graph());
+            }
         }
         return this;
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java	Fri Jun 01 19:27:46 2012 +0200
@@ -24,12 +24,15 @@
 
 import java.lang.reflect.*;
 
+import sun.misc.*;
+
 import com.oracle.graal.cri.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.nodes.type.*;
 import com.oracle.max.cri.ci.*;
+import com.oracle.max.cri.ri.*;
 
 /**
  * The {@code LoadIndexedNode} represents a read from an element of an array.
@@ -61,7 +64,8 @@
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        if (index().isConstant() && array().isConstant() && !array().isNullConstant()) {
+        RiRuntime runtime = tool.runtime();
+        if (runtime != null && index().isConstant() && array().isConstant() && !array().isNullConstant()) {
             CiConstant arrayConst = array().asConstant();
             if (tool.isImmutable(arrayConst)) {
                 int index = index().asConstant().asInt();
@@ -69,7 +73,7 @@
                 int length = Array.getLength(array);
                 if (index >= 0 && index < length) {
                     return ConstantNode.forCiConstant(elementKind().readUnsafeConstant(array,
-                                    elementKind().arrayBaseOffset() + index * elementKind().arrayIndexScale()), tool.runtime(), graph());
+                                    elementKind().arrayBaseOffset() + index * elementKind().arrayIndexScale()), runtime, graph());
                 }
             }
         }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/Snippets.java	Fri Jun 01 19:27:28 2012 +0200
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/Snippets.java	Fri Jun 01 19:27:46 2012 +0200
@@ -91,13 +91,12 @@
     }
 
     private static StructuredGraph buildSnippetGraph(final RiResolvedMethod snippetRiMethod, final GraalRuntime runtime, final CiTarget target, final BoxingMethodPool pool) {
-        return Debug.scope("BuildSnippetGraph", snippetRiMethod, new Callable<StructuredGraph>() {
-
+        final StructuredGraph graph = new StructuredGraph(snippetRiMethod);
+        return Debug.scope("BuildSnippetGraph", new Object[] {snippetRiMethod, graph}, new Callable<StructuredGraph>() {
             @Override
             public StructuredGraph call() throws Exception {
                 GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault();
                 GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config, OptimisticOptimizations.NONE);
-                StructuredGraph graph = new StructuredGraph(snippetRiMethod);
                 graphBuilder.apply(graph);
 
                 Debug.dump(graph, "%s: %s", snippetRiMethod.name(), GraphBuilderPhase.class.getSimpleName());
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Fri Jun 01 19:27:28 2012 +0200
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Fri Jun 01 19:27:46 2012 +0200
@@ -191,7 +191,7 @@
     // class C extends B { public void foo() { } }
     // class D extends B { }
     // Would lead to identify C.foo() as the unique concrete method for I.foo() without seeing A.foo().
-    return false;
+    return NULL;
   }
   methodHandle unique_concrete;
   {