Search in sources :

Example 1 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class OptimizedAssumption method invalidateImpl.

@TruffleBoundary
private synchronized void invalidateImpl(String message) {
    /*
         * Check again, now that we are holding the lock. Since isValid is defined volatile,
         * double-checked locking is allowed.
         */
    if (!isValid) {
        return;
    }
    boolean invalidatedADependency = false;
    Entry e = dependencies;
    while (e != null) {
        OptimizedAssumptionDependency dependency = e.awaitDependency();
        if (dependency != null) {
            OptimizedCallTarget callTarget = invalidateWithReason(dependency, "assumption invalidated");
            invalidatedADependency = true;
            if (TruffleCompilerOptions.getValue(TraceTruffleAssumptions)) {
                logInvalidatedDependency(dependency, message);
            }
            if (callTarget != null) {
                callTarget.getCompilationProfile().reportInvalidated();
            }
        }
        e = e.next;
    }
    dependencies = null;
    size = 0;
    sizeAfterLastRemove = 0;
    isValid = false;
    if (TruffleCompilerOptions.getValue(TraceTruffleAssumptions)) {
        if (invalidatedADependency) {
            logStackTrace();
        }
    }
}
Also used : OptimizedAssumptionDependency(org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 2 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class DebuggerSessionSnippets method notifyCallback.

@TruffleBoundary
void notifyCallback(DebuggerNode source, MaterializedFrame frame, SuspendAnchor suspendAnchor, InputValuesProvider inputValuesProvider, Object returnValue, BreakpointConditionFailure conditionFailure) {
    ThreadSuspension suspensionDisabled = threadSuspensions.get();
    if (suspensionDisabled != null && !suspensionDisabled.enabled) {
        return;
    }
    // SuspensionFilter:
    if (source.isStepNode()) {
        if (ignoreLanguageContextInitialization.get() && !source.getContext().isLanguageContextInitialized()) {
            return;
        }
    }
    Thread currentThread = Thread.currentThread();
    SuspendedEvent event = currentSuspendedEventMap.get(currentThread);
    if (event != null) {
        if (Debugger.TRACE) {
            trace("ignored suspended reason: recursive from source:%s context:%s location:%s", source, source.getContext(), source.getSuspendAnchors());
        }
        // avoid recursive suspensions in non legacy mode.
        return;
    }
    if (source.consumeIsDuplicate(this)) {
        if (Debugger.TRACE) {
            trace("ignored suspended reason: duplicate from source:%s context:%s location:%s", source, source.getContext(), source.getSuspendAnchors());
        }
        return;
    }
    // only the first DebuggerNode for a source location and thread will reach here.
    // mark all other nodes at this source location as duplicates
    List<DebuggerNode> nodes = collectDebuggerNodes(source, suspendAnchor);
    for (DebuggerNode node : nodes) {
        if (node == source) {
            // for the current one we won't call isDuplicate
            continue;
        }
        node.markAsDuplicate(this);
    }
    SteppingStrategy s = getSteppingStrategy(currentThread);
    if (suspendNext) {
        synchronized (this) {
            // double checked locking to avoid more than one suspension
            if (suspendNext) {
                s = SteppingStrategy.createAlwaysHalt();
                setSteppingStrategy(currentThread, s, true);
                suspendNext = false;
            }
        }
    }
    if (s == null) {
        // a new Thread just appeared
        s = notifyNewThread(currentThread);
    }
    Map<Breakpoint, Throwable> breakpointFailures = null;
    if (conditionFailure != null) {
        breakpointFailures = new HashMap<>();
        Breakpoint fb = conditionFailure.getBreakpoint();
        if (fb.isGlobal()) {
            fb = fb.getROWrapper();
        }
        breakpointFailures.put(fb, conditionFailure.getConditionFailure());
    }
    List<Breakpoint> breaks = null;
    for (DebuggerNode node : nodes) {
        Breakpoint breakpoint = node.getBreakpoint();
        if (breakpoint == null || !isBreakpointsActive()) {
            // not a breakpoint node
            continue;
        }
        boolean hit = true;
        BreakpointConditionFailure failure = null;
        try {
            hit = breakpoint.notifyIndirectHit(source, node, frame);
        } catch (BreakpointConditionFailure e) {
            failure = e;
        }
        if (hit) {
            if (breaks == null) {
                breaks = new ArrayList<>();
            }
            breaks.add(breakpoint.isGlobal() ? breakpoint.getROWrapper() : breakpoint);
        }
        if (failure != null) {
            if (breakpointFailures == null) {
                breakpointFailures = new HashMap<>();
            }
            Breakpoint fb = failure.getBreakpoint();
            if (fb.isGlobal()) {
                fb = fb.getROWrapper();
            }
            breakpointFailures.put(fb, failure.getConditionFailure());
        }
    }
    boolean hitStepping = s.step(this, source.getContext(), suspendAnchor);
    boolean hitBreakpoint = breaks != null && !breaks.isEmpty();
    if (hitStepping || hitBreakpoint) {
        s.consume();
        doSuspend(SuspendedContext.create(source.getContext()), suspendAnchor, frame, inputValuesProvider, returnValue, breaks, breakpointFailures);
    } else {
        if (Debugger.TRACE) {
            trace("ignored suspended reason: strategy(%s) from source:%s context:%s location:%s", s, source, source.getContext(), source.getSuspendAnchors());
        }
    }
    if (s.isKill()) {
        // ComposedStrategy can become kill
        throw new KillException();
    }
}
Also used : BreakpointConditionFailure(com.oracle.truffle.api.debug.Breakpoint.BreakpointConditionFailure) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 3 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class SetThreadSuspensionEnabledNode method getThreadSuspension.

@TruffleBoundary
protected ThreadSuspension getThreadSuspension(DebuggerSession[] sessions) {
    assert sessions.length == 1;
    ThreadSuspension threadSuspension = new ThreadSuspension(true);
    sessions[0].threadSuspensions.set(threadSuspension);
    return threadSuspension;
}
Also used : ThreadSuspension(com.oracle.truffle.api.debug.DebuggerSession.ThreadSuspension) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 4 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class PolyglotContextImpl method printResult.

@TruffleBoundary
private static void printResult(PolyglotLanguageContext languageContext, Object result) {
    String stringResult = LANGUAGE.toStringIfVisible(languageContext.env, result, true);
    if (stringResult != null) {
        try {
            OutputStream out = languageContext.context.out;
            out.write(stringResult.getBytes(StandardCharsets.UTF_8));
            out.write(System.getProperty("line.separator").getBytes(StandardCharsets.UTF_8));
        } catch (IOException ioex) {
            // out stream has problems.
            throw new IllegalStateException(ioex);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 5 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary in project graal by oracle.

the class TruffleBoundaryPhase method run.

@Override
@SuppressWarnings("deprecation")
protected void run(StructuredGraph graph) {
    for (Node n : graph.getNodes()) {
        if (n instanceof InvokeWithExceptionNode) {
            InvokeWithExceptionNode invoke = (InvokeWithExceptionNode) n;
            ExceptionObjectNode exceptionObject = (ExceptionObjectNode) invoke.exceptionEdge();
            FixedNode originalNext = exceptionObject.next();
            if (!(originalNext instanceof DeoptimizeNode)) {
                TruffleBoundary truffleBoundary = invoke.callTarget().targetMethod().getAnnotation(TruffleBoundary.class);
                if (truffleBoundary != null) {
                    if (!truffleBoundary.throwsControlFlowException() && truffleBoundary.transferToInterpreterOnException()) {
                        addDeoptimizeNode(graph, originalNext);
                    }
                }
            }
        }
    }
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) Node(org.graalvm.compiler.graph.Node) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Aggregations

TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)49 RootNode (com.oracle.truffle.api.nodes.RootNode)6 Property (com.oracle.truffle.api.object.Property)6 Specialization (com.oracle.truffle.api.dsl.Specialization)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)5 BigInteger (java.math.BigInteger)4 Node (com.oracle.truffle.api.nodes.Node)3 SourceSection (com.oracle.truffle.api.source.SourceSection)3 ByteBuffer (java.nio.ByteBuffer)3 Substitute (com.oracle.svm.core.annotate.Substitute)2 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)2 Source (com.oracle.truffle.api.source.Source)2 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)2 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Assumption (com.oracle.truffle.api.Assumption)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1