Search in sources :

Example 1 with ProfilingPlugin

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

the class BytecodeParser method genIf.

protected void genIf(LogicNode conditionInput, BciBlock trueBlockInput, BciBlock falseBlockInput, double probabilityInput) {
    BciBlock trueBlock = trueBlockInput;
    BciBlock falseBlock = falseBlockInput;
    LogicNode condition = conditionInput;
    double probability = probabilityInput;
    FrameState stateBefore = null;
    ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin();
    if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
        stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
    }
    // Remove a logic negation node.
    if (condition instanceof LogicNegationNode) {
        LogicNegationNode logicNegationNode = (LogicNegationNode) condition;
        BciBlock tmpBlock = trueBlock;
        trueBlock = falseBlock;
        falseBlock = tmpBlock;
        probability = 1 - probability;
        condition = logicNegationNode.getValue();
    }
    if (condition instanceof LogicConstantNode) {
        genConstantTargetIf(trueBlock, falseBlock, condition);
    } else {
        if (condition.graph() == null) {
            condition = genUnique(condition);
        }
        if (isNeverExecutedCode(probability)) {
            append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, true));
            if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
                profilingPlugin.profileGoto(this, method, bci(), falseBlock.startBci, stateBefore);
            }
            appendGoto(falseBlock);
            return;
        } else if (isNeverExecutedCode(1 - probability)) {
            append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, false));
            if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
                profilingPlugin.profileGoto(this, method, bci(), trueBlock.startBci, stateBefore);
            }
            appendGoto(trueBlock);
            return;
        }
        if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
            profilingPlugin.profileIf(this, method, bci(), condition, trueBlock.startBci, falseBlock.startBci, stateBefore);
        }
        int oldBci = stream.currentBCI();
        int trueBlockInt = checkPositiveIntConstantPushed(trueBlock);
        if (trueBlockInt != -1) {
            int falseBlockInt = checkPositiveIntConstantPushed(falseBlock);
            if (falseBlockInt != -1) {
                if (tryGenConditionalForIf(trueBlock, falseBlock, condition, oldBci, trueBlockInt, falseBlockInt)) {
                    return;
                }
            }
        }
        this.controlFlowSplit = true;
        FixedNode trueSuccessor = createTarget(trueBlock, frameState, false, false);
        FixedNode falseSuccessor = createTarget(falseBlock, frameState, false, true);
        ValueNode ifNode = genIfNode(condition, trueSuccessor, falseSuccessor, probability);
        postProcessIfNode(ifNode);
        append(ifNode);
    }
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LogicNegationNode(org.graalvm.compiler.nodes.LogicNegationNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) 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 2 with ProfilingPlugin

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

the class BytecodeParser method genGoto.

protected void genGoto() {
    ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin();
    if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
        FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
        int targetBci = currentBlock.getSuccessor(0).startBci;
        profilingPlugin.profileGoto(this, method, bci(), targetBci, stateBefore);
    }
    appendGoto(currentBlock.getSuccessor(0));
    assert currentBlock.numNormalSuccessors() == 1;
}
Also used : FrameState(org.graalvm.compiler.nodes.FrameState) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ProfilingPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin)

Example 3 with ProfilingPlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin 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 4 with ProfilingPlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin 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)

Aggregations

RuntimeConstraint (jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)4 FrameState (org.graalvm.compiler.nodes.FrameState)4 ProfilingPlugin (org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin)4 BciBlock (org.graalvm.compiler.java.BciBlockMapping.BciBlock)3 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)2 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 Indent (org.graalvm.compiler.debug.Indent)1 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 LogicNegationNode (org.graalvm.compiler.nodes.LogicNegationNode)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 StartNode (org.graalvm.compiler.nodes.StartNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1