com.oracle.truffle.api.interop.UnsupportedMessageException Java Examples
The following examples show how to use
com.oracle.truffle.api.interop.UnsupportedMessageException.
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: MapDeviceArrayFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Specialization(limit = "3") Object doMap(Object source, Type elementType, CUDARuntime runtime, @CachedLibrary("source") InteropLibrary interop, @CachedContext(GrCUDALanguage.class) @SuppressWarnings("unused") GrCUDAContext context, @Cached(value = "createLoop(source)", uncached = "createUncachedLoop(source, context)") CallTarget loop) { if (source instanceof DeviceArray && ((DeviceArray) source).getElementType() == elementType) { return source; } if (!interop.hasArrayElements(source)) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException("cannot map from non-array to DeviceArray"); } long size; try { size = interop.getArraySize(source); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException("cannot read array size"); } DeviceArray result = new DeviceArray(runtime, size, elementType); loop.call(size, source, result); return result; }
Example #2
Source File: MappedFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 #3
Source File: MappedFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@ExportMessage Object execute(Object[] arguments, @CachedLibrary("this.parent") InteropLibrary parentInterop, @CachedLibrary(limit = "2") InteropLibrary memberInterop) throws ArityException, UnsupportedTypeException, UnsupportedMessageException { if (arguments.length != 3) { CompilerDirectives.transferToInterpreter(); throw ArityException.create(3, arguments.length); } Object value = parentInterop.execute(parent, arguments); try { return memberInterop.readMember(value, name); } catch (UnsupportedMessageException | UnknownIdentifierException e) { CompilerDirectives.transferToInterpreter(); throw new MapException("cannot read member '" + name + "' from argument " + parent); } }
Example #4
Source File: HashemInvokeNode.java From mr-hashemi with Universal Permissive License v1.0 | 6 votes |
@ExplodeLoop @Override public Object executeGeneric(VirtualFrame frame) { Object function = functionNode.executeGeneric(frame); /* * The number of arguments is constant for one invoke node. During compilation, the loop is * unrolled and the execute methods of all arguments are inlined. This is triggered by the * ExplodeLoop annotation on the method. The compiler assertion below illustrates that the * array length is really constant. */ CompilerAsserts.compilationConstant(argumentNodes.length); Object[] argumentValues = new Object[argumentNodes.length]; for (int i = 0; i < argumentNodes.length; i++) { argumentValues[i] = argumentNodes[i].executeGeneric(frame); } try { return library.execute(function, argumentValues); } catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) { /* Execute was not successful. */ throw HashemUndefinedNameException.undefinedBebin(this, function); } }
Example #5
Source File: HashemToMemberNode.java From mr-hashemi with Universal Permissive License v1.0 | 6 votes |
@Specialization(limit = "LIMIT") protected static String fromInterop(Object value, @CachedLibrary("value") InteropLibrary interop) throws UnknownIdentifierException { try { if (interop.fitsInLong(value)) { return longToString(interop.asLong(value)); } else if (interop.isString(value)) { return interop.asString(value); } else if (interop.isNumber(value) && value instanceof HashemBigNumber) { return bigNumberToString((HashemBigNumber) value); } else { throw error(value); } } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw new AssertionError(); } }
Example #6
Source File: HashemUnboxNode.java From mr-hashemi with Universal Permissive License v1.0 | 6 votes |
@Specialization(limit = "LIMIT") public static Object fromForeign(Object value, @CachedLibrary("value") InteropLibrary interop) { try { if (interop.fitsInLong(value)) { return interop.asLong(value); } else if (interop.fitsInFloat(value)) { return interop.asFloat(value); } else if (interop.isString(value)) { return interop.asString(value); } else if (interop.isBoolean(value)) { return interop.asBoolean(value); } else { return value; } } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw new AssertionError(); } }
Example #7
Source File: CallNode.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Specialization Object doDefault(VirtualFrame frame, @CachedLibrary(limit = "2") InteropLibrary interop, @CachedContext(GrCUDALanguage.class) GrCUDAContext context) { String[] functionName = identifier.getIdentifierName(); Namespace namespace = context.getRootNamespace(); Optional<Object> maybeFunction = namespace.lookup(functionName); if (!maybeFunction.isPresent() || !(maybeFunction.get() instanceof Function)) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException("function '" + GrCUDAException.format(functionName) + "' not found", this); } Function function = (Function) maybeFunction.get(); Object[] argumentValues = new Object[argumentNodes.length]; for (int i = 0; i < argumentNodes.length; i++) { argumentValues[i] = argumentNodes[i].execute(frame); } try { return interop.execute(function, argumentValues); } catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException(e.getMessage(), this); } }
Example #8
Source File: PolyglotPlugin.java From trufflesqueak with MIT License | 5 votes |
@Specialization(guards = {"member.isByteType()", "lib.isMemberWritable(object, member.asStringUnsafe())"}, limit = "2") protected static final Object doWrite(@SuppressWarnings("unused") final Object receiver, final Object object, final NativeObject member, final Object value, @CachedLibrary("object") final InteropLibrary lib) { try { lib.writeMember(object, member.asStringUnsafe(), value); return value; } catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException e) { throw primitiveFailedInInterpreterCapturing(e); } }
Example #9
Source File: MappedFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 #10
Source File: TensorRTRegistry.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 #11
Source File: Function.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #12
Source File: Function.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #13
Source File: PolyglotPlugin.java From trufflesqueak with MIT License | 5 votes |
@Specialization(guards = "lib.isBoolean(object)", limit = "2") protected static final boolean doAsBoolean(@SuppressWarnings("unused") final Object receiver, final Object object, @CachedLibrary("object") final InteropLibrary lib) { try { return BooleanObject.wrap(lib.asBoolean(object)); } catch (final UnsupportedMessageException e) { throw primitiveFailedInInterpreterCapturing(e); } }
Example #14
Source File: TensorRTRegistry.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void checkTRTReturnCode(Object result, String function) { int returnCode; try { returnCode = INTEROP.asInt(result); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw new RuntimeException("expected return code as Integer object in " + function + ", got " + result.getClass().getName()); } if (returnCode < 0) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException(returnCode, trtReturnCodeToString(returnCode), new String[]{function}); } }
Example #15
Source File: JavaObjectWrapper.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage protected byte asByte(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { if (isNumber()) { return lib.asByte(wrappedObject); } else { throw UnsupportedMessageException.create(); } }
Example #16
Source File: AbstractFactory.java From nodeprof.js with Apache License 2.0 | 5 votes |
protected static Object readCBProperty(DynamicObject cb, String name) { if (cb == null) { return null; } try { Object val = InteropLibrary.getFactory().getUncached(cb).readMember(cb, name); return val == null ? null : val; } catch (UnknownIdentifierException | UnsupportedMessageException e) { return null; } }
Example #17
Source File: PointersObject.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage protected static RuntimeException throwException(final PointersObject receiver, @Shared("inheritsFromNode") @Cached final InheritsFromNode inheritsFromNode, @CachedContext(SqueakLanguage.class) final SqueakImageContext image) throws UnsupportedMessageException { if (isException(receiver, inheritsFromNode, image)) { throw new SqueakInteropException(receiver); } else { throw UnsupportedMessageException.create(); } }
Example #18
Source File: CUBLASRegistry.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void checkCUBLASReturnCode(Object result, String... function) { CompilerAsserts.neverPartOfCompilation(); int returnCode; try { returnCode = InteropLibrary.getFactory().getUncached().asInt(result); } catch (UnsupportedMessageException e) { throw new GrCUDAInternalException("expected return code as Integer object in " + function + ", got " + result.getClass().getName()); } if (returnCode != 0) { throw new GrCUDAException(returnCode, cublasReturnCodeToString(returnCode), function); } }
Example #19
Source File: SqueakFFIPrims.java From trufflesqueak with MIT License | 5 votes |
private static Object calloutToLib(final SqueakImageContext image, final String name, final Object[] argumentsConverted, final String nfiCode) throws UnsupportedMessageException, ArityException, UnknownIdentifierException, UnsupportedTypeException { final Source source = Source.newBuilder("nfi", nfiCode, "native").build(); final Object ffiTest = image.env.parseInternal(source).call(); final InteropLibrary interopLib = InteropLibrary.getFactory().getUncached(ffiTest); return interopLib.invokeMember(ffiTest, name, argumentsConverted); }
Example #20
Source File: ContextObjectInfo.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage @TruffleBoundary public void writeMember(final String member, final Object value) throws UnknownIdentifierException, UnsupportedMessageException { if (frame == null) { throw UnsupportedMessageException.create(); } final FrameSlot slot = slots.get(member); if (slot != null) { FrameAccess.setStackSlot(frame, slot, value); } else { throw UnknownIdentifierException.create(member); } }
Example #21
Source File: UnixOSProcessPlugin.java From trufflesqueak with MIT License | 5 votes |
@Specialization(guards = "supportsNFI") protected final NativeObject doErrorMessageAt(@SuppressWarnings("unused") final Object receiver, final long index, @CachedLibrary("getSysCallObject()") final InteropLibrary lib, @CachedLibrary(limit = "1") final InteropLibrary resultLib, @CachedContext(SqueakLanguage.class) final SqueakImageContext image) { try { return image.asByteString(resultLib.asString(lib.execute(sysCallObject, (int) index))); } catch (final UnsupportedMessageException | UnsupportedTypeException | ArityException e) { throw PrimitiveFailed.andTransferToInterpreterWithError(e); } }
Example #22
Source File: MappedFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 #23
Source File: JavaMethodWrapper.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage @TruffleBoundary protected Object readMember(final String member) throws UnsupportedMessageException { if (NAME_MEMBER.equals(member)) { return method.getName(); } else if (RECEIVER_MEMBER.equals(member)) { return receiver; } else if (PARAMETER_COUNT.equals(member)) { return method.getParameterCount(); } else { throw UnsupportedMessageException.create(); } }
Example #24
Source File: PolyglotPlugin.java From trufflesqueak with MIT License | 5 votes |
@Specialization(guards = "lib.hasLanguage(object)") protected static final Object getLanguage(@SuppressWarnings("unused") final Object receiver, final Object object, @CachedContext(SqueakLanguage.class) final SqueakImageContext image, @CachedLibrary(limit = "2") final InteropLibrary lib) { try { return image.env.asGuestValue(lib.getLanguage(object)); } catch (final UnsupportedMessageException e) { throw primitiveFailedInInterpreterCapturing(e); } }
Example #25
Source File: JavaObjectWrapper.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage protected int asInt(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { if (isNumber()) { return lib.asInt(wrappedObject); } else { throw UnsupportedMessageException.create(); } }
Example #26
Source File: MapFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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: MapFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @ExportMessage @TruffleBoundary public MappedFunction execute(Object[] arguments) throws ArityException, UnsupportedTypeException { if (arguments.length == 0) { throw ArityException.create(1, 0); } Object function = arguments[0]; if (!INTEROP.isExecutable(function)) { throw UnsupportedTypeException.create(arguments, "expecting executable function as first argument"); } String description = null; if (arguments.length > 1) { Object last = arguments[arguments.length - 1]; if (INTEROP.isString(last)) { try { description = INTEROP.asString(last); } catch (UnsupportedMessageException e) { throw new GrCUDAInternalException("mismatch between isString and asString"); } } } Object[] values = new Object[arguments.length - 1 - (description == null ? 0 : 1)]; ArgumentSet argSet = new ArgumentSet(); ArgumentSet shreddedArgSet = new ArgumentSet(); ArgumentSet valueSet = new ArgumentSet(); for (int i = 0; i < values.length; i++) { values[i] = bindArgument(arguments[i + 1], argSet, shreddedArgSet, valueSet); } Object boundReturn = bindArgument(returnValue, argSet, shreddedArgSet, valueSet); int[] shreddedIndexes = new int[shreddedArgSet.nameList.size()]; for (String name : shreddedArgSet.nameList.getKeys()) { shreddedIndexes[shreddedArgSet.nameList.get(name)] = argSet.readMember(name); } Integer returnValueIndex = valueSet.nameList.get("return"); return new MappedFunction(function, values, shreddedIndexes, valueSet.nameList.size(), boundReturn, returnValueIndex, description); }
Example #28
Source File: JavaMethodWrapper.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage @TruffleBoundary protected Object execute(final Object[] arguments) throws UnsupportedMessageException { try { return JavaObjectWrapper.wrap(method.invoke(receiver, arguments)); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw UnsupportedMessageException.create(); } }
Example #29
Source File: PolyglotPlugin.java From trufflesqueak with MIT License | 5 votes |
@Specialization(guards = "lib.isException(object)") protected static final Object doThrowException(@SuppressWarnings("unused") final Object receiver, final Object object, @CachedLibrary(limit = "2") final InteropLibrary lib) { try { throw lib.throwException(object); } catch (final UnsupportedMessageException e) { throw primitiveFailedInInterpreterCapturing(e); } }
Example #30
Source File: LargeIntegerObject.java From trufflesqueak with MIT License | 5 votes |
@ExportMessage public long asLong() throws UnsupportedMessageException { try { return longValueExact(); } catch (final ArithmeticException e) { throw UnsupportedMessageException.create(); } }