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, ""));
}
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");
}
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"));
}
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 */
}
}
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);
}
Aggregations