Search in sources :

Example 6 with UnknownIdentifierException

use of com.oracle.truffle.api.interop.UnknownIdentifierException in project graal by oracle.

the class ValidTruffleObject15Test method expectUnsupportedSpecializationException.

@Test(expected = UnsupportedSpecializationException.class)
public void expectUnsupportedSpecializationException() {
    ValidTruffleObject15 object = new ValidTruffleObject15();
    Node read = Message.WRITE.createNode();
    try {
        ForeignAccess.sendWrite(read, object, "name", new UnknownObject());
    } catch (UnknownIdentifierException e) {
        Assert.fail();
    } catch (UnsupportedMessageException e) {
        Assert.fail();
    } catch (UnsupportedTypeException e) {
        Assert.fail();
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) Node(com.oracle.truffle.api.nodes.Node) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Test(org.junit.Test)

Example 7 with UnknownIdentifierException

use of com.oracle.truffle.api.interop.UnknownIdentifierException in project graal by oracle.

the class TestMemberAccess method testMethods.

@Test
public void testMethods() throws InvocationTargetException, IllegalAccessException, InteropException {
    TestClass t = new TestClass();
    Method[] methods = t.getClass().getDeclaredMethods();
    for (Method m : methods) {
        if (m.getParameterCount() == 0) {
            m.setAccessible(true);
            String name = m.getName();
            if (name.startsWith("method")) {
                boolean isPublic = (m.getModifiers() & Modifier.PUBLIC) != 0;
                boolean wasUIE = false;
                try {
                    testForValue(name, m.invoke(t));
                } catch (UnknownIdentifierException e) {
                    if (isPublic) {
                        throw e;
                    }
                    wasUIE = true;
                }
                if (!isPublic && !wasUIE) {
                    fail("expected UnknownIdentifierException when accessing method: " + name);
                }
            }
        }
    }
}
Also used : UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 8 with UnknownIdentifierException

use of com.oracle.truffle.api.interop.UnknownIdentifierException in project graal by oracle.

the class TestMemberAccess method getValueFromMember.

private Object getValueFromMember(Class<?> javaClazz, String name, Object... parameters) throws InteropException {
    TruffleObject clazz = JavaInterop.asTruffleObject(javaClazz);
    Object o = ForeignAccess.sendNew(newNode, clazz);
    try {
        o = ForeignAccess.sendRead(readNode, (TruffleObject) o, name);
    } catch (UnknownIdentifierException e) {
        o = ForeignAccess.sendRead(readNode, clazz, name);
    }
    if (o instanceof TruffleObject && ForeignAccess.sendIsExecutable(isExecutableNode, (TruffleObject) o)) {
        o = ForeignAccess.sendExecute(executeNode, (TruffleObject) o, parameters);
    }
    if (o instanceof TruffleObject && ForeignAccess.sendIsBoxed(isBoxedNode, (TruffleObject) o)) {
        o = ForeignAccess.sendUnbox(unboxNode, (TruffleObject) o);
    }
    return o;
}
Also used : UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 9 with UnknownIdentifierException

use of com.oracle.truffle.api.interop.UnknownIdentifierException in project graal by oracle.

the class VisibilityTest method invokeRun.

private static Object invokeRun(Object obj, Class<?> methodClass, Object... args) throws InteropException {
    TruffleObject receiver = JavaInterop.asTruffleObject(obj);
    try {
        Object result = ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), receiver, "run", args);
        Assert.assertSame(methodClass, run);
        return result;
    } catch (UnknownIdentifierException uie) {
        Assert.assertSame(methodClass, null);
        Assert.assertNull(run);
        return null;
    } finally {
        run = null;
    }
}
Also used : UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 10 with UnknownIdentifierException

use of com.oracle.truffle.api.interop.UnknownIdentifierException in project sulong by graalvm.

the class LLVMTruffleInvoke method doInvoke.

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

UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)11 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)8 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)6 Test (org.junit.Test)6 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)4 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)3 Specialization (com.oracle.truffle.api.dsl.Specialization)2 CallTarget (com.oracle.truffle.api.CallTarget)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 TruffleContext (com.oracle.truffle.api.TruffleContext)1 TruffleException (com.oracle.truffle.api.TruffleException)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 ArityException (com.oracle.truffle.api.interop.ArityException)1 InteropException (com.oracle.truffle.api.interop.InteropException)1 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)1 Node (com.oracle.truffle.api.nodes.Node)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 LanguageContext (com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext)1 ValueHostInteropTest (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1