src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MemoryScheduleTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test

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

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.test;
  24 
  25 import static org.graalvm.compiler.core.common.GraalOptions.OptImplicitNullChecks;
  26 import static org.graalvm.compiler.core.common.GraalOptions.OptScheduleOutOfLoops;
  27 import static org.graalvm.compiler.graph.test.matchers.NodeIterableCount.hasCount;
  28 import static org.hamcrest.core.IsInstanceOf.instanceOf;
  29 import static org.junit.Assert.assertThat;
  30 
  31 import java.util.ArrayList;
  32 import java.util.List;
  33 
  34 import org.junit.Assert;
  35 import org.junit.Test;
  36 
  37 import org.graalvm.compiler.api.directives.GraalDirectives;
  38 import org.graalvm.compiler.debug.Debug;
  39 import org.graalvm.compiler.debug.Debug.Scope;
  40 import org.graalvm.compiler.graph.Node;
  41 import org.graalvm.compiler.graph.iterators.NodeIterable;
  42 import org.graalvm.compiler.nodes.ReturnNode;
  43 import org.graalvm.compiler.nodes.StartNode;
  44 import org.graalvm.compiler.nodes.StructuredGraph;
  45 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  46 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  47 import org.graalvm.compiler.nodes.cfg.Block;
  48 import org.graalvm.compiler.nodes.memory.FloatingReadNode;
  49 import org.graalvm.compiler.nodes.memory.WriteNode;
  50 import org.graalvm.compiler.nodes.spi.LoweringTool;
  51 import org.graalvm.compiler.options.OptionValues;
  52 import org.graalvm.compiler.phases.OptimisticOptimizations;
  53 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  54 import org.graalvm.compiler.phases.common.FloatingReadPhase;
  55 import org.graalvm.compiler.phases.common.GuardLoweringPhase;
  56 import org.graalvm.compiler.phases.common.LoweringPhase;
  57 import org.graalvm.compiler.phases.common.RemoveValueProxyPhase;
  58 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  59 import org.graalvm.compiler.phases.schedule.SchedulePhase;
  60 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
  61 import org.graalvm.compiler.phases.tiers.HighTierContext;
  62 import org.graalvm.compiler.phases.tiers.MidTierContext;


  63 
  64 /**
  65  * In these test the FrameStates are explicitly cleared out, so that the scheduling of
  66  * FloatingReadNodes depends solely on the scheduling algorithm. The FrameStates normally keep the
  67  * FloatingReadNodes above a certain point, so that they (most of the time...) magically do the
  68  * right thing.
  69  *
  70  * The scheduling shouldn't depend on FrameStates, which is tested by this class.
  71  */
  72 public class MemoryScheduleTest extends GraphScheduleTest {
  73 
  74     private enum TestMode {
  75         WITH_FRAMESTATES,
  76         WITHOUT_FRAMESTATES,
  77         INLINED_WITHOUT_FRAMESTATES
  78     }
  79 
  80     public static class Container {
  81 
  82         public int a;


 689         boolean readNodeFound = false;
 690         for (Node node : schedule.nodesFor(schedule.getCFG().getStartBlock())) {
 691             if (node instanceof FloatingReadNode) {
 692                 assertTrue(!writeNodeFound);
 693                 readNodeFound = true;
 694             } else if (node instanceof WriteNode) {
 695                 writeNodeFound = true;
 696             }
 697         }
 698         assertTrue(readNodeFound);
 699     }
 700 
 701     private ScheduleResult getFinalSchedule(final String snippet, final TestMode mode) {
 702         return getFinalSchedule(snippet, mode, SchedulingStrategy.LATEST_OUT_OF_LOOPS);
 703     }
 704 
 705     @SuppressWarnings("try")
 706     private ScheduleResult getFinalSchedule(final String snippet, final TestMode mode, final SchedulingStrategy schedulingStrategy) {
 707         OptionValues options = new OptionValues(getInitialOptions(), OptScheduleOutOfLoops, schedulingStrategy == SchedulingStrategy.LATEST_OUT_OF_LOOPS, OptImplicitNullChecks, false);
 708         final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, options);
 709         try (Scope d = Debug.scope("FloatingReadTest", graph)) {

 710             HighTierContext context = getDefaultHighTierContext();
 711             CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
 712             canonicalizer.apply(graph, context);
 713             if (mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
 714                 new InliningPhase(canonicalizer).apply(graph, context);
 715             }
 716             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
 717             if (mode == TestMode.WITHOUT_FRAMESTATES || mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
 718                 graph.clearAllStateAfter();
 719             }
 720             Debug.dump(Debug.BASIC_LEVEL, graph, "after removal of framestates");
 721 
 722             new FloatingReadPhase().apply(graph);
 723             new RemoveValueProxyPhase().apply(graph);
 724 
 725             MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
 726             new GuardLoweringPhase().apply(graph, midContext);
 727             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
 728             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.LOW_TIER).apply(graph, midContext);
 729 
 730             SchedulePhase schedule = new SchedulePhase(schedulingStrategy);
 731             schedule.apply(graph);
 732             assertDeepEquals(1, graph.getNodes().filter(StartNode.class).count());
 733             return graph.getLastSchedule();
 734         } catch (Throwable e) {
 735             throw Debug.handle(e);
 736         }
 737     }
 738 }


  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.test;
  24 
  25 import static org.graalvm.compiler.core.common.GraalOptions.OptImplicitNullChecks;
  26 import static org.graalvm.compiler.core.common.GraalOptions.OptScheduleOutOfLoops;
  27 import static org.graalvm.compiler.graph.test.matchers.NodeIterableCount.hasCount;
  28 import static org.hamcrest.core.IsInstanceOf.instanceOf;
  29 import static org.junit.Assert.assertThat;
  30 
  31 import java.util.ArrayList;
  32 import java.util.List;
  33 



  34 import org.graalvm.compiler.api.directives.GraalDirectives;
  35 import org.graalvm.compiler.debug.DebugContext;

  36 import org.graalvm.compiler.graph.Node;
  37 import org.graalvm.compiler.graph.iterators.NodeIterable;
  38 import org.graalvm.compiler.nodes.ReturnNode;
  39 import org.graalvm.compiler.nodes.StartNode;
  40 import org.graalvm.compiler.nodes.StructuredGraph;
  41 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  42 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  43 import org.graalvm.compiler.nodes.cfg.Block;
  44 import org.graalvm.compiler.nodes.memory.FloatingReadNode;
  45 import org.graalvm.compiler.nodes.memory.WriteNode;
  46 import org.graalvm.compiler.nodes.spi.LoweringTool;
  47 import org.graalvm.compiler.options.OptionValues;
  48 import org.graalvm.compiler.phases.OptimisticOptimizations;
  49 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  50 import org.graalvm.compiler.phases.common.FloatingReadPhase;
  51 import org.graalvm.compiler.phases.common.GuardLoweringPhase;
  52 import org.graalvm.compiler.phases.common.LoweringPhase;
  53 import org.graalvm.compiler.phases.common.RemoveValueProxyPhase;
  54 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  55 import org.graalvm.compiler.phases.schedule.SchedulePhase;
  56 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
  57 import org.graalvm.compiler.phases.tiers.HighTierContext;
  58 import org.graalvm.compiler.phases.tiers.MidTierContext;
  59 import org.junit.Assert;
  60 import org.junit.Test;
  61 
  62 /**
  63  * In these test the FrameStates are explicitly cleared out, so that the scheduling of
  64  * FloatingReadNodes depends solely on the scheduling algorithm. The FrameStates normally keep the
  65  * FloatingReadNodes above a certain point, so that they (most of the time...) magically do the
  66  * right thing.
  67  *
  68  * The scheduling shouldn't depend on FrameStates, which is tested by this class.
  69  */
  70 public class MemoryScheduleTest extends GraphScheduleTest {
  71 
  72     private enum TestMode {
  73         WITH_FRAMESTATES,
  74         WITHOUT_FRAMESTATES,
  75         INLINED_WITHOUT_FRAMESTATES
  76     }
  77 
  78     public static class Container {
  79 
  80         public int a;


 687         boolean readNodeFound = false;
 688         for (Node node : schedule.nodesFor(schedule.getCFG().getStartBlock())) {
 689             if (node instanceof FloatingReadNode) {
 690                 assertTrue(!writeNodeFound);
 691                 readNodeFound = true;
 692             } else if (node instanceof WriteNode) {
 693                 writeNodeFound = true;
 694             }
 695         }
 696         assertTrue(readNodeFound);
 697     }
 698 
 699     private ScheduleResult getFinalSchedule(final String snippet, final TestMode mode) {
 700         return getFinalSchedule(snippet, mode, SchedulingStrategy.LATEST_OUT_OF_LOOPS);
 701     }
 702 
 703     @SuppressWarnings("try")
 704     private ScheduleResult getFinalSchedule(final String snippet, final TestMode mode, final SchedulingStrategy schedulingStrategy) {
 705         OptionValues options = new OptionValues(getInitialOptions(), OptScheduleOutOfLoops, schedulingStrategy == SchedulingStrategy.LATEST_OUT_OF_LOOPS, OptImplicitNullChecks, false);
 706         final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, options);
 707         DebugContext debug = graph.getDebug();
 708         try (DebugContext.Scope d = debug.scope("FloatingReadTest", graph)) {
 709             HighTierContext context = getDefaultHighTierContext();
 710             CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
 711             canonicalizer.apply(graph, context);
 712             if (mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
 713                 new InliningPhase(canonicalizer).apply(graph, context);
 714             }
 715             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
 716             if (mode == TestMode.WITHOUT_FRAMESTATES || mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
 717                 graph.clearAllStateAfter();
 718             }
 719             debug.dump(DebugContext.BASIC_LEVEL, graph, "after removal of framestates");
 720 
 721             new FloatingReadPhase().apply(graph);
 722             new RemoveValueProxyPhase().apply(graph);
 723 
 724             MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
 725             new GuardLoweringPhase().apply(graph, midContext);
 726             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
 727             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.LOW_TIER).apply(graph, midContext);
 728 
 729             SchedulePhase schedule = new SchedulePhase(schedulingStrategy);
 730             schedule.apply(graph);
 731             assertDeepEquals(1, graph.getNodes().filter(StartNode.class).count());
 732             return graph.getLastSchedule();
 733         } catch (Throwable e) {
 734             throw debug.handle(e);
 735         }
 736     }
 737 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MemoryScheduleTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File