< prev index next >

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

Print this page




  58 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderTool;
  59 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
  60 import org.graalvm.compiler.nodes.java.ExceptionObjectNode;
  61 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
  62 import org.graalvm.compiler.nodes.spi.StampProvider;
  63 import org.graalvm.compiler.nodes.type.StampTool;
  64 import org.graalvm.compiler.phases.OptimisticOptimizations;
  65 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  66 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality;
  67 import org.graalvm.compiler.phases.common.inlining.InliningUtil;
  68 import org.graalvm.compiler.phases.util.Providers;
  69 import org.graalvm.compiler.word.WordTypes;
  70 import org.graalvm.word.LocationIdentity;
  71 
  72 import jdk.vm.ci.code.BytecodeFrame;
  73 import jdk.vm.ci.meta.ConstantReflectionProvider;
  74 import jdk.vm.ci.meta.JavaKind;
  75 import jdk.vm.ci.meta.JavaType;
  76 import jdk.vm.ci.meta.MetaAccessProvider;
  77 import jdk.vm.ci.meta.ResolvedJavaMethod;
  78 import jdk.vm.ci.meta.ResolvedJavaType;
  79 import jdk.vm.ci.meta.Signature;
  80 
  81 /**
  82  * A utility for manually creating a graph. This will be expanded as necessary to support all
  83  * subsystems that employ manual graph creation (as opposed to {@linkplain GraphBuilderPhase
  84  * bytecode parsing} based graph creation).
  85  */
  86 public class GraphKit implements GraphBuilderTool {
  87 
  88     protected final Providers providers;
  89     protected final StructuredGraph graph;
  90     protected final WordTypes wordTypes;
  91     protected final GraphBuilderConfiguration.Plugins graphBuilderPlugins;
  92     protected FixedWithNextNode lastFixedNode;
  93 
  94     private final List<Structure> structures;
  95 
  96     protected abstract static class Structure {
  97     }
  98 


 235         }
 236         MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, bci));
 237         InvokeNode invoke = append(new InvokeNode(callTarget, bci));
 238 
 239         if (frameStateBuilder != null) {
 240             if (invoke.getStackKind() != JavaKind.Void) {
 241                 frameStateBuilder.push(invoke.getStackKind(), invoke);
 242             }
 243             invoke.setStateAfter(frameStateBuilder.create(bci, invoke));
 244             if (invoke.getStackKind() != JavaKind.Void) {
 245                 frameStateBuilder.pop(invoke.getStackKind());
 246             }
 247         }
 248         return invoke;
 249     }
 250 
 251     protected MethodCallTargetNode createMethodCallTarget(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, StampPair returnStamp, @SuppressWarnings("unused") int bci) {
 252         return new MethodCallTargetNode(invokeKind, targetMethod, args, returnStamp, null);
 253     }
 254 




 255     /**
 256      * Determines if a given set of arguments is compatible with the signature of a given method.
 257      *
 258      * @return true if {@code args} are compatible with the signature if {@code method}
 259      * @throws AssertionError if {@code args} are not compatible with the signature if
 260      *             {@code method}
 261      */
 262     public boolean checkArgs(ResolvedJavaMethod method, ValueNode... args) {
 263         Signature signature = method.getSignature();
 264         boolean isStatic = method.isStatic();
 265         if (signature.getParameterCount(!isStatic) != args.length) {
 266             throw new AssertionError(graph + ": wrong number of arguments to " + method);
 267         }
 268         int argIndex = 0;
 269         if (!isStatic) {
 270             ResolvedJavaType expectedType = method.getDeclaringClass();
 271             JavaKind expected = wordTypes == null ? expectedType.getJavaKind() : wordTypes.asKind(expectedType);
 272             JavaKind actual = args[argIndex++].stamp().getStackKind();
 273             assert expected == actual : graph + ": wrong kind of value for receiver argument of call to " + method + " [" + actual + " != " + expected + "]";
 274         }
 275         for (int i = 0; i != signature.getParameterCount(false); i++) {
 276             JavaType expectedType = signature.getParameterType(i, method.getDeclaringClass());
 277             JavaKind expected = wordTypes == null ? expectedType.getJavaKind().getStackKind() : wordTypes.asKind(expectedType).getStackKind();
 278             JavaKind actual = args[argIndex++].stamp().getStackKind();
 279             if (expected != actual) {
 280                 throw new AssertionError(graph + ": wrong kind of value for argument " + i + " of call to " + method + " [" + actual + " != " + expected + "]");
 281             }
 282         }
 283         return true;
 284     }
 285 
 286     /**
 287      * Recursively {@linkplain #inline inlines} all invocations currently in the graph.
 288      */
 289     public void inlineInvokes() {
 290         while (!graph.getNodes().filter(InvokeNode.class).isEmpty()) {
 291             for (InvokeNode invoke : graph.getNodes().filter(InvokeNode.class).snapshot()) {
 292                 inline(invoke);
 293             }
 294         }
 295 
 296         // Clean up all code that is now dead after inlining.
 297         new DeadCodeEliminationPhase().apply(graph);




  58 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderTool;
  59 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
  60 import org.graalvm.compiler.nodes.java.ExceptionObjectNode;
  61 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
  62 import org.graalvm.compiler.nodes.spi.StampProvider;
  63 import org.graalvm.compiler.nodes.type.StampTool;
  64 import org.graalvm.compiler.phases.OptimisticOptimizations;
  65 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  66 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality;
  67 import org.graalvm.compiler.phases.common.inlining.InliningUtil;
  68 import org.graalvm.compiler.phases.util.Providers;
  69 import org.graalvm.compiler.word.WordTypes;
  70 import org.graalvm.word.LocationIdentity;
  71 
  72 import jdk.vm.ci.code.BytecodeFrame;
  73 import jdk.vm.ci.meta.ConstantReflectionProvider;
  74 import jdk.vm.ci.meta.JavaKind;
  75 import jdk.vm.ci.meta.JavaType;
  76 import jdk.vm.ci.meta.MetaAccessProvider;
  77 import jdk.vm.ci.meta.ResolvedJavaMethod;

  78 import jdk.vm.ci.meta.Signature;
  79 
  80 /**
  81  * A utility for manually creating a graph. This will be expanded as necessary to support all
  82  * subsystems that employ manual graph creation (as opposed to {@linkplain GraphBuilderPhase
  83  * bytecode parsing} based graph creation).
  84  */
  85 public class GraphKit implements GraphBuilderTool {
  86 
  87     protected final Providers providers;
  88     protected final StructuredGraph graph;
  89     protected final WordTypes wordTypes;
  90     protected final GraphBuilderConfiguration.Plugins graphBuilderPlugins;
  91     protected FixedWithNextNode lastFixedNode;
  92 
  93     private final List<Structure> structures;
  94 
  95     protected abstract static class Structure {
  96     }
  97 


 234         }
 235         MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, bci));
 236         InvokeNode invoke = append(new InvokeNode(callTarget, bci));
 237 
 238         if (frameStateBuilder != null) {
 239             if (invoke.getStackKind() != JavaKind.Void) {
 240                 frameStateBuilder.push(invoke.getStackKind(), invoke);
 241             }
 242             invoke.setStateAfter(frameStateBuilder.create(bci, invoke));
 243             if (invoke.getStackKind() != JavaKind.Void) {
 244                 frameStateBuilder.pop(invoke.getStackKind());
 245             }
 246         }
 247         return invoke;
 248     }
 249 
 250     protected MethodCallTargetNode createMethodCallTarget(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, StampPair returnStamp, @SuppressWarnings("unused") int bci) {
 251         return new MethodCallTargetNode(invokeKind, targetMethod, args, returnStamp, null);
 252     }
 253 
 254     protected final JavaKind asKind(JavaType type) {
 255         return wordTypes != null ? wordTypes.asKind(type) : type.getJavaKind();
 256     }
 257 
 258     /**
 259      * Determines if a given set of arguments is compatible with the signature of a given method.
 260      *
 261      * @return true if {@code args} are compatible with the signature if {@code method}
 262      * @throws AssertionError if {@code args} are not compatible with the signature if
 263      *             {@code method}
 264      */
 265     public boolean checkArgs(ResolvedJavaMethod method, ValueNode... args) {
 266         Signature signature = method.getSignature();
 267         boolean isStatic = method.isStatic();
 268         if (signature.getParameterCount(!isStatic) != args.length) {
 269             throw new AssertionError(graph + ": wrong number of arguments to " + method);
 270         }
 271         int argIndex = 0;
 272         if (!isStatic) {
 273             JavaKind expected = asKind(method.getDeclaringClass());

 274             JavaKind actual = args[argIndex++].stamp().getStackKind();
 275             assert expected == actual : graph + ": wrong kind of value for receiver argument of call to " + method + " [" + actual + " != " + expected + "]";
 276         }
 277         for (int i = 0; i != signature.getParameterCount(false); i++) {
 278             JavaKind expected = asKind(signature.getParameterType(i, method.getDeclaringClass())).getStackKind();

 279             JavaKind actual = args[argIndex++].stamp().getStackKind();
 280             if (expected != actual) {
 281                 throw new AssertionError(graph + ": wrong kind of value for argument " + i + " of call to " + method + " [" + actual + " != " + expected + "]");
 282             }
 283         }
 284         return true;
 285     }
 286 
 287     /**
 288      * Recursively {@linkplain #inline inlines} all invocations currently in the graph.
 289      */
 290     public void inlineInvokes() {
 291         while (!graph.getNodes().filter(InvokeNode.class).isEmpty()) {
 292             for (InvokeNode invoke : graph.getNodes().filter(InvokeNode.class).snapshot()) {
 293                 inline(invoke);
 294             }
 295         }
 296 
 297         // Clean up all code that is now dead after inlining.
 298         new DeadCodeEliminationPhase().apply(graph);


< prev index next >