< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderContext.java

Print this page




  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.nodes.graphbuilderconf;
  26 
  27 import static jdk.vm.ci.meta.DeoptimizationAction.InvalidateReprofile;
  28 import static jdk.vm.ci.meta.DeoptimizationReason.NullCheckException;
  29 import static org.graalvm.compiler.core.common.type.StampFactory.objectNonNull;
  30 
  31 import org.graalvm.compiler.bytecode.Bytecode;
  32 import org.graalvm.compiler.bytecode.BytecodeProvider;
  33 import org.graalvm.compiler.core.common.type.AbstractPointerStamp;
  34 import org.graalvm.compiler.core.common.type.ObjectStamp;
  35 import org.graalvm.compiler.core.common.type.Stamp;
  36 import org.graalvm.compiler.core.common.type.StampFactory;
  37 import org.graalvm.compiler.core.common.type.StampPair;
  38 import org.graalvm.compiler.debug.GraalError;
  39 import org.graalvm.compiler.nodes.AbstractBeginNode;
  40 import org.graalvm.compiler.nodes.AbstractMergeNode;
  41 import org.graalvm.compiler.nodes.CallTargetNode;
  42 import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
  43 import org.graalvm.compiler.nodes.ConstantNode;
  44 import org.graalvm.compiler.nodes.DynamicPiNode;
  45 import org.graalvm.compiler.nodes.FixedGuardNode;

  46 import org.graalvm.compiler.nodes.LogicNode;
  47 import org.graalvm.compiler.nodes.NodeView;
  48 import org.graalvm.compiler.nodes.PiNode;
  49 import org.graalvm.compiler.nodes.StateSplit;
  50 import org.graalvm.compiler.nodes.ValueNode;
  51 import org.graalvm.compiler.nodes.calc.IsNullNode;
  52 import org.graalvm.compiler.nodes.calc.NarrowNode;
  53 import org.graalvm.compiler.nodes.calc.SignExtendNode;
  54 import org.graalvm.compiler.nodes.calc.ZeroExtendNode;
  55 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode.BytecodeExceptionKind;
  56 import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode;
  57 import org.graalvm.compiler.nodes.type.StampTool;
  58 
  59 import jdk.vm.ci.code.BailoutException;
  60 import jdk.vm.ci.meta.Assumptions;
  61 import jdk.vm.ci.meta.DeoptimizationAction;
  62 import jdk.vm.ci.meta.DeoptimizationReason;
  63 import jdk.vm.ci.meta.JavaKind;
  64 import jdk.vm.ci.meta.JavaType;
  65 import jdk.vm.ci.meta.ResolvedJavaMethod;


  75      * when {@code value.getJavaKind()} is different from the kind that the bytecode instruction
  76      * currently being parsed pushes to the stack.
  77      *
  78      * @param kind the kind to use when type checking this operation
  79      * @param value the value to push to the stack. The value must already have been
  80      *            {@linkplain #append(ValueNode) appended}.
  81      */
  82     void push(JavaKind kind, ValueNode value);
  83 
  84     /**
  85      * Pops a value from the frame state stack using an explicit kind.
  86      *
  87      * @param slotKind the kind to use when type checking this operation
  88      * @return the value on the top of the stack
  89      */
  90     default ValueNode pop(JavaKind slotKind) {
  91         throw GraalError.unimplemented();
  92     }
  93 
  94     /**
  95      * Adds a node to the graph. If the node is in the graph, returns immediately. If the node is a
  96      * {@link StateSplit} with a null {@linkplain StateSplit#stateAfter() frame state}, the frame
  97      * state is initialized.
  98      *
  99      * @param value the value to add to the graph and push to the stack. The
 100      *            {@code value.getJavaKind()} kind is used when type checking this operation.
 101      * @return a node equivalent to {@code value} in the graph
 102      */
 103     default <T extends ValueNode> T add(T value) {
 104         if (value.graph() != null) {
 105             assert !(value instanceof StateSplit) || ((StateSplit) value).stateAfter() != null;
 106             return value;
 107         }
 108         return GraphBuilderContextUtil.setStateAfterIfNecessary(this, append(value));
 109     }
 110 
 111     /**
 112      * Adds a node and its inputs to the graph. If the node is in the graph, returns immediately. If
 113      * the node is a {@link StateSplit} with a null {@linkplain StateSplit#stateAfter() frame state}
 114      * , the frame state is initialized.
 115      *
 116      * @param value the value to add to the graph and push to the stack. The
 117      *            {@code value.getJavaKind()} kind is used when type checking this operation.
 118      * @return a node equivalent to {@code value} in the graph
 119      */
 120     default <T extends ValueNode> T addWithInputs(T value) {
 121         if (value.graph() != null) {
 122             assert !(value instanceof StateSplit) || ((StateSplit) value).stateAfter() != null;
 123             return value;
 124         }
 125         return GraphBuilderContextUtil.setStateAfterIfNecessary(this, append(value));
 126     }
 127 
 128     default ValueNode addNonNullCast(ValueNode value) {
 129         AbstractPointerStamp valueStamp = (AbstractPointerStamp) value.stamp(NodeView.DEFAULT);
 130         if (valueStamp.nonNull()) {
 131             return value;
 132         } else {
 133             LogicNode isNull = add(IsNullNode.create(value));
 134             FixedGuardNode fixedGuard = add(new FixedGuardNode(isNull, DeoptimizationReason.NullCheckException, DeoptimizationAction.None, true));
 135             Stamp newStamp = valueStamp.improveWith(StampFactory.objectNonNull());
 136             return add(PiNode.create(value, newStamp, fixedGuard));
 137         }
 138     }
 139 
 140     /**
 141      * Adds a node with a non-void kind to the graph, pushes it to the stack. If the returned node
 142      * is a {@link StateSplit} with a null {@linkplain StateSplit#stateAfter() frame state}, the
 143      * frame state is initialized.
 144      *
 145      * @param kind the kind to use when type checking this operation
 146      * @param value the value to add to the graph and push to the stack
 147      * @return a node equivalent to {@code value} in the graph
 148      */
 149     default <T extends ValueNode> T addPush(JavaKind kind, T value) {
 150         T equivalentValue = value.graph() != null ? value : append(value);
 151         push(kind, equivalentValue);
 152         return GraphBuilderContextUtil.setStateAfterIfNecessary(this, equivalentValue);
 153     }
 154 
 155     /**
 156      * Handles an invocation that a plugin determines can replace the original invocation (i.e., the
 157      * one for which the plugin was applied). This applies all standard graph builder processing to
 158      * the replaced invocation including applying any relevant plugins.
 159      *
 160      * @param invokeKind the kind of the replacement invocation
 161      * @param targetMethod the target of the replacement invocation
 162      * @param args the arguments to the replacement invocation
 163      * @param forceInlineEverything specifies if all invocations encountered in the scope of
 164      *            handling the replaced invoke are to be force inlined
 165      */
 166     void handleReplacedInvoke(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, boolean forceInlineEverything);
 167 
 168     void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType);
 169 
 170     /**
 171      * Intrinsifies an invocation of a given method by inlining the bytecodes of a given
 172      * substitution method.
 173      *
 174      * @param bytecodeProvider used to get the bytecodes to parse for the substitution method
 175      * @param targetMethod the method being intrinsified
 176      * @param substitute the intrinsic implementation
 177      * @param receiver the receiver, or null for static methods
 178      * @param argsIncludingReceiver the arguments with which to inline the invocation
 179      *
 180      * @return whether the intrinsification was successful
 181      */
 182     boolean intrinsify(BytecodeProvider bytecodeProvider, ResolvedJavaMethod targetMethod, ResolvedJavaMethod substitute, InvocationPlugin.Receiver receiver, ValueNode[] argsIncludingReceiver);
 183 
 184     /**
 185      * Creates a snap shot of the current frame state with the BCI of the instruction after the one
 186      * currently being parsed and assigns it to a given {@linkplain StateSplit#hasSideEffect() side


 262 
 263     /**
 264      * Gets the intrinsic of the current parsing context or {@code null} if not
 265      * {@link #parsingIntrinsic() parsing an intrinsic}.
 266      */
 267     IntrinsicContext getIntrinsic();
 268 
 269     BailoutException bailout(String string);
 270 
 271     default ValueNode nullCheckedValue(ValueNode value) {
 272         return nullCheckedValue(value, InvalidateReprofile);
 273     }
 274 
 275     /**
 276      * Gets a version of a given value that has a {@linkplain StampTool#isPointerNonNull(ValueNode)
 277      * non-null} stamp.
 278      */
 279     default ValueNode nullCheckedValue(ValueNode value, DeoptimizationAction action) {
 280         if (!StampTool.isPointerNonNull(value)) {
 281             LogicNode condition = getGraph().unique(IsNullNode.create(value));
 282             ObjectStamp receiverStamp = (ObjectStamp) value.stamp(NodeView.DEFAULT);
 283             Stamp stamp = receiverStamp.join(objectNonNull());
 284             FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, NullCheckException, action, true));
 285             ValueNode nonNullReceiver = getGraph().addOrUniqueWithInputs(PiNode.create(value, stamp, fixedGuard));
 286             // TODO: Propogating the non-null into the frame state would
 287             // remove subsequent null-checks on the same value. However,
 288             // it currently causes an assertion failure when merging states.
 289             //
 290             // frameState.replace(value, nonNullReceiver);
 291             return nonNullReceiver;
 292         }
 293         return value;
 294     }
 295 
 296     default void genCheckcastDynamic(ValueNode object, ValueNode javaClass) {
 297         LogicNode condition = InstanceOfDynamicNode.create(getAssumptions(), getConstantReflection(), javaClass, object, true);
 298         if (condition.isTautology()) {
 299             addPush(JavaKind.Object, object);
 300         } else {
 301             append(condition);
 302             FixedGuardNode fixedGuard = add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
 303             addPush(JavaKind.Object, DynamicPiNode.create(getAssumptions(), getConstantReflection(), object, fixedGuard, javaClass));
 304         }
 305     }




  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.nodes.graphbuilderconf;
  26 
  27 import static jdk.vm.ci.meta.DeoptimizationAction.InvalidateReprofile;
  28 import static jdk.vm.ci.meta.DeoptimizationReason.NullCheckException;
  29 import static org.graalvm.compiler.core.common.type.StampFactory.objectNonNull;
  30 
  31 import org.graalvm.compiler.bytecode.Bytecode;
  32 import org.graalvm.compiler.bytecode.BytecodeProvider;
  33 import org.graalvm.compiler.core.common.type.AbstractPointerStamp;

  34 import org.graalvm.compiler.core.common.type.Stamp;
  35 import org.graalvm.compiler.core.common.type.StampFactory;
  36 import org.graalvm.compiler.core.common.type.StampPair;
  37 import org.graalvm.compiler.debug.GraalError;
  38 import org.graalvm.compiler.nodes.AbstractBeginNode;
  39 import org.graalvm.compiler.nodes.AbstractMergeNode;
  40 import org.graalvm.compiler.nodes.CallTargetNode;
  41 import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
  42 import org.graalvm.compiler.nodes.ConstantNode;
  43 import org.graalvm.compiler.nodes.DynamicPiNode;
  44 import org.graalvm.compiler.nodes.FixedGuardNode;
  45 import org.graalvm.compiler.nodes.Invoke;
  46 import org.graalvm.compiler.nodes.LogicNode;
  47 import org.graalvm.compiler.nodes.NodeView;
  48 import org.graalvm.compiler.nodes.PiNode;
  49 import org.graalvm.compiler.nodes.StateSplit;
  50 import org.graalvm.compiler.nodes.ValueNode;
  51 import org.graalvm.compiler.nodes.calc.IsNullNode;
  52 import org.graalvm.compiler.nodes.calc.NarrowNode;
  53 import org.graalvm.compiler.nodes.calc.SignExtendNode;
  54 import org.graalvm.compiler.nodes.calc.ZeroExtendNode;
  55 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode.BytecodeExceptionKind;
  56 import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode;
  57 import org.graalvm.compiler.nodes.type.StampTool;
  58 
  59 import jdk.vm.ci.code.BailoutException;
  60 import jdk.vm.ci.meta.Assumptions;
  61 import jdk.vm.ci.meta.DeoptimizationAction;
  62 import jdk.vm.ci.meta.DeoptimizationReason;
  63 import jdk.vm.ci.meta.JavaKind;
  64 import jdk.vm.ci.meta.JavaType;
  65 import jdk.vm.ci.meta.ResolvedJavaMethod;


  75      * when {@code value.getJavaKind()} is different from the kind that the bytecode instruction
  76      * currently being parsed pushes to the stack.
  77      *
  78      * @param kind the kind to use when type checking this operation
  79      * @param value the value to push to the stack. The value must already have been
  80      *            {@linkplain #append(ValueNode) appended}.
  81      */
  82     void push(JavaKind kind, ValueNode value);
  83 
  84     /**
  85      * Pops a value from the frame state stack using an explicit kind.
  86      *
  87      * @param slotKind the kind to use when type checking this operation
  88      * @return the value on the top of the stack
  89      */
  90     default ValueNode pop(JavaKind slotKind) {
  91         throw GraalError.unimplemented();
  92     }
  93 
  94     /**
  95      * Adds a node and all its inputs to the graph. If the node is in the graph, returns
  96      * immediately. If the node is a {@link StateSplit} with a null
  97      * {@linkplain StateSplit#stateAfter() frame state} , the frame state is initialized.
  98      *
  99      * @param value the value to add to the graph and push to the stack. The
 100      *            {@code value.getJavaKind()} kind is used when type checking this operation.
 101      * @return a node equivalent to {@code value} in the graph
 102      */
 103     default <T extends ValueNode> T add(T value) {
 104         if (value.graph() != null) {
 105             assert !(value instanceof StateSplit) || ((StateSplit) value).stateAfter() != null;
 106             return value;
 107         }
 108         return GraphBuilderContextUtil.setStateAfterIfNecessary(this, append(value));
 109     }
 110 

















 111     default ValueNode addNonNullCast(ValueNode value) {
 112         AbstractPointerStamp valueStamp = (AbstractPointerStamp) value.stamp(NodeView.DEFAULT);
 113         if (valueStamp.nonNull()) {
 114             return value;
 115         } else {
 116             LogicNode isNull = add(IsNullNode.create(value));
 117             FixedGuardNode fixedGuard = add(new FixedGuardNode(isNull, DeoptimizationReason.NullCheckException, DeoptimizationAction.None, true));
 118             Stamp newStamp = valueStamp.improveWith(StampFactory.objectNonNull());
 119             return add(PiNode.create(value, newStamp, fixedGuard));
 120         }
 121     }
 122 
 123     /**
 124      * Adds a node with a non-void kind to the graph, pushes it to the stack. If the returned node
 125      * is a {@link StateSplit} with a null {@linkplain StateSplit#stateAfter() frame state}, the
 126      * frame state is initialized.
 127      *
 128      * @param kind the kind to use when type checking this operation
 129      * @param value the value to add to the graph and push to the stack
 130      * @return a node equivalent to {@code value} in the graph
 131      */
 132     default <T extends ValueNode> T addPush(JavaKind kind, T value) {
 133         T equivalentValue = value.graph() != null ? value : append(value);
 134         push(kind, equivalentValue);
 135         return GraphBuilderContextUtil.setStateAfterIfNecessary(this, equivalentValue);
 136     }
 137 
 138     /**
 139      * Handles an invocation that a plugin determines can replace the original invocation (i.e., the
 140      * one for which the plugin was applied). This applies all standard graph builder processing to
 141      * the replaced invocation including applying any relevant plugins.
 142      *
 143      * @param invokeKind the kind of the replacement invocation
 144      * @param targetMethod the target of the replacement invocation
 145      * @param args the arguments to the replacement invocation
 146      * @param forceInlineEverything specifies if all invocations encountered in the scope of
 147      *            handling the replaced invoke are to be force inlined
 148      */
 149     Invoke handleReplacedInvoke(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, boolean forceInlineEverything);
 150 
 151     void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType);
 152 
 153     /**
 154      * Intrinsifies an invocation of a given method by inlining the bytecodes of a given
 155      * substitution method.
 156      *
 157      * @param bytecodeProvider used to get the bytecodes to parse for the substitution method
 158      * @param targetMethod the method being intrinsified
 159      * @param substitute the intrinsic implementation
 160      * @param receiver the receiver, or null for static methods
 161      * @param argsIncludingReceiver the arguments with which to inline the invocation
 162      *
 163      * @return whether the intrinsification was successful
 164      */
 165     boolean intrinsify(BytecodeProvider bytecodeProvider, ResolvedJavaMethod targetMethod, ResolvedJavaMethod substitute, InvocationPlugin.Receiver receiver, ValueNode[] argsIncludingReceiver);
 166 
 167     /**
 168      * Creates a snap shot of the current frame state with the BCI of the instruction after the one
 169      * currently being parsed and assigns it to a given {@linkplain StateSplit#hasSideEffect() side


 245 
 246     /**
 247      * Gets the intrinsic of the current parsing context or {@code null} if not
 248      * {@link #parsingIntrinsic() parsing an intrinsic}.
 249      */
 250     IntrinsicContext getIntrinsic();
 251 
 252     BailoutException bailout(String string);
 253 
 254     default ValueNode nullCheckedValue(ValueNode value) {
 255         return nullCheckedValue(value, InvalidateReprofile);
 256     }
 257 
 258     /**
 259      * Gets a version of a given value that has a {@linkplain StampTool#isPointerNonNull(ValueNode)
 260      * non-null} stamp.
 261      */
 262     default ValueNode nullCheckedValue(ValueNode value, DeoptimizationAction action) {
 263         if (!StampTool.isPointerNonNull(value)) {
 264             LogicNode condition = getGraph().unique(IsNullNode.create(value));


 265             FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, NullCheckException, action, true));
 266             ValueNode nonNullReceiver = getGraph().addOrUniqueWithInputs(PiNode.create(value, objectNonNull(), fixedGuard));
 267             // TODO: Propogating the non-null into the frame state would
 268             // remove subsequent null-checks on the same value. However,
 269             // it currently causes an assertion failure when merging states.
 270             //
 271             // frameState.replace(value, nonNullReceiver);
 272             return nonNullReceiver;
 273         }
 274         return value;
 275     }
 276 
 277     default void genCheckcastDynamic(ValueNode object, ValueNode javaClass) {
 278         LogicNode condition = InstanceOfDynamicNode.create(getAssumptions(), getConstantReflection(), javaClass, object, true);
 279         if (condition.isTautology()) {
 280             addPush(JavaKind.Object, object);
 281         } else {
 282             append(condition);
 283             FixedGuardNode fixedGuard = add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
 284             addPush(JavaKind.Object, DynamicPiNode.create(getAssumptions(), getConstantReflection(), object, fixedGuard, javaClass));
 285         }
 286     }


< prev index next >