# HG changeset patch # User Doug Simon # Date 1351161745 -7200 # Node ID 77fb2026fcbe871464fb7ac134b8aa42f4704c93 # Parent 1112609bb5dc9c6a2ae0035f3401689feca3c08f added test case to demonstrate current limitation in the IfNode simplification of removing intermediate materializations diff -r 1112609bb5dc -r 77fb2026fcbe graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/InstanceOfTest.java --- a/graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/InstanceOfTest.java Thu Oct 25 12:29:56 2012 +0200 +++ b/graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/InstanceOfTest.java Thu Oct 25 12:42:25 2012 +0200 @@ -30,8 +30,9 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.java.*; import com.oracle.graal.phases.*; -import com.oracle.graal.phases.common.*; -import com.oracle.graal.snippets.CheckCastTest.*; +import com.oracle.graal.snippets.CheckCastTest.Depth12; +import com.oracle.graal.snippets.CheckCastTest.Depth13; +import com.oracle.graal.snippets.CheckCastTest.Depth14; /** * Tests the implementation of instanceof, allowing profiling information to @@ -41,7 +42,7 @@ @Override protected void editPhasePlan(ResolvedJavaMethod method, StructuredGraph graph, PhasePlan phasePlan) { - phasePlan.disablePhase(InliningPhase.class); + // phasePlan.disablePhase(InliningPhase.class); } @Override @@ -199,10 +200,10 @@ public static int isThrowableInt(Object o) { if (o instanceof Throwable) { - return 1; + return id(1); } if (o instanceof Throwable) { - return 2; + return id(2); } return 0; } @@ -213,9 +214,9 @@ public static int isMapInt(Object o) { if (o instanceof Map) { - return 1; + return id(1); } - return 0; + return id(0); } public static boolean isDepth12(Object o) { @@ -228,4 +229,44 @@ } return id(0); } + + /** + * This test exists to show the kind of pattern that *should* be optimizable by {@code removeIntermediateMaterialization()} + * in {@link IfNode}. The optimization is currently blocked for the code pattern in this method because of a non-null + * frame state at the position indicated in the source. For this particular method, the frame state could be ignored + * as there are no deopt points after the merge. However, this is not the case for all methods where this pattern is + * present. The problem (yet to be solved) is figuring how how to evacuate the frame state of the merge to + * the code paths that result from the transformation. + *

+ * The test exists in this source file as the transformation was originally motivated by the need to + * remove use of special JumpNodes in the {@code InstanceOfSnippets}. The transformation works for + * the snippet as all frame state are stripped from snippets. + */ + @Test + public void test_removeIntermediateMaterialization() { + List list = Arrays.asList("1", "2", "3", "4"); + test("removeIntermediateMaterialization", profile(), list, "2", "yes", "no"); + test("removeIntermediateMaterialization", profile(), list, null, "yes", "no"); + test("removeIntermediateMaterialization", profile(), null, "2", "yes", "no"); + } + + public static String removeIntermediateMaterialization(List list, Object e, String a, String b) { + boolean test; + if (list == null || e == null) { + test = false; + } else { + test = false; + for (Object i : list) { + if (i.equals(e)) { + test = true; + break; + } + } + } + // The merge here has a non-null frame state + if (test) { + return a; + } + return b; + } }