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

The following examples show how to use com.oracle.truffle.api.interop.UnsupportedTypeException. 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: MapArgObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object execute(Object[] arguments) throws UnsupportedMessageException, UnsupportedTypeException, ArityException {
    if (value instanceof MapArgObjectMember) {
        MapArgObjectMember member = (MapArgObjectMember) value;
        if (MAP.equals(member.name)) {
            checkArity(arguments, 1);
            return new MapArgObject(member.parent).map(arguments[0]);
        } else if (SHRED.equals(member.name)) {
            checkArity(arguments, 0);
            CompilerAsserts.neverPartOfCompilation();
            return new MapArgObject(member.parent).shred();
        } else if (DESCRIBE.equals(member.name)) {
            checkArity(arguments, 0);
            CompilerAsserts.neverPartOfCompilation();
            return new MapArgObject(member.parent).describe();
        } else if (BIND.equals(member.name)) {
            checkArity(arguments, 3);
            return member.parent.bind(arguments[0], arguments[1], arguments[2]);
        }
    }
    CompilerDirectives.transferToInterpreter();
    throw UnsupportedMessageException.create();
}
 
Example #2
Source File: DeviceArrayCopyFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary(limit = "3") InteropLibrary pointerAccess,
                @CachedLibrary(limit = "3") InteropLibrary numElementsAccess) throws UnsupportedTypeException, ArityException, IndexOutOfBoundsException {
    long numElements;
    if (arguments.length == 1) {
        numElements = deviceArray.getArraySize();
    } else if (arguments.length == 2) {
        numElements = extractNumber(arguments[1], "numElements", numElementsAccess);
    } else {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(1, arguments.length);
    }
    long pointer = extractPointer(arguments[0], "fromPointer", pointerAccess);
    if (direction == CopyDirection.FROM_POINTER) {
        deviceArray.copyFrom(pointer, numElements);
    }
    if (direction == CopyDirection.TO_POINTER) {
        deviceArray.copyTo(pointer, numElements);
    }
    return deviceArray;
}
 
Example #3
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 6 votes vote down vote up
@TruffleBoundary
@Specialization(guards = "receiver.isDefaultClass()")
protected static final Object doObjectCached(final JavaObjectWrapper receiver, final Object[] args) throws UnsupportedTypeException {
    assert !receiver.isArrayClass();
    iterateConstructors: for (final Constructor<?> constructor : receiver.asClass().getConstructors()) {
        if (constructor.getParameterCount() == args.length) {
            for (int i = 0; i < args.length; i++) {
                if (!constructor.getParameterTypes()[i].isAssignableFrom(args[i].getClass())) {
                    continue iterateConstructors;
                }
            }
            // Arguments should fit into constructor.
            try {
                return wrap(constructor.newInstance(args));
            } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                throw UnsupportedTypeException.create(args);
            }
        }
    }
    throw UnsupportedTypeException.create(args);
}
 
Example #4
Source File: DeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@TruffleBoundary
public Object call(Object[] arguments) throws ArityException, UnsupportedTypeException {
    if (arguments.length < 1) {
        throw ArityException.create(1, arguments.length);
    }
    String typeName = expectString(arguments[0], "first argument of DeviceArray must be string (type name)");
    Type elementType;
    try {
        elementType = Type.fromGrCUDATypeString(typeName);
    } catch (TypeException e) {
        throw new GrCUDAException(e.getMessage());
    }
    if (arguments.length == 1) {
        return new TypedDeviceArrayFunction(runtime, elementType);
    } else {
        return createArray(arguments, 1, elementType, runtime);
    }
}
 
Example #5
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Specialization(guards = "cachedReceiver == receiver", limit = "1")
static Object executeCached(@SuppressWarnings("unused") MappedFunction receiver, Object[] arguments,
                @Cached("receiver") MappedFunction cachedReceiver,
                @CachedLibrary("cachedReceiver.function") InteropLibrary functionInterop,
                @CachedLibrary("cachedReceiver.returnValue") InteropLibrary resultInterop,
                @Cached(value = "createInterop(cachedReceiver)") InteropLibrary[] valueInterop)
                throws IllegalStateException, UnsupportedTypeException, ArityException, UnsupportedMessageException {
    Object[] shredded = createShredded(cachedReceiver.shreddedArguments, arguments);
    Object[] values = new Object[receiver.valueCount];
    ArgumentArray wrappedArguments = new ArgumentArray(arguments);
    ArgumentArray wrappedShreddedArguments = new ArgumentArray(shredded);
    ArgumentArray wrappedValueArguments = new ArgumentArray(values);
    Object[] mappedArguments = mapArguments(valueInterop, cachedReceiver, wrappedArguments, wrappedShreddedArguments, wrappedValueArguments);
    Object result = functionInterop.execute(cachedReceiver.function, mappedArguments);
    return processResult(receiver, resultInterop, values, wrappedArguments, wrappedShreddedArguments, wrappedValueArguments, result);
}
 
Example #6
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 #7
Source File: Kernel.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary(limit = "3") InteropLibrary gridSizeAccess,
                @CachedLibrary(limit = "3") InteropLibrary gridSizeElementAccess,
                @CachedLibrary(limit = "3") InteropLibrary blockSizeAccess,
                @CachedLibrary(limit = "3") InteropLibrary blockSizeElementAccess,
                @CachedLibrary(limit = "3") InteropLibrary sharedMemoryAccess) throws UnsupportedTypeException, ArityException {
    int dynamicSharedMemoryBytes;
    if (arguments.length == 2) {
        dynamicSharedMemoryBytes = 0;
    } else if (arguments.length == 3) {
        // dynamic shared memory specified
        dynamicSharedMemoryBytes = extractNumber(arguments[2], "dynamicSharedMemory", sharedMemoryAccess);
    } else {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(2, arguments.length);
    }

    Dim3 gridSize = extractDim3(arguments[0], "gridSize", gridSizeAccess, gridSizeElementAccess);
    Dim3 blockSize = extractDim3(arguments[1], "blockSize", blockSizeAccess, blockSizeElementAccess);
    KernelConfig config = new KernelConfig(gridSize, blockSize, dynamicSharedMemoryBytes);

    return new ConfiguredKernel(this, config);
}
 
Example #8
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("this.function") InteropLibrary mapInterop) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
    if (arguments.length != 3) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(3, arguments.length);
    }
    Object value = parentInterop.execute(parent, arguments);
    try {
        return mapInterop.execute(function, value);
    } catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new MapException("cannot map argument " + parent);
    }
}
 
Example #9
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
@SuppressWarnings("deprecation") // isAccessible deprecated in Java 11
public Object invokeMember(final String member, final Object... arguments) throws UnknownIdentifierException, UnsupportedTypeException {
    final Method method = getMethods().get(member);
    if (method != null) {
        try {
            if (!method.isAccessible()) {
                method.setAccessible(true);
            }
            return wrap(method.invoke(wrappedObject, arguments));
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw UnsupportedTypeException.create(arguments);
        }
    } else {
        throw UnknownIdentifierException.create(member);
    }
}
 
Example #10
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected MapBoundArgObjectBase bind(Object argumentSet, Object shreddedArgumentSet, Object valueSet)
                throws UnsupportedMessageException, ArityException, UnsupportedTypeException {
    MapBoundArgObjectBase[] newValues = new MapBoundArgObjectBase[values.length];
    for (int i = 0; i < values.length; i++) {
        newValues[i] = values[i].bind(argumentSet, shreddedArgumentSet, valueSet);
    }
    return new MapBoundArgObjectSize(newValues);
}
 
Example #11
Source File: CUDAFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@TruffleBoundary
protected Object call(Object[] arguments) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
    try {
        return function.call(runtime, arguments);
    } catch (InteropException e) {
        throw new GrCUDAException(e);
    }
}
 
Example #12
Source File: NodeProfJalangi.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
/**
 * register hooks
 *
 * @param analysis object
 * @param name functionName
 * @param callback experimental extra feature for specialization, e.g., "this.putFieldPre.arr"
 */
@TruffleBoundary
public void registerCallback(Object analysis, Object name, Object callback) throws UnsupportedTypeException {
    if (!jalangiAnalyses.containsKey(analysis)) {
        jalangiAnalyses.put(analysis, new JalangiAnalysis(this, analysis));
    }
    jalangiAnalyses.get(analysis).registerCallback(name, callback);
}
 
Example #13
Source File: MapDeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
public Object execute(Object[] arguments,
                @CachedLibrary(limit = "2") InteropLibrary stringInterop,
                @Cached("createIdentityProfile()") ValueProfile elementTypeStringProfile,
                @Cached("createIdentityProfile()") ValueProfile elementTypeProfile,
                @Cached MapArrayNode mapNode) throws ArityException, UnsupportedTypeException {
    if (arguments.length < 1) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(1, arguments.length);
    }
    String typeName;
    try {
        typeName = elementTypeStringProfile.profile(stringInterop.asString(arguments[0]));
    } catch (UnsupportedMessageException e1) {
        throw UnsupportedTypeException.create(arguments, "first argument of MapDeviceArray must be string (type name)");
    }
    Type elementType;
    try {
        elementType = elementTypeProfile.profile(Type.fromGrCUDATypeString(typeName));
    } catch (TypeException e) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAInternalException(e.getMessage());
    }
    if (arguments.length == 1) {
        return new TypedMapDeviceArrayFunction(runtime, elementType);
    } else {
        if (arguments.length != 2) {
            CompilerDirectives.transferToInterpreter();
            throw ArityException.create(2, arguments.length);
        }
        return mapNode.execute(arguments[1], elementType, runtime);
    }
}
 
Example #14
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary("this.parent") InteropLibrary parentInterop) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
    if (arguments.length != 3) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(3, arguments.length);
    }
    return new ShreddedObject(parentInterop.execute(parent, arguments));
}
 
Example #15
Source File: DeviceArrayCopyFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static long extractPointer(Object valueObj, String argumentName, InteropLibrary access) throws UnsupportedTypeException {
    try {
        if (access.isPointer(valueObj)) {
            return access.asPointer(valueObj);
        }
        return access.asLong(valueObj);
    } catch (UnsupportedMessageException e) {
        CompilerDirectives.transferToInterpreter();
        throw UnsupportedTypeException.create(new Object[]{valueObj}, "integer expected for " + argumentName);
    }
}
 
Example #16
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExplodeLoop
private static Object[] mapArguments(InteropLibrary[] valueInterop, MappedFunction receiver, ArgumentArray arguments, ArgumentArray shredded, ArgumentArray values) {
    Object[] result = new Object[valueInterop.length];
    for (int i = 0; i < valueInterop.length; i++) {
        try {
            result[i] = valueInterop[i].execute(receiver.values[i], arguments, shredded, values);
        } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
            CompilerDirectives.transferToInterpreter();
            throw new MapException("cannot map parameter " + i + ": " + e.getMessage());
        }
    }
    return result;
}
 
Example #17
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Object processResult(MappedFunction receiver, InteropLibrary resultInterop, Object[] values, ArgumentArray wrappedArguments, ArgumentArray wrappedShreddedArguments,
                ArgumentArray wrappedValueArguments, Object result) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
    if (receiver.returnValueIndex != null) {
        values[receiver.returnValueIndex] = result;
    }
    return resultInterop.execute(receiver.returnValue, wrappedArguments, wrappedShreddedArguments, wrappedValueArguments);
}
 
Example #18
Source File: DeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object invokeMember(String memberName,
                Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute)
                throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
}
 
Example #19
Source File: DeviceArrayCopyFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static int extractNumber(Object valueObj, String argumentName, InteropLibrary access) throws UnsupportedTypeException {
    try {
        return access.asInt(valueObj);
    } catch (UnsupportedMessageException e) {
        CompilerDirectives.transferToInterpreter();
        throw UnsupportedTypeException.create(new Object[]{valueObj}, "integer expected for " + argumentName);
    }
}
 
Example #20
Source File: Function.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static int expectInt(Object number) throws UnsupportedTypeException {
    CompilerAsserts.neverPartOfCompilation();
    try {
        return INTEROP.asInt(number);
    } catch (UnsupportedMessageException e) {
        throw UnsupportedTypeException.create(new Object[]{number}, "expected integer number argument");
    }
}
 
Example #21
Source File: AbstractOSProcessPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
protected final long getValue(final InteropLibrary lib) {
    try {
        return (int) lib.execute(sysCallObject);
    } catch (final UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        throw PrimitiveFailed.andTransferToInterpreterWithError(e);
    }
}
 
Example #22
Source File: GetDevicesFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@TruffleBoundary
public Object call(Object[] arguments) throws UnsupportedTypeException, ArityException {
    checkArgumentLength(arguments, 0);
    int numDevices = runtime.cudaGetDeviceCount();
    return new DeviceList(numDevices, runtime);
}
 
Example #23
Source File: Function.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected static long expectLong(Object number, String message) throws UnsupportedTypeException {
    CompilerAsserts.neverPartOfCompilation();
    try {
        return INTEROP.asLong(number);
    } catch (UnsupportedMessageException e) {
        throw UnsupportedTypeException.create(new Object[]{number}, message);
    }
}
 
Example #24
Source File: MapArgObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public MapArgObject map(Object function) throws UnsupportedTypeException {
    CompilerAsserts.neverPartOfCompilation();
    if (!MapFunction.INTEROP.isExecutable(function)) {
        throw UnsupportedTypeException.create(new Object[]{function}, "expecting executable mapping function");
    }
    return new MapArgObject(new MapArgObjectMap(function, value));
}
 
Example #25
Source File: Function.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected static int expectPositiveInt(Object number) throws UnsupportedTypeException {
    int value = expectInt(number);
    if (value < 0) {
        CompilerDirectives.transferToInterpreter();
        throw UnsupportedTypeException.create(new Object[]{number}, "expected positive int number argument");
    }
    return value;
}
 
Example #26
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Object bindArgument(Object argument, ArgumentSet argSet, ArgumentSet shreddedArgSet, ArgumentSet valueSet) throws UnsupportedTypeException {
    try {
        if (INTEROP.isMemberInvocable(argument, "bind")) {
            return INTEROP.invokeMember(argument, "bind", argSet, shreddedArgSet, valueSet);
        } else {
            Object readMember = INTEROP.readMember(argument, "bind");
            return INTEROP.execute(readMember, argSet, shreddedArgSet, valueSet);
        }
    } catch (UnsupportedMessageException | UnknownIdentifierException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAInternalException("unable to bind argument " + argument);
    }
}
 
Example #27
Source File: AbstractOSProcessPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
protected final long setValue(final InteropLibrary lib, final long id, final long value) {
    try {
        return (int) lib.execute(sysCallObject, (int) id, (int) value);
    } catch (final UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        throw PrimitiveFailed.andTransferToInterpreterWithError(e);
    }
}
 
Example #28
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Specialization(guards = "SIZE.equals(member)")
static MapFunctionBase readMemberSize(MapFunction receiver, String member) {
    return new MapFunctionBase(arguments -> {
        if (arguments.length == 0) {
            throw ArityException.create(1, 0);
        }
        try {
            return receiver.size((MapArgObject) arguments[0], Arrays.copyOfRange(arguments, 1, arguments.length, MapArgObject[].class));
        } catch (ClassCastException | ArrayStoreException e) {
            throw UnsupportedTypeException.create(arguments, "expected argument objects");
        }
    });
}
 
Example #29
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static String checkString(Object argument, String message) throws UnsupportedTypeException {
    CompilerAsserts.neverPartOfCompilation();
    try {
        return INTEROP.asString(argument);
    } catch (UnsupportedMessageException e) {
        throw UnsupportedTypeException.create(new Object[]{argument}, message);
    }
}
 
Example #30
Source File: Function.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected static String expectString(Object argument, String errorMessage) throws UnsupportedTypeException {
    CompilerAsserts.neverPartOfCompilation();
    try {
        return INTEROP.asString(argument);
    } catch (UnsupportedMessageException e) {
        throw UnsupportedTypeException.create(new Object[]{argument}, errorMessage);
    }
}