Search in sources :

Example 1 with StackPointer

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

the class LLVMDispatchNode method doNative.

@Specialization(replaces = "doCachedNative", guards = "descriptor.isNativeFunction()")
protected Object doNative(LLVMFunctionDescriptor descriptor, Object[] arguments, @Cached("createToNativeNodes()") LLVMNativeConvertNode[] toNative, @Cached("createFromNativeNode()") LLVMNativeConvertNode fromNative, @Cached("createNativeCallNode()") Node nativeCall, @Cached("getBindNode()") Node bindNode, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("nativeCallStatisticsEnabled(context)") boolean statistics) {
    Object[] nativeArgs = prepareNativeArguments(arguments, toNative);
    TruffleObject boundSymbol = LLVMNativeCallUtils.bindNativeSymbol(bindNode, descriptor.getNativeFunction(), getSignature());
    Object returnValue;
    try (StackPointer save = ((StackPointer) arguments[0]).newFrame()) {
        returnValue = LLVMNativeCallUtils.callNativeFunction(statistics, context, nativeCall, boundSymbol, nativeArgs, descriptor);
    }
    return fromNative.executeConvert(returnValue);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 2 with StackPointer

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

the class LLVMDispatchNode method doCachedNative.

/*
     * Function is not defined in the user program (not available as LLVM IR). No intrinsic
     * available. We do a native call.
     */
@Specialization(limit = "10", guards = { "descriptor == cachedDescriptor", "descriptor.isNativeFunction()" })
protected Object doCachedNative(@SuppressWarnings("unused") LLVMFunctionDescriptor descriptor, Object[] arguments, @Cached("descriptor") LLVMFunctionDescriptor cachedDescriptor, @Cached("createToNativeNodes()") LLVMNativeConvertNode[] toNative, @Cached("createFromNativeNode()") LLVMNativeConvertNode fromNative, @Cached("createNativeCallNode()") Node nativeCall, @Cached("bindSymbol(cachedDescriptor)") TruffleObject cachedBoundFunction, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("nativeCallStatisticsEnabled(context)") boolean statistics) {
    Object[] nativeArgs = prepareNativeArguments(arguments, toNative);
    Object returnValue;
    try (StackPointer save = ((StackPointer) arguments[0]).newFrame()) {
        returnValue = LLVMNativeCallUtils.callNativeFunction(statistics, context, nativeCall, cachedBoundFunction, nativeArgs, cachedDescriptor);
    }
    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 3 with StackPointer

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

the class LLVMGlobalRootNode method execute.

@Override
@ExplodeLoop
public Object execute(VirtualFrame frame) {
    try (StackPointer basePointer = getContext().getThreadingStack().getStack().newFrame()) {
        try {
            TruffleObject appPath = (TruffleObject) ctxRef.get().getEnv().asGuestValue(applicationPath.getBytes());
            LLVMTruffleObject applicationPathObj = new LLVMTruffleObject(LLVMTypedForeignObject.createUnknown(appPath));
            Object[] realArgs = new Object[] { basePointer, mainFunctionType, applicationPathObj };
            Object result = startFunction.call(realArgs);
            getContext().awaitThreadTermination();
            return result;
        } catch (LLVMExitException e) {
            LLVMContext context = getContext();
            // if any variant of exit or abort was called, we know that all the necessary
            // cleanup was already done
            context.setCleanupNecessary(false);
            context.awaitThreadTermination();
            return e.getReturnCode();
        } catch (SulongRuntimeException e) {
            CompilerDirectives.transferToInterpreter();
            throw e;
        } catch (GuestLanguageRuntimeException e) {
            CompilerDirectives.transferToInterpreter();
            return e.handleExit();
        } finally {
            // if not done already, we want at least call a shutdown command
            getContext().shutdownThreads();
        }
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) SulongRuntimeException(com.oracle.truffle.llvm.runtime.SulongRuntimeException) GuestLanguageRuntimeException(com.oracle.truffle.llvm.runtime.GuestLanguageRuntimeException) LLVMExitException(com.oracle.truffle.llvm.runtime.LLVMExitException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTypedForeignObject(com.oracle.truffle.llvm.runtime.interop.LLVMTypedForeignObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 4 with StackPointer

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

the class LLVMNativeDispatchNode method doGeneric.

@Specialization
protected Object doGeneric(LLVMAddress function, Object[] arguments, @Cached("getContextReference()") ContextReference<LLVMContext> context, @Cached("identityFunction()") TruffleObject identity, @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, dispatchIdentity(identity, function.getVal()), 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 5 with StackPointer

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

the class LLVMTruffleExecute method doExecute.

@ExplodeLoop
private Object doExecute(VirtualFrame frame, TruffleObject value, LLVMContext context, 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 {
        LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
        Object rawValue;
        try (StackPointer save = stack.newFrame()) {
            rawValue = ForeignAccess.sendExecute(foreignExecute, value, evaluatedArgs);
        }
        return toLLVM.executeWithTarget(rawValue);
    } catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) 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