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);
}
}
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();
}
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));
}
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;
}
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();
}
Aggregations