Java源码示例:com.oracle.truffle.api.interop.InvalidArrayIndexException

示例1
@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);
    }
}
 
示例2
@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);
    }
}
 
示例3
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        throw InvalidArrayIndexException.create(index);
    }
    return keys[(int) index];
}
 
示例4
@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);
    }
}
 
示例5
@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;
}
 
示例6
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return names[(int) index];
}
 
示例7
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        throw InvalidArrayIndexException.create(index);
    }
    return keys[(int) index];
}
 
示例8
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    try {
        return keys[(int) index];
    } catch (IndexOutOfBoundsException e) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
}
 
示例9
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;
}
 
示例10
@ExportMessage
public Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= values.length)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return values[(int) index];
}
 
示例11
@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;
}
 
示例12
@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);
    }
}
 
示例13
@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]);
}
 
示例14
@ExportMessage
@TruffleBoundary
public Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= propertyMap.size())) {
        throw InvalidArrayIndexException.create(index);
    }
    return names[(int) index];
}
 
示例15
@ExportMessage
Object readArrayElement(long index) throws InvalidArrayIndexException {
    if ((index < 0) || (index >= devices.length)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return devices[(int) index];
}
 
示例16
@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);
    }
}
 
示例17
@ExportMessage
public Object readArrayElement(long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    return values[(int) index];
}
 
示例18
@ExportMessage
public void writeArrayElement(long index, Object value) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        CompilerDirectives.transferToInterpreter();
        throw InvalidArrayIndexException.create(index);
    }
    values[(int) index] = value;
}
 
示例19
@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;
    }
}
 
示例20
@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);
    }
}
 
示例21
@ExportMessage
protected final Object readArrayElement(final long index) throws InvalidArrayIndexException {
    if (isArrayElementReadable(index)) {
        return literals[(int) index];
    } else {
        throw InvalidArrayIndexException.create(index);
    }
}
 
示例22
@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);
    }
}
 
示例23
@ExportMessage
protected Object readArrayElement(final long index) throws InvalidArrayIndexException {
    if (!isArrayElementReadable(index)) {
        throw InvalidArrayIndexException.create(index);
    }
    return keys[(int) index];
}
 
示例24
@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);
    }
}
 
示例25
@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);
    }
}
 
示例26
@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);
    }
}
 
示例27
@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");
    }
}
 
示例28
@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);
}
 
示例29
@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);
}
 
示例30
protected abstract Object execute(Object object, int index) throws UnsupportedMessageException, InvalidArrayIndexException;