Search in sources :

Example 51 with FrameState

use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.

the class BytecodeParser method genReturn.

protected void genReturn(ValueNode returnVal, JavaKind returnKind) {
    if (parsingIntrinsic() && returnVal != null) {
        if (returnVal instanceof StateSplit) {
            StateSplit stateSplit = (StateSplit) returnVal;
            FrameState stateAfter = stateSplit.stateAfter();
            if (stateSplit.hasSideEffect()) {
                assert stateSplit != null;
                if (stateAfter.bci == BytecodeFrame.AFTER_BCI) {
                    assert stateAfter.usages().count() == 1;
                    assert stateAfter.usages().first() == stateSplit;
                    stateAfter.replaceAtUsages(graph.add(new FrameState(BytecodeFrame.AFTER_BCI, returnVal)));
                    GraphUtil.killWithUnusedFloatingInputs(stateAfter);
                } else {
                    /*
                         * This must be the return value from within a partial intrinsification.
                         */
                    assert !BytecodeFrame.isPlaceholderBci(stateAfter.bci);
                }
            } else {
                assert stateAfter == null;
            }
        }
    }
    ValueNode realReturnVal = processReturnValue(returnVal, returnKind);
    frameState.setRethrowException(false);
    frameState.clearStack();
    beforeReturn(realReturnVal, returnKind);
    if (parent == null) {
        append(new ReturnNode(realReturnVal));
    } else {
        if (returnDataList == null) {
            returnDataList = new ArrayList<>();
        }
        returnDataList.add(new ReturnToCallerData(realReturnVal, lastInstr));
        lastInstr = null;
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 52 with FrameState

use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.

the class BytecodeParser method build.

@SuppressWarnings("try")
protected void build(FixedWithNextNode startInstruction, FrameStateBuilder startFrameState) {
    if (PrintProfilingInformation.getValue(options) && profilingInfo != null) {
        TTY.println("Profiling info for " + method.format("%H.%n(%p)"));
        TTY.println(Util.indent(profilingInfo.toString(method, CodeUtil.NEW_LINE), "  "));
    }
    try (Indent indent = debug.logAndIndent("build graph for %s", method)) {
        if (bytecodeProvider.shouldRecordMethodDependencies()) {
            assert getParent() != null || method.equals(graph.method());
            // Record method dependency in the graph
            graph.recordMethod(method);
        }
        // compute the block map, setup exception handlers and get the entrypoint(s)
        BciBlockMapping newMapping = BciBlockMapping.create(stream, code, options, graph.getDebug());
        this.blockMap = newMapping;
        this.firstInstructionArray = new FixedWithNextNode[blockMap.getBlockCount()];
        this.entryStateArray = new FrameStateBuilder[blockMap.getBlockCount()];
        if (!method.isStatic()) {
            originalReceiver = startFrameState.loadLocal(0, JavaKind.Object);
        }
        /*
             * Configure the assertion checking behavior of the FrameStateBuilder. This needs to be
             * done only when assertions are enabled, so it is wrapped in an assertion itself.
             */
        assert computeKindVerification(startFrameState);
        try (DebugContext.Scope s = debug.scope("LivenessAnalysis")) {
            int maxLocals = method.getMaxLocals();
            liveness = LocalLiveness.compute(debug, stream, blockMap.getBlocks(), maxLocals, blockMap.getLoopCount());
        } catch (Throwable e) {
            throw debug.handle(e);
        }
        lastInstr = startInstruction;
        this.setCurrentFrameState(startFrameState);
        stream.setBCI(0);
        BciBlock startBlock = blockMap.getStartBlock();
        if (this.parent == null) {
            StartNode startNode = graph.start();
            if (method.isSynchronized()) {
                assert !parsingIntrinsic();
                startNode.setStateAfter(createFrameState(BytecodeFrame.BEFORE_BCI, startNode));
            } else {
                if (!parsingIntrinsic()) {
                    if (graph.method() != null && graph.method().isJavaLangObjectInit()) {
                    /*
                             * Don't clear the receiver when Object.<init> is the compilation root.
                             * The receiver is needed as input to RegisterFinalizerNode.
                             */
                    } else {
                        frameState.clearNonLiveLocals(startBlock, liveness, true);
                    }
                    assert bci() == 0;
                    startNode.setStateAfter(createFrameState(bci(), startNode));
                } else {
                    if (startNode.stateAfter() == null) {
                        FrameState stateAfterStart = createStateAfterStartOfReplacementGraph();
                        startNode.setStateAfter(stateAfterStart);
                    }
                }
            }
        }
        try (DebugCloseable context = openNodeContext()) {
            if (method.isSynchronized()) {
                finishPrepare(lastInstr, BytecodeFrame.BEFORE_BCI);
                // add a monitor enter to the start block
                methodSynchronizedObject = synchronizedObject(frameState, method);
                frameState.clearNonLiveLocals(startBlock, liveness, true);
                assert bci() == 0;
                genMonitorEnter(methodSynchronizedObject, bci());
            }
            ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin();
            if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
                FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
                profilingPlugin.profileInvoke(this, method, stateBefore);
            }
            finishPrepare(lastInstr, 0);
            genInfoPointNode(InfopointReason.METHOD_START, null);
        }
        currentBlock = blockMap.getStartBlock();
        setEntryState(startBlock, frameState);
        if (startBlock.isLoopHeader) {
            appendGoto(startBlock);
        } else {
            setFirstInstruction(startBlock, lastInstr);
        }
        BciBlock[] blocks = blockMap.getBlocks();
        for (BciBlock block : blocks) {
            processBlock(block);
        }
    }
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) Indent(org.graalvm.compiler.debug.Indent) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) FrameState(org.graalvm.compiler.nodes.FrameState) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ProfilingPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin)

Example 53 with FrameState

use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.

the class BytecodeParser method genGetStatic.

private void genGetStatic(JavaField field) {
    ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, null);
    if (resolvedField == null) {
        return;
    }
    if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
        graph.recordField(resolvedField);
    }
    /*
         * Javac does not allow use of "$assertionsDisabled" for a field name but Eclipse does, in
         * which case a suffix is added to the generated field.
         */
    if ((parsingIntrinsic() || graphBuilderConfig.omitAssertions()) && resolvedField.isSynthetic() && resolvedField.getName().startsWith("$assertionsDisabled")) {
        frameState.push(field.getJavaKind(), ConstantNode.forBoolean(true, graph));
        return;
    }
    ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();
    if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedField.getDeclaringClass())) {
        FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
        classInitializationPlugin.apply(this, resolvedField.getDeclaringClass(), stateBefore);
    }
    for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
        if (plugin.handleLoadStaticField(this, resolvedField)) {
            return;
        }
    }
    frameState.push(field.getJavaKind(), append(genLoadField(null, resolvedField)));
}
Also used : NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) FrameState(org.graalvm.compiler.nodes.FrameState) ClassInitializationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 54 with FrameState

use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.

the class BytecodeParser method genConstantTargetIf.

private void genConstantTargetIf(BciBlock trueBlock, BciBlock falseBlock, LogicNode condition) {
    LogicConstantNode constantLogicNode = (LogicConstantNode) condition;
    boolean value = constantLogicNode.getValue();
    BciBlock nextBlock = falseBlock;
    if (value) {
        nextBlock = trueBlock;
    }
    int startBci = nextBlock.startBci;
    int targetAtStart = stream.readUByte(startBci);
    if (targetAtStart == Bytecodes.GOTO && nextBlock.getPredecessorCount() == 1) {
        // This is an empty block. Skip it.
        BciBlock successorBlock = nextBlock.successors.get(0);
        ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin();
        if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
            FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
            profilingPlugin.profileGoto(this, method, bci(), successorBlock.startBci, stateBefore);
        }
        appendGoto(successorBlock);
        assert nextBlock.numNormalSuccessors() == 1;
    } else {
        ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin();
        if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
            FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
            profilingPlugin.profileGoto(this, method, bci(), nextBlock.startBci, stateBefore);
        }
        appendGoto(nextBlock);
    }
}
Also used : LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) FrameState(org.graalvm.compiler.nodes.FrameState) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ProfilingPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin)

Example 55 with FrameState

use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.

the class BytecodeParser method genInvokeStatic.

void genInvokeStatic(JavaMethod target) {
    if (callTargetIsResolved(target)) {
        ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
        ResolvedJavaType holder = resolvedTarget.getDeclaringClass();
        if (!holder.isInitialized() && ResolveClassBeforeStaticInvoke.getValue(options)) {
            handleUnresolvedInvoke(target, InvokeKind.Static);
        } else {
            ValueNode classInit = null;
            ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin();
            if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedTarget.getDeclaringClass())) {
                FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
                classInit = classInitializationPlugin.apply(this, resolvedTarget.getDeclaringClass(), stateBefore);
            }
            ValueNode[] args = frameState.popArguments(resolvedTarget.getSignature().getParameterCount(false));
            Invoke invoke = appendInvoke(InvokeKind.Static, resolvedTarget, args);
            if (invoke != null) {
                invoke.setClassInit(classInit);
            }
        }
    } else {
        handleUnresolvedInvoke(target, InvokeKind.Static);
    }
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState) ClassInitializationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolveClassBeforeStaticInvoke(org.graalvm.compiler.core.common.GraalOptions.ResolveClassBeforeStaticInvoke) Invoke(org.graalvm.compiler.nodes.Invoke)

Aggregations

FrameState (org.graalvm.compiler.nodes.FrameState)73 ValueNode (org.graalvm.compiler.nodes.ValueNode)38 Node (org.graalvm.compiler.graph.Node)27 FixedNode (org.graalvm.compiler.nodes.FixedNode)21 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)19 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)19 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)16 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)16 PhiNode (org.graalvm.compiler.nodes.PhiNode)16 EndNode (org.graalvm.compiler.nodes.EndNode)15 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)15 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)14 MergeNode (org.graalvm.compiler.nodes.MergeNode)14 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)13 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)12 StateSplit (org.graalvm.compiler.nodes.StateSplit)12 MonitorIdNode (org.graalvm.compiler.nodes.java.MonitorIdNode)12 DebugContext (org.graalvm.compiler.debug.DebugContext)11 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)11 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)11