src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/MethodSubstitutionTest.java
changeset 58877 aec7bf35d6f5
parent 58299 6df94ce3ab2f
equal deleted inserted replaced
58876:1a8d65e71a66 58877:aec7bf35d6f5
    23 
    23 
    24 
    24 
    25 package org.graalvm.compiler.replacements.test;
    25 package org.graalvm.compiler.replacements.test;
    26 
    26 
    27 import java.lang.reflect.InvocationTargetException;
    27 import java.lang.reflect.InvocationTargetException;
       
    28 import java.util.Arrays;
    28 
    29 
    29 import org.graalvm.compiler.api.replacements.MethodSubstitution;
    30 import org.graalvm.compiler.api.replacements.MethodSubstitution;
    30 import org.graalvm.compiler.core.test.GraalCompilerTest;
    31 import org.graalvm.compiler.core.test.GraalCompilerTest;
    31 import org.graalvm.compiler.debug.DebugContext;
    32 import org.graalvm.compiler.debug.DebugContext;
    32 import org.graalvm.compiler.graph.Node;
    33 import org.graalvm.compiler.graph.Node;
    33 import org.graalvm.compiler.nodes.Invoke;
    34 import org.graalvm.compiler.nodes.Invoke;
    34 import org.graalvm.compiler.nodes.StructuredGraph;
    35 import org.graalvm.compiler.nodes.StructuredGraph;
    35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
    36 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
    36 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
    37 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
    37 import org.graalvm.compiler.nodes.spi.LoweringTool;
    38 import org.graalvm.compiler.nodes.spi.LoweringTool;
    38 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
       
    39 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
    39 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
    40 import org.graalvm.compiler.phases.common.LoweringPhase;
    40 import org.graalvm.compiler.phases.common.LoweringPhase;
    41 import org.graalvm.compiler.phases.tiers.HighTierContext;
    41 import org.graalvm.compiler.phases.tiers.HighTierContext;
    42 import org.graalvm.compiler.replacements.nodes.MacroNode;
    42 import org.graalvm.compiler.replacements.nodes.MacroNode;
    43 
    43 
    76             StructuredGraph graph = parseEager(method, AllowAssumptions.YES, debug);
    76             StructuredGraph graph = parseEager(method, AllowAssumptions.YES, debug);
    77             HighTierContext context = getDefaultHighTierContext();
    77             HighTierContext context = getDefaultHighTierContext();
    78             debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    78             debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    79             createInliningPhase().apply(graph, context);
    79             createInliningPhase().apply(graph, context);
    80             debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    80             debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    81             new CanonicalizerPhase().apply(graph, context);
    81             createCanonicalizerPhase().apply(graph, context);
    82             new DeadCodeEliminationPhase().apply(graph);
    82             new DeadCodeEliminationPhase().apply(graph);
    83             // Try to ensure any macro nodes are lowered to expose any resulting invokes
    83             // Try to ensure any macro nodes are lowered to expose any resulting invokes
    84             if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
    84             if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
    85                 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    85                 new LoweringPhase(this.createCanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    86             }
    86             }
    87             if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
    87             if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
    88                 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
    88                 new LoweringPhase(this.createCanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
    89             }
    89             }
    90             assertNotInGraph(graph, MacroNode.class);
    90             assertNotInGraph(graph, MacroNode.class);
    91             if (name != null) {
    91             if (name != null) {
    92                 for (Node node : graph.getNodes()) {
    92                 for (Node node : graph.getNodes()) {
    93                     if (node instanceof Invoke) {
    93                     if (node instanceof Invoke) {
   151             // Verify that the generated code and the original produce the same value
   151             // Verify that the generated code and the original produce the same value
   152             assertDeepEquals(expected, executeVarargsSafe(code, arg1, arg2));
   152             assertDeepEquals(expected, executeVarargsSafe(code, arg1, arg2));
   153         }
   153         }
   154     }
   154     }
   155 
   155 
   156     protected static StructuredGraph assertInGraph(StructuredGraph graph, Class<?> clazz) {
   156     protected static StructuredGraph assertInGraph(StructuredGraph graph, Class<?>... clazzes) {
   157         for (Node node : graph.getNodes()) {
   157         for (Node node : graph.getNodes()) {
   158             if (clazz.isInstance(node)) {
   158             for (Class<?> clazz : clazzes) {
   159                 return graph;
   159                 if (clazz.isInstance(node)) {
       
   160                     return graph;
       
   161                 }
   160             }
   162             }
   161         }
   163         }
   162         fail("Graph does not contain a node of class " + clazz.getName());
   164         if (clazzes.length == 1) {
       
   165             fail("Graph does not contain a node of class " + clazzes[0].getName());
       
   166         } else {
       
   167             fail("Graph does not contain a node of one these classes class " + Arrays.toString(clazzes));
       
   168 
       
   169         }
   163         return graph;
   170         return graph;
   164     }
   171     }
   165 
   172 
   166     protected static Object executeVarargsSafe(InstalledCode code, Object... args) {
   173     protected static Object executeVarargsSafe(InstalledCode code, Object... args) {
   167         try {
   174         try {