Search in sources :

Example 31 with ExportMessage

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

the class EspressoInterop method isTime.

@ExportMessage
static boolean isTime(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Meta meta = receiver.getKlass().getMeta();
    return instanceOf(receiver, meta.java_time_LocalTime) || instanceOf(receiver, meta.java_time_Instant) || instanceOf(receiver, meta.java_time_ZonedDateTime) || instanceOf(receiver, meta.java_util_Date);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 32 with ExportMessage

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

the class EspressoInterop method asDuration.

@ExportMessage
static Duration asDuration(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
    receiver.checkNotForeign();
    if (isDuration(receiver)) {
        Meta meta = receiver.getKlass().getMeta();
        // Avoid expensive calls to Duration.{getSeconds/getNano} by extracting the private
        // fields directly.
        long seconds = (long) meta.java_time_Duration_seconds.get(receiver);
        int nanos = (int) meta.java_time_Duration_nanos.get(receiver);
        return Duration.ofSeconds(seconds, nanos);
    }
    error.enter();
    throw UnsupportedMessageException.create();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 33 with ExportMessage

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

the class EspressoInterop method fitsInDouble.

@ExportMessage
static boolean fitsInDouble(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    Meta meta = klass.getMeta();
    if (isAtMostInt(klass) || klass == meta.java_lang_Double) {
        return true;
    }
    if (klass == meta.java_lang_Long) {
        long content = meta.java_lang_Long_value.getLong(receiver);
        double doubleContent = content;
        return (long) doubleContent == content;
    }
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return !Float.isFinite(content) || (double) content == content;
    }
    return false;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 34 with ExportMessage

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

the class MapEntryInterop method readArrayElement.

@ExportMessage
public static Object readArrayElement(StaticObject receiver, long index, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws InvalidArrayIndexException {
    Meta meta = receiver.getKlass().getMeta();
    Method m;
    if (index == 0) {
        m = doLookup(receiver, meta.java_util_Map_Entry, meta.java_util_Map_Entry_getKey);
    } else if (index == 1) {
        m = doLookup(receiver, meta.java_util_Map_Entry, meta.java_util_Map_Entry_getValue);
    } else {
        throw InvalidArrayIndexException.create(index);
    }
    try {
        return invoke.execute(m, receiver, EMPTY_ARRAY);
    } 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 35 with ExportMessage

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

the class MapInterop method removeHashEntry.

@ExportMessage
public static void removeHashEntry(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 remove = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_remove.getITableIndex());
    try {
        invoke.execute(remove, 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)

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