Search in sources :

Example 51 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class MapEntryInterop method writeArrayElement.

@ExportMessage
public static void writeArrayElement(StaticObject receiver, long index, Object value, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws InvalidArrayIndexException {
    if (index != 1) {
        throw InvalidArrayIndexException.create(index);
    }
    Meta meta = receiver.getKlass().getMeta();
    Method m = doLookup(receiver, meta.java_util_Map_Entry, meta.java_util_Map_Entry_setValue);
    try {
        invoke.execute(m, receiver, new Object[] { value });
    } catch (ArityException | UnsupportedTypeException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Method(com.oracle.truffle.espresso.impl.Method) ArityException(com.oracle.truffle.api.interop.ArityException) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 52 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class MapInterop method writeHashEntry.

@ExportMessage
public static void writeHashEntry(StaticObject receiver, Object key, Object value, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws UnknownKeyException {
    Meta meta = receiver.getKlass().getMeta();
    Method put = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_put.getITableIndex());
    try {
        invoke.execute(put, receiver, new Object[] { key, value });
    } catch (UnsupportedTypeException e) {
        throw UnknownKeyException.create(key);
    } catch (ArityException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Method(com.oracle.truffle.espresso.impl.Method) ArityException(com.oracle.truffle.api.interop.ArityException) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 53 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class MapInterop method readHashValue.

@ExportMessage
public static Object readHashValue(StaticObject receiver, Object key, @Cached.Exclusive @Cached InvokeEspressoNode invoke, @Cached.Shared("contains") @Cached InvokeEspressoNode contains) throws UnsupportedMessageException, UnknownKeyException {
    if (!isHashEntryReadable(receiver, key, contains)) {
        throw UnsupportedMessageException.create();
    }
    Meta meta = receiver.getKlass().getMeta();
    Method get = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_get.getITableIndex());
    try {
        return invoke.execute(get, receiver, new Object[] { key });
    } catch (UnsupportedTypeException e) {
        throw UnknownKeyException.create(key);
    } catch (ArityException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Method(com.oracle.truffle.espresso.impl.Method) ArityException(com.oracle.truffle.api.interop.ArityException) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 54 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class MapInterop method getHashSize.

@ExportMessage
public static long getHashSize(StaticObject receiver, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws UnsupportedMessageException {
    if (!hasHashEntries(receiver)) {
        throw UnsupportedMessageException.create();
    }
    Meta meta = receiver.getKlass().getMeta();
    Method size = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_size.getITableIndex());
    try {
        return (int) invoke.execute(size, receiver, EMPTY_ARRAY);
    } catch (UnsupportedTypeException | ArityException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Method(com.oracle.truffle.espresso.impl.Method) ArityException(com.oracle.truffle.api.interop.ArityException) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 55 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class LLVMVaListStorage method invokeMember.

@ExportMessage
public Object invokeMember(String member, Object[] arguments, @Cached.Shared("escapeNode") @Cached LLVMPointerDataEscapeNode pointerEscapeNode) throws ArityException, UnknownIdentifierException, UnsupportedTypeException {
    if (GET_MEMBER.equals(member)) {
        if (arguments.length == 2) {
            if (!(arguments[0] instanceof Integer)) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                throw UnsupportedTypeException.create(new Object[] { arguments[0] }, "Index argument must be an integer");
            }
            int i = (Integer) arguments[0];
            if (i >= realArguments.length - numberOfExplicitArguments) {
                CompilerDirectives.transferToInterpreterAndInvalidate();
                throw new ArrayIndexOutOfBoundsException(i);
            }
            Object arg = realArguments[numberOfExplicitArguments + i];
            if (!(arguments[1] instanceof LLVMInteropType.Structured)) {
                return arg;
            }
            LLVMInteropType.Structured type = (LLVMInteropType.Structured) arguments[1];
            if (!LLVMPointer.isInstance(arg)) {
                // arg's types
                return arg;
            }
            LLVMPointer ptrArg = LLVMPointer.cast(arg);
            return pointerEscapeNode.executeWithType(ptrArg, type);
        } else {
            throw ArityException.create(2, 2, arguments.length);
        }
    }
    throw UnknownIdentifierException.create(member);
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMInteropType(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Aggregations

ExportMessage (com.oracle.truffle.api.library.ExportMessage)68 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)24 Meta (com.oracle.truffle.espresso.meta.Meta)24 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 Method (com.oracle.truffle.espresso.impl.Method)13 ByteBuffer (java.nio.ByteBuffer)10 ByteOrder (java.nio.ByteOrder)10 Klass (com.oracle.truffle.espresso.impl.Klass)8 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)8 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)8 Value (org.graalvm.polyglot.Value)8 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)8 ArityException (com.oracle.truffle.api.interop.ArityException)7 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)7 ProxyNativeObject (org.graalvm.polyglot.proxy.ProxyNativeObject)7 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)6 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 Field (com.oracle.truffle.espresso.impl.Field)4 ProxyHashMap (org.graalvm.polyglot.proxy.ProxyHashMap)4