# HG changeset patch # User Thomas Wuerthinger # Date 1338571666 -7200 # Node ID 64b1fceb45709dcd9b5c1ce46a5bda1198aee836 # Parent 5134cd2f25ed57f4d45f467f785dc4bd97b61991# Parent af838558e9e58368fb3e8124e155a171d97d4d1d Merge. diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java --- 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 addDuplicates(Iterable newNodes, Map 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 map; + public MapReplacement(Map 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 addDuplicates(Iterable newNodes, Map replacements) { + public Map addDuplicates(Iterable newNodes, DuplicationReplacement replacements) { if (replacements == null) { - replacements = Collections.emptyMap(); + replacements = NO_REPLACEMENT; } return NodeClass.addGraphDuplicate(this, newNodes, replacements); } diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java --- 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 addGraphDuplicate(Graph graph, Iterable nodes, Map replacements) { + static Map addGraphDuplicate(Graph graph, Iterable nodes, DuplicationReplacement replacements) { Map newNodes = new IdentityHashMap<>(); + Map 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 entry : replacements.entrySet()) { + for (Entry 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 entry : replacements.entrySet()) { + for (Entry 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)); + } } } } diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ControlSplitNode.java --- 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; + } } diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingReadNode.java --- 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()); diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadHubNode.java --- 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; } diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java --- 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()); diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java --- 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()); } } diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadFieldNode.java --- 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; } diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/LoadIndexedNode.java --- 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()); } } } diff -r 5134cd2f25ed -r 64b1fceb4570 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/Snippets.java --- 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() { - + final StructuredGraph graph = new StructuredGraph(snippetRiMethod); + return Debug.scope("BuildSnippetGraph", new Object[] {snippetRiMethod, graph}, new Callable() { @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()); diff -r 5134cd2f25ed -r 64b1fceb4570 src/share/vm/graal/graalCompilerToVM.cpp --- 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; {