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;
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations