Search in sources :

Example 46 with TruffleBoundary

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

the class LLVMContext method releaseHandle.

@TruffleBoundary
public void releaseHandle(LLVMMemory memory, LLVMAddress address) {
    synchronized (handlesLock) {
        final TruffleObject object = toManaged.get(address);
        if (object == null) {
            throw new UnsupportedOperationException("Cannot resolve native handle: " + address);
        }
        toManaged.remove(address);
        toNative.remove(getIdentityKey(object));
        memory.free(address);
    }
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 47 with TruffleBoundary

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

the class LLVMSourceScope method create.

@TruffleBoundary
public static Iterable<Scope> create(Node node, Frame frame, LLVMContext context) {
    final LLVMSourceContext sourceContext = context.getSourceContext();
    final RootNode rootNode = node.getRootNode();
    LLVMNode llvmNode = findStatementNode(node);
    if (rootNode == null || llvmNode == null) {
        return Collections.singleton(new LLVMSourceScope(sourceContext, node).toScope(frame));
    }
    LLVMSourceLocation scope = llvmNode.getSourceLocation();
    final SourceSection sourceSection = llvmNode.getSourceSection();
    LLVMSourceScope baseScope = new LLVMSourceScope(sourceContext, new LinkedList<>(), rootNode);
    LLVMSourceScope staticScope = null;
    for (boolean isLocalScope = true; isLocalScope && scope != null; scope = scope.getParent()) {
        final LLVMSourceScope next = toScope(scope, sourceContext, rootNode, sourceSection);
        copySymbols(next, baseScope);
        if (scope.getKind() == LLVMSourceLocation.Kind.FUNCTION) {
            baseScope.setName(next.getName());
            if (scope.getCompileUnit() != null) {
                staticScope = toScope(scope.getCompileUnit(), sourceContext, null, sourceSection);
            }
            isLocalScope = false;
        }
    }
    List<Scope> scopeList = new ArrayList<>();
    scopeList.add(baseScope.toScope(frame));
    for (; scope != null; scope = scope.getParent()) {
        // e.g. lambdas are compiled to calls to a method in a locally defined class. We
        // cannot access the locals of the enclosing function since they do not lie on the
        // function's frame. They are still accessible from the calling function's frame, so
        // we can simply ignore this scope here. Also, any variables actually used in the
        // lambda would still be available as the members of the 'this' pointer.
        final LLVMSourceScope next = toScope(scope, sourceContext, null, sourceSection);
        switch(scope.getKind()) {
            case NAMESPACE:
            case FILE:
            case BLOCK:
                if (next.hasSymbols()) {
                    scopeList.add(next.toScope(frame));
                }
                break;
            case COMPILEUNIT:
                if (staticScope == null) {
                    staticScope = next;
                } else {
                    copySymbols(next, staticScope);
                }
                break;
        }
    }
    if (staticScope != null && staticScope.hasSymbols()) {
        scopeList.add(staticScope.toScope(frame));
    }
    return Collections.unmodifiableList(scopeList);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Scope(com.oracle.truffle.api.Scope) ArrayList(java.util.ArrayList) SourceSection(com.oracle.truffle.api.source.SourceSection) LLVMNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMNode) LLVMSourceContext(com.oracle.truffle.llvm.runtime.debug.LLVMSourceContext) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 48 with TruffleBoundary

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

the class LongDivision method divu128by64.

@TruffleBoundary
public static Result divu128by64(long a1, long a0, long b) {
    if (a1 == 0 && a0 > 0 && b > 0) {
        return new Result(a0 / b, a0 % b);
    }
    BigInteger x = u128(a1, a0);
    BigInteger y = u64(b);
    BigInteger[] result = x.divideAndRemainder(y);
    BigInteger q = result[0];
    BigInteger r = result[1];
    if (q.bitLength() > 64) {
        return Result.OVERFLOW;
    } else {
        return new Result(q.longValue(), r.longValue());
    }
}
Also used : BigInteger(java.math.BigInteger) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 49 with TruffleBoundary

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

the class LongMultiplication method multiplyHigh.

@TruffleBoundary
public static long multiplyHigh(long u, long v) {
    BigInteger x = BigInteger.valueOf(u);
    BigInteger y = BigInteger.valueOf(v);
    BigInteger z = x.multiply(y);
    return high(z);
}
Also used : BigInteger(java.math.BigInteger) 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