Search in sources :

Example 36 with TruffleBoundary

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

the class RuntimeStrengthenStampsPhase method printStaticTruffleBoundaries.

private void printStaticTruffleBoundaries() {
    HashSet<ResolvedJavaMethod> foundBoundaries = new HashSet<>();
    int callSiteCount = 0;
    int calleeCount = 0;
    for (CallTreeNode node : methods.values()) {
        StructuredGraph graph = node.graph;
        for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod targetMethod = callTarget.targetMethod();
            TruffleBoundary truffleBoundary = targetMethod.getAnnotation(TruffleBoundary.class);
            if (truffleBoundary != null) {
                ++callSiteCount;
                if (foundBoundaries.contains(targetMethod)) {
                // nothing to do
                } else {
                    foundBoundaries.add(targetMethod);
                    System.out.println("Truffle boundary found: " + targetMethod);
                    calleeCount++;
                }
            }
        }
    }
    System.out.println(String.format("Number of Truffle call boundaries: %d, number of unique called methods outside the boundary: %d", callSiteCount, calleeCount));
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) HashSet(java.util.HashSet)

Example 37 with TruffleBoundary

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

the class PolyglotLanguageContext method toHostValue.

@TruffleBoundary
Value toHostValue(Object value) {
    assert value != null;
    assert !(value instanceof Value);
    Object receiver = value;
    PolyglotValue cache = valueCache.get(receiver.getClass());
    if (cache == null) {
        receiver = convertToInterop(receiver);
        cache = lookupValueCache(receiver);
    }
    return getAPIAccess().newValue(receiver, cache);
}
Also used : Value(org.graalvm.polyglot.Value) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 38 with TruffleBoundary

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

the class PolyglotLanguageContext method toGuestValues.

@TruffleBoundary
static Object[] toGuestValues(Object languageContext, Object[] args) {
    Object[] newArgs = args;
    for (int i = 0; i < args.length; i++) {
        Object arg = args[i];
        Object newArg = toGuestValue(languageContext, arg);
        if (newArg != arg) {
            if (newArgs == args) {
                newArgs = Arrays.copyOf(args, args.length);
            }
            newArgs[i] = newArg;
        }
    }
    return newArgs;
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 39 with TruffleBoundary

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

the class CyclicAssumptionSnippets method invalidate.

/**
 * @since 0.33
 */
@TruffleBoundary
public void invalidate(String message) {
    Assumption newAssumption = Truffle.getRuntime().createAssumption(name);
    Assumption oldAssumption = ASSUMPTION_UPDATER.getAndSet(this, newAssumption);
    oldAssumption.invalidate(message);
}
Also used : Assumption(com.oracle.truffle.api.Assumption) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 40 with TruffleBoundary

use of com.oracle.truffle.api.CompilerDirectives.TruffleBoundary 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)

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