com.oracle.truffle.api.interop.InvalidArrayIndexException Java Examples

The following examples show how to use com.oracle.truffle.api.interop.InvalidArrayIndexException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"lib.hasMembers(object)"}, limit = "2")
protected static final ArrayObject doGetMembers(@SuppressWarnings("unused") final Object receiver, final Object object, final boolean includeInternal,
                @CachedLibrary("object") final InteropLibrary lib,
                @CachedLibrary(limit = "2") final InteropLibrary membersLib,
                @CachedLibrary(limit = "2") final InteropLibrary memberNameLib,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    // TODO: is unpacking really necessary?
    try {
        final Object members = lib.getMembers(object, includeInternal);
        final int size = (int) membersLib.getArraySize(members);
        final Object[] byteStrings = new Object[size];
        for (int i = 0; i < size; i++) {
            final Object memberName = membersLib.readArrayElement(members, i);
            byteStrings[i] = image.asByteString(memberNameLib.asString(memberName));
        }
        return image.asArrayOfObjects(byteStrings);
    } catch (final UnsupportedMessageException | InvalidArrayIndexException e) {
        throw primitiveFailedInInterpreterCapturing(e);
    }
}
 
Example #2
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary("this.parent") InteropLibrary parentInterop,
                @CachedLibrary(limit = "2") InteropLibrary elementInterop) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
    if (arguments.length != 3) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(3, arguments.length);
    }
    Object value = parentInterop.execute(parent, arguments);
    try {
        return elementInterop.readArrayElement(value, index);
    } catch (UnsupportedMessageException | InvalidArrayIndexException e) {
        CompilerDirectives.transferToInterpreter();
        throw new MapException("cannot read element '" + index + "' from argument " + parent);
    }
}
 
Example #3
Source File: ArgumentArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
public Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return values[(int) index];
}
 
Example #4
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"lib.isArrayElementWritable(object, index)"}, limit = "2")
protected static final Object doWrite(@SuppressWarnings("unused") final Object receiver, final Object object, final long index, final Object value,
                @CachedLibrary("object") final InteropLibrary lib) {
    try {
        lib.writeArrayElement(object, index - 1, value);
        return value;
    } catch (InvalidArrayIndexException | UnsupportedMessageException | UnsupportedTypeException e) {
        throw primitiveFailedInInterpreterCapturing(e);
    }
}
 
Example #5
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"lib.isArrayElementRemovable(object, to0(index))"}, limit = "2")
protected static final Object doRemoveArrayElement(@SuppressWarnings("unused") final Object receiver, final Object object, final long index,
                @CachedLibrary("object") final InteropLibrary lib) {
    try {
        lib.removeArrayElement(object, index - 1);
        return object;
    } catch (final UnsupportedMessageException | InvalidArrayIndexException e) {
        throw primitiveFailedInInterpreterCapturing(e);
    }
}
 
Example #6
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"lib.isArrayElementReadable(object, to0(index))"}, limit = "2")
protected static final Object doReadArrayElement(@SuppressWarnings("unused") final Object receiver, final Object object, final long index,
                @Cached final WrapToSqueakNode wrapNode,
                @CachedLibrary("object") final InteropLibrary lib) {
    try {
        return wrapNode.executeWrap(lib.readArrayElement(object, index - 1));
    } catch (final UnsupportedMessageException | InvalidArrayIndexException e) {
        throw primitiveFailedInInterpreterCapturing(e);
    }
}
 
Example #7
Source File: InteropArray.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected Object readArrayElement(final long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        throw InvalidArrayIndexException.create(index);
    }
    return keys[(int) index];
}
 
Example #8
Source File: CompiledCodeObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected final void writeArrayElement(final long index, final Object value,
                @Exclusive @Cached final WrapToSqueakNode wrapNode) throws InvalidArrayIndexException {
    if (isArrayElementReadable(index)) {
        literals[(int) index] = wrapNode.executeWrap(value);
    } else {
        throw InvalidArrayIndexException.create(index);
    }
}
 
