use of com.oracle.truffle.api.interop.TruffleObject 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);
}
use of com.oracle.truffle.api.interop.TruffleObject 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);
}
use of com.oracle.truffle.api.interop.TruffleObject 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();
}
}
}
use of com.oracle.truffle.api.interop.TruffleObject in project sulong by graalvm.
the class LLVMToFunctionNode method doTruffleObject.
@Specialization
protected Object doTruffleObject(LLVMTruffleObject from, @Cached("create()") LLVMAsForeignNode asForeign) {
TruffleObject foreign = asForeign.execute(from);
if (ForeignAccess.sendIsNull(isNull, foreign)) {
return LLVMAddress.fromLong(0);
} else if (ForeignAccess.sendIsExecutable(isExecutable, foreign)) {
return from;
}
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException("Not a function");
}
use of com.oracle.truffle.api.interop.TruffleObject 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);
}
Aggregations