Search in sources :

Example 76 with InteropLibrary

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

the class InteropLibraryBaseTest method assertNoArray.

protected final void assertNoArray(Object value) {
    InteropLibrary lib = createLibrary(InteropLibrary.class, value);
    assertFalse(lib.hasArrayElements(value));
    assertFalse(lib.isArrayElementInsertable(value, 0L));
    assertFalse(lib.isArrayElementModifiable(value, 0L));
    assertFalse(lib.isArrayElementReadable(value, 0L));
    assertFalse(lib.isArrayElementRemovable(value, 0L));
    assertUnsupported(() -> lib.readArrayElement(value, 0));
    assertUnsupported(() -> lib.getArraySize(value));
    assertUnsupported(() -> lib.removeArrayElement(value, 0));
    assertUnsupported(() -> lib.writeArrayElement(value, 0, ""));
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary)

Example 77 with InteropLibrary

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

the class SpecializationSlowPathOnlyModeTest method testNoFastPathIsExecutedWithLibrary.

@Test
public void testNoFastPathIsExecutedWithLibrary() throws InvalidArrayIndexException, UnsupportedMessageException, UnsupportedTypeException {
    SpecializationTestingTruffleObj obj = new SpecializationTestingTruffleObj();
    InteropLibrary lib = InteropLibrary.getUncached(obj);
    assertTrue(lib.isArrayElementRemovable(obj, 1));
    assertEquals("generic", lib.readArrayElement(obj, 0));
    lib.writeArrayElement(obj, 0, "dummy");
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Example 78 with InteropLibrary

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

the class MergedLibraryTest method testMembers.

@Test
public void testMembers() throws UnsupportedMessageException, UnknownIdentifierException, UnsupportedTypeException {
    Shape shape = Shape.newBuilder().build();
    DynamicObject obj = new MyObject(shape);
    InteropLibrary interop = adopt(InteropLibrary.getFactory().create(obj));
    assertTrue(interop.accepts(obj));
    assertTrue(interop.isMemberInsertable(obj, "key"));
    interop.writeMember(obj, "key", "value");
    assertTrue(interop.isMemberReadable(obj, "key"));
    assertEquals("value", interop.readMember(obj, "key"));
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) AbstractLibraryTest(com.oracle.truffle.api.test.AbstractLibraryTest) Test(org.junit.Test)

Example 79 with InteropLibrary

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

the class VM method processCallBackResult.

/**
 * Registers this known VM method's function pointer. Later native method bindings can perform a
 * lookup when trying to bind to a function pointer, and if a match happens, this is a known VM
 * method, and we can link directly to it thus bypassing native calls.
 *
 * @param name The name of the VM method, previously extracted from {@code args[0]}.
 * @param factory The node factory of the requested VM method.
 * @param args A length {@linkplain #lookupCallBackArgsCount() 2} arguments array: At position 0
 *            is a native pointer to the name of the method. At position 1 is the address of the
 *            {@code JVM_*} symbol exported by {@code mokapot}.
 */
@Override
@TruffleBoundary
protected void processCallBackResult(String name, CallableFromNative.Factory factory, Object... args) {
    assert args.length == lookupCallBackArgsCount();
    try {
        InteropLibrary uncached = InteropLibrary.getUncached();
        Object ptr = args[1];
        if (factory != null && !uncached.isNull(ptr) && uncached.isPointer(ptr)) {
            long jvmMethodAddress = uncached.asPointer(ptr);
            knownVmMethods.put(jvmMethodAddress, factory);
        }
    } catch (UnsupportedMessageException e) {
    /* Ignore */
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 80 with InteropLibrary

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

the class JavaMemberOffsetGetter method buildInfos.

private static Map<String, Long> buildInfos(JniEnv jni, Structs structs, TruffleObject info) {
    Map<String, Long> map = new HashMap<>();
    InteropLibrary library = InteropLibrary.getUncached();
    assert !library.isNull(info);
    TruffleObject current = NativeUtils.dereferencePointerPointer(library, info);
    while (!library.isNull(current)) {
        MemberInfo.MemberInfoWrapper wrapper = structs.memberInfo.wrap(jni, current);
        long offset = wrapper.offset();
        String str = NativeUtils.interopPointerToString(wrapper.id());
        map.put(str, offset);
        current = wrapper.next();
    }
    return Collections.unmodifiableMap(map);
}
Also used : HashMap(java.util.HashMap) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Aggregations

InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)158 Test (org.junit.Test)76 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)60 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)51 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)18 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)18 ArityException (com.oracle.truffle.api.interop.ArityException)16 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)15 WasmInstance (org.graalvm.wasm.WasmInstance)15 WebAssembly (org.graalvm.wasm.api.WebAssembly)15 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)12 RootNode (com.oracle.truffle.api.nodes.RootNode)12 InteropException (com.oracle.truffle.api.interop.InteropException)11 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)11 Dictionary (org.graalvm.wasm.api.Dictionary)8 SourceSection (com.oracle.truffle.api.source.SourceSection)6 CallTarget (com.oracle.truffle.api.CallTarget)5 Node (com.oracle.truffle.api.nodes.Node)5 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)5 WasmJsApiException (org.graalvm.wasm.exception.WasmJsApiException)5