use of com.oracle.truffle.api.exception.AbstractTruffleException in project graal by oracle.
the class HostEntryPoint method remoteMessage.
public Object remoteMessage(long contextId, long receiverId, Message message, Object[] args) {
Context c = unmarshall(Context.class, contextId);
c.enter();
try {
Object receiver = unmarshall(Object.class, receiverId);
Object[] localValues = unmarshallAtGuest(contextId, args);
ReflectionLibrary lib = ReflectionLibrary.getFactory().getUncached(receiver);
Object result;
try {
result = lib.send(receiver, message, localValues);
} catch (Exception e) {
// probably needs to support TruffleException too, but this is just a sketch
if (e instanceof AbstractTruffleException) {
// also send over stack traces and messages
return new GuestExceptionPointer(guestToHost(e), e.getMessage());
} else {
throw new RuntimeException("Internal error thrown by remote message.", e);
}
}
return marshallAtGuest(result);
} finally {
c.leave();
}
}
use of com.oracle.truffle.api.exception.AbstractTruffleException in project graal by oracle.
the class AbstractExecutableTestLanguage method parse.
@Override
@SuppressWarnings("unused")
protected final CallTarget parse(ParsingRequest request) throws Exception {
ExecutableContext executableContext = TestAPIAccessor.engineAccess().getCurrentContext(AbstractExecutableTestLanguage.this.getClass());
Object[] ctxArgs = createArgumentsArray(executableContext);
onParse(request, executableContext.env, ctxArgs);
String rootNodeName = getRootName(request, executableContext.env, ctxArgs);
SourceSection srcSec = request.getSource().createSection(0, request.getSource().getLength());
return new RootNode(this, null) {
@Child
InteropLibrary interopLibrary = interop;
private final SourceSection sourceSection = srcSec;
@CompilationFinal(dimensions = 1)
private final Object[] contextArguments = ctxArgs;
@Override
public Object execute(VirtualFrame frame) {
ExecutableContext execCtx = TestAPIAccessor.engineAccess().getCurrentContext(AbstractExecutableTestLanguage.this.getClass());
try {
Object returnValue = AbstractExecutableTestLanguage.this.execute(this, execCtx.env, contextArguments, frame.getArguments());
if (returnValue == null) {
return NullObject.SINGLETON;
}
return returnValue;
} catch (AbstractTruffleException e) {
throw e;
} catch (Exception e) {
throw throwAssertionError(e);
}
}
@TruffleBoundary
private AssertionError throwAssertionError(Exception e) {
throw new AssertionError(e);
}
@Override
public String getName() {
return rootNodeName;
}
@Override
public SourceSection getSourceSection() {
return srcSec;
}
}.getCallTarget();
}
use of com.oracle.truffle.api.exception.AbstractTruffleException in project graal by oracle.
the class InsightObjectTest method wrongReturnValueCall.
@Test
public void wrongReturnValueCall() throws Exception {
try (Context c = InsightObjectFactory.newContext()) {
Value agent = InsightObjectFactory.readInsight(c, null);
InsightAPI agentAPI = agent.as(InsightAPI.class);
Assert.assertNotNull("Agent API obtained", agentAPI);
// @formatter:off
Source sampleScript = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(\n" + " DEFINE(meaning,\n" + " EXPRESSION(\n" + " CONSTANT(6),\n" + " CONSTANT(7)\n" + " )\n" + " ),\n" + " CALL(meaning)\n" + ")", "sample.px").build();
// @formatter:on
final InsightAPI.OnEventHandler return42 = (ctx, frame) -> {
try {
ctx.returnValue(Collections.emptyMap());
} catch (RuntimeException ex) {
assertTrue("Expecting TruffleException: " + ex, ex instanceof AbstractTruffleException);
}
ctx.returnNow(42);
};
agentAPI.on("return", return42, createConfig(true, false, false, "meaning.*", null));
Value fourtyTwo = c.eval(sampleScript);
agentAPI.off("return", return42);
assertEquals(42, fourtyTwo.asInt());
}
}
use of com.oracle.truffle.api.exception.AbstractTruffleException in project graal by oracle.
the class InteropDefaultsTest method testExceptionDefaults.
@Test
public void testExceptionDefaults() throws UnsupportedMessageException {
Object empty = new TruffleObject() {
};
InteropLibrary emptyLib = createLibrary(InteropLibrary.class, empty);
assertFalse(emptyLib.isException(empty));
assertFalse(emptyLib.hasExceptionCause(empty));
assertFalse(emptyLib.hasExceptionMessage(empty));
assertFalse(emptyLib.hasExceptionStackTrace(empty));
assertFails(() -> emptyLib.getExceptionCause(empty), UnsupportedMessageException.class);
assertFails(() -> emptyLib.getExceptionExitStatus(empty), UnsupportedMessageException.class);
assertFails(() -> emptyLib.isExceptionIncompleteSource(empty), UnsupportedMessageException.class);
assertFails(() -> emptyLib.getExceptionMessage(empty), UnsupportedMessageException.class);
assertFails(() -> emptyLib.getExceptionStackTrace(empty), UnsupportedMessageException.class);
assertFails(() -> emptyLib.getExceptionType(empty), UnsupportedMessageException.class);
AbstractTruffleException cause = new Exception("Cause Exception");
String message = "Enclosing exception";
AbstractTruffleException exception = new Exception(message, cause);
InteropLibrary exceptionLib = createLibrary(InteropLibrary.class, exception);
assertTrue(exceptionLib.isException(exception));
assertTrue(exceptionLib.hasExceptionCause(exception));
assertTrue(exceptionLib.hasExceptionMessage(exception));
assertTrue(exceptionLib.hasExceptionStackTrace(exception));
assertEquals(cause, exceptionLib.getExceptionCause(exception));
assertEquals(message, exceptionLib.getExceptionMessage(exception));
assertEquals(ExceptionType.RUNTIME_ERROR, exceptionLib.getExceptionType(exception));
assertFalse(exceptionLib.isExceptionIncompleteSource(exception));
assertFails(() -> exceptionLib.getExceptionExitStatus(exception), UnsupportedMessageException.class);
exceptionLib.getExceptionStackTrace(exception);
LegacyCatchableException legacyCatchableException = new LegacyCatchableException(message);
InteropLibrary legacyCatchableExceptionLib = createLibrary(InteropLibrary.class, legacyCatchableException);
assertTrue(legacyCatchableExceptionLib.isException(legacyCatchableException));
assertFalse(legacyCatchableExceptionLib.hasExceptionCause(legacyCatchableException));
assertTrue(legacyCatchableExceptionLib.hasExceptionMessage(legacyCatchableException));
assertTrue(legacyCatchableExceptionLib.hasExceptionStackTrace(legacyCatchableException));
assertFails(() -> legacyCatchableExceptionLib.getExceptionCause(legacyCatchableException), UnsupportedMessageException.class);
assertEquals(message, legacyCatchableExceptionLib.getExceptionMessage(legacyCatchableException));
assertEquals(ExceptionType.RUNTIME_ERROR, legacyCatchableExceptionLib.getExceptionType(legacyCatchableException));
assertFails(() -> legacyCatchableExceptionLib.getExceptionExitStatus(legacyCatchableException), UnsupportedMessageException.class);
assertFalse(legacyCatchableExceptionLib.isExceptionIncompleteSource(legacyCatchableException));
legacyCatchableExceptionLib.getExceptionStackTrace(legacyCatchableException);
LegacyUncatchableException legacyUncatchableException = new LegacyUncatchableException();
InteropLibrary legacyUncatchableExceptionLib = createLibrary(InteropLibrary.class, legacyUncatchableException);
assertFalse(legacyUncatchableExceptionLib.isException(legacyUncatchableException));
assertFalse(legacyUncatchableExceptionLib.hasExceptionCause(legacyUncatchableException));
assertFalse(legacyUncatchableExceptionLib.hasExceptionMessage(legacyUncatchableException));
assertFalse(legacyUncatchableExceptionLib.hasExceptionStackTrace(legacyUncatchableException));
assertFails(() -> legacyUncatchableExceptionLib.getExceptionCause(legacyUncatchableException), UnsupportedMessageException.class);
assertFails(() -> legacyUncatchableExceptionLib.getExceptionMessage(legacyUncatchableException), UnsupportedMessageException.class);
assertFails(() -> legacyUncatchableExceptionLib.getExceptionType(legacyUncatchableException), UnsupportedMessageException.class);
assertFails(() -> legacyUncatchableExceptionLib.getExceptionExitStatus(legacyUncatchableException), UnsupportedMessageException.class);
assertFails(() -> legacyUncatchableExceptionLib.isExceptionIncompleteSource(legacyUncatchableException), UnsupportedMessageException.class);
assertFails(() -> legacyUncatchableExceptionLib.getExceptionStackTrace(legacyUncatchableException), UnsupportedMessageException.class);
LegacyInternalError legacyInternalError = new LegacyInternalError(message);
InteropLibrary legacyInternalErrorLib = createLibrary(InteropLibrary.class, legacyInternalError);
assertFalse(legacyInternalErrorLib.isException(legacyInternalError));
assertFalse(legacyInternalErrorLib.hasExceptionCause(legacyInternalError));
assertFalse(legacyInternalErrorLib.hasExceptionMessage(legacyInternalError));
assertFalse(legacyInternalErrorLib.hasExceptionStackTrace(legacyInternalError));
assertFails(() -> legacyInternalErrorLib.getExceptionCause(legacyInternalError), UnsupportedMessageException.class);
assertFails(() -> legacyInternalErrorLib.getExceptionMessage(legacyInternalError), UnsupportedMessageException.class);
assertFails(() -> legacyInternalErrorLib.getExceptionType(legacyInternalError), UnsupportedMessageException.class);
assertFails(() -> legacyInternalErrorLib.getExceptionExitStatus(legacyInternalError), UnsupportedMessageException.class);
assertFails(() -> legacyInternalErrorLib.isExceptionIncompleteSource(legacyInternalError), UnsupportedMessageException.class);
assertFails(() -> legacyInternalErrorLib.getExceptionStackTrace(legacyInternalError), UnsupportedMessageException.class);
}
Aggregations