Search in sources :

Example 41 with Meta

use of com.oracle.truffle.espresso.meta.Meta 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 42 with Meta

use of com.oracle.truffle.espresso.meta.Meta 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 43 with Meta

use of com.oracle.truffle.espresso.meta.Meta 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 44 with Meta

use of com.oracle.truffle.espresso.meta.Meta 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)

Example 45 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class MapInterop method getHashEntriesIterator.

@SuppressWarnings("static-method")
@ExportMessage
public static Object getHashEntriesIterator(StaticObject receiver, @CachedLibrary(limit = "1") InteropLibrary setLibrary, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws UnsupportedMessageException {
    if (!hasHashEntries(receiver)) {
        throw UnsupportedMessageException.create();
    }
    Meta meta = receiver.getKlass().getMeta();
    Method entrySet = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_entrySet.getITableIndex());
    Object set = null;
    try {
        set = invoke.execute(entrySet, receiver, EMPTY_ARRAY);
    } catch (ArityException | UnsupportedTypeException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
    assert set != null;
    assert setLibrary.hasIterator(set);
    return setLibrary.getIterator(set);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) ArityException(com.oracle.truffle.api.interop.ArityException) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Aggregations

Meta (com.oracle.truffle.espresso.meta.Meta)82 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)29 Method (com.oracle.truffle.espresso.impl.Method)27 ExportMessage (com.oracle.truffle.api.library.ExportMessage)24 Klass (com.oracle.truffle.espresso.impl.Klass)21 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)21 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)21 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)20 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)17 ArityException (com.oracle.truffle.api.interop.ArityException)9 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)9 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)9 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)8 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)6 NativeType (com.oracle.truffle.espresso.ffi.NativeType)4 Field (com.oracle.truffle.espresso.impl.Field)4 ArrayList (java.util.ArrayList)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)3