Search in sources :

Example 11 with StackPointer

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

the class LLVMNativeDispatchNode method doCached.

@Specialization(guards = "function.getVal() == cachedFunction.getVal()")
@SuppressWarnings("unused")
protected Object doCached(LLVMAddress function, Object[] arguments, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("function") LLVMAddress cachedFunction, @Cached("identityFunction()") TruffleObject identity, @Cached("dispatchIdentity(identity, cachedFunction.getVal())") TruffleObject nativeFunctionHandle, @Cached("createToNativeNodes()") LLVMNativeConvertNode[] toNative, @Cached("createFromNativeNode()") LLVMNativeConvertNode fromNative, @Cached("nativeCallStatisticsEnabled(context)") boolean statistics) {
    Object[] nativeArgs = prepareNativeArguments(arguments, toNative);
    Object returnValue;
    try (StackPointer save = ((StackPointer) arguments[0]).newFrame()) {
        returnValue = LLVMNativeCallUtils.callNativeFunction(statistics, context, nativeCallNode, nativeFunctionHandle, nativeArgs, null);
    }
    return fromNative.executeConvert(returnValue);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 12 with StackPointer

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

Example 13 with StackPointer

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

the class LLVMForeignCallNode method directCall.

private Object directCall(Object[] arguments, DirectCallNode callNode, PackForeignArgumentsNode packNode, LLVMGetStackNode getStack, LLVMContext context) {
    Object result;
    LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
    try (StackPointer stackPointer = stack.newFrame()) {
        result = callNode.call(packNode.pack(arguments, stackPointer));
    }
    return prepareValueForEscape.executeWithTarget(result);
}
Also used : StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack)

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