Example #9
Source File: CompiledCodeObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected final Object readArrayElement(final long index) throws InvalidArrayIndexException {
    if (isArrayElementReadable(index)) {
        return literals[(int) index];
    } else {
        throw InvalidArrayIndexException.create(index);
    }
}
 
Example #10
Source File: ArrayObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected void writeArrayElement(final long index, final Object value,
                @Exclusive @Cached final WrapToSqueakNode wrapNode,
                @Cached final ArrayObjectWriteNode writeNode) throws InvalidArrayIndexException {
    try {
        writeNode.execute(this, index, wrapNode.executeWrap(value));
    } catch (final ArrayIndexOutOfBoundsException e) {
        throw InvalidArrayIndexException.create(index);
    }
}
 
Example #11
Source File: TensorRTRegistry.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected Object call(Object[] arguments) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
    checkArgumentLength(arguments, 3);
    int engineHandle = expectInt(arguments[0]);
    int batchSize = expectInt(arguments[1]);

    // extract pointers from buffers array argument
    Object bufferArg = arguments[2];
    if (!INTEROP.hasArrayElements(bufferArg)) {
        throw UnsupportedMessageException.create();
    }
    int numBuffers = (int) INTEROP.getArraySize(bufferArg);
    try (UnsafeHelper.PointerArray pointerArray = UnsafeHelper.createPointerArray(numBuffers)) {
        if (nfiFunction == null) {
            // load function symbol lazily
            CompilerDirectives.transferToInterpreterAndInvalidate();
            nfiFunction = factory.makeFunction(context.getCUDARuntime(), libraryPath, DEFAULT_LIBRARY_HINT);
        }
        for (int i = 0; i < numBuffers; ++i) {
            try {
                Object buffer = INTEROP.readArrayElement(bufferArg, i);
                if (!(buffer instanceof DeviceArray) && !(buffer instanceof GPUPointer)) {
                    UnsupportedTypeException.create(new Object[]{buffer});
                }
                pointerArray.setValueAt(i, INTEROP.asPointer(buffer));
            } catch (InvalidArrayIndexException e) {
                InvalidArrayIndexException.create(i);
            }
        }
        long stream = 0;
        long eventConsumed = 0;
        Object result = INTEROP.execute(nfiFunction, engineHandle, batchSize, pointerArray.getAddress(), stream, eventConsumed);
        if (!INTEROP.fitsInInt(result)) {
            CompilerDirectives.transferToInterpreter();
            throw new RuntimeException("result of 'enqueue' is not an int");
        }
        return INTEROP.asInt(result) == 1;
    }
}
 
Example #12
Source File: ArgumentArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
public void writeArrayElement(long index, Object value) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    values[(int) index] = value;
}
 
Example #13
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        throw InvalidArrayIndexException.create(index);
    }
    return keys[(int) index];
}
 
Example #14
Source File: HashemInstrumentTest.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    try {
        return keys[(int) index];
    } catch (IndexOutOfBoundsException e) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
}
 
Example #15
Source File: HashemReadPropertyNode.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@Specialization(guards = "arrays.hasArrayElements(receiver)", limit = "LIBRARY_LIMIT")
protected Object writeArray(Object receiver, Object index,
                            @CachedLibrary("receiver") InteropLibrary arrays,
                            @CachedLibrary("index") InteropLibrary numbers) {
    try {
        return arrays.readArrayElement(receiver, numbers.asLong(index));
    } catch (UnsupportedMessageException | InvalidArrayIndexException e) {
        // read was not successful. InHashemiwe only have basic support for errors.
        throw HashemUndefinedNameException.undefinedProperty(this, index);
    }
}
 
Example #16
Source File: HashemWritePropertyNode.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@Specialization(guards = "arrays.hasArrayElements(receiver)", limit = "LIBRARY_LIMIT")
protected Object write(Object receiver, Object index, Object value,
                @CachedLibrary("receiver") InteropLibrary arrays,
                @CachedLibrary("index") InteropLibrary numbers) {
    try {
        arrays.writeArrayElement(receiver, numbers.asLong(index), value);
    } catch (UnsupportedMessageException | UnsupportedTypeException | InvalidArrayIndexException e) {
        // read was not successful. InHashemiwe only have basic support for errors.
        throw HashemUndefinedNameException.undefinedProperty(this, index);
    }
    return value;
}
 
Example #17
Source File: FunctionsObject.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return names[(int) index];
}
 
Example #18
Source File: HashemObjectType.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        throw InvalidArrayIndexException.create(index);
    }
    return keys[(int) index];
}
 
Example #19
Source File: MultiDimDeviceArrayView.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index,
                @Shared("elementType") @Cached("createIdentityProfile()") ValueProfile elementTypeProfile) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= mdDeviceArray.getElementsInDimension(thisDimension))) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    if ((thisDimension + 1) == mdDeviceArray.getNumberDimensions()) {
        long flatIndex = offset + index * stride;
        switch (elementTypeProfile.profile(mdDeviceArray.getElementType())) {
            case CHAR:
                return mdDeviceArray.getNativeView().getByte(flatIndex);
            case SINT16:
                return mdDeviceArray.getNativeView().getShort(flatIndex);
            case SINT32:
                return mdDeviceArray.getNativeView().getInt(flatIndex);
            case SINT64:
                return mdDeviceArray.getNativeView().getLong(flatIndex);
            case FLOAT:
                return mdDeviceArray.getNativeView().getFloat(flatIndex);
            case DOUBLE:
                return mdDeviceArray.getNativeView().getDouble(flatIndex);
        }
        return null;
    } else {
        long off = offset + index * stride;
        long newStride = mdDeviceArray.getStrideInDimension(thisDimension + 1);
        return new MultiDimDeviceArrayView(mdDeviceArray, thisDimension + 1, off, newStride);
    }
}
 
Example #20
Source File: MapFunctionTest.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static boolean checkArray(Object value, Object array) {
    try {
        Assert.assertEquals(Array.getLength(array), INTEROP.getArraySize(value));
        for (int i = 0; i < Array.getLength(array); i++) {
            Assert.assertEquals(Array.get(array, i), INTEROP.readArrayElement(value, i));
        }
    } catch (UnsupportedMessageException | IllegalArgumentException | ArrayIndexOutOfBoundsException | InvalidArrayIndexException e) {
        throw new AssertionError(e);
    }
    return true;
}
 
Example #21
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
public Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= values.length)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return values[(int) index];
}
 
Example #22
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index,
                @Shared("elementType") @Cached("createIdentityProfile()") ValueProfile elementTypeProfile) throws InvalidArrayIndexException {
    if (arrayFreed) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAException(ACCESSED_FREED_MEMORY_MESSAGE);
    }
    if ((index < 0) || (index >= numElements)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);

    }
    switch (elementTypeProfile.profile(elementType)) {
        case CHAR:
            return nativeView.getByte(index);
        case SINT16:
            return nativeView.getShort(index);
        case SINT32:
            return nativeView.getInt(index);
        case SINT64:
            return nativeView.getLong(index);
        case FLOAT:
            return nativeView.getFloat(index);
        case DOUBLE:
            return nativeView.getDouble(index);
    }
    return null;
}
 
Example #23
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
public void writeArrayElement(long index, Object value,
                @CachedLibrary(limit = "3") InteropLibrary valueLibrary,
                @Shared("elementType") @Cached("createIdentityProfile()") ValueProfile elementTypeProfile) throws UnsupportedTypeException, InvalidArrayIndexException {
    if (arrayFreed) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAException(ACCESSED_FREED_MEMORY_MESSAGE);
    }
    if ((index < 0) || (index >= numElements)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    try {
        switch (elementTypeProfile.profile(elementType)) {

            case CHAR:
                nativeView.setByte(index, valueLibrary.asByte(value));
                break;
            case SINT16:
                nativeView.setShort(index, valueLibrary.asShort(value));
                break;
            case SINT32:
                nativeView.setInt(index, valueLibrary.asInt(value));
                break;
            case SINT64:
                nativeView.setLong(index, valueLibrary.asLong(value));
                break;
            case FLOAT:
                // going via "double" to allow floats to be initialized with doubles
                nativeView.setFloat(index, (float) valueLibrary.asDouble(value));
                break;
            case DOUBLE:
                nativeView.setDouble(index, valueLibrary.asDouble(value));
                break;
        }
    } catch (UnsupportedMessageException e) {
        CompilerDirectives.transferToInterpreter();
        throw UnsupportedTypeException.create(new Object[]{value}, "value cannot be coerced to " + elementType);
    }
}
 
Example #24
Source File: MultiDimDeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= elementsPerDimension[0])) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    long offset = index * stridePerDimension[0];
    return new MultiDimDeviceArrayView(this, 1, offset, stridePerDimension[1]);
}
 
Example #25
Source File: GPUDeviceProperties.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= propertyMap.size())) {
        throw InvalidArrayIndexException.create(index);
    }
    return names[(int) index];
}
 
Example #26
Source File: DeviceList.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= devices.length)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return devices[(int) index];
}
 
Example #27
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 4 votes vote down vote up
@Specialization(limit = "1")
protected static final Object doTruffleObject(final TruffleObject object, final int index, @CachedLibrary("object") final InteropLibrary lib)
                throws UnsupportedMessageException, InvalidArrayIndexException {
    return lib.readArrayElement(object, index);
}
 
Example #28
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 4 votes vote down vote up
@Specialization(limit = "1")
protected static final void doTruffleObject(final TruffleObject object, final int index, final Object value, @CachedLibrary("object") final InteropLibrary lib)
                throws UnsupportedMessageException, InvalidArrayIndexException, UnsupportedTypeException {
    lib.writeArrayElement(object, index, value);
}
 
Example #29
Source File: MultiDimDeviceArrayView.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExportMessage
void writeArrayElement(long index, Object value,
                @CachedLibrary(limit = "3") InteropLibrary valueLibrary,
                @Shared("elementType") @Cached("createIdentityProfile()") ValueProfile elementTypeProfile) throws UnsupportedTypeException, InvalidArrayIndexException {
    if ((index < 0) || (index >= mdDeviceArray.getElementsInDimension(thisDimension))) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    if ((thisDimension + 1) == mdDeviceArray.getNumberDimensions()) {
        long flatIndex = offset + index * stride;
        try {
            switch (elementTypeProfile.profile(mdDeviceArray.getElementType())) {
                case CHAR:
                    mdDeviceArray.getNativeView().setByte(flatIndex, valueLibrary.asByte(value));
                    break;
                case SINT16:
                    mdDeviceArray.getNativeView().setShort(flatIndex, valueLibrary.asShort(value));
                    break;
                case SINT32:
                    mdDeviceArray.getNativeView().setInt(flatIndex, valueLibrary.asInt(value));
                    break;
                case SINT64:
                    mdDeviceArray.getNativeView().setLong(flatIndex, valueLibrary.asLong(value));
                    break;
                case FLOAT:
                    // InteropLibrary does not downcast Double to Float due loss of precision
                    mdDeviceArray.getNativeView().setFloat(flatIndex, (float) valueLibrary.asDouble(value));
                    break;
                case DOUBLE:
                    mdDeviceArray.getNativeView().setDouble(flatIndex, valueLibrary.asDouble(value));
                    break;
            }
        } catch (UnsupportedMessageException e) {
            CompilerDirectives.transferToInterpreter();
            throw UnsupportedTypeException.create(new Object[]{value}, "value cannot be coerced to " + mdDeviceArray.getElementType());
        }
    } else {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException("tried to write non-last dimension in MultiDimDeviceArrayView");
    }
}
 
Example #30
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License votes vote down vote up
protected abstract Object execute(Object object, int index) throws UnsupportedMessageException, InvalidArrayIndexException;