Search in sources :

Example 36 with Meta

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

the class EspressoInterop method asInstant.

@ExportMessage
@TruffleBoundary
static Instant asInstant(StaticObject receiver, @CachedLibrary("receiver") InteropLibrary receiverLibrary, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
    receiver.checkNotForeign();
    if (receiverLibrary.isInstant(receiver)) {
        StaticObject instant;
        Meta meta = receiver.getKlass().getMeta();
        if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
            instant = (StaticObject) meta.java_time_ZonedDateTime_toInstant.invokeDirect(receiver);
        } else if (instanceOf(receiver, meta.java_util_Date)) {
            int index = meta.java_util_Date_toInstant.getVTableIndex();
            Method virtualToInstant = receiver.getKlass().vtableLookup(index);
            instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
        } else {
            instant = receiver;
        }
        assert instanceOf(instant, meta.java_time_Instant);
        long seconds = (long) meta.java_time_Instant_seconds.get(instant);
        int nanos = (int) meta.java_time_Instant_nanos.get(instant);
        return Instant.ofEpochSecond(seconds, nanos);
    }
    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 37 with Meta

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

the class EspressoInterop method fitsInByte.

@ExportMessage
static boolean fitsInByte(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    if (isAtMostByte(klass)) {
        return true;
    }
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Short) {
        short content = meta.java_lang_Short_value.getShort(receiver);
        return (byte) content == content;
    }
    if (klass == meta.java_lang_Integer) {
        int content = meta.java_lang_Integer_value.getInt(receiver);
        return (byte) content == content;
    }
    if (klass == meta.java_lang_Long) {
        long content = meta.java_lang_Long_value.getLong(receiver);
        return (byte) content == content;
    }
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return (byte) content == content && !isNegativeZero(content);
    }
    if (klass == meta.java_lang_Double) {
        double content = meta.java_lang_Double_value.getDouble(receiver);
        return (byte) content == content && !isNegativeZero(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 38 with Meta

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

the class EspressoInterop method fitsInLong.

@ExportMessage
static boolean fitsInLong(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    if (isAtMostLong(klass)) {
        return true;
    }
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (long) content == content;
    }
    if (klass == meta.java_lang_Double) {
        double content = meta.java_lang_Double_value.getDouble(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (long) 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 39 with Meta

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

the class EspressoInterop method fitsInInt.

@ExportMessage
static boolean fitsInInt(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    if (isAtMostInt(klass)) {
        return true;
    }
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Long) {
        long content = meta.java_lang_Long_value.getLong(receiver);
        return (int) content == content;
    }
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (int) content == content;
    }
    if (klass == meta.java_lang_Double) {
        double content = meta.java_lang_Double_value.getDouble(receiver);
        return (int) content == content && !isNegativeZero(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 40 with Meta

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

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