Search in sources :

Example 6 with InvalidArrayIndexException

use of com.oracle.truffle.api.interop.InvalidArrayIndexException in project graal by oracle.

the class TruffleObject2JSON method fromArray.

static JSONArray fromArray(TruffleObject array) {
    JSONArray json = new JSONArray();
    long size;
    try {
        size = INTEROP.getArraySize(array);
    } catch (UnsupportedMessageException ex) {
        return json;
    }
    if (size > 0) {
        for (long i = 0; i < size; i++) {
            try {
                Object value = INTEROP.readArrayElement(array, i);
                json.put((int) i, from(value));
            } catch (UnsupportedMessageException | InvalidArrayIndexException ex) {
                // ignore that element
                break;
            }
        }
    }
    return json;
}
Also used : InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 7 with InvalidArrayIndexException

use of com.oracle.truffle.api.interop.InvalidArrayIndexException in project graal by oracle.

the class PolyglotArrayTestBase method polyglotArrayToJavaArray.

protected static Object[] polyglotArrayToJavaArray(Object expected) {
    try {
        InteropLibrary expectedInterop = InteropLibrary.getUncached(expected);
        int length = Math.toIntExact(expectedInterop.getArraySize(expected));
        Object[] array = new Object[length];
        for (int i = 0; i < length; i++) {
            array[i] = expectedInterop.readArrayElement(expected, i);
        }
        return array;
    } catch (UnsupportedMessageException | InvalidArrayIndexException e) {
        throw new AssertionError(e);
    }
}
Also used : InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 8 with InvalidArrayIndexException

use of com.oracle.truffle.api.interop.InvalidArrayIndexException in project graal by oracle.

the class VMEventListenerImpl method onMethodEntry.

@Override
@TruffleBoundary
public boolean onMethodEntry(MethodRef method, Object scope) {
    boolean active = false;
    // collect variable information from scope
    List<MethodVariable> variables = new ArrayList<>(1);
    try {
        if (UNCACHED.hasMembers(scope)) {
            Object identifiers = UNCACHED.getMembers(scope);
            if (UNCACHED.hasArrayElements(identifiers)) {
                long size = UNCACHED.getArraySize(identifiers);
                for (long i = 0; i < size; i++) {
                    String identifier = (String) UNCACHED.readArrayElement(identifiers, i);
                    Object value = UNCACHED.readMember(scope, identifier);
                    variables.add(new MethodVariable(identifier, value));
                }
            }
        }
    } catch (UnsupportedMessageException | InvalidArrayIndexException | UnknownIdentifierException e) {
    // not able to fetch locals, so leave variables list empty
    }
    for (MethodHook hook : method.getMethodHooks()) {
        // pass on the variables to the method entry hook
        if (hook.onMethodEnter(method, variables.toArray(new MethodVariable[variables.size()]))) {
            // OK, tell the Debug API to suspend the thread now
            debuggerController.prepareMethodBreakpoint(new MethodBreakpointEvent((MethodBreakpointInfo) hook, null));
            debuggerController.suspend(context.asGuestThread(Thread.currentThread()));
            active = true;
            switch(hook.getKind()) {
                case ONE_TIME:
                    if (hook.hasFired()) {
                        method.removedMethodHook(hook);
                    }
                    break;
                case INDEFINITE:
                    // leave the hook active
                    break;
            }
        }
    }
    return active;
}
Also used : MethodBreakpointEvent(com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointEvent) ArrayList(java.util.ArrayList) MethodBreakpointInfo(com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 9 with InvalidArrayIndexException

use of com.oracle.truffle.api.interop.InvalidArrayIndexException in project graal by oracle.

the class Target_java_lang_System method handleForeignArray.

@TruffleBoundary
private static void handleForeignArray(Object src, int srcPos, Object dest, int destPos, int length, Klass destType, Meta meta, SubstitutionProfiler profiler) {
    InteropLibrary library = InteropLibrary.getUncached();
    ToEspressoNode toEspressoNode = ToEspressoNodeGen.getUncached();
    if (library.isNull(src) || library.isNull(dest)) {
        throw throwNullPointerEx(meta, profiler);
    }
    if (!library.hasArrayElements(src) || !library.hasArrayElements(dest)) {
        throw throwArrayStoreEx(meta, profiler);
    }
    try {
        int srclen = (int) library.getArraySize(src);
        int destlen = (int) library.getArraySize(dest);
        boundsCheck(meta, srclen, srcPos, destlen, destPos, length, profiler);
        for (int i = 0; i < length; i++) {
            Object cpy = toEspressoNode.execute(library.readArrayElement(src, i + srcPos), destType);
            library.writeArrayElement(dest, destPos + i, cpy);
        }
    } catch (UnsupportedMessageException | UnsupportedTypeException e) {
        CompilerDirectives.transferToInterpreter();
        throw EspressoError.shouldNotReachHere();
    } catch (InvalidArrayIndexException e) {
        throw throwArrayStoreEx(meta, profiler);
    }
}
Also used : InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) ToEspressoNode(com.oracle.truffle.espresso.nodes.interop.ToEspressoNode) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 10 with InvalidArrayIndexException

use of com.oracle.truffle.api.interop.InvalidArrayIndexException in project graal by oracle.

the class TruffleObject2JSON method fromObject.

static JSONObject fromObject(TruffleObject object) {
    JSONObject json = new JSONObject();
    Object keys;
    try {
        keys = INTEROP.getMembers(object);
    } catch (UnsupportedMessageException ex) {
        return json;
    }
    long size;
    try {
        size = INTEROP.getArraySize(keys);
    } catch (UnsupportedMessageException ex) {
        return json;
    }
    if (size > 0) {
        for (long i = 0; i < size; i++) {
            try {
                Object key = INTEROP.readArrayElement(keys, i);
                Object value = INTEROP.readMember(object, INTEROP.asString(key));
                json.put(key.toString(), from(value));
            } catch (UnknownIdentifierException | UnsupportedMessageException | InvalidArrayIndexException ex) {
            // ignore that key
            }
        }
    }
    return json;
}
Also used : InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Aggregations

InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)17 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)12 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)8 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)8 Test (org.junit.Test)4 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)3 WebAssembly (org.graalvm.wasm.api.WebAssembly)3 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 WasmModule (org.graalvm.wasm.WasmModule)2 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)1 StandardTags (com.oracle.truffle.api.instrumentation.StandardTags)1 Tag (com.oracle.truffle.api.instrumentation.Tag)1 NodeLibrary (com.oracle.truffle.api.interop.NodeLibrary)1 StopIterationException (com.oracle.truffle.api.interop.StopIterationException)1 ExportMessage (com.oracle.truffle.api.library.ExportMessage)1 ExecutableNode (com.oracle.truffle.api.nodes.ExecutableNode)1