Search in sources :

Example 6 with StackPointer

use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer 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 7 with StackPointer

use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.

the class LLVMStackRestore method doVoid.

@Specialization
protected Object doVoid(VirtualFrame frame, LLVMAddress addr) {
    StackPointer pointer = (StackPointer) FrameUtil.getObjectSafe(frame, getStackPointerSlot());
    pointer.set(addr.getVal());
    return null;
}
Also used : StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 8 with StackPointer

use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.

the class LLVMContext method initialize.

public void initialize() {
    assert !initialized && !cleanupNecessary && globalScope.functionExists("@__sulong_init_context");
    if (!initialized) {
        initialized = true;
        cleanupNecessary = true;
        LLVMFunctionDescriptor initContextDescriptor = globalScope.getFunctionDescriptor("@__sulong_init_context");
        RootCallTarget initContextFunction = initContextDescriptor.getLLVMIRFunction();
        try (StackPointer stackPointer = threadingStack.getStack().newFrame()) {
            Object[] args = new Object[] { stackPointer, toTruffleObjects(getApplicationArguments()), toTruffleObjects(getEnvironmentVariables()) };
            initContextFunction.call(args);
        }
    }
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTypedForeignObject(com.oracle.truffle.llvm.runtime.interop.LLVMTypedForeignObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 9 with StackPointer

use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.

the class LLVMForeignCallNode method callIndirect.

@Specialization(replaces = "callDirectCached")
protected Object callIndirect(LLVMFunctionDescriptor function, Object[] arguments, @Cached("create()") IndirectCallNode callNode, @Cached("createSlowPackArguments()") SlowPackForeignArgumentsNode slowPack, @Cached("create()") LLVMGetStackNode getStack, @Cached("getLLVMMemory()") LLVMMemory memory) {
    assert !(function.getType().getReturnType() instanceof StructureType);
    LLVMStack stack = getStack.executeWithTarget(function.getContext().getThreadingStack(), Thread.currentThread());
    Object result;
    try (StackPointer stackPointer = stack.newFrame()) {
        result = callNode.call(getCallTarget(function), slowPack.pack(function, memory, arguments, stackPointer));
    }
    return prepareValueForEscape.executeWithTarget(result);
}
Also used : StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 10 with StackPointer

use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.

the class LLVMTruffleInvoke method doInvoke.

@ExplodeLoop
private Object doInvoke(VirtualFrame frame, TruffleObject value, String id, ContextReference<LLVMContext> contextReference, LLVMGetStackNode getStack) {
    Object[] evaluatedArgs = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
        evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
    }
    try {
        LLVMContext context = contextReference.get();
        LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
        Object rawValue;
        try (StackPointer save = stack.newFrame()) {
            rawValue = ForeignAccess.sendInvoke(foreignInvoke, value, id, evaluatedArgs);
        }
        return toLLVM.executeWithTarget(rawValue);
    } catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) ArityException(com.oracle.truffle.api.interop.ArityException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Aggregations

StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)13 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)8 Specialization (com.oracle.truffle.api.dsl.Specialization)6 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)4 RootCallTarget (com.oracle.truffle.api.RootCallTarget)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)3 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)3 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)3 ArityException (com.oracle.truffle.api.interop.ArityException)2 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)2 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)2 LLVMTypedForeignObject (com.oracle.truffle.llvm.runtime.interop.LLVMTypedForeignObject)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 ControlFlowException (com.oracle.truffle.api.nodes.ControlFlowException)1 GuestLanguageRuntimeException (com.oracle.truffle.llvm.runtime.GuestLanguageRuntimeException)1 LLVMExitException (com.oracle.truffle.llvm.runtime.LLVMExitException)1 SulongRuntimeException (com.oracle.truffle.llvm.runtime.SulongRuntimeException)1 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)1