Search in sources :

Example 86 with JavaKind

use of jdk.vm.ci.meta.JavaKind in project graal by oracle.

the class ReturnNode method verifyReturn.

private boolean verifyReturn(TargetDescription target) {
    if (graph().method() != null) {
        JavaKind actual = result == null ? JavaKind.Void : result.getStackKind();
        JavaKind expected = graph().method().getSignature().getReturnKind().getStackKind();
        if (actual == target.wordJavaKind && expected == JavaKind.Object) {
            // OK, we're compiling a snippet that returns a Word
            return true;
        }
        assert actual == expected : "return kind doesn't match: actual " + actual + ", expected: " + expected;
    }
    return true;
}
Also used : JavaKind(jdk.vm.ci.meta.JavaKind)

Example 87 with JavaKind

use of jdk.vm.ci.meta.JavaKind in project graal by oracle.

the class InliningUtil method handleAfterBciFrameState.

private static FrameState handleAfterBciFrameState(FrameState frameState, Invoke invoke, boolean alwaysDuplicateStateAfter) {
    FrameState stateAtReturn = invoke.stateAfter();
    JavaKind invokeReturnKind = invoke.asNode().getStackKind();
    FrameState stateAfterReturn = stateAtReturn;
    if (frameState.getCode() == null) {
        // that was parsed for post-parse intrinsification
        for (Node usage : frameState.usages()) {
            if (usage instanceof ForeignCallNode) {
                // A foreign call inside an intrinsic needs to have
                // the BCI of the invoke being intrinsified
                ForeignCallNode foreign = (ForeignCallNode) usage;
                foreign.setBci(invoke.bci());
            }
        }
    }
    // value (top of stack)
    assert !frameState.rethrowException() : frameState;
    if (frameState.stackSize() > 0 && (alwaysDuplicateStateAfter || stateAfterReturn.stackAt(0) != frameState.stackAt(0))) {
        // A non-void return value.
        stateAfterReturn = stateAtReturn.duplicateModified(invokeReturnKind, invokeReturnKind, frameState.stackAt(0));
    } else {
        // A void return value.
        stateAfterReturn = stateAtReturn.duplicate();
    }
    assert stateAfterReturn.bci != BytecodeFrame.UNKNOWN_BCI;
    // Return value does no longer need to be limited by the monitor exit.
    for (MonitorExitNode n : frameState.usages().filter(MonitorExitNode.class)) {
        n.clearEscapedReturnValue();
    }
    frameState.replaceAndDelete(stateAfterReturn);
    return stateAfterReturn;
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) FrameState(org.graalvm.compiler.nodes.FrameState) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 88 with JavaKind

use of jdk.vm.ci.meta.JavaKind in project graal by oracle.

the class InliningUtil method processFrameStates.

protected static void processFrameStates(Invoke invoke, StructuredGraph inlineGraph, EconomicMap<Node, Node> duplicates, FrameState stateAtExceptionEdge, boolean alwaysDuplicateStateAfter) {
    FrameState stateAtReturn = invoke.stateAfter();
    FrameState outerFrameState = null;
    JavaKind invokeReturnKind = invoke.asNode().getStackKind();
    EconomicMap<Node, Node> replacements = EconomicMap.create();
    for (FrameState original : inlineGraph.getNodes(FrameState.TYPE)) {
        FrameState frameState = (FrameState) duplicates.get(original);
        if (frameState != null && frameState.isAlive()) {
            if (outerFrameState == null) {
                outerFrameState = stateAtReturn.duplicateModifiedDuringCall(invoke.bci(), invokeReturnKind);
            }
            processFrameState(frameState, invoke, replacements, inlineGraph.method(), stateAtExceptionEdge, outerFrameState, alwaysDuplicateStateAfter, invoke.callTarget().targetMethod(), invoke.callTarget().arguments());
        }
    }
    // If processing the frame states replaced any nodes, update the duplicates map.
    duplicates.replaceAll((key, value) -> replacements.containsKey(value) ? replacements.get(value) : value);
}
Also used : AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) FrameState(org.graalvm.compiler.nodes.FrameState) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 89 with JavaKind

use of jdk.vm.ci.meta.JavaKind in project graal by oracle.

the class InliningUtil method processFrameState.

public static FrameState processFrameState(FrameState frameState, Invoke invoke, EconomicMap<Node, Node> replacements, ResolvedJavaMethod inlinedMethod, FrameState stateAtExceptionEdge, FrameState outerFrameState, boolean alwaysDuplicateStateAfter, ResolvedJavaMethod invokeTargetMethod, List<ValueNode> invokeArgsList) {
    assert outerFrameState == null || !outerFrameState.isDeleted() : outerFrameState;
    final FrameState stateAtReturn = invoke.stateAfter();
    JavaKind invokeReturnKind = invoke.asNode().getStackKind();
    if (frameState.bci == BytecodeFrame.AFTER_BCI) {
        return handleAfterBciFrameState(frameState, invoke, alwaysDuplicateStateAfter);
    } else if (stateAtExceptionEdge != null && isStateAfterException(frameState)) {
        // pop exception object from invoke's stateAfter and replace with this frameState's
        // exception object (top of stack)
        FrameState stateAfterException = stateAtExceptionEdge;
        if (frameState.stackSize() > 0 && stateAtExceptionEdge.stackAt(0) != frameState.stackAt(0)) {
            stateAfterException = stateAtExceptionEdge.duplicateModified(JavaKind.Object, JavaKind.Object, frameState.stackAt(0));
        }
        frameState.replaceAndDelete(stateAfterException);
        return stateAfterException;
    } else if ((frameState.bci == BytecodeFrame.UNWIND_BCI && frameState.graph().getGuardsStage() == GuardsStage.FLOATING_GUARDS) || frameState.bci == BytecodeFrame.AFTER_EXCEPTION_BCI) {
        /*
             * This path converts the frame states relevant for exception unwinding to
             * deoptimization. This is only allowed in configurations when Graal compiles code for
             * speculative execution (e.g., JIT compilation in HotSpot) but not when compiled code
             * must be deoptimization free (e.g., AOT compilation for native image generation).
             * There is currently no global flag in StructuredGraph to distinguish such modes, but
             * the GuardsStage during inlining indicates the mode in which Graal operates.
             */
        handleMissingAfterExceptionFrameState(frameState, invoke, replacements, alwaysDuplicateStateAfter);
        return frameState;
    } else if (frameState.bci == BytecodeFrame.BEFORE_BCI) {
        // must re-execute the intrinsified invocation
        assert frameState.outerFrameState() == null;
        ValueNode[] invokeArgs = invokeArgsList.isEmpty() ? NO_ARGS : invokeArgsList.toArray(new ValueNode[invokeArgsList.size()]);
        FrameState stateBeforeCall = stateAtReturn.duplicateModifiedBeforeCall(invoke.bci(), invokeReturnKind, invokeTargetMethod.getSignature().toParameterKinds(!invokeTargetMethod.isStatic()), invokeArgs);
        frameState.replaceAndDelete(stateBeforeCall);
        return stateBeforeCall;
    } else {
        // only handle the outermost frame states
        if (frameState.outerFrameState() == null) {
            assert checkInlineeFrameState(invoke, inlinedMethod, frameState);
            frameState.setOuterFrameState(outerFrameState);
        }
        return frameState;
    }
}
Also used : FrameState(org.graalvm.compiler.nodes.FrameState) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 90 with JavaKind

use of jdk.vm.ci.meta.JavaKind in project graal by oracle.

the class MultiTypeGuardInlineInfo method duplicateInvokeForInlining.

private static Invoke duplicateInvokeForInlining(StructuredGraph graph, Invoke invoke, AbstractMergeNode exceptionMerge, PhiNode exceptionObjectPhi, boolean useForInlining) {
    Invoke result = (Invoke) invoke.asNode().copyWithInputs();
    Node callTarget = result.callTarget().copyWithInputs();
    result.asNode().replaceFirstInput(result.callTarget(), callTarget);
    result.setUseForInlining(useForInlining);
    JavaKind kind = invoke.asNode().getStackKind();
    if (kind != JavaKind.Void) {
        FrameState stateAfter = invoke.stateAfter();
        stateAfter = stateAfter.duplicate(stateAfter.bci);
        stateAfter.replaceFirstInput(invoke.asNode(), result.asNode());
        result.setStateAfter(stateAfter);
    }
    if (invoke instanceof InvokeWithExceptionNode) {
        assert exceptionMerge != null && exceptionObjectPhi != null;
        InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
        ExceptionObjectNode exceptionEdge = (ExceptionObjectNode) invokeWithException.exceptionEdge();
        FrameState stateAfterException = exceptionEdge.stateAfter();
        ExceptionObjectNode newExceptionEdge = (ExceptionObjectNode) exceptionEdge.copyWithInputs();
        // set new state (pop old exception object, push new one)
        newExceptionEdge.setStateAfter(stateAfterException.duplicateModified(JavaKind.Object, JavaKind.Object, newExceptionEdge));
        EndNode endNode = graph.add(new EndNode());
        newExceptionEdge.setNext(endNode);
        exceptionMerge.addForwardEnd(endNode);
        exceptionObjectPhi.addInput(newExceptionEdge);
        ((InvokeWithExceptionNode) result).setExceptionEdge(newExceptionEdge);
    }
    return result;
}
Also used : EndNode(org.graalvm.compiler.nodes.EndNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FrameState(org.graalvm.compiler.nodes.FrameState) Invoke(org.graalvm.compiler.nodes.Invoke) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

JavaKind (jdk.vm.ci.meta.JavaKind)90 ValueNode (org.graalvm.compiler.nodes.ValueNode)44 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)24 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)17 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)16 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)13 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)12 JavaType (jdk.vm.ci.meta.JavaType)11 Stamp (org.graalvm.compiler.core.common.type.Stamp)10 LocationIdentity (org.graalvm.word.LocationIdentity)10 ArrayList (java.util.ArrayList)9 JavaConstant (jdk.vm.ci.meta.JavaConstant)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)8 FrameState (org.graalvm.compiler.nodes.FrameState)8 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)8 Signature (jdk.vm.ci.meta.Signature)7 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)6 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)6 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)6