< prev index next >

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

Print this page
rev 52509 : [mq]: graal


  64         @Fold
  65         int getNumber() {
  66             // we want to test whether @Fold works, so prevent automatic constant folding
  67             return GraalDirectives.opaque(number);
  68         }
  69     }
  70 
  71     @ClassSubstitution(TestMethod.class)
  72     private static class TestMethodSubstitution {
  73 
  74         private static final FoldUtils utils = new FoldUtils(21);
  75 
  76         @MethodSubstitution
  77         public static int test() {
  78             return FoldUtils.multiply(utils.getNumber(), 2);
  79         }
  80     }
  81 
  82     @Override
  83     protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
  84         InjectionProvider injection = new NodeIntrinsificationProvider(getMetaAccess(), getSnippetReflection(), getProviders().getForeignCalls(), getProviders().getLowerer(), null);
  85         new PluginFactory_FoldTest().registerPlugins(invocationPlugins, injection);
  86         BytecodeProvider replacementBytecodeProvider = getSystemClassLoaderBytecodeProvider();
  87         Registration r = new Registration(invocationPlugins, TestMethod.class, replacementBytecodeProvider);
  88         r.registerMethodSubstitution(TestMethodSubstitution.class, "test");
  89         super.registerInvocationPlugins(invocationPlugins);
  90     }
  91 
  92     public static int callTest() {
  93         return TestMethod.test();
  94     }
  95 
  96     @Override
  97     protected boolean checkHighTierGraph(StructuredGraph graph) {
  98         // check that folding happened correctly
  99         StartNode start = graph.start();
 100         assert start.next() instanceof ReturnNode : "expected ReturnNode, got " + start.next();
 101 
 102         ReturnNode ret = (ReturnNode) start.next();
 103         assert ret.result().isConstant() : "expected ConstantNode, got " + ret.result();
 104         return true;


  64         @Fold
  65         int getNumber() {
  66             // we want to test whether @Fold works, so prevent automatic constant folding
  67             return GraalDirectives.opaque(number);
  68         }
  69     }
  70 
  71     @ClassSubstitution(TestMethod.class)
  72     private static class TestMethodSubstitution {
  73 
  74         private static final FoldUtils utils = new FoldUtils(21);
  75 
  76         @MethodSubstitution
  77         public static int test() {
  78             return FoldUtils.multiply(utils.getNumber(), 2);
  79         }
  80     }
  81 
  82     @Override
  83     protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
  84         InjectionProvider injection = new NodeIntrinsificationProvider(getMetaAccess(), getSnippetReflection(), getProviders().getForeignCalls(), null);
  85         new PluginFactory_FoldTest().registerPlugins(invocationPlugins, injection);
  86         BytecodeProvider replacementBytecodeProvider = getSystemClassLoaderBytecodeProvider();
  87         Registration r = new Registration(invocationPlugins, TestMethod.class, replacementBytecodeProvider);
  88         r.registerMethodSubstitution(TestMethodSubstitution.class, "test");
  89         super.registerInvocationPlugins(invocationPlugins);
  90     }
  91 
  92     public static int callTest() {
  93         return TestMethod.test();
  94     }
  95 
  96     @Override
  97     protected boolean checkHighTierGraph(StructuredGraph graph) {
  98         // check that folding happened correctly
  99         StartNode start = graph.start();
 100         assert start.next() instanceof ReturnNode : "expected ReturnNode, got " + start.next();
 101 
 102         ReturnNode ret = (ReturnNode) start.next();
 103         assert ret.result().isConstant() : "expected ConstantNode, got " + ret.result();
 104         return true;
< prev index next >