# HG changeset patch # User Doug Simon # Date 1382651208 -7200 # Node ID 6332050441ebb59971132ed5cbb484036e2bc409 # Parent 388bb7650808fa46ecdc3b0903272b2989dc4fde fixed tests that need to take into account ConstantNodes not recording their usages (GRAAL-508) diff -r 388bb7650808 -r 6332050441eb graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest.java Thu Oct 24 16:21:25 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest.java Thu Oct 24 23:46:48 2013 +0200 @@ -22,6 +22,7 @@ */ package com.oracle.graal.compiler.test; +import static com.oracle.graal.nodes.ConstantNode.*; import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import static org.junit.Assert.*; @@ -144,7 +145,9 @@ new ConditionalEliminationPhase(getMetaAccess()).apply(graph); new CanonicalizerPhase(true).apply(graph, new PhaseContext(getProviders(), null)); for (ConstantNode constant : graph.getNodes().filter(ConstantNode.class)) { - assertTrue("unexpected constant: " + constant, constant.asConstant().isNull() || constant.asConstant().asInt() > 0); + if (ConstantNodeRecordsUsages || !constant.gatherUsages().isEmpty()) { + assertTrue("unexpected constant: " + constant, constant.asConstant().isNull() || constant.asConstant().asInt() > 0); + } } } @@ -176,7 +179,9 @@ new ConditionalEliminationPhase(getMetaAccess()).apply(graph); new CanonicalizerPhase(true).apply(graph, new PhaseContext(getProviders(), null)); for (ConstantNode constant : graph.getNodes().filter(ConstantNode.class)) { - assertTrue("unexpected constant: " + constant, constant.asConstant().isNull() || constant.asConstant().asInt() > 0); + if (ConstantNodeRecordsUsages || !constant.gatherUsages().isEmpty()) { + assertTrue("unexpected constant: " + constant, constant.asConstant().isNull() || constant.asConstant().asInt() > 0); + } } } diff -r 388bb7650808 -r 6332050441eb graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Oct 24 16:21:25 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Oct 24 23:46:48 2013 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.compiler.test; import static com.oracle.graal.api.code.CodeUtil.*; +import static com.oracle.graal.nodes.ConstantNode.*; import static com.oracle.graal.phases.GraalOptions.*; import java.io.*; @@ -116,12 +117,32 @@ assertEquals(expected, graph, false); } + protected int countUnusedConstants(StructuredGraph graph) { + int total = 0; + for (ConstantNode node : graph.getNodes().filter(ConstantNode.class)) { + if (!ConstantNodeRecordsUsages) { + if (node.gatherUsages().isEmpty()) { + total++; + } + } else { + if (node.usages().isEmpty()) { + total++; + } + } + } + return total; + } + + protected int getNodeCountExcludingUnusedConstants(StructuredGraph graph) { + return graph.getNodeCount() - countUnusedConstants(graph); + } + protected void assertEquals(StructuredGraph expected, StructuredGraph graph, boolean excludeVirtual) { String expectedString = getCanonicalGraphString(expected, excludeVirtual); String actualString = getCanonicalGraphString(graph, excludeVirtual); String mismatchString = "mismatch in graphs:\n========= expected =========\n" + expectedString + "\n\n========= actual =========\n" + actualString; - if (!excludeVirtual && expected.getNodeCount() != graph.getNodeCount()) { + if (!excludeVirtual && getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) { Debug.dump(expected, "Node count not matching - expected"); Debug.dump(graph, "Node count not matching - actual"); Assert.fail("Graphs do not have the same number of nodes: " + expected.getNodeCount() + " vs. " + graph.getNodeCount() + "\n" + mismatchString); @@ -161,16 +182,18 @@ } result.append("\n"); for (Node node : schedule.getBlockToNodesMap().get(block)) { - if (!excludeVirtual || !(node instanceof VirtualObjectNode || node instanceof ProxyNode)) { - int id; - if (canonicalId.get(node) != null) { - id = canonicalId.get(node); - } else { - id = nextId++; - canonicalId.set(node, id); + if (node.recordsUsages()) { + if (!excludeVirtual || !(node instanceof VirtualObjectNode || node instanceof ProxyNode)) { + int id; + if (canonicalId.get(node) != null) { + id = canonicalId.get(node); + } else { + id = nextId++; + canonicalId.set(node, id); + } + String name = node instanceof ConstantNode ? node.toString(Verbosity.Name) : node.getClass().getSimpleName(); + result.append(" " + id + "|" + name + (excludeVirtual ? "\n" : " (" + node.usages().count() + ")\n")); } - String name = node instanceof ConstantNode ? node.toString(Verbosity.Name) : node.getClass().getSimpleName(); - result.append(" " + id + "|" + name + (excludeVirtual ? "\n" : " (" + node.usages().count() + ")\n")); } } } diff -r 388bb7650808 -r 6332050441eb graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TypeSystemTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TypeSystemTest.java Thu Oct 24 16:21:25 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TypeSystemTest.java Thu Oct 24 23:46:48 2013 +0200 @@ -197,7 +197,7 @@ @Override protected void assertEquals(StructuredGraph expected, StructuredGraph graph) { - if (expected.getNodeCount() != graph.getNodeCount()) { + if (getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) { outputGraph(expected, "expected"); outputGraph(graph, "actual"); Assert.fail("Graphs do not have the same number of nodes: " + expected.getNodeCount() + " vs. " + graph.getNodeCount()); @@ -225,7 +225,7 @@ } private static void outputNode(Node node) { - TTY.print(" " + node + " (usage count: " + node.usages().count() + ") (inputs:"); + TTY.print(" " + node + " (usage count: " + (node.recordsUsages() ? node.usages().count() : "?") + ") (inputs:"); for (Node input : node.inputs()) { TTY.print(" " + input.toString(Verbosity.Id)); } diff -r 388bb7650808 -r 6332050441eb graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/CompiledMethodTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/CompiledMethodTest.java Thu Oct 24 16:21:25 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/CompiledMethodTest.java Thu Oct 24 23:46:48 2013 +0200 @@ -63,7 +63,7 @@ if (node instanceof ConstantNode) { ConstantNode constant = (ConstantNode) node; if (constant.kind() == Kind.Object && " ".equals(constant.value.asObject())) { - graph.replaceFloating(constant, ConstantNode.forObject("-", getMetaAccess(), graph)); + constant.replace(ConstantNode.forObject("-", getMetaAccess(), graph)); } } } diff -r 388bb7650808 -r 6332050441eb graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java Thu Oct 24 16:21:25 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/AheadOfTimeVerificationPhase.java Thu Oct 24 23:46:48 2013 +0200 @@ -39,7 +39,9 @@ @Override protected boolean verify(StructuredGraph graph, PhaseContext context) { for (ConstantNode node : graph.getNodes().filter(ConstantNode.class)) { - assert !isObject(node) || isNullReference(node) || isInternedString(node) : "illegal object constant: " + node; + if (node.recordsUsages() || !node.gatherUsages().isEmpty()) { + assert !isObject(node) || isNullReference(node) || isInternedString(node) : "illegal object constant: " + node; + } } return true; } diff -r 388bb7650808 -r 6332050441eb graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/LoadJavaMirrorWithKlassPhase.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/LoadJavaMirrorWithKlassPhase.java Thu Oct 24 16:21:25 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/LoadJavaMirrorWithKlassPhase.java Thu Oct 24 23:46:48 2013 +0200 @@ -68,7 +68,7 @@ LocationNode location = graph.unique(ConstantLocationNode.create(FINAL_LOCATION, stamp.kind(), classMirrorOffset, graph)); FloatingReadNode freadNode = graph.unique(new FloatingReadNode(klassNode, location, null, stamp)); - graph.replaceFloating(node, freadNode); + node.replace(freadNode); } } } diff -r 388bb7650808 -r 6332050441eb graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java Thu Oct 24 16:21:25 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java Thu Oct 24 23:46:48 2013 +0200 @@ -65,6 +65,35 @@ this.value = value; } + /** + * Computes the usages of this node by iterating over all the nodes in the graph, searching for + * those that have this node as an input. + */ + public List gatherUsages() { + assert !ConstantNodeRecordsUsages; + List usages = new ArrayList<>(); + for (Node node : graph().getNodes()) { + for (Node input : node.inputs()) { + if (input == this) { + usages.add(node); + } + } + } + return usages; + } + + public void replace(Node replacement) { + if (!recordsUsages()) { + List usages = gatherUsages(); + for (Node usage : usages) { + usage.replaceFirstInput(this, replacement); + } + graph().removeFloating(this); + } else { + graph().replaceFloating(this, replacement); + } + } + @Override public void generate(LIRGeneratorTool gen) { if (gen.canInlineConstant(value) || onlyUsedInVirtualState()) {