Search in sources :

Example 66 with Meta

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

the class Target_java_lang_ref_Reference method init.

@Substitution(hasReceiver = true, methodName = "<init>")
public static void init(@JavaType(Reference.class) StaticObject self, @JavaType(Object.class) StaticObject referent, @JavaType(ReferenceQueue.class) StaticObject queue, @Inject EspressoContext context) {
    // Guest referent field is ignored for weak/soft/final/phantom references.
    EspressoReference ref = null;
    Meta meta = context.getMeta();
    if (InterpreterToVM.instanceOf(self, meta.java_lang_ref_WeakReference)) {
        ref = EspressoReference.createWeak(context, self, referent);
    } else if (InterpreterToVM.instanceOf(self, meta.java_lang_ref_SoftReference)) {
        ref = EspressoReference.createSoft(context, self, referent);
    } else if (InterpreterToVM.instanceOf(self, meta.java_lang_ref_FinalReference)) {
        ref = EspressoReference.createFinal(context, self, referent);
    } else if (InterpreterToVM.instanceOf(self, meta.java_lang_ref_PhantomReference)) {
        ref = EspressoReference.createPhantom(context, self, referent);
    }
    if (ref != null) {
        // Weak/Soft/Final/Phantom reference.
        meta.HIDDEN_HOST_REFERENCE.setHiddenObject(self, ref);
    } else {
        // Strong reference.
        meta.java_lang_ref_Reference_referent.set(self, referent);
    }
    if (StaticObject.isNull(queue)) {
        meta.java_lang_ref_Reference_queue.set(self, meta.java_lang_ref_ReferenceQueue_NULL.get(meta.java_lang_ref_ReferenceQueue.tryInitializeAndGetStatics()));
    } else {
        meta.java_lang_ref_Reference_queue.set(self, queue);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference)

Example 67 with Meta

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

the class StaticObject method toString.

@TruffleBoundary
@Override
public final String toString() {
    if (this == NULL) {
        return "null";
    }
    if (isForeignObject()) {
        return "foreign object: " + getKlass().getTypeAsString();
    }
    if (getKlass() == getKlass().getMeta().java_lang_String) {
        Meta meta = getKlass().getMeta();
        StaticObject value = meta.java_lang_String_value.getObject(this);
        if (value == null || isNull(value)) {
            // Prevents debugger crashes when trying to inspect a string in construction.
            return "<UNINITIALIZED>";
        }
        return Meta.toHostStringStatic(this);
    }
    if (isArray()) {
        return unwrap().toString();
    }
    if (getKlass() == getKlass().getMeta().java_lang_Class) {
        return "mirror: " + getMirrorKlass().toString();
    }
    return getKlass().getType().toString();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 68 with Meta

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

the class BaseInterop method toDisplayString.

@ExportMessage
@TruffleBoundary
public static Object toDisplayString(StaticObject object, boolean allowSideEffects) {
    if (object.isForeignObject()) {
        InteropLibrary interopLibrary = InteropLibrary.getUncached();
        try {
            return "Foreign object: " + interopLibrary.asString(interopLibrary.toDisplayString(object.rawForeignObject(), allowSideEffects));
        } catch (UnsupportedMessageException e) {
            throw EspressoError.shouldNotReachHere("Interop library failed to convert display string to string");
        }
    }
    if (StaticObject.isNull(object)) {
        return "NULL";
    }
    Klass thisKlass = object.getKlass();
    Meta meta = thisKlass.getMeta();
    if (allowSideEffects) {
        // Call guest toString.
        int toStringIndex = meta.java_lang_Object_toString.getVTableIndex();
        Method toString = thisKlass.vtableLookup(toStringIndex);
        return meta.toHostString((StaticObject) toString.invokeDirect(object));
    }
    // Handle some special instances without side effects.
    if (thisKlass == meta.java_lang_Class) {
        return "class " + thisKlass.getTypeAsString();
    }
    if (thisKlass == meta.java_lang_String) {
        return meta.toHostString(object);
    }
    return thisKlass.getTypeAsString() + "@" + Integer.toHexString(System.identityHashCode(object));
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Method(com.oracle.truffle.espresso.impl.Method) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 69 with Meta

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

the class EspressoInterop method fitsInShort.

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

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

the class EspressoInterop method asDate.

@ExportMessage
@TruffleBoundary
static LocalDate asDate(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
    receiver.checkNotForeign();
    if (isDate(receiver)) {
        Meta meta = receiver.getKlass().getMeta();
        if (instanceOf(receiver, meta.java_time_LocalDate)) {
            int year = (int) meta.java_time_LocalDate_year.get(receiver);
            short month = (short) meta.java_time_LocalDate_month.get(receiver);
            short day = (short) meta.java_time_LocalDate_day.get(receiver);
            return LocalDate.of(year, month, day);
        } else if (instanceOf(receiver, meta.java_time_LocalDateTime)) {
            StaticObject localDate = (StaticObject) meta.java_time_LocalDateTime_toLocalDate.invokeDirect(receiver);
            assert instanceOf(localDate, meta.java_time_LocalDate);
            return asDate(localDate, error);
        } else if (instanceOf(receiver, meta.java_time_Instant)) {
            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 localDate = (StaticObject) meta.java_time_ZonedDateTime_toLocalDate.invokeDirect(zonedDateTime);
            assert instanceOf(localDate, meta.java_time_LocalDate);
            return asDate(localDate, error);
        } else if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
            StaticObject localDate = (StaticObject) meta.java_time_ZonedDateTime_toLocalDate.invokeDirect(receiver);
            assert instanceOf(localDate, meta.java_time_LocalDate);
            return asDate(localDate, error);
        } else if (instanceOf(receiver, meta.java_util_Date)) {
            // return ((Date) obj).toInstant().atZone(UTC).toLocalDate();
            int index = meta.java_util_Date_toInstant.getVTableIndex();
            Method virtualToInstant = receiver.getKlass().vtableLookup(index);
            StaticObject instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
            return asDate(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)

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