src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/util/GraalUtil.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.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/util

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/util/GraalUtil.java

Print this page




   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.microbenchmarks.graal.util;
  24 
  25 import java.lang.reflect.Method;
  26 import java.util.List;
  27 
  28 import org.graalvm.compiler.api.test.Graal;
  29 import org.graalvm.compiler.graph.Node;
  30 import org.graalvm.compiler.java.GraphBuilderPhase;
  31 import org.graalvm.compiler.nodes.StructuredGraph;
  32 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  33 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  34 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  35 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  36 import org.graalvm.compiler.options.OptionValues;
  37 import org.graalvm.compiler.phases.OptimisticOptimizations;
  38 import org.graalvm.compiler.phases.PhaseSuite;
  39 import org.graalvm.compiler.phases.tiers.HighTierContext;
  40 
  41 import jdk.vm.ci.meta.ResolvedJavaMethod;
  42 
  43 public class GraalUtil {
  44 
  45     public static Method getMethod(Class<?> declaringClass, String name, Class<?>... parameterTypes) {
  46         try {
  47             if (parameterTypes == null) {
  48                 Method found = null;
  49                 for (Method m : declaringClass.getDeclaredMethods()) {
  50                     if (m.getName().equals(name)) {
  51                         if (found != null) {
  52                             throw new RuntimeException("more than one method named " + name + " in " + declaringClass);
  53                         }
  54                         found = m;
  55                     }
  56                 }


 116             parameters = null;
 117         }
 118         return getGraph(declaringClass, name, parameters);
 119     }
 120 
 121     public static StructuredGraph getGraph(Class<?> declaringClass, String name, Class<?>... parameterTypes) {
 122         return getGraph(getMethod(declaringClass, name, parameterTypes));
 123     }
 124 
 125     public static StructuredGraph getGraph(Method method) {
 126         GraalState graal = new GraalState();
 127         ResolvedJavaMethod javaMethod = graal.metaAccess.lookupJavaMethod(method);
 128         return getGraph(graal, javaMethod);
 129     }
 130 
 131     public static StructuredGraph getGraph(GraalState graal, ResolvedJavaMethod javaMethod) {
 132         return getGraph(graal, javaMethod, StructuredGraph.USE_PROFILING_INFO);
 133     }
 134 
 135     public static StructuredGraph getGraph(GraalState graal, ResolvedJavaMethod javaMethod, boolean useProfilingInfo) {
 136         StructuredGraph graph = new StructuredGraph.Builder(Graal.getRequiredCapability(OptionValues.class), AllowAssumptions.YES).useProfilingInfo(useProfilingInfo).method(javaMethod).build();

 137         PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
 138         graphBuilderSuite.appendPhase(new GraphBuilderPhase(GraphBuilderConfiguration.getDefault(new Plugins(new InvocationPlugins()))));
 139         graphBuilderSuite.apply(graph, new HighTierContext(graal.providers, graphBuilderSuite, OptimisticOptimizations.ALL));
 140         return graph;
 141     }
 142 
 143     public static Node[] getNodes(StructuredGraph graph) {
 144         List<Node> nodeList = graph.getNodes().snapshot();
 145         return nodeList.toArray(new Node[nodeList.size()]);
 146     }
 147 }


   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.microbenchmarks.graal.util;
  24 
  25 import java.lang.reflect.Method;
  26 import java.util.List;
  27 

  28 import org.graalvm.compiler.graph.Node;
  29 import org.graalvm.compiler.java.GraphBuilderPhase;
  30 import org.graalvm.compiler.nodes.StructuredGraph;
  31 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  32 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  33 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  34 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;

  35 import org.graalvm.compiler.phases.OptimisticOptimizations;
  36 import org.graalvm.compiler.phases.PhaseSuite;
  37 import org.graalvm.compiler.phases.tiers.HighTierContext;
  38 
  39 import jdk.vm.ci.meta.ResolvedJavaMethod;
  40 
  41 public class GraalUtil {
  42 
  43     public static Method getMethod(Class<?> declaringClass, String name, Class<?>... parameterTypes) {
  44         try {
  45             if (parameterTypes == null) {
  46                 Method found = null;
  47                 for (Method m : declaringClass.getDeclaredMethods()) {
  48                     if (m.getName().equals(name)) {
  49                         if (found != null) {
  50                             throw new RuntimeException("more than one method named " + name + " in " + declaringClass);
  51                         }
  52                         found = m;
  53                     }
  54                 }


 114             parameters = null;
 115         }
 116         return getGraph(declaringClass, name, parameters);
 117     }
 118 
 119     public static StructuredGraph getGraph(Class<?> declaringClass, String name, Class<?>... parameterTypes) {
 120         return getGraph(getMethod(declaringClass, name, parameterTypes));
 121     }
 122 
 123     public static StructuredGraph getGraph(Method method) {
 124         GraalState graal = new GraalState();
 125         ResolvedJavaMethod javaMethod = graal.metaAccess.lookupJavaMethod(method);
 126         return getGraph(graal, javaMethod);
 127     }
 128 
 129     public static StructuredGraph getGraph(GraalState graal, ResolvedJavaMethod javaMethod) {
 130         return getGraph(graal, javaMethod, StructuredGraph.USE_PROFILING_INFO);
 131     }
 132 
 133     public static StructuredGraph getGraph(GraalState graal, ResolvedJavaMethod javaMethod, boolean useProfilingInfo) {
 134         StructuredGraph graph = new StructuredGraph.Builder(graal.options, graal.debug, AllowAssumptions.YES).useProfilingInfo(
 135                         useProfilingInfo).method(javaMethod).build();
 136         PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
 137         graphBuilderSuite.appendPhase(new GraphBuilderPhase(GraphBuilderConfiguration.getDefault(new Plugins(new InvocationPlugins()))));
 138         graphBuilderSuite.apply(graph, new HighTierContext(graal.providers, graphBuilderSuite, OptimisticOptimizations.ALL));
 139         return graph;
 140     }
 141 
 142     public static Node[] getNodes(StructuredGraph graph) {
 143         List<Node> nodeList = graph.getNodes().snapshot();
 144         return nodeList.toArray(new Node[nodeList.size()]);
 145     }
 146 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.microbenchmarks/src/org/graalvm/compiler/microbenchmarks/graal/util/GraalUtil.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File