Search in sources :

Example 11 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class TraceAllocationPhase method apply.

@SuppressWarnings("try")
public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context, boolean dumpTrace) {
    DebugContext debug = lirGenRes.getLIR().getDebug();
    try (DebugContext.Scope s = debug.scope(getName(), this)) {
        try (DebugCloseable a = timer.start(debug);
            DebugCloseable c = memUseTracker.start(debug)) {
            if (dumpTrace) {
                if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
                    debug.dump(DebugContext.DETAILED_LEVEL, trace, "Before %s (Trace%s: %s)", getName(), trace.getId(), trace);
                }
            }
            run(target, lirGenRes, trace, context);
            allocatedTraces.increment(debug);
            if (dumpTrace) {
                if (debug.isDumpEnabled(DebugContext.VERBOSE_LEVEL)) {
                    debug.dump(DebugContext.VERBOSE_LEVEL, trace, "After %s (Trace%s: %s)", getName(), trace.getId(), trace);
                }
            }
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 12 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class BytecodeParser method loadLocalObject.

@SuppressWarnings("try")
public void loadLocalObject(int index) {
    ValueNode value = frameState.loadLocal(index, JavaKind.Object);
    int nextBCI = stream.nextBCI();
    int nextBC = stream.readUByte(nextBCI);
    if (nextBCI <= currentBlock.endBci && nextBC == Bytecodes.GETFIELD) {
        stream.next();
        try (DebugCloseable ignored = openNodeContext()) {
            genGetField(stream.readCPI(), Bytecodes.GETFIELD, value);
        }
    } else {
        frameState.push(JavaKind.Object, value);
    }
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)

Example 13 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class BytecodeParser method tryInvocationPlugin.

@SuppressWarnings("try")
protected boolean tryInvocationPlugin(InvokeKind invokeKind, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType, JavaType returnType) {
    InvocationPlugin plugin = graphBuilderConfig.getPlugins().getInvocationPlugins().lookupInvocation(targetMethod);
    if (plugin != null) {
        if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
            // method should be called.
            assert !targetMethod.hasBytecodes() : "TODO: when does this happen?";
            return false;
        }
        InvocationPluginReceiver pluginReceiver = invocationPluginReceiver.init(targetMethod, args);
        IntrinsicGuard intrinsicGuard = null;
        if (invokeKind.isIndirect()) {
            intrinsicGuard = guardIntrinsic(args, targetMethod, pluginReceiver);
            if (intrinsicGuard == null) {
                return false;
            } else if (intrinsicGuard.nonIntrinsicBranch == null) {
                assert lastInstr instanceof FixedGuardNode;
            }
        }
        InvocationPluginAssertions assertions = Assertions.assertionsEnabled() ? new InvocationPluginAssertions(plugin, args, targetMethod, resultType) : null;
        try (DebugCloseable context = openNodeContext(targetMethod)) {
            if (plugin.execute(this, targetMethod, pluginReceiver, args)) {
                afterInvocationPluginExecution(true, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
                return true;
            } else {
                afterInvocationPluginExecution(false, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
            }
        }
    }
    return false;
}
Also used : InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 14 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class BytecodeParser method iterateBytecodesForBlock.

@SuppressWarnings("try")
protected void iterateBytecodesForBlock(BciBlock block) {
    if (block.isLoopHeader) {
        // Create the loop header block, which later will merge the backward branches of
        // the loop.
        controlFlowSplit = true;
        LoopBeginNode loopBegin = appendLoopBegin(this.lastInstr, block.startBci);
        lastInstr = loopBegin;
        // Create phi functions for all local variables and operand stack slots.
        frameState.insertLoopPhis(liveness, block.loopId, loopBegin, forceLoopPhis(), stampFromValueForForcedPhis());
        loopBegin.setStateAfter(createFrameState(block.startBci, loopBegin));
        /*
             * We have seen all forward branches. All subsequent backward branches will merge to the
             * loop header. This ensures that the loop header has exactly one non-loop predecessor.
             */
        setFirstInstruction(block, loopBegin);
        /*
             * We need to preserve the frame state builder of the loop header so that we can merge
             * values for phi functions, so make a copy of it.
             */
        setEntryState(block, frameState.copy());
        debug.log("  created loop header %s", loopBegin);
    } else if (lastInstr instanceof MergeNode) {
        /*
             * All inputs of non-loop phi nodes are known by now. We can infer the stamp for the
             * phi, so that parsing continues with more precise type information.
             */
        frameState.inferPhiStamps((AbstractMergeNode) lastInstr);
    }
    assert lastInstr.next() == null : "instructions already appended at block " + block;
    debug.log("  frameState: %s", frameState);
    lastInstr = finishInstruction(lastInstr, frameState);
    int endBCI = stream.endBCI();
    stream.setBCI(block.startBci);
    int bci = block.startBci;
    BytecodesParsed.add(debug, block.endBci - bci);
    /* Reset line number for new block */
    if (graphBuilderConfig.insertFullInfopoints()) {
        previousLineNumber = -1;
    }
    while (bci < endBCI) {
        try (DebugCloseable context = openNodeContext()) {
            if (graphBuilderConfig.insertFullInfopoints() && !parsingIntrinsic()) {
                currentLineNumber = lnt != null ? lnt.getLineNumber(bci) : -1;
                if (currentLineNumber != previousLineNumber) {
                    genInfoPointNode(InfopointReason.BYTECODE_POSITION, null);
                    previousLineNumber = currentLineNumber;
                }
            }
            // read the opcode
            int opcode = stream.currentBC();
            assert traceState();
            assert traceInstruction(bci, opcode, bci == block.startBci);
            if (parent == null && bci == entryBCI) {
                if (block.getJsrScope() != JsrScope.EMPTY_SCOPE) {
                    throw new JsrNotSupportedBailout("OSR into a JSR scope is not supported");
                }
                EntryMarkerNode x = append(new EntryMarkerNode());
                frameState.insertProxies(value -> graph.unique(new EntryProxyNode(value, x)));
                x.setStateAfter(createFrameState(bci, x));
            }
            processBytecode(bci, opcode);
        } catch (BailoutException e) {
            // Don't wrap bailouts as parser errors
            throw e;
        } catch (Throwable e) {
            throw throwParserError(e);
        }
        if (lastInstr == null || lastInstr.next() != null) {
            break;
        }
        stream.next();
        bci = stream.currentBCI();
        assert block == currentBlock;
        assert checkLastInstruction();
        lastInstr = finishInstruction(lastInstr, frameState);
        if (bci < endBCI) {
            if (bci > block.endBci) {
                assert !block.getSuccessor(0).isExceptionEntry;
                assert block.numNormalSuccessors() == 1;
                // we fell through to the next block, add a goto and break
                appendGoto(block.getSuccessor(0));
                break;
            }
        }
    }
}
Also used : AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) EntryMarkerNode(org.graalvm.compiler.nodes.EntryMarkerNode) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException) BailoutException(jdk.vm.ci.code.BailoutException) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) EntryProxyNode(org.graalvm.compiler.nodes.EntryProxyNode)

Example 15 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.

the class BytecodeParser method tryFastInlineAccessor.

/**
 * Tries to inline {@code targetMethod} if it is an instance field accessor. This avoids the
 * overhead of creating and using a nested {@link BytecodeParser} object.
 */
@SuppressWarnings("try")
private boolean tryFastInlineAccessor(ValueNode[] args, ResolvedJavaMethod targetMethod) {
    byte[] bytecode = targetMethod.getCode();
    if (bytecode != null && bytecode.length == ACCESSOR_BYTECODE_LENGTH && Bytes.beU1(bytecode, 0) == ALOAD_0 && Bytes.beU1(bytecode, 1) == GETFIELD) {
        int b4 = Bytes.beU1(bytecode, 4);
        if (b4 >= IRETURN && b4 <= ARETURN) {
            int cpi = Bytes.beU2(bytecode, 2);
            JavaField field = targetMethod.getConstantPool().lookupField(cpi, targetMethod, GETFIELD);
            if (field instanceof ResolvedJavaField) {
                ValueNode receiver = invocationPluginReceiver.init(targetMethod, args).get();
                ResolvedJavaField resolvedField = (ResolvedJavaField) field;
                try (DebugCloseable context = openNodeContext(targetMethod, 1)) {
                    genGetField(resolvedField, receiver);
                    notifyBeforeInline(targetMethod);
                    printInlining(targetMethod, targetMethod, true, "inline accessor method (bytecode parsing)");
                    notifyAfterInline(targetMethod);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) JavaField(jdk.vm.ci.meta.JavaField) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Aggregations

DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)48 DebugContext (org.graalvm.compiler.debug.DebugContext)23 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)18 ValueNode (org.graalvm.compiler.nodes.ValueNode)14 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)9 OptionValues (org.graalvm.compiler.options.OptionValues)9 FixedNode (org.graalvm.compiler.nodes.FixedNode)8 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)8 Node (org.graalvm.compiler.graph.Node)7 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 MergeNode (org.graalvm.compiler.nodes.MergeNode)7 EndNode (org.graalvm.compiler.nodes.EndNode)6 StartNode (org.graalvm.compiler.nodes.StartNode)6 Method (java.lang.reflect.Method)5 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)5 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)5 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)5