< prev index next >

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

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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 
  24 
  25 package org.graalvm.compiler.replacements.test;
  26 
  27 import static org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo;
  28 

  29 import org.graalvm.compiler.core.common.type.StampFactory;
  30 import org.graalvm.compiler.core.test.GraalCompilerTest;
  31 import org.graalvm.compiler.debug.DebugContext;
  32 import org.graalvm.compiler.nodes.AbstractBeginNode;
  33 import org.graalvm.compiler.nodes.StructuredGraph;
  34 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  35 import org.graalvm.compiler.nodes.ValueNode;
  36 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  37 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  38 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
  39 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
  40 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  41 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
  42 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType;
  43 import org.graalvm.compiler.nodes.memory.ReadNode;
  44 import org.graalvm.compiler.nodes.memory.address.AddressNode;
  45 import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode;
  46 import org.graalvm.compiler.nodes.spi.CoreProviders;
  47 import org.graalvm.compiler.phases.OptimisticOptimizations;
  48 import org.graalvm.compiler.phases.common.CanonicalizerPhase;


 121     }
 122 
 123     class InlineAll implements InlineInvokePlugin {
 124         @Override
 125         public InlineInfo shouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
 126             return createStandardInlineInfo(method);
 127         }
 128     }
 129 
 130     @Test
 131     @SuppressWarnings("try")
 132     public void test() {
 133         ResolvedJavaMethod testMethod = getResolvedJavaMethod(PEGraphDecoderTest.class, "doTest", Object.class);
 134         StructuredGraph targetGraph = null;
 135         DebugContext debug = getDebugContext();
 136         try (DebugContext.Scope scope = debug.scope("GraphPETest", testMethod)) {
 137             GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true);
 138             registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins());
 139             targetGraph = new StructuredGraph.Builder(getInitialOptions(), debug, AllowAssumptions.YES).method(testMethod).build();
 140             CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES,
 141                             null, null, new InlineInvokePlugin[]{new InlineAll()}, null, null, null, null, null);
 142 
 143             decoder.decode(testMethod, false, false);
 144             debug.dump(DebugContext.BASIC_LEVEL, targetGraph, "Target Graph");
 145             targetGraph.verify();
 146 
 147             CoreProviders context = getProviders();
 148             new CanonicalizerPhase().apply(targetGraph, context);
 149             targetGraph.verify();
 150 
 151         } catch (Throwable ex) {
 152             if (targetGraph != null) {
 153                 debug.dump(DebugContext.BASIC_LEVEL, targetGraph, ex.toString());
 154             }
 155             debug.handle(ex);
 156         }
 157     }
 158 }
   1 /*
   2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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 
  24 
  25 package org.graalvm.compiler.replacements.test;
  26 
  27 import static org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo;
  28 
  29 import jdk.internal.vm.compiler.collections.EconomicMap;
  30 import org.graalvm.compiler.core.common.type.StampFactory;
  31 import org.graalvm.compiler.core.test.GraalCompilerTest;
  32 import org.graalvm.compiler.debug.DebugContext;
  33 import org.graalvm.compiler.nodes.AbstractBeginNode;
  34 import org.graalvm.compiler.nodes.StructuredGraph;
  35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  36 import org.graalvm.compiler.nodes.ValueNode;
  37 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  38 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  39 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
  40 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
  41 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  42 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
  43 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType;
  44 import org.graalvm.compiler.nodes.memory.ReadNode;
  45 import org.graalvm.compiler.nodes.memory.address.AddressNode;
  46 import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode;
  47 import org.graalvm.compiler.nodes.spi.CoreProviders;
  48 import org.graalvm.compiler.phases.OptimisticOptimizations;
  49 import org.graalvm.compiler.phases.common.CanonicalizerPhase;


 122     }
 123 
 124     class InlineAll implements InlineInvokePlugin {
 125         @Override
 126         public InlineInfo shouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
 127             return createStandardInlineInfo(method);
 128         }
 129     }
 130 
 131     @Test
 132     @SuppressWarnings("try")
 133     public void test() {
 134         ResolvedJavaMethod testMethod = getResolvedJavaMethod(PEGraphDecoderTest.class, "doTest", Object.class);
 135         StructuredGraph targetGraph = null;
 136         DebugContext debug = getDebugContext();
 137         try (DebugContext.Scope scope = debug.scope("GraphPETest", testMethod)) {
 138             GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true);
 139             registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins());
 140             targetGraph = new StructuredGraph.Builder(getInitialOptions(), debug, AllowAssumptions.YES).method(testMethod).build();
 141             CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES,
 142                             null, null, new InlineInvokePlugin[]{new InlineAll()}, null, null, null, null, null, null, EconomicMap.create());
 143 
 144             decoder.decode(testMethod, false, false);
 145             debug.dump(DebugContext.BASIC_LEVEL, targetGraph, "Target Graph");
 146             targetGraph.verify();
 147 
 148             CoreProviders context = getProviders();
 149             new CanonicalizerPhase().apply(targetGraph, context);
 150             targetGraph.verify();
 151 
 152         } catch (Throwable ex) {
 153             if (targetGraph != null) {
 154                 debug.dump(DebugContext.BASIC_LEVEL, targetGraph, ex.toString());
 155             }
 156             debug.handle(ex);
 157         }
 158     }
 159 }
< prev index next >