Mercurial > hg > truffle
changeset 21351:1b3270c6d87c
Fix materialization of instanceof when sharing instantiation
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Tue, 12 May 2015 13:27:01 -0700 |
parents | f85738837dae |
children | 6d5a198d23e6 |
files | graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/InstanceOfTest.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java |
diffstat | 2 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/InstanceOfTest.java Tue May 12 21:36:57 2015 +0200 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/InstanceOfTest.java Tue May 12 13:27:01 2015 -0700 @@ -412,4 +412,23 @@ test("arrayCopyTypeName", (Object) new Object[]{"one", "two", "three"}); test("arrayCopyTypeName", (Object) new String[]{"one", "two", "three"}); } + + public int conditionalInstantiation(Object o) { + int total = 0; + if (o instanceof CharSequence) { + if (o instanceof StringBuilder || o instanceof String) { + total = 9; + } + total += (o instanceof String ? 2 : 1); + } + + return total; + } + + @Test + public void testInstantiation() { + test("conditionalInstantiation", "foo"); + test("conditionalInstantiation", new StringBuilder()); + test("conditionalInstantiation", 1); + } }
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java Tue May 12 21:36:57 2015 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java Tue May 12 13:27:01 2015 -0700 @@ -96,7 +96,17 @@ protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, Instantiation instantiation, Node usage, final StructuredGraph graph) { InstanceOfUsageReplacer replacer; if (usage instanceof IfNode || usage instanceof FixedGuardNode || usage instanceof ShortCircuitOrNode || usage instanceof GuardingPiNode || usage instanceof ConditionAnchorNode) { - replacer = new NonMaterializationUsageReplacer(instantiation, ConstantNode.forInt(1, graph), ConstantNode.forInt(0, graph), instanceOf, usage); + ValueNode trueValue = ConstantNode.forInt(1, graph); + ValueNode falseValue = ConstantNode.forInt(0, graph); + if (instantiation.isInitialized() && (trueValue != instantiation.trueValue || falseValue != instantiation.falseValue)) { + /* + * This code doesn't really care what values are used so adopt the values from the + * previous instantiation. + */ + trueValue = instantiation.trueValue; + falseValue = instantiation.falseValue; + } + replacer = new NonMaterializationUsageReplacer(instantiation, trueValue, falseValue, instanceOf, usage); } else { assert usage instanceof ConditionalNode : "unexpected usage of " + instanceOf + ": " + usage; ConditionalNode c = (ConditionalNode) usage;