< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.api.directives.test/src/org/graalvm/compiler/api/directives/test/ControlFlowAnchorDirectiveTest.java

Print this page




  29 import java.lang.annotation.Target;
  30 import java.util.Arrays;
  31 import java.util.Collections;
  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.core.test.GraalCompilerTest;
  39 import org.graalvm.compiler.graph.Node;
  40 import org.graalvm.compiler.graph.iterators.NodeIterable;
  41 import org.graalvm.compiler.nodes.IfNode;
  42 import org.graalvm.compiler.nodes.LoopBeginNode;
  43 import org.graalvm.compiler.nodes.ReturnNode;
  44 import org.graalvm.compiler.nodes.StructuredGraph;
  45 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  46 import org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode;
  47 
  48 import jdk.vm.ci.meta.ResolvedJavaMethod;



  49 
  50 public class ControlFlowAnchorDirectiveTest extends GraalCompilerTest {
  51 
  52     @Retention(RetentionPolicy.RUNTIME)
  53     @Target(ElementType.METHOD)
  54     @Repeatable(AnchorSnippet.class)
  55     private @interface NodeCount {
  56 
  57         Class<? extends Node> nodeClass();
  58 
  59         int expectedCount();
  60     }
  61 
  62     @Retention(RetentionPolicy.RUNTIME)
  63     @Target(ElementType.METHOD)
  64     private @interface AnchorSnippet {
  65         NodeCount[] value();
  66     }
  67 
  68     @NodeCount(nodeClass = ReturnNode.class, expectedCount = 1)


 219      */
 220     @Test
 221     public void testClone() {
 222         StructuredGraph g = parseEager("preventPeelSnippet", AllowAssumptions.NO);
 223         g.copy(g.getDebug());
 224     }
 225 
 226     private static List<NodeCount> getNodeCountAnnotations(StructuredGraph graph) {
 227         ResolvedJavaMethod method = graph.method();
 228         AnchorSnippet snippet = method.getAnnotation(AnchorSnippet.class);
 229         if (snippet != null) {
 230             return Arrays.asList(snippet.value());
 231         }
 232 
 233         NodeCount single = method.getAnnotation(NodeCount.class);
 234         if (single != null) {
 235             return Collections.singletonList(single);
 236         }
 237 
 238         return Collections.emptyList();





 239     }
 240 
 241     @Override
 242     protected boolean checkLowTierGraph(StructuredGraph graph) {
 243         List<ControlFlowAnchorNode> anchors = graph.getNodes().filter(ControlFlowAnchorNode.class).snapshot();
 244         for (int i = 0; i < anchors.size(); i++) {
 245             ControlFlowAnchorNode a = anchors.get(i);
 246             for (int j = i + 1; j < anchors.size(); j++) {
 247                 ControlFlowAnchorNode b = anchors.get(j);
 248                 if (a.valueEquals(b)) {
 249                     Assert.fail("found duplicated control flow anchors (" + a + " and " + b + ")");
 250                 }
 251             }
 252         }
 253 
 254         for (NodeCount nodeCount : getNodeCountAnnotations(graph)) {
 255             NodeIterable<? extends Node> nodes = graph.getNodes().filter(nodeCount.nodeClass());
 256             Assert.assertEquals(nodeCount.nodeClass().getSimpleName(), nodeCount.expectedCount(), nodes.count());
 257         }
 258         return true;


  29 import java.lang.annotation.Target;
  30 import java.util.Arrays;
  31 import java.util.Collections;
  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.core.test.GraalCompilerTest;
  39 import org.graalvm.compiler.graph.Node;
  40 import org.graalvm.compiler.graph.iterators.NodeIterable;
  41 import org.graalvm.compiler.nodes.IfNode;
  42 import org.graalvm.compiler.nodes.LoopBeginNode;
  43 import org.graalvm.compiler.nodes.ReturnNode;
  44 import org.graalvm.compiler.nodes.StructuredGraph;
  45 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  46 import org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode;
  47 
  48 import jdk.vm.ci.meta.ResolvedJavaMethod;
  49 import org.graalvm.compiler.phases.OptimisticOptimizations;
  50 import org.graalvm.compiler.phases.OptimisticOptimizations.Optimization;
  51 import org.graalvm.compiler.phases.tiers.HighTierContext;
  52 
  53 public class ControlFlowAnchorDirectiveTest extends GraalCompilerTest {
  54 
  55     @Retention(RetentionPolicy.RUNTIME)
  56     @Target(ElementType.METHOD)
  57     @Repeatable(AnchorSnippet.class)
  58     private @interface NodeCount {
  59 
  60         Class<? extends Node> nodeClass();
  61 
  62         int expectedCount();
  63     }
  64 
  65     @Retention(RetentionPolicy.RUNTIME)
  66     @Target(ElementType.METHOD)
  67     private @interface AnchorSnippet {
  68         NodeCount[] value();
  69     }
  70 
  71     @NodeCount(nodeClass = ReturnNode.class, expectedCount = 1)


 222      */
 223     @Test
 224     public void testClone() {
 225         StructuredGraph g = parseEager("preventPeelSnippet", AllowAssumptions.NO);
 226         g.copy(g.getDebug());
 227     }
 228 
 229     private static List<NodeCount> getNodeCountAnnotations(StructuredGraph graph) {
 230         ResolvedJavaMethod method = graph.method();
 231         AnchorSnippet snippet = method.getAnnotation(AnchorSnippet.class);
 232         if (snippet != null) {
 233             return Arrays.asList(snippet.value());
 234         }
 235 
 236         NodeCount single = method.getAnnotation(NodeCount.class);
 237         if (single != null) {
 238             return Collections.singletonList(single);
 239         }
 240 
 241         return Collections.emptyList();
 242     }
 243 
 244     @Override
 245     protected HighTierContext getDefaultHighTierContext() {
 246         return new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL.remove(Optimization.RemoveNeverExecutedCode));
 247     }
 248 
 249     @Override
 250     protected boolean checkLowTierGraph(StructuredGraph graph) {
 251         List<ControlFlowAnchorNode> anchors = graph.getNodes().filter(ControlFlowAnchorNode.class).snapshot();
 252         for (int i = 0; i < anchors.size(); i++) {
 253             ControlFlowAnchorNode a = anchors.get(i);
 254             for (int j = i + 1; j < anchors.size(); j++) {
 255                 ControlFlowAnchorNode b = anchors.get(j);
 256                 if (a.valueEquals(b)) {
 257                     Assert.fail("found duplicated control flow anchors (" + a + " and " + b + ")");
 258                 }
 259             }
 260         }
 261 
 262         for (NodeCount nodeCount : getNodeCountAnnotations(graph)) {
 263             NodeIterable<? extends Node> nodes = graph.getNodes().filter(nodeCount.nodeClass());
 264             Assert.assertEquals(nodeCount.nodeClass().getSimpleName(), nodeCount.expectedCount(), nodes.count());
 265         }
 266         return true;
< prev index next >