Search in sources :

Example 1 with ProxyHashMap

use of org.graalvm.polyglot.proxy.ProxyHashMap 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 2 with ProxyHashMap

use of org.graalvm.polyglot.proxy.ProxyHashMap 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 3 with ProxyHashMap

use of org.graalvm.polyglot.proxy.ProxyHashMap in project graal by oracle.

the class HostProxy method getHashEntriesIterator.

@ExportMessage
@TruffleBoundary
Object getHashEntriesIterator(@CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyHashMap) {
        Object result = guestToHostCall(library, cache.getHashEntriesIterator, context, proxy);
        Object guestValue = context.toGuestValue(library, result);
        InteropLibrary interop = InteropLibrary.getFactory().getUncached();
        if (!interop.isIterator(guestValue)) {
            throw illegalProxy(context, "getHashEntriesIterator() returned an invalid value %s but must return an iterator.", context.asValue(library, guestValue).toString());
        }
        return guestValue;
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyHashMap(org.graalvm.polyglot.proxy.ProxyHashMap) 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) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 4 with ProxyHashMap

use of org.graalvm.polyglot.proxy.ProxyHashMap in project graal by oracle.

the class HostProxy method writeHashEntry.

@ExportMessage
@TruffleBoundary
void writeHashEntry(Object key, Object value, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyHashMap) {
        Value keyValue = this.context.asValue(library, key);
        Value valueValue = this.context.asValue(library, value);
        guestToHostCall(library, cache.putHashEntry, this.context, proxy, keyValue, valueValue);
    } 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)

Aggregations

TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)4 ExportMessage (com.oracle.truffle.api.library.ExportMessage)4 ProxyHashMap (org.graalvm.polyglot.proxy.ProxyHashMap)4 Value (org.graalvm.polyglot.Value)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 ProxyNativeObject (org.graalvm.polyglot.proxy.ProxyNativeObject)2 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)2 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)1