src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/StaticAnalysis.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/StaticAnalysis.java

Print this page




   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 package org.graalvm.compiler.core.test.tutorial;
  24 
  25 import static org.graalvm.compiler.core.common.CompilationIdentifier.INVALID_COMPILATION_ID;
  26 
  27 import java.util.ArrayDeque;
  28 import java.util.Collections;
  29 import java.util.Deque;
  30 import java.util.HashMap;
  31 import java.util.HashSet;
  32 import java.util.Map;
  33 import java.util.Set;
  34 
  35 import org.graalvm.compiler.debug.Debug;
  36 import org.graalvm.compiler.debug.GraalError;
  37 import org.graalvm.compiler.debug.Debug.Scope;
  38 import org.graalvm.compiler.graph.Node;
  39 import org.graalvm.compiler.graph.NodeMap;
  40 import org.graalvm.compiler.java.GraphBuilderPhase;
  41 import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
  42 import org.graalvm.compiler.nodes.ConstantNode;
  43 import org.graalvm.compiler.nodes.FixedNode;
  44 import org.graalvm.compiler.nodes.Invoke;
  45 import org.graalvm.compiler.nodes.ParameterNode;
  46 import org.graalvm.compiler.nodes.ReturnNode;
  47 import org.graalvm.compiler.nodes.StructuredGraph;
  48 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  49 import org.graalvm.compiler.nodes.ValueNode;
  50 import org.graalvm.compiler.nodes.ValuePhiNode;
  51 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  52 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode;
  53 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  54 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  55 import org.graalvm.compiler.nodes.java.LoadFieldNode;
  56 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
  57 import org.graalvm.compiler.nodes.java.NewArrayNode;
  58 import org.graalvm.compiler.nodes.java.NewInstanceNode;
  59 import org.graalvm.compiler.nodes.java.StoreFieldNode;
  60 import org.graalvm.compiler.nodes.spi.StampProvider;
  61 import org.graalvm.compiler.nodes.util.GraphUtil;
  62 import org.graalvm.compiler.phases.OptimisticOptimizations;
  63 import org.graalvm.compiler.phases.graph.StatelessPostOrderNodeIterator;
  64 
  65 import jdk.vm.ci.meta.JavaConstant;
  66 import jdk.vm.ci.meta.JavaKind;
  67 import jdk.vm.ci.meta.MetaAccessProvider;
  68 import jdk.vm.ci.meta.ResolvedJavaField;


 224         }
 225 
 226         /**
 227          * All {@link TypeFlow#getTypes() types} that the return value of this method can have.
 228          */
 229         public TypeFlow getFormalReturn() {
 230             return formalReturn;
 231         }
 232 
 233         @Override
 234         @SuppressWarnings("try")
 235         protected void process() {
 236             if (!processed) {
 237                 /* We want to process a method only once. */
 238                 processed = true;
 239 
 240                 /*
 241                  * Build the Graal graph for the method using the bytecode parser provided by Graal.
 242                  */
 243 
 244                 StructuredGraph graph = new StructuredGraph(method, AllowAssumptions.NO, INVALID_COMPILATION_ID);
 245                 /*
 246                  * Support for graph dumping, IGV uses this information to show the method name of a
 247                  * graph.
 248                  */
 249                 try (Scope scope = Debug.scope("graph building", graph)) {
 250                     /*
 251                      * We want all types to be resolved by the graph builder, i.e., we want classes
 252                      * referenced by the bytecodes to be loaded and initialized. Since we do not run
 253                      * the code before static analysis, the classes would otherwise be not loaded
 254                      * yet and the bytecode parser would only create a graph.
 255                      */
 256                     Plugins plugins = new Plugins(new InvocationPlugins(metaAccess));
 257                     GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
 258                     /*
 259                      * For simplicity, we ignore all exception handling during the static analysis.
 260                      * This is a constraint of this example code, a real static analysis needs to
 261                      * handle the Graal nodes for throwing and handling exceptions.
 262                      */
 263                     graphBuilderConfig = graphBuilderConfig.withBytecodeExceptionMode(BytecodeExceptionMode.OmitAll);
 264                     /*




   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 package org.graalvm.compiler.core.test.tutorial;
  24 
  25 import static org.graalvm.compiler.core.test.GraalCompilerTest.getInitialOptions;
  26 
  27 import java.util.ArrayDeque;
  28 import java.util.Collections;
  29 import java.util.Deque;
  30 import java.util.HashMap;
  31 import java.util.HashSet;
  32 import java.util.Map;
  33 import java.util.Set;
  34 
  35 import org.graalvm.compiler.debug.Debug;
  36 import org.graalvm.compiler.debug.GraalError;
  37 import org.graalvm.compiler.debug.Debug.Scope;
  38 import org.graalvm.compiler.graph.Node;
  39 import org.graalvm.compiler.graph.NodeMap;
  40 import org.graalvm.compiler.java.GraphBuilderPhase;
  41 import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
  42 import org.graalvm.compiler.nodes.ConstantNode;
  43 import org.graalvm.compiler.nodes.FixedNode;
  44 import org.graalvm.compiler.nodes.Invoke;
  45 import org.graalvm.compiler.nodes.ParameterNode;
  46 import org.graalvm.compiler.nodes.ReturnNode;
  47 import org.graalvm.compiler.nodes.StructuredGraph;

  48 import org.graalvm.compiler.nodes.ValueNode;
  49 import org.graalvm.compiler.nodes.ValuePhiNode;
  50 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  51 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode;
  52 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  53 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  54 import org.graalvm.compiler.nodes.java.LoadFieldNode;
  55 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
  56 import org.graalvm.compiler.nodes.java.NewArrayNode;
  57 import org.graalvm.compiler.nodes.java.NewInstanceNode;
  58 import org.graalvm.compiler.nodes.java.StoreFieldNode;
  59 import org.graalvm.compiler.nodes.spi.StampProvider;
  60 import org.graalvm.compiler.nodes.util.GraphUtil;
  61 import org.graalvm.compiler.phases.OptimisticOptimizations;
  62 import org.graalvm.compiler.phases.graph.StatelessPostOrderNodeIterator;
  63 
  64 import jdk.vm.ci.meta.JavaConstant;
  65 import jdk.vm.ci.meta.JavaKind;
  66 import jdk.vm.ci.meta.MetaAccessProvider;
  67 import jdk.vm.ci.meta.ResolvedJavaField;


 223         }
 224 
 225         /**
 226          * All {@link TypeFlow#getTypes() types} that the return value of this method can have.
 227          */
 228         public TypeFlow getFormalReturn() {
 229             return formalReturn;
 230         }
 231 
 232         @Override
 233         @SuppressWarnings("try")
 234         protected void process() {
 235             if (!processed) {
 236                 /* We want to process a method only once. */
 237                 processed = true;
 238 
 239                 /*
 240                  * Build the Graal graph for the method using the bytecode parser provided by Graal.
 241                  */
 242 
 243                 StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).method(method).build();
 244                 /*
 245                  * Support for graph dumping, IGV uses this information to show the method name of a
 246                  * graph.
 247                  */
 248                 try (Scope scope = Debug.scope("graph building", graph)) {
 249                     /*
 250                      * We want all types to be resolved by the graph builder, i.e., we want classes
 251                      * referenced by the bytecodes to be loaded and initialized. Since we do not run
 252                      * the code before static analysis, the classes would otherwise be not loaded
 253                      * yet and the bytecode parser would only create a graph.
 254                      */
 255                     Plugins plugins = new Plugins(new InvocationPlugins(metaAccess));
 256                     GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
 257                     /*
 258                      * For simplicity, we ignore all exception handling during the static analysis.
 259                      * This is a constraint of this example code, a real static analysis needs to
 260                      * handle the Graal nodes for throwing and handling exceptions.
 261                      */
 262                     graphBuilderConfig = graphBuilderConfig.withBytecodeExceptionMode(BytecodeExceptionMode.OmitAll);
 263                     /*


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/tutorial/StaticAnalysis.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File