Search in sources :

Example 86 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class EspressoInterop method asTime.

@ExportMessage
@TruffleBoundary
static LocalTime asTime(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
    receiver.checkNotForeign();
    if (isTime(receiver)) {
        Meta meta = receiver.getKlass().getMeta();
        if (instanceOf(receiver, meta.java_time_LocalTime)) {
            byte hour = (byte) meta.java_time_LocalTime_hour.get(receiver);
            byte minute = (byte) meta.java_time_LocalTime_minute.get(receiver);
            byte second = (byte) meta.java_time_LocalTime_second.get(receiver);
            int nano = (int) meta.java_time_LocalTime_nano.get(receiver);
            return LocalTime.of(hour, minute, second, nano);
        } else if (instanceOf(receiver, meta.java_time_LocalDateTime)) {
            StaticObject localTime = (StaticObject) meta.java_time_LocalDateTime_toLocalTime.invokeDirect(receiver);
            return asTime(localTime, error);
        } else if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
            StaticObject localTime = (StaticObject) meta.java_time_ZonedDateTime_toLocalTime.invokeDirect(receiver);
            return asTime(localTime, error);
        } else if (instanceOf(receiver, meta.java_time_Instant)) {
            // return ((Instant) obj).atZone(UTC).toLocalTime();
            StaticObject zoneIdUTC = (StaticObject) meta.java_time_ZoneId_of.invokeDirect(null, meta.toGuestString("UTC"));
            assert instanceOf(zoneIdUTC, meta.java_time_ZoneId);
            StaticObject zonedDateTime = (StaticObject) meta.java_time_Instant_atZone.invokeDirect(receiver, zoneIdUTC);
            assert instanceOf(zonedDateTime, meta.java_time_ZonedDateTime);
            StaticObject localTime = (StaticObject) meta.java_time_ZonedDateTime_toLocalTime.invokeDirect(zonedDateTime);
            assert instanceOf(localTime, meta.java_time_LocalTime);
            return asTime(localTime, error);
        } else if (instanceOf(receiver, meta.java_util_Date)) {
            // return ((Date) obj).toInstant().atZone(UTC).toLocalTime();
            int index = meta.java_util_Date_toInstant.getVTableIndex();
            Method virtualToInstant = receiver.getKlass().vtableLookup(index);
            StaticObject instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
            return asTime(instant, error);
        }
    }
    error.enter();
    throw UnsupportedMessageException.create();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 87 with Method

use of com.oracle.truffle.espresso.impl.Method 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 88 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class MapInterop method containsKey.

private static boolean containsKey(StaticObject receiver, Object key, InvokeEspressoNode invokeContains) {
    Meta meta = receiver.getKlass().getMeta();
    Method containsKey = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_containsKey.getITableIndex());
    try {
        return (boolean) invokeContains.execute(containsKey, receiver, new Object[] { key });
    } catch (UnsupportedTypeException | ArityException e) {
        throw EspressoError.shouldNotReachHere(e);
    }
}
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)

Example 89 with Method

use of com.oracle.truffle.espresso.impl.Method 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 90 with Method

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

Aggregations

Method (com.oracle.truffle.espresso.impl.Method)91 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)57 Meta (com.oracle.truffle.espresso.meta.Meta)27 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)22 Klass (com.oracle.truffle.espresso.impl.Klass)19 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)19 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)16 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)14 ExportMessage (com.oracle.truffle.api.library.ExportMessage)12 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)10 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)9 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)8 ArityException (com.oracle.truffle.api.interop.ArityException)8 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)8 ArrayList (java.util.ArrayList)8 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)7 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)5 Field (com.oracle.truffle.espresso.impl.Field)4 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)3 Signature (com.oracle.truffle.espresso.descriptors.Symbol.Signature)3