use of com.oracle.truffle.api.library.ExportMessage 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);
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInstrumentableNode method getScope.
@ExportMessage
@TruffleBoundary
@SuppressWarnings("static-method")
public final Object getScope(Frame frame, @SuppressWarnings("unused") boolean nodeEnter) {
// construct the current scope with valid local variables information
Method method = getMethod();
Local[] liveLocals = method.getLocalVariableTable().getLocalsAt(getBci(frame));
if (liveLocals.length == 0) {
// class was compiled without a local variable table
// include "this" in method arguments throughout the method
boolean hasReceiver = !method.isStatic();
int localCount = hasReceiver ? 1 : 0;
localCount += method.getParameterCount();
liveLocals = new Local[localCount];
Klass[] parameters = (Klass[]) method.getParameters();
Utf8ConstantTable utf8Constants = getContext().getLanguage().getUtf8ConstantTable();
int startslot = 0;
if (hasReceiver) {
// include 'this' and method arguments
liveLocals[0] = new Local(utf8Constants.getOrCreate(Symbol.Name.thiz), utf8Constants.getOrCreate(method.getDeclaringKlass().getType()), 0, 65536, 0);
startslot++;
}
// include method parameters
for (int i = startslot; i < localCount; i++) {
Klass param = hasReceiver ? parameters[i - 1] : parameters[i];
liveLocals[i] = new Local(utf8Constants.getOrCreate(ByteSequence.create("param_" + (i))), utf8Constants.getOrCreate(param.getType()), 0, 65536, i);
}
}
return EspressoScope.createVariables(liveLocals, frame, method.getName());
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class Klass method writeMember.
@ExportMessage
final void writeMember(String member, Object value, @Shared("lookupField") @Cached LookupFieldNode lookupFieldNode, @Shared("error") @Cached BranchProfile error, @Exclusive @Cached ToEspressoNode toEspressoNode) throws UnknownIdentifierException, UnsupportedTypeException {
Field field = lookupFieldNode.execute(this, member, true);
// Can only write to non-final fields.
if (field != null && !field.isFinalFlagSet()) {
Object espressoValue = toEspressoNode.execute(value, field.resolveTypeKlass());
field.set(tryInitializeAndGetStatics(), espressoValue);
} else {
error.enter();
throw UnknownIdentifierException.create(member);
}
}
use of com.oracle.truffle.api.library.ExportMessage 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.api.library.ExportMessage 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;
}
Aggregations