Search in sources :

Example 11 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method removeHashEntry.

@ExportMessage
@TruffleBoundary
void removeHashEntry(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);
        guestToHostCall(library, cache.removeHashEntry, context, proxy, keyValue);
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyHashMap(org.graalvm.polyglot.proxy.ProxyHashMap) Value(org.graalvm.polyglot.Value) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 12 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method invokeMember.

@ExportMessage
@TruffleBoundary
Object invokeMember(String member, Object[] arguments, @CachedLibrary("this") InteropLibrary library, @Shared("executables") @CachedLibrary(limit = "LIMIT") InteropLibrary executables, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException, UnsupportedTypeException, ArityException, UnknownIdentifierException {
    if (proxy instanceof ProxyObject) {
        if (!isMemberExisting(member, library, cache)) {
            throw UnknownIdentifierException.create(member);
        }
        Object memberObject;
        try {
            memberObject = readMember(member, library, cache);
        } catch (UnsupportedOperationException e) {
            throw UnsupportedMessageException.create();
        }
        memberObject = context.toGuestValue(library, memberObject);
        if (executables.isExecutable(memberObject)) {
            return executables.execute(memberObject, arguments);
        } else {
            throw UnsupportedMessageException.create();
        }
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) 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 13 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method writeMember.

@ExportMessage
@TruffleBoundary
void writeMember(String member, Object value, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyObject) {
        Value castValue = context.asValue(library, value);
        guestToHostCall(library, cache.putMember, context, proxy, member, castValue);
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) Value(org.graalvm.polyglot.Value) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 14 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method execute.

@ExportMessage
@TruffleBoundary
Object execute(Object[] arguments, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyExecutable) {
        Value[] convertedArguments = context.language.access.toValues(context.internalContext, arguments);
        Object result = guestToHostCall(library, cache.execute, context, proxy, convertedArguments);
        return context.toGuestValue(library, result);
    }
    throw UnsupportedMessageException.create();
}
Also used : ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) 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 15 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method getMembers.

@ExportMessage
@TruffleBoundary
Object getMembers(@SuppressWarnings("unused") boolean includeInternal, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyObject) {
        Object result = guestToHostCall(library, cache.memberKeys, context, proxy);
        if (result == null) {
            result = EMPTY;
        }
        Object guestValue = context.toGuestValue(library, result);
        InteropLibrary interop = InteropLibrary.getFactory().getUncached();
        if (!interop.hasArrayElements(guestValue)) {
            if (guestValue instanceof HostObject) {
                HostObject hostObject = (HostObject) guestValue;
                if (hostObject.obj.getClass().isArray() && !hostObject.getHostClassCache().isArrayAccess()) {
                    throw illegalProxy(context, "getMemberKeys() returned a Java array %s, but allowArrayAccess in HostAccess is false.", context.asValue(library, guestValue).toString());
                } else if (hostObject.obj instanceof List && !hostObject.getHostClassCache().isListAccess()) {
                    throw illegalProxy(context, "getMemberKeys() returned a Java List %s, but allowListAccess in HostAccess is false.", context.asValue(library, guestValue).toString());
                }
            }
            throw illegalProxy(context, "getMemberKeys() returned invalid value %s but must return an array of member key Strings.", context.asValue(library, guestValue).toString());
        }
        // Todo: Use interop to determine an array element type when the GR-5737 is resolved.
        for (int i = 0; i < interop.getArraySize(guestValue); i++) {
            try {
                Object element = interop.readArrayElement(guestValue, i);
                if (!interop.isString(element)) {
                    throw illegalProxy(context, "getMemberKeys() returned invalid value %s but must return an array of member key Strings.", context.asValue(library, guestValue).toString());
                }
            } catch (UnsupportedOperationException e) {
                CompilerDirectives.shouldNotReachHere(e);
            } catch (InvalidArrayIndexException e) {
                continue;
            }
        }
        return guestValue;
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyNativeObject(org.graalvm.polyglot.proxy.ProxyNativeObject) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) List(java.util.List) 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