Search in sources :

Example 6 with ExportMessage

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;
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 7 with ExportMessage

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()]));
}
Also used : LookupDeclaredMethod(com.oracle.truffle.espresso.nodes.interop.LookupDeclaredMethod) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 8 with ExportMessage

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);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 9 with ExportMessage

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();
    }
}
Also used : ProxyHashMap(org.graalvm.polyglot.proxy.ProxyHashMap) Value(org.graalvm.polyglot.Value) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyNativeObject(org.graalvm.polyglot.proxy.ProxyNativeObject) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 10 with ExportMessage

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();
}
Also used : ProxyInstantiable(org.graalvm.polyglot.proxy.ProxyInstantiable) Value(org.graalvm.polyglot.Value) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyNativeObject(org.graalvm.polyglot.proxy.ProxyNativeObject) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

ExportMessage (com.oracle.truffle.api.library.ExportMessage)68 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)24 Meta (com.oracle.truffle.espresso.meta.Meta)24 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 Method (com.oracle.truffle.espresso.impl.Method)13 ByteBuffer (java.nio.ByteBuffer)10 ByteOrder (java.nio.ByteOrder)10 Klass (com.oracle.truffle.espresso.impl.Klass)8 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)8 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)8 Value (org.graalvm.polyglot.Value)8 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)8 ArityException (com.oracle.truffle.api.interop.ArityException)7 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)7 ProxyNativeObject (org.graalvm.polyglot.proxy.ProxyNativeObject)7 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)6 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 Field (com.oracle.truffle.espresso.impl.Field)4 ProxyHashMap (org.graalvm.polyglot.proxy.ProxyHashMap)4