36 import org.graalvm.compiler.nodes.extended.BoxNode; |
36 import org.graalvm.compiler.nodes.extended.BoxNode; |
37 import org.graalvm.compiler.nodes.extended.ValueAnchorNode; |
37 import org.graalvm.compiler.nodes.extended.ValueAnchorNode; |
38 import org.graalvm.compiler.nodes.java.LoadFieldNode; |
38 import org.graalvm.compiler.nodes.java.LoadFieldNode; |
39 import org.graalvm.compiler.nodes.virtual.AllocatedObjectNode; |
39 import org.graalvm.compiler.nodes.virtual.AllocatedObjectNode; |
40 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode; |
40 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode; |
41 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
|
42 import org.graalvm.compiler.phases.schedule.SchedulePhase; |
41 import org.graalvm.compiler.phases.schedule.SchedulePhase; |
43 import org.graalvm.compiler.test.SubprocessUtil; |
42 import org.graalvm.compiler.test.SubprocessUtil; |
44 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase; |
43 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase; |
45 import org.junit.Assert; |
44 import org.junit.Assert; |
46 import org.junit.Assume; |
45 import org.junit.Assume; |
325 prepareGraph("testChangeHandlingSnippet", false); |
324 prepareGraph("testChangeHandlingSnippet", false); |
326 Assert.assertEquals(2, graph.getNodes().filter(CommitAllocationNode.class).count()); |
325 Assert.assertEquals(2, graph.getNodes().filter(CommitAllocationNode.class).count()); |
327 Assert.assertEquals(1, graph.getNodes().filter(BoxNode.class).count()); |
326 Assert.assertEquals(1, graph.getNodes().filter(BoxNode.class).count()); |
328 List<Node> nodes = graph.getNodes().snapshot(); |
327 List<Node> nodes = graph.getNodes().snapshot(); |
329 // verify that an additional run doesn't add or remove nodes |
328 // verify that an additional run doesn't add or remove nodes |
330 new PartialEscapePhase(false, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context); |
329 new PartialEscapePhase(false, false, createCanonicalizerPhase(), null, graph.getOptions()).apply(graph, context); |
331 Assert.assertEquals(nodes.size(), graph.getNodeCount()); |
330 Assert.assertEquals(nodes.size(), graph.getNodeCount()); |
332 for (Node node : nodes) { |
331 for (Node node : nodes) { |
333 Assert.assertTrue(node.isAlive()); |
332 Assert.assertTrue(node.isAlive()); |
334 } |
333 } |
335 } |
334 } |
360 public void testRemovalSpecialCase() { |
359 public void testRemovalSpecialCase() { |
361 prepareGraph("testRemovalSpecialCaseSnippet", false); |
360 prepareGraph("testRemovalSpecialCaseSnippet", false); |
362 Assert.assertEquals(2, graph.getNodes().filter(CommitAllocationNode.class).count()); |
361 Assert.assertEquals(2, graph.getNodes().filter(CommitAllocationNode.class).count()); |
363 // create the situation by removing the if |
362 // create the situation by removing the if |
364 graph.replaceFixedWithFloating(graph.getNodes().filter(LoadFieldNode.class).first(), graph.unique(ConstantNode.forInt(0))); |
363 graph.replaceFixedWithFloating(graph.getNodes().filter(LoadFieldNode.class).first(), graph.unique(ConstantNode.forInt(0))); |
365 new CanonicalizerPhase().apply(graph, context); |
364 createCanonicalizerPhase().apply(graph, context); |
366 // verify that an additional run removes all allocations |
365 // verify that an additional run removes all allocations |
367 new PartialEscapePhase(false, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context); |
366 new PartialEscapePhase(false, false, createCanonicalizerPhase(), null, graph.getOptions()).apply(graph, context); |
368 Assert.assertEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count()); |
367 Assert.assertEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count()); |
369 } |
368 } |
370 |
369 |
371 public volatile int field2; |
370 public volatile int field2; |
372 |
371 |
438 } |
437 } |
439 |
438 |
440 @Test |
439 @Test |
441 public void testFullyUnrolledLoop() { |
440 public void testFullyUnrolledLoop() { |
442 prepareGraph("testFullyUnrolledLoopSnippet", false); |
441 prepareGraph("testFullyUnrolledLoopSnippet", false); |
443 new LoopFullUnrollPhase(new CanonicalizerPhase(), new DefaultLoopPolicies()).apply(graph, context); |
442 new LoopFullUnrollPhase(createCanonicalizerPhase(), new DefaultLoopPolicies()).apply(graph, context); |
444 new PartialEscapePhase(false, new CanonicalizerPhase(), graph.getOptions()).apply(graph, context); |
443 new PartialEscapePhase(false, createCanonicalizerPhase(), graph.getOptions()).apply(graph, context); |
445 Assert.assertEquals(1, returnNodes.size()); |
444 Assert.assertEquals(1, returnNodes.size()); |
446 Assert.assertTrue(returnNodes.get(0).result() instanceof AllocatedObjectNode); |
445 Assert.assertTrue(returnNodes.get(0).result() instanceof AllocatedObjectNode); |
447 CommitAllocationNode commit = ((AllocatedObjectNode) returnNodes.get(0).result()).getCommit(); |
446 CommitAllocationNode commit = ((AllocatedObjectNode) returnNodes.get(0).result()).getCommit(); |
448 Assert.assertEquals(2, commit.getValues().size()); |
447 Assert.assertEquals(2, commit.getValues().size()); |
449 Assert.assertEquals(1, commit.getVirtualObjects().size()); |
448 Assert.assertEquals(1, commit.getVirtualObjects().size()); |