< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/EATestBase.java

Print this page




 135      * graph.
 136      *
 137      * @param snippet the name of the method whose graph should be processed
 138      * @param expectedConstantResult if this is non-null, the resulting graph needs to have the
 139      *            given constant return value
 140      * @param iterativeEscapeAnalysis true if escape analysis should be run for more than one
 141      *            iteration
 142      */
 143     protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis) {
 144         testEscapeAnalysis(snippet, expectedConstantResult, iterativeEscapeAnalysis, 0);
 145     }
 146 
 147     protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis, int expectedAllocationCount) {
 148         prepareGraph(snippet, iterativeEscapeAnalysis);
 149         if (expectedConstantResult != null) {
 150             for (ReturnNode returnNode : returnNodes) {
 151                 Assert.assertTrue(returnNode.result().toString(), returnNode.result().isConstant());
 152                 Assert.assertEquals(expectedConstantResult, returnNode.result().asConstant());
 153             }
 154         }
 155         int newInstanceCount = graph.getNodes().filter(isA(NewInstanceNode.class).or(NewArrayNode.class).or(AllocatedObjectNode.class)).count();
 156         Assert.assertEquals("Expected allocation count does not match", expectedAllocationCount, newInstanceCount);
 157         if (expectedAllocationCount == 0) {
 158             Assert.assertTrue("Unexpected CommitAllocationNode", graph.getNodes().filter(CommitAllocationNode.class).isEmpty());
 159         }




 160     }
 161 
 162     @SuppressWarnings("try")
 163     protected void prepareGraph(String snippet, boolean iterativeEscapeAnalysis) {
 164         ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
 165         DebugContext debug = getDebugContext();
 166         try (DebugContext.Scope s = debug.scope(getClass(), method, getCodeCache())) {
 167             graph = parseEager(method, AllowAssumptions.YES, debug);
 168             context = getDefaultHighTierContext();
 169             createInliningPhase().apply(graph, context);
 170             new DeadCodeEliminationPhase().apply(graph);
 171             canonicalizeGraph();
 172             new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
 173             postEACanonicalizeGraph();
 174             returnNodes = graph.getNodes(ReturnNode.TYPE).snapshot();
 175         } catch (Throwable e) {
 176             throw debug.handle(e);
 177         }
 178     }
 179 


 135      * graph.
 136      *
 137      * @param snippet the name of the method whose graph should be processed
 138      * @param expectedConstantResult if this is non-null, the resulting graph needs to have the
 139      *            given constant return value
 140      * @param iterativeEscapeAnalysis true if escape analysis should be run for more than one
 141      *            iteration
 142      */
 143     protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis) {
 144         testEscapeAnalysis(snippet, expectedConstantResult, iterativeEscapeAnalysis, 0);
 145     }
 146 
 147     protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis, int expectedAllocationCount) {
 148         prepareGraph(snippet, iterativeEscapeAnalysis);
 149         if (expectedConstantResult != null) {
 150             for (ReturnNode returnNode : returnNodes) {
 151                 Assert.assertTrue(returnNode.result().toString(), returnNode.result().isConstant());
 152                 Assert.assertEquals(expectedConstantResult, returnNode.result().asConstant());
 153             }
 154         }
 155         int newInstanceCount = getAllocationCount();
 156         Assert.assertEquals("Expected allocation count does not match", expectedAllocationCount, newInstanceCount);
 157         if (expectedAllocationCount == 0) {
 158             Assert.assertTrue("Unexpected CommitAllocationNode", graph.getNodes().filter(CommitAllocationNode.class).isEmpty());
 159         }
 160     }
 161 
 162     protected int getAllocationCount() {
 163         return graph.getNodes().filter(isA(NewInstanceNode.class).or(NewArrayNode.class).or(AllocatedObjectNode.class)).count();
 164     }
 165 
 166     @SuppressWarnings("try")
 167     protected void prepareGraph(String snippet, boolean iterativeEscapeAnalysis) {
 168         ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
 169         DebugContext debug = getDebugContext();
 170         try (DebugContext.Scope s = debug.scope(getClass(), method, getCodeCache())) {
 171             graph = parseEager(method, AllowAssumptions.YES, debug);
 172             context = getDefaultHighTierContext();
 173             createInliningPhase().apply(graph, context);
 174             new DeadCodeEliminationPhase().apply(graph);
 175             canonicalizeGraph();
 176             new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
 177             postEACanonicalizeGraph();
 178             returnNodes = graph.getNodes(ReturnNode.TYPE).snapshot();
 179         } catch (Throwable e) {
 180             throw debug.handle(e);
 181         }
 182     }
 183 
< prev index next >