Search in sources :

Example 26 with TruffleBoundary

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

the class LLVMRunDestructorFunctions method runDestructorFunctions.

@TruffleBoundary
private void runDestructorFunctions() {
    // is only executed once per context so it will be executed in the interpreter only
    LLVMContext context = getContextReference().get();
    RootCallTarget[] targets = context.getDestructorFunctions().toArray(new RootCallTarget[0]);
    for (RootCallTarget target : targets) {
        try (StackPointer stackPointer = context.getThreadingStack().getStack().newFrame()) {
            callNode.call(target, new Object[] { stackPointer });
        }
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) RootCallTarget(com.oracle.truffle.api.RootCallTarget) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 27 with TruffleBoundary

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

the class LLVMSourceScope method getVariables.

@TruffleBoundary
protected Object getVariables(Frame frame) {
    final Map<String, LLVMDebugObject> vars = new HashMap<>();
    if (frame != null && !symbols.isEmpty()) {
        for (FrameSlot slot : frame.getFrameDescriptor().getSlots()) {
            if (slot.getIdentifier() instanceof LLVMSourceSymbol && frame.getValue(slot) instanceof LLVMDebugValue) {
                final LLVMSourceSymbol symbol = (LLVMSourceSymbol) slot.getIdentifier();
                final LLVMDebugObject value = ((LLVMDebugValue) frame.getValue(slot)).getValue(symbol);
                if (symbols.contains(symbol)) {
                    vars.put(symbol.getName(), value);
                }
            }
        }
    }
    for (LLVMSourceSymbol symbol : symbols) {
        if (!vars.containsKey(symbol.getName())) {
            LLVMDebugValue dbgVal = context.getStatic(symbol);
            if (dbgVal == null) {
                final LLVMFrameValueAccess allocation = context.getFrameValue(symbol);
                if (allocation != null && frame != null) {
                    dbgVal = allocation.getValue(frame);
                }
            }
            if (dbgVal == null) {
                dbgVal = LLVMDebugValue.UNAVAILABLE;
            }
            vars.put(symbol.getName(), dbgVal.getValue(symbol));
        }
    }
    return new LLVMSourceScopeVariables(vars);
}
Also used : LLVMDebugObject(com.oracle.truffle.llvm.runtime.debug.LLVMDebugObject) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) HashMap(java.util.HashMap) LLVMSourceSymbol(com.oracle.truffle.llvm.runtime.debug.LLVMSourceSymbol) LLVMDebugValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebugValue) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 28 with TruffleBoundary

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

the class LLVMIVarBit method logicalRightShift.

@TruffleBoundary
public LLVMIVarBit logicalRightShift(LLVMIVarBit right) {
    int shiftAmount = right.getIntValue();
    BigInteger mask = BigInteger.valueOf(-1).shiftLeft(bits - shiftAmount).not();
    BigInteger result = new BigInteger(arr).shiftRight(shiftAmount).and(mask);
    return asIVar(result);
}
Also used : BigInteger(java.math.BigInteger) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 29 with TruffleBoundary

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

the class LLVMIVarBit method getByteBuffer.

@TruffleBoundary
private ByteBuffer getByteBuffer(int minSizeBytes, boolean signExtend) {
    int allocationSize = Math.max(minSizeBytes, getByteSize());
    ByteBuffer bb = ByteBuffer.allocate(allocationSize).order(ByteOrder.BIG_ENDIAN);
    boolean truncation = bits > minSizeBytes * Byte.SIZE;
    boolean shouldAddLeadingOnes = signExtend && mostSignificantBit();
    if (!truncation) {
        int bytesToFillUp = minSizeBytes - getByteSize();
        if (shouldAddLeadingOnes) {
            for (int i = 0; i < bytesToFillUp; i++) {
                bb.put((byte) -1);
            }
        } else {
            for (int i = 0; i < bytesToFillUp; i++) {
                bb.put((byte) 0);
            }
        }
    }
    if (bits % Byte.SIZE == 0) {
        bb.put(arr, 0, getByteSize());
    } else {
        BitSet bitSet = new BitSet(Byte.SIZE);
        int bitsToSet = bits % Byte.SIZE;
        for (int i = 0; i < bitsToSet; i++) {
            boolean isBitSet = ((arr[0] >> i) & 1) == 1;
            if (isBitSet) {
                bitSet.set(i);
            }
        }
        if (shouldAddLeadingOnes) {
            for (int i = bitsToSet; i < Byte.SIZE; i++) {
                bitSet.set(i);
            }
        }
        byte firstByteResult;
        if (bitSet.isEmpty()) {
            firstByteResult = 0;
        } else {
            firstByteResult = bitSet.toByteArray()[0];
        }
        // FIXME actually need to truncate or sign extend individual bits
        bb.put(firstByteResult);
        for (int i = 1; i < arr.length; i++) {
            bb.put(arr[i]);
        }
    }
    bb.position(Math.max(0, getByteSize() - minSizeBytes));
    return bb;
}
Also used : BitSet(java.util.BitSet) ByteBuffer(java.nio.ByteBuffer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 30 with TruffleBoundary

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

the class NFIContextExtension method createNativeWrapper.

@TruffleBoundary
public TruffleObject createNativeWrapper(LLVMFunctionDescriptor descriptor) {
    TruffleObject wrapper = null;
    try {
        String signature = getNativeSignature(descriptor.getType(), 0);
        TruffleObject createNativeWrapper = getNativeFunction(descriptor.getContext(), "@createNativeWrapper", String.format("(env, %s):object", signature));
        try {
            wrapper = (TruffleObject) ForeignAccess.sendExecute(Message.createExecute(1).createNode(), createNativeWrapper, descriptor);
        } catch (InteropException ex) {
            throw new AssertionError(ex);
        }
    } catch (UnsupportedNativeTypeException ex) {
    // ignore, fall back to tagged id
    }
    return wrapper;
}
Also used : InteropException(com.oracle.truffle.api.interop.InteropException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) 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