use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoBindings method readMember.
@ExportMessage
Object readMember(String member, @CachedLibrary("this") InteropLibrary self, @Exclusive @Cached BranchProfile error) throws UnknownIdentifierException {
if (!isMemberReadable(member)) {
error.enter();
throw UnknownIdentifierException.create(member);
}
EspressoContext context = EspressoContext.get(self);
if (withNativeJavaVM && JAVA_VM.equals(member)) {
return context.getVM().getJavaVM();
}
Meta meta = context.getMeta();
try {
StaticObject clazz = (StaticObject) meta.java_lang_Class_forName_String_boolean_ClassLoader.invokeDirect(null, meta.toGuestString(member), false, loader);
return clazz.getMirrorKlass();
} catch (EspressoException e) {
error.enter();
if (InterpreterToVM.instanceOf(e.getGuestException(), meta.java_lang_ClassNotFoundException)) {
throw UnknownIdentifierException.create(member, e);
}
// exception during class loading
throw e;
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class Klass method getMembers.
@TruffleBoundary
@ExportMessage
final Object getMembers(@SuppressWarnings("unused") boolean includeInternal) {
EconomicSet<String> members = EconomicSet.create();
members.add(STATIC_TO_CLASS);
members.add(CLASS_TO_STATIC);
for (Method m : getDeclaredMethods()) {
if (m.isStatic() && m.isPublic()) {
members.add(m.getName().toString());
}
}
if (getMeta()._void != this) {
members.add(ARRAY);
}
if (isArray()) {
members.add(COMPONENT);
}
if (getSuperKlass() != null) {
members.add(SUPER);
}
for (Field f : getDeclaredFields()) {
if (f.isPublic() && f.isStatic()) {
members.add(f.getNameAsString());
}
}
return new KeysArray(members.toArray(new String[members.size()]));
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class Klass method readMember.
@ExportMessage
Object readMember(String member, @Shared("lookupField") @Cached LookupFieldNode lookupFieldNode, @Shared("error") @Cached BranchProfile error) throws UnknownIdentifierException {
Field field = lookupFieldNode.execute(this, member, true);
if (field != null) {
Object result = field.get(this.tryInitializeAndGetStatics());
if (result instanceof StaticObject && ((StaticObject) result).isForeignObject()) {
return ((StaticObject) result).rawForeignObject();
}
return result;
}
// Klass<T>.class == Class<T>
if (STATIC_TO_CLASS.equals(member)) {
return mirror();
}
// Klass<T>.static == Klass<T>
if (CLASS_TO_STATIC.equals(member)) {
return this;
}
if (getMeta()._void != this && ARRAY.equals(member)) {
return array();
}
if (isArray() && COMPONENT.equals(member)) {
return ((ArrayKlass) this).getComponentType();
}
if (getSuperKlass() != null && SUPER.equals(member)) {
return getSuperKlass();
}
error.enter();
throw UnknownIdentifierException.create(member);
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostProxy method readHashValue.
@ExportMessage
@TruffleBoundary
Object readHashValue(Object key, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException, UnknownKeyException {
if (proxy instanceof ProxyHashMap) {
if (!isHashValueExisting(key, library, cache)) {
throw UnknownKeyException.create(key);
}
Value keyValue = context.asValue(library, key);
Object result = guestToHostCall(library, cache.getHashValue, context, proxy, keyValue);
return context.toGuestValue(library, result);
} else {
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostProxy method instantiate.
@ExportMessage
@TruffleBoundary
Object instantiate(Object[] arguments, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
if (proxy instanceof ProxyInstantiable) {
Value[] convertedArguments = cache.language.access.toValues(context.internalContext, arguments);
Object result = guestToHostCall(library, cache.instantiate, context, proxy, convertedArguments);
return context.toGuestValue(library, result);
}
throw UnsupportedMessageException.create();
}
Aggregations