use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.
the class LLVMDispatchNode method getSignature.
private String getSignature() {
if (signature == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
try {
LLVMContext context = getContextReference().get();
NFIContextExtension nfiContextExtension = context.getContextExtension(NFIContextExtension.class);
this.signature = nfiContextExtension.getNativeSignature(type, LLVMCallNode.USER_ARGUMENT_OFFSET);
} catch (UnsupportedNativeTypeException ex) {
throw new AssertionError(ex);
}
}
return signature;
}
use of com.oracle.truffle.llvm.runtime.LLVMContext 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.llvm.runtime.LLVMContext in project sulong by graalvm.
the class LLVMNativeDispatchNode method identityFunction.
@TruffleBoundary
protected TruffleObject identityFunction() {
LLVMContext context = getContextReference().get();
NFIContextExtension nfiContextExtension = context.getContextExtension(NFIContextExtension.class);
String signature;
try {
signature = nfiContextExtension.getNativeSignature(type, LLVMCallNode.USER_ARGUMENT_OFFSET);
} catch (UnsupportedNativeTypeException e) {
throw new IllegalStateException(e);
}
return nfiContextExtension.getNativeFunction(context, "@identity", String.format("(POINTER):%s", signature));
}
use of com.oracle.truffle.llvm.runtime.LLVMContext in project sulong by graalvm.
the class LLVMPolyglotExport method doExport.
@Specialization
protected Object doExport(Object name, Object value, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
String symbolName = readString.executeWithTarget(name);
LLVMContext ctx = ctxRef.get();
Object escaped = escape.executeWithTarget(value);
try {
ForeignAccess.sendWrite(write, (TruffleObject) ctx.getEnv().getPolyglotBindings(), symbolName, escaped);
} catch (InteropException ex) {
throw ex.raise();
}
return null;
}
use of com.oracle.truffle.llvm.runtime.LLVMContext 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 });
}
}
}
Aggregations