< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/RootMethodSubstitutionTest.java

Print this page




  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 
  24 
  25 package org.graalvm.compiler.replacements.test;
  26 
  27 import java.util.ArrayList;
  28 import java.util.List;
  29 
  30 import jdk.internal.vm.compiler.collections.MapCursor;
  31 import org.graalvm.compiler.api.test.Graal;
  32 import org.graalvm.compiler.core.common.CompilationIdentifier;
  33 import org.graalvm.compiler.core.common.GraalOptions;
  34 import org.graalvm.compiler.core.target.Backend;
  35 import org.graalvm.compiler.core.test.GraalCompilerTest;
  36 import org.graalvm.compiler.debug.DebugContext;
  37 import org.graalvm.compiler.nodes.StructuredGraph;

  38 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  39 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
  40 import org.graalvm.compiler.options.OptionValues;
  41 import org.graalvm.compiler.phases.util.Providers;
  42 import org.graalvm.compiler.runtime.RuntimeProvider;
  43 import org.junit.Test;
  44 import org.junit.runner.RunWith;
  45 import org.junit.runners.Parameterized;
  46 
  47 import jdk.vm.ci.meta.MetaAccessProvider;
  48 import jdk.vm.ci.meta.ResolvedJavaMethod;
  49 import jdk.vm.ci.meta.ResolvedJavaType;
  50 
  51 /**
  52  * Exercise
  53  * {@link org.graalvm.compiler.nodes.spi.Replacements#getIntrinsicGraph(ResolvedJavaMethod, CompilationIdentifier, DebugContext)}
  54  * with regular method substitutions and encoded graphs.
  55  */
  56 @RunWith(Parameterized.class)
  57 public class RootMethodSubstitutionTest extends GraalCompilerTest {


  78                 Class<?> clazz = Class.forName(typeName, true, cl);
  79                 type = metaAccess.lookupJavaType(clazz);
  80             } catch (ClassNotFoundException e) {
  81                 continue;
  82             }
  83 
  84             for (InvocationPlugins.Binding binding : cursor.getValue()) {
  85                 if (binding.plugin instanceof MethodSubstitutionPlugin) {
  86                     ResolvedJavaMethod original = null;
  87                     for (ResolvedJavaMethod declared : type.getDeclaredMethods()) {
  88                         if (declared.getName().equals(binding.name)) {
  89                             if (declared.isStatic() == binding.isStatic) {
  90                                 if (declared.getSignature().toMethodDescriptor().startsWith(binding.argumentsDescriptor)) {
  91                                     original = declared;
  92                                     break;
  93                                 }
  94                             }
  95                         }
  96                     }
  97                     if (!original.isNative()) {
  98                         ret.add(new Object[]{original});




  99                     }
 100                 }
 101             }
 102         }
 103         return ret;
 104     }
 105 
 106     private final ResolvedJavaMethod method;
 107 
 108     private StructuredGraph getIntrinsicGraph(boolean useEncodedGraphs) {
 109         OptionValues options = new OptionValues(getDebugContext().getOptions(), GraalOptions.UseEncodedGraphs, useEncodedGraphs);
 110         DebugContext debugContext = DebugContext.create(options, getDebugContext().getDescription(), getDebugHandlersFactories());
 111         return getReplacements().getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, debugContext);
 112     }
 113 
 114     StructuredGraph expectedGraph;
 115     StructuredGraph actualGraph;
 116 
 117     @Override
 118     protected boolean checkHighTierGraph(StructuredGraph graph) {




  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 
  24 
  25 package org.graalvm.compiler.replacements.test;
  26 
  27 import java.util.ArrayList;
  28 import java.util.List;
  29 
  30 import jdk.internal.vm.compiler.collections.MapCursor;
  31 import org.graalvm.compiler.api.test.Graal;
  32 import org.graalvm.compiler.core.common.CompilationIdentifier;
  33 import org.graalvm.compiler.core.common.GraalOptions;
  34 import org.graalvm.compiler.core.target.Backend;
  35 import org.graalvm.compiler.core.test.GraalCompilerTest;
  36 import org.graalvm.compiler.debug.DebugContext;
  37 import org.graalvm.compiler.nodes.StructuredGraph;
  38 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
  39 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  40 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
  41 import org.graalvm.compiler.options.OptionValues;
  42 import org.graalvm.compiler.phases.util.Providers;
  43 import org.graalvm.compiler.runtime.RuntimeProvider;
  44 import org.junit.Test;
  45 import org.junit.runner.RunWith;
  46 import org.junit.runners.Parameterized;
  47 
  48 import jdk.vm.ci.meta.MetaAccessProvider;
  49 import jdk.vm.ci.meta.ResolvedJavaMethod;
  50 import jdk.vm.ci.meta.ResolvedJavaType;
  51 
  52 /**
  53  * Exercise
  54  * {@link org.graalvm.compiler.nodes.spi.Replacements#getIntrinsicGraph(ResolvedJavaMethod, CompilationIdentifier, DebugContext)}
  55  * with regular method substitutions and encoded graphs.
  56  */
  57 @RunWith(Parameterized.class)
  58 public class RootMethodSubstitutionTest extends GraalCompilerTest {


  79                 Class<?> clazz = Class.forName(typeName, true, cl);
  80                 type = metaAccess.lookupJavaType(clazz);
  81             } catch (ClassNotFoundException e) {
  82                 continue;
  83             }
  84 
  85             for (InvocationPlugins.Binding binding : cursor.getValue()) {
  86                 if (binding.plugin instanceof MethodSubstitutionPlugin) {
  87                     ResolvedJavaMethod original = null;
  88                     for (ResolvedJavaMethod declared : type.getDeclaredMethods()) {
  89                         if (declared.getName().equals(binding.name)) {
  90                             if (declared.isStatic() == binding.isStatic) {
  91                                 if (declared.getSignature().toMethodDescriptor().startsWith(binding.argumentsDescriptor)) {
  92                                     original = declared;
  93                                     break;
  94                                 }
  95                             }
  96                         }
  97                     }
  98                     if (!original.isNative()) {
  99                         // Make sure the plugin we found hasn't been overridden.
 100                         InvocationPlugin plugin = providers.getReplacements().getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(original);
 101                         if (plugin instanceof MethodSubstitutionPlugin) {
 102                             ret.add(new Object[]{original});
 103                         }
 104                     }
 105                 }
 106             }
 107         }
 108         return ret;
 109     }
 110 
 111     private final ResolvedJavaMethod method;
 112 
 113     private StructuredGraph getIntrinsicGraph(boolean useEncodedGraphs) {
 114         OptionValues options = new OptionValues(getDebugContext().getOptions(), GraalOptions.UseEncodedGraphs, useEncodedGraphs);
 115         DebugContext debugContext = DebugContext.create(options, getDebugContext().getDescription(), getDebugHandlersFactories());
 116         return getReplacements().getIntrinsicGraph(method, CompilationIdentifier.INVALID_COMPILATION_ID, debugContext);
 117     }
 118 
 119     StructuredGraph expectedGraph;
 120     StructuredGraph actualGraph;
 121 
 122     @Override
 123     protected boolean checkHighTierGraph(StructuredGraph graph) {


< prev index next >