Skip to content
Snippets Groups Projects
Commit ade851c7 authored by Lukas Stadler's avatar Lukas Stadler Committed by stepan
Browse files

unify interop exception handling in FFI

parent b895c86f
No related branches found
No related tags found
No related merge requests found
Showing
with 66 additions and 61 deletions
......@@ -24,6 +24,7 @@ package com.oracle.truffle.r.ffi.impl.llvm;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.ffi.impl.interop.NativeDoubleArray;
......@@ -51,8 +52,8 @@ class TruffleLLVM_C implements CRFFI {
}
assert numArgs == args.length;
ForeignAccess.sendExecute(messageNode, nativeCallInfo.address.asTruffleObject(), wargs);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......
......@@ -115,8 +115,8 @@ final class TruffleLLVM_Call implements CallRFFI {
} else if (value instanceof TruffleObject) {
ForeignAccess.sendExecute(executeNode, INIT_VAR_FUN.OBJ.symbolHandle.asTruffleObject(), i, value);
}
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
} finally {
......@@ -138,8 +138,8 @@ final class TruffleLLVM_Call implements CallRFFI {
// llvm specific callbacks
ForeignAccess.sendExecute(executeNode, symbolHandle.asTruffleObject(), callbacks.length, new BytesToNativeCharArrayCall(upCallsRFFIImpl));
ForeignAccess.sendExecute(executeNode, symbolHandle.asTruffleObject(), callbacks.length + 1, new CharSXPToNativeArrayCall(upCallsRFFIImpl));
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......@@ -231,8 +231,8 @@ final class TruffleLLVM_Call implements CallRFFI {
result = unwrap.execute(result);
}
return result;
} catch (InteropException t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
} finally {
RContext.getRForeignAccessFactory().setIsNull(isNullSetting);
}
......
......@@ -23,6 +23,7 @@
package com.oracle.truffle.r.ffi.impl.llvm;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
......@@ -70,8 +71,8 @@ final class TruffleLLVM_PkgInit extends Generic_PkgInit {
ForeignAccess.sendExecute(executeNode, callbackSymbol, PkgInitUpCalls.Index.forceSymbols.ordinal(), new ForceSymbolsCall(trufflePkgInit));
ForeignAccess.sendExecute(executeNode, callbackSymbol, PkgInitUpCalls.Index.registerCCallable.ordinal(), new RegisterCCallableCall(trufflePkgInit));
ForeignAccess.sendExecute(executeNode, callbackSymbol, PkgInitUpCalls.Index.getCCallable.ordinal(), new GetCCallableCall(trufflePkgInit));
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......@@ -89,10 +90,9 @@ final class TruffleLLVM_PkgInit extends Generic_PkgInit {
protected Object setSymbol(DLLInfo dllInfo, int nstOrd, long routines, int index) {
Node executeNode = Message.createExecute(4).createNode();
try {
Object result = ForeignAccess.sendExecute(executeNode, setSymbolHandle, dllInfo, nstOrd, routines, index);
return result;
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
return ForeignAccess.sendExecute(executeNode, setSymbolHandle, dllInfo, nstOrd, routines, index);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -26,6 +26,7 @@ import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.ffi.impl.interop.NativeDoubleArray;
......@@ -85,8 +86,8 @@ public class TruffleLLVM_Stats implements StatsRFFI {
NativeDoubleArray nwork = new NativeDoubleArray(work);
NativeIntegerArray niwork = new NativeIntegerArray(iwork)) {
return (int) ForeignAccess.sendExecute(messageNode, fftWork.asTruffleObject(), na, nseg, n, nspn, isn, nwork, niwork);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......@@ -124,8 +125,8 @@ public class TruffleLLVM_Stats implements StatsRFFI {
try (NativeIntegerArray npmaxf = new NativeIntegerArray(pmaxf);
NativeIntegerArray npmaxp = new NativeIntegerArray(pmaxp)) {
ForeignAccess.sendExecute(messageNode, fftFactor.asTruffleObject(), n, npmaxf, npmaxp);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......
......@@ -23,6 +23,7 @@
package com.oracle.truffle.r.ffi.impl.llvm;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
......@@ -48,8 +49,8 @@ public class TruffleLLVM_Tools implements ToolsRFFI {
try {
ForeignAccess.sendExecute(executeNode, callbackSymbol, new RConnGetCCall());
addCallbackDone = true;
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......
......@@ -25,6 +25,7 @@ package com.oracle.truffle.r.ffi.impl.llvm;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.runtime.RInternalError;
......@@ -53,8 +54,8 @@ public class TruffleLLVM_UserRng implements UserRngRFFI {
init(1);
try {
ForeignAccess.sendExecute(message, Function.Init.getSymbolHandle().asTruffleObject(), seed);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -67,8 +68,8 @@ public class TruffleLLVM_UserRng implements UserRngRFFI {
try {
Object address = ForeignAccess.sendExecute(message, Function.Rand.getSymbolHandle().asTruffleObject());
return (double) ForeignAccess.sendExecute(readPointerNode, TruffleLLVM_CAccess.Function.READ_POINTER_DOUBLE.getSymbolHandle().asTruffleObject(), address);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -81,8 +82,8 @@ public class TruffleLLVM_UserRng implements UserRngRFFI {
try {
Object address = ForeignAccess.sendExecute(message, Function.NSeed.getSymbolHandle().asTruffleObject());
return (int) ForeignAccess.sendExecute(readPointerNode, TruffleLLVM_CAccess.Function.READ_POINTER_INT.getSymbolHandle().asTruffleObject(), address);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -98,8 +99,8 @@ public class TruffleLLVM_UserRng implements UserRngRFFI {
Object seed = ForeignAccess.sendExecute(readPointerNode, TruffleLLVM_CAccess.Function.READ_ARRAY_INT.getSymbolHandle().asTruffleObject(), address, i);
n[i] = (int) seed;
}
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......
......@@ -85,8 +85,8 @@ public class TruffleNFI_Call implements CallRFFI {
SymbolHandle symbolHandle = DLL.findSymbol(initVarFun.funName, null); // libR
try {
initVarFun.initFunction = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", initVarFun.signature);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
Node executeNode = Message.createExecute(2).createNode();
......@@ -109,8 +109,8 @@ public class TruffleNFI_Call implements CallRFFI {
} else {
ForeignAccess.sendExecute(executeNode, INIT_VAR_FUN.OBJ.initFunction, i, value);
}
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
} finally {
......@@ -130,8 +130,8 @@ public class TruffleNFI_Call implements CallRFFI {
TruffleObject addCallbackFunction = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", addCallbackSignature);
ForeignAccess.sendExecute(executeNode, addCallbackFunction, callback.ordinal(), callback.call);
}
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......@@ -162,8 +162,8 @@ public class TruffleNFI_Call implements CallRFFI {
SymbolHandle symbolHandle = DLL.findSymbol(returnArrayFun.funName, null); // libR
try {
returnArrayFun.function = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", returnArrayFun.signature);
} catch (InteropException t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -181,8 +181,8 @@ public class TruffleNFI_Call implements CallRFFI {
} else {
throw RInternalError.shouldNotReachHere();
}
} catch (InteropException t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......@@ -204,8 +204,8 @@ public class TruffleNFI_Call implements CallRFFI {
throw RInternalError.shouldNotReachHere();
}
} catch (InteropException t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......@@ -213,8 +213,8 @@ public class TruffleNFI_Call implements CallRFFI {
Node executeNode = Message.createExecute(1).createNode();
try {
ForeignAccess.sendExecute(executeNode, ReturnArray.FREE.function, address);
} catch (InteropException t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......
......@@ -23,6 +23,7 @@
package com.oracle.truffle.r.ffi.impl.nfi;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
......@@ -84,8 +85,8 @@ public final class TruffleNFI_PkgInit extends Generic_PkgInit {
}
symbolHandle = DLL.findSymbol("Rdynload_setSymbol", null);
setSymbolFunction = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", SETSYMBOL_SIGNATURE);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
......@@ -100,13 +101,12 @@ public final class TruffleNFI_PkgInit extends Generic_PkgInit {
}
@Override
protected Object setSymbol(DLLInfo dllInfo, int nstOrd, long routines, int index) {
protected DotSymbol setSymbol(DLLInfo dllInfo, int nstOrd, long routines, int index) {
Node executeNode = Message.createExecute(4).createNode();
try {
DotSymbol result = (DotSymbol) ForeignAccess.sendExecute(executeNode, setSymbolFunction, dllInfo, nstOrd, routines, index);
return result;
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere(t);
return (DotSymbol) ForeignAccess.sendExecute(executeNode, setSymbolFunction, dllInfo, nstOrd, routines, index);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -67,8 +67,8 @@ public class TruffleNFI_Tools implements ToolsRFFI {
try {
TruffleObject function = (TruffleObject) ForeignAccess.sendInvoke(bind, symbolHandle.asTruffleObject(), "bind", "(env, (object): sint32): void");
ForeignAccess.sendExecute(executeNode, function, new RConnGetCCall());
} catch (InteropException t) {
throw RInternalError.shouldNotReachHere(t);
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......
......@@ -25,6 +25,7 @@ package com.oracle.truffle.r.ffi.impl.nfi;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
......@@ -50,8 +51,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
Node bind = Message.createInvoke(1).createNode();
try {
targetFunction = (TruffleObject) ForeignAccess.sendInvoke(bind, function.getSymbolHandle().asTruffleObject(), "bind", signature);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -64,8 +65,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
init(Function.Init, "(sint32): void");
try {
ForeignAccess.sendExecute(message, targetFunction, seed);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -78,8 +79,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
try {
Object address = ForeignAccess.sendExecute(message, targetFunction);
return (double) ForeignAccess.sendExecute(readPointerNode, TruffleNFI_CAccess.Function.READ_POINTER_DOUBLE.getSymbolFunction(), address);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -92,8 +93,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
try {
Object address = ForeignAccess.sendExecute(message, targetFunction);
return (int) ForeignAccess.sendExecute(readPointerNode, TruffleNFI_CAccess.Function.READ_POINTER_INT.getSymbolFunction(), address);
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......@@ -108,8 +109,8 @@ public class TruffleNFI_UserRng implements UserRngRFFI {
for (int i = 0; i < n.length; i++) {
n[i] = (int) ForeignAccess.sendExecute(readPointerNode, TruffleNFI_CAccess.Function.READ_ARRAY_INT.getSymbolFunction(), address, i);
}
} catch (Throwable t) {
throw RInternalError.shouldNotReachHere();
} catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment