Search in sources :

Example 31 with DebugCloseable

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

the class GraphKit method createInvokeWithExceptionAndUnwind.

@SuppressWarnings("try")
public InvokeWithExceptionNode createInvokeWithExceptionAndUnwind(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int invokeBci, int exceptionEdgeBci, ValueNode... args) {
    try (DebugCloseable context = graph.withNodeSourcePosition(NodeSourcePosition.substitution(graph.currentNodeSourcePosition(), method))) {
        InvokeWithExceptionNode result = startInvokeWithException(method, invokeKind, frameStateBuilder, invokeBci, exceptionEdgeBci, args);
        exceptionPart();
        ExceptionObjectNode exception = exceptionObject();
        append(new UnwindNode(exception));
        endInvokeWithException();
        return result;
    }
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) UnwindNode(org.graalvm.compiler.nodes.UnwindNode)

Example 32 with DebugCloseable

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

the class ReplacementsImpl method getSnippet.

@Override
@SuppressWarnings("try")
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
    assert method.hasBytecodes() : "Snippet must not be abstract or native";
    StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null;
    if (graph == null || (trackNodeSourcePosition && !graph.trackNodeSourcePosition())) {
        try (DebugContext debug = openDebugContext("Snippet_", method);
            DebugCloseable a = SnippetPreparationTime.start(debug)) {
            StructuredGraph newGraph = makeGraph(debug, defaultBytecodeProvider, method, args, recursiveEntry, trackNodeSourcePosition, replaceePosition);
            DebugContext.counter("SnippetNodeCount[%#s]", method).add(newGraph.getDebug(), newGraph.getNodeCount());
            if (!UseSnippetGraphCache.getValue(options) || args != null) {
                return newGraph;
            }
            newGraph.freeze();
            if (graph != null) {
                graphs.replace(method, graph, newGraph);
            } else {
                graphs.putIfAbsent(method, newGraph);
            }
            graph = graphs.get(method);
        }
    }
    assert !trackNodeSourcePosition || graph.trackNodeSourcePosition();
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Snippet(org.graalvm.compiler.api.replacements.Snippet) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 33 with DebugCloseable

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

the class MacroNode method replaceWithInvoke.

@SuppressWarnings("try")
public InvokeNode replaceWithInvoke() {
    try (DebugCloseable context = withNodeSourcePosition()) {
        InvokeNode invoke = createInvoke();
        graph().replaceFixedWithFixed(this, invoke);
        return invoke;
    }
}
Also used : InvokeNode(org.graalvm.compiler.nodes.InvokeNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 34 with DebugCloseable

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

the class TruffleCompilerImpl method compileAST.

/**
 * Compiles a Truffle AST. If compilation succeeds, the AST will have compiled code associated
 * with it that can be executed instead of interpreting the AST.
 *
 * @param compilable representation of the AST to be compiled
 * @param inliningPlan
 * @param compilationId identifier to be used for the compilation
 * @param cancellable an object polled during the compilation process to
 *            {@linkplain CancellationBailoutException abort} early if the thread owning the
 *            cancellable requests it
 * @param listener
 */
@SuppressWarnings("try")
public void compileAST(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, CompilationIdentifier compilationId, Cancellable cancellable, TruffleCompilerListener listener) {
    final CompilationPrinter printer = CompilationPrinter.begin(TruffleCompilerOptions.getOptions(), compilationId, new TruffleDebugJavaMethod(compilable), INVOCATION_ENTRY_BCI);
    StructuredGraph graph = null;
    try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(TruffleCompilerOptions.getOptions())) {
        PhaseSuite<HighTierContext> graphBuilderSuite = createGraphBuilderSuite();
        // Failed speculations must be collected before any compilation or
        // partial evaluation is performed.
        SpeculationLog speculationLog = compilable.getSpeculationLog();
        if (speculationLog != null) {
            speculationLog.collectFailedSpeculations();
        }
        try (DebugCloseable a = PartialEvaluationTime.start(debug);
            DebugCloseable c = PartialEvaluationMemUse.start(debug)) {
            graph = partialEvaluator.createGraph(debug, compilable, inliningPlan, AllowAssumptions.YES, compilationId, speculationLog, cancellable);
        }
        // Check if the task has been cancelled
        if (cancellable != null && cancellable.isCancelled()) {
            return;
        }
        if (listener != null) {
            listener.onTruffleTierFinished(compilable, inliningPlan, new GraphInfoImpl(graph));
        }
        CompilationResult compilationResult = compilePEGraph(graph, compilable.toString(), graphBuilderSuite, compilable, asCompilationRequest(compilationId), listener);
        if (listener != null) {
            listener.onSuccess(compilable, inliningPlan, new GraphInfoImpl(graph), new CompilationResultInfoImpl(compilationResult));
        }
        // Partial evaluation and installation are included in
        // compilation time and memory usage reported by printer
        printer.finish(compilationResult);
    } catch (Throwable t) {
        // graph is null
        if (listener != null) {
            BailoutException bailout = t instanceof BailoutException ? (BailoutException) t : null;
            boolean permanentBailout = bailout != null ? bailout.isPermanent() : false;
            listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout);
        }
        throw t;
    }
}
Also used : CompilationAlarm(org.graalvm.compiler.core.common.util.CompilationAlarm) TruffleDebugJavaMethod(org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod) CancellationBailoutException(org.graalvm.compiler.core.common.CancellationBailoutException) BailoutException(jdk.vm.ci.code.BailoutException) RetryableBailoutException(org.graalvm.compiler.core.common.RetryableBailoutException) SpeculationLog(jdk.vm.ci.meta.SpeculationLog) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationPrinter(org.graalvm.compiler.core.CompilationPrinter) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 35 with DebugCloseable

use of org.graalvm.compiler.debug.DebugCloseable 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)

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