Search in sources :

Example 1 with ControlFlowException

use of com.oracle.truffle.api.nodes.ControlFlowException in project graal by oracle.

the class TruffleStackTrace method fillIn.

@TruffleBoundary
static TruffleStackTrace fillIn(Throwable t) {
    if (t instanceof ControlFlowException) {
        return EMPTY;
    }
    LazyStackTrace lazy = findImpl(t);
    if (lazy == null) {
        Throwable insertCause = findInsertCause(t);
        if (insertCause == null) {
            return null;
        }
        insert(insertCause, lazy = new LazyStackTrace());
    }
    if (lazy.stackTrace != null) {
        // stack trace already exists
        return lazy.stackTrace;
    }
    int stackFrameLimit;
    Node topCallSite;
    if (t instanceof TruffleException) {
        TruffleException te = (TruffleException) t;
        topCallSite = te.getLocation();
        stackFrameLimit = te.getStackTraceElementLimit();
    } else {
        topCallSite = null;
        stackFrameLimit = -1;
    }
    // add the lazily captured stack frames above the manually queried ones
    ArrayList<TracebackElement> elements = new ArrayList<>();
    TracebackElement currentElement = lazy.current;
    while (currentElement != null) {
        elements.add(currentElement);
        currentElement = currentElement.last;
    }
    Collections.reverse(elements);
    List<TruffleStackTraceElement> frames = new ArrayList<>();
    for (TracebackElement element : elements) {
        if (element.root != null) {
            frames.add(new TruffleStackTraceElement(topCallSite, element.root, element.frame));
            topCallSite = null;
        }
        if (element.callNode != null) {
            topCallSite = element.callNode;
        }
    }
    int lazyFrames = frames.size();
    // attach the remaining stack trace elements
    addStackFrames(stackFrameLimit, lazyFrames, topCallSite, frames);
    return lazy.stackTrace = new TruffleStackTrace(frames, lazyFrames);
}
Also used : ControlFlowException(com.oracle.truffle.api.nodes.ControlFlowException) Node(com.oracle.truffle.api.nodes.Node) ArrayList(java.util.ArrayList) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 2 with ControlFlowException

use of com.oracle.truffle.api.nodes.ControlFlowException in project sulong by graalvm.

the class LLVMContext method dispose.

public void dispose(LLVMMemory memory) {
    printNativeCallStatistic();
    // - _exit(), _Exit(), or abort(): no cleanup necessary
    if (cleanupNecessary) {
        try {
            RootCallTarget disposeContext = globalScope.getFunctionDescriptor("@__sulong_dispose_context").getLLVMIRFunction();
            try (StackPointer stackPointer = threadingStack.getStack().newFrame()) {
                disposeContext.call(stackPointer);
            }
        } catch (ControlFlowException e) {
        // nothing needs to be done as the behavior is not defined
        }
    }
    threadingStack.freeMainStack(memory);
    globalStack.free();
}
Also used : ControlFlowException(com.oracle.truffle.api.nodes.ControlFlowException) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Aggregations

ControlFlowException (com.oracle.truffle.api.nodes.ControlFlowException)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 Node (com.oracle.truffle.api.nodes.Node)1 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)1 ArrayList (java.util.ArrayList)1