Search in sources :

Example 1 with FrameStateBuilder

use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.

the class SubstrateGraphKit method mergeUnwinds.

/**
 * A graph with multiple unwinds is invalid. Merge the various unwind paths.
 */
public void mergeUnwinds() {
    List<UnwindNode> unwinds = new ArrayList<>();
    for (Node node : getGraph().getNodes()) {
        if (node instanceof UnwindNode) {
            unwinds.add((UnwindNode) node);
        }
    }
    if (unwinds.size() > 1) {
        MergeNode unwindMergeNode = add(new MergeNode());
        ValueNode exceptionValue = InliningUtil.mergeValueProducers(unwindMergeNode, unwinds, null, UnwindNode::exception);
        UnwindNode unwindReplacement = add(new UnwindNode(exceptionValue));
        unwindMergeNode.setNext(unwindReplacement);
        FrameStateBuilder exceptionState = getFrameState().copy();
        exceptionState.clearStack();
        exceptionState.push(JavaKind.Object, exceptionValue);
        exceptionState.setRethrowException(true);
        unwindMergeNode.setStateAfter(exceptionState.create(BytecodeFrame.AFTER_EXCEPTION_BCI, unwindMergeNode));
    }
}
Also used : MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptEntryNode(com.oracle.svm.core.graal.nodes.DeoptEntryNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CFunctionEpilogueNode(com.oracle.svm.core.nodes.CFunctionEpilogueNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) CFunctionPrologueNode(com.oracle.svm.core.nodes.CFunctionPrologueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) Node(org.graalvm.compiler.graph.Node) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) ArrayList(java.util.ArrayList) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) UnwindNode(org.graalvm.compiler.nodes.UnwindNode)

Example 2 with FrameStateBuilder

use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.

the class CFunctionCallStubMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
    CFunction annotation = method.getAnnotation(CFunction.class);
    boolean needsTransition = annotation.transition() != Transition.NO_TRANSITION;
    if (purpose == Purpose.PREPARE_RUNTIME_COMPILATION && needsTransition) {
        /*
             * C function calls that need a transition cannot be runtime compiled (and cannot be
             * inlined during runtime compilation). Deoptimization could be required while we are
             * blocked in native code, which means the deoptimization stub would need to do the
             * native-to-Java transition.
             */
        ImageSingletons.lookup(CFunctionFeature.class).warnRuntimeCompilationReachableCFunctionWithTransition(this);
        return null;
    }
    boolean deoptimizationTarget = method instanceof SharedMethod && ((SharedMethod) method).isDeoptTarget();
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    FrameStateBuilder state = kit.getFrameState();
    ValueNode callAddress = kit.unique(new CGlobalDataLoadAddressNode(linkage));
    List<ValueNode> arguments = kit.loadArguments(method.toParameterTypes());
    Signature signature = adaptSignatureAndConvertArguments(method, providers, nativeLibraries, kit, method.getSignature(), arguments);
    state.clearLocals();
    ValueNode returnValue = kit.createCFunctionCall(callAddress, method, arguments, signature, needsTransition, deoptimizationTarget);
    returnValue = adaptReturnValue(method, providers, nativeLibraries, kit, returnValue);
    kit.createReturn(returnValue, signature.getReturnKind());
    assert kit.getGraph().verify();
    return kit.getGraph();
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) Signature(jdk.vm.ci.meta.Signature) ValueNode(org.graalvm.compiler.nodes.ValueNode) CFunction(org.graalvm.nativeimage.c.function.CFunction) SharedMethod(com.oracle.svm.core.meta.SharedMethod) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)

Example 3 with FrameStateBuilder

use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.

the class GraphKit method startInvokeWithException.

public InvokeWithExceptionNode startInvokeWithException(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int invokeBci, int exceptionEdgeBci, ValueNode... args) {
    assert method.isStatic() == (invokeKind == InvokeKind.Static);
    Signature signature = method.getSignature();
    JavaType returnType = signature.getReturnType(null);
    assert checkArgs(method, args);
    StampPair returnStamp = graphBuilderPlugins.getOverridingStamp(this, returnType, false);
    if (returnStamp == null) {
        returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
    }
    ExceptionObjectNode exceptionObject = add(new ExceptionObjectNode(getMetaAccess()));
    if (frameStateBuilder != null) {
        FrameStateBuilder exceptionState = frameStateBuilder.copy();
        exceptionState.clearStack();
        exceptionState.push(JavaKind.Object, exceptionObject);
        exceptionState.setRethrowException(false);
        exceptionObject.setStateAfter(exceptionState.create(exceptionEdgeBci, exceptionObject));
    }
    MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, invokeBci));
    InvokeWithExceptionNode invoke = append(new InvokeWithExceptionNode(callTarget, exceptionObject, invokeBci));
    AbstractBeginNode noExceptionEdge = graph.add(KillingBeginNode.create(LocationIdentity.any()));
    invoke.setNext(noExceptionEdge);
    if (frameStateBuilder != null) {
        if (invoke.getStackKind() != JavaKind.Void) {
            frameStateBuilder.push(invoke.getStackKind(), invoke);
        }
        invoke.setStateAfter(frameStateBuilder.create(invokeBci, invoke));
        if (invoke.getStackKind() != JavaKind.Void) {
            frameStateBuilder.pop(invoke.getStackKind());
        }
    }
    lastFixedNode = null;
    InvokeWithExceptionStructure s = new InvokeWithExceptionStructure();
    s.state = InvokeWithExceptionStructure.State.INVOKE;
    s.noExceptionEdge = noExceptionEdge;
    s.exceptionEdge = exceptionObject;
    s.exceptionObject = exceptionObject;
    pushStructure(s);
    return invoke;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 4 with FrameStateBuilder

use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.

the class JNIFieldAccessorMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    JNIGraphKit kit = new JNIGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    FrameStateBuilder state = new FrameStateBuilder(null, method, graph);
    state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins());
    ValueNode vmThread = kit.loadLocal(0, signature.getParameterKind(0));
    kit.append(new CEntryPointEnterNode(EnterAction.Enter, vmThread));
    List<ValueNode> arguments = kit.loadArguments(signature.toParameterTypes(null));
    ValueNode object;
    if (isStatic) {
        if (fieldKind.isPrimitive()) {
            object = kit.getStaticPrimitiveFieldsArray();
        } else {
            object = kit.getStaticObjectFieldsArray();
        }
    } else {
        ValueNode handle = arguments.get(1);
        object = kit.unboxHandle(handle);
    }
    ValueNode fieldId = arguments.get(2);
    ValueNode offset = kit.getFieldOffsetFromId(fieldId);
    ValueNode returnValue;
    if (isSetter) {
        // void
        returnValue = null;
        ValueNode newValue = arguments.get(3);
        if (fieldKind.isObject()) {
            newValue = kit.unboxHandle(newValue);
        }
        kit.append(new RawStoreNode(object, offset, newValue, fieldKind, LocationIdentity.ANY_LOCATION));
    } else {
        returnValue = kit.append(new RawLoadNode(object, offset, fieldKind, LocationIdentity.ANY_LOCATION));
        if (fieldKind.isObject()) {
            returnValue = kit.boxObjectInLocalHandle(returnValue);
        }
    }
    kit.append(new CEntryPointLeaveNode(LeaveAction.Leave));
    JavaKind returnKind = isSetter ? JavaKind.Void : fieldKind;
    kit.createReturn(returnValue, returnKind);
    assert graph.verify();
    return graph;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CEntryPointEnterNode(com.oracle.svm.core.graal.nodes.CEntryPointEnterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 5 with FrameStateBuilder

use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.

the class DeletedMethod method buildGraph.

public static StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, String message) {
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    FrameStateBuilder state = new FrameStateBuilder(null, method, graph);
    state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins());
    /*
         * A random, but unique and consistent, number for every invoke. This is necessary because
         * we, e.g., look up static analysis results by bci.
         */
    int bci = 0;
    graph.start().setStateAfter(state.create(bci++, graph.start()));
    String msg = AnnotationSubstitutionProcessor.deleteErrorMessage(method, message, false);
    ValueNode msgNode = ConstantNode.forConstant(SubstrateObjectConstant.forObject(msg), providers.getMetaAccess(), graph);
    ValueNode exceptionNode = kit.createInvokeWithExceptionAndUnwind(providers.getMetaAccess().lookupJavaMethod(reportErrorMethod), InvokeKind.Static, state, bci++, bci++, msgNode);
    kit.append(new UnwindNode(exceptionNode));
    kit.mergeUnwinds();
    assert graph.verify();
    return graph;
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) UnwindNode(org.graalvm.compiler.nodes.UnwindNode)

Aggregations

FrameStateBuilder (org.graalvm.compiler.java.FrameStateBuilder)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)6 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 CEntryPointEnterNode (com.oracle.svm.core.graal.nodes.CEntryPointEnterNode)3 CEntryPointLeaveNode (com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode)3 Signature (jdk.vm.ci.meta.Signature)3 HostedGraphKit (com.oracle.svm.hosted.phases.HostedGraphKit)2 JavaKind (jdk.vm.ci.meta.JavaKind)2 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 UnwindNode (org.graalvm.compiler.nodes.UnwindNode)2 UniverseMetaAccess (com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess)1 CGlobalDataLoadAddressNode (com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)1 DeoptEntryNode (com.oracle.svm.core.graal.nodes.DeoptEntryNode)1 SharedMethod (com.oracle.svm.core.meta.SharedMethod)1 CFunctionEpilogueNode (com.oracle.svm.core.nodes.CFunctionEpilogueNode)1 CFunctionPrologueNode (com.oracle.svm.core.nodes.CFunctionPrologueNode)1 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)1 JNIEnvironment (com.oracle.svm.jni.nativeapi.JNIEnvironment)1 ArrayList (java.util.ArrayList)1