Java Code Examples for com.oracle.truffle.api.interop.UnsupportedTypeException#create()
The following examples show how to use
com.oracle.truffle.api.interop.UnsupportedTypeException#create() .
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: JavaObjectWrapper.java From trufflesqueak with MIT License | 6 votes |
@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 2
Source File: ClassObject.java From trufflesqueak with MIT License | 6 votes |
@Specialization(guards = "arguments.length == 1") protected static final Object doOneArgument(final ClassObject receiver, final Object[] arguments, @Shared("newObjectNode") @Cached final SqueakObjectNewNode newObjectNode, @CachedLibrary(limit = "2") final InteropLibrary functions, @CachedLibrary(limit = "2") final InteropLibrary initializer, @CachedContext(SqueakLanguage.class) final SqueakImageContext theImage) throws UnsupportedTypeException { if (functions.fitsInInt(arguments[0])) { final AbstractSqueakObjectWithHash newObject; try { newObject = newObjectNode.execute(theImage, receiver, functions.asInt(arguments[0])); } catch (final UnsupportedMessageException e) { throw UnsupportedTypeException.create(arguments, "Second argument violates interop contract."); } initializeObject(arguments, initializer, newObject); return newObject; } else { throw UnsupportedTypeException.create(arguments, "Second argument must be the size as an integer."); } }
Example 3
Source File: JalangiAnalysis.java From nodeprof.js with Apache License 2.0 | 6 votes |
/** * register hooks * * @param name of the hook * @throws UnsupportedTypeException * @callback function to be called for the specified hook */ @TruffleBoundary public void registerCallback(Object name, Object callback) throws UnsupportedTypeException { if (callback instanceof DynamicObject) { if (GlobalConfiguration.DEBUG) { Logger.debug("Jalangi analysis registering callback: " + name); } if (unimplementedCallbacks.contains(name)) { Logger.warning("Jalangi analysis callback not implemented in NodeProf: " + name); } GlobalObjectCache.getInstance().addDynamicObject((DynamicObject) callback); this.callbacks.put(name.toString(), (DynamicObject) callback); } else { throw UnsupportedTypeException.create(new Object[]{callback}); } }
Example 4
Source File: Function.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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); } }
Example 5
Source File: ClassObject.java From trufflesqueak with MIT License | 5 votes |
private static void initializeObject(final Object[] arguments, final InteropLibrary initializer, final AbstractSqueakObjectWithHash newObject) throws UnsupportedTypeException { try { initializer.invokeMember(newObject, "initialize"); } catch (UnsupportedMessageException | ArityException | UnknownIdentifierException | UnsupportedTypeException e) { throw UnsupportedTypeException.create(arguments, "Failed to initialize new object"); } }
Example 6
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 7
Source File: Function.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static long expectPositiveLong(Object number) throws UnsupportedTypeException { long value = expectLong(number); if (value < 0) { CompilerDirectives.transferToInterpreter(); throw UnsupportedTypeException.create(new Object[]{number}, "expected positive long number argument"); } return value; }
Example 8
Source File: Function.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 9
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 10
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 11
Source File: DeviceArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 12
Source File: MapDeviceArrayFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 13
Source File: DeviceArrayCopyFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 14
Source File: DeviceArrayCopyFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 15
Source File: MapArgObject.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 16
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 17
Source File: MapFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 18
Source File: MapFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 19
Source File: Kernel.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
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: MultiDimDeviceArrayView.java From grcuda with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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"); } }