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

The following examples show how to use com.oracle.truffle.api.interop.UnknownIdentifierException. 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: AbstractSqueakObject.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExportMessage
public Object readMember(final String member,
                @Shared("lookupNode") @Cached final LookupMethodByStringNode lookupNode,
                @Shared("classNode") @Cached final SqueakObjectClassNode classNode,
                @Exclusive @Cached("createBinaryProfile()") final ConditionProfile alternativeProfile) throws UnknownIdentifierException {
    final ClassObject classObject = classNode.executeLookup(this);
    final String selectorString = toSelector(member);
    final Object methodObject = lookupNode.executeLookup(classObject, selectorString);
    if (alternativeProfile.profile(methodObject instanceof CompiledMethodObject)) {
        return new BoundMethod((CompiledMethodObject) methodObject, this);
    } else {
        final Object methodObjectAlternative = lookupNode.executeLookup(classObject, toAlternativeSelector(selectorString));
        if (methodObjectAlternative instanceof CompiledMethodObject) {
            return new BoundMethod((CompiledMethodObject) methodObjectAlternative, this);
        } else {
            throw UnknownIdentifierException.create(member);
        }
    }
}
 
Example #2
Source File: GPUDeviceProperties.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object readMember(String member) throws UnknownIdentifierException {
    if (!isMemberReadable(member)) {
        throw UnknownIdentifierException.create(member);
    }
    Object value = properties.get(member);
    if (value == null) {
        DeviceProperty prop = PROPERTY_SET.getProperty(member);
        value = prop.getValue(deviceId, runtime);
        if (prop.isStaticProperty()) {
            properties.put(member, value);
        }
    }
    return value;
}
 
Example #3
Source File: ShreddedObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(String member,
                @CachedLibrary("this.delegate") InteropLibrary memberInterop) {
    if (memberInterop.isMemberReadable(delegate, member)) {
        try {
            return memberInterop.readMember(delegate, member);
        } catch (UnsupportedMessageException | UnknownIdentifierException e) {
            CompilerDirectives.transferToInterpreter();
            throw new MapException("cannot read 'readable' member: " + e.getMessage());
        }
    } else {
        if (memberInterop.hasArrayElements(delegate)) {
            return new ShreddedObjectMember(delegate, member);
        } else {
            CompilerDirectives.transferToInterpreter();
            throw new MapException("cannot shred object without size and member");
        }
    }
}
 
Example #4
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 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 #5
Source File: Device.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(memberName, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(memberName);
    }
    if (ID.equals(memberName)) {
        return deviceId;
    }
    if (PROPERTIES.equals(memberName)) {
        return properties;
    }
    if (IS_CURRENT.equals(memberName)) {
        return new IsCurrentFunction(deviceId, runtime);
    }
    if (SET_CURRENT.equals(memberName)) {
        return new SetCurrentFunction(deviceId, runtime);
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
Example #6
Source File: MultiDimDeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String member,
                @Shared("member") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(member, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(member);
    }
    if (POINTER.equals(memberProfile.profile(member))) {
        return getPointer();
    }
    if (IS_MEMORY_FREED.equals(memberProfile.profile(member))) {
        return arrayFreed;
    }
    if (FREE.equals(memberProfile.profile(member))) {
        return new MultiDimDeviceArrayFreeFunction();
    }
    CompilerDirectives.transferToInterpreter();
    throw new GrCUDAInternalException("trying to read unknown member '" + member + "'");
}
 
Example #7
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (!isMemberReadable(memberName, memberProfile)) {
        CompilerDirectives.transferToInterpreter();
        throw UnknownIdentifierException.create(memberName);
    }
    if (POINTER.equals(memberName)) {
        return getPointer();
    }
    if (COPY_FROM.equals(memberName)) {
        return new DeviceArrayCopyFunction(this, DeviceArrayCopyFunction.CopyDirection.FROM_POINTER);
    }
    if (COPY_TO.equals(memberName)) {
        return new DeviceArrayCopyFunction(this, DeviceArrayCopyFunction.CopyDirection.TO_POINTER);
    }
    if (FREE.equals(memberName)) {
        return new DeviceArrayFreeFunction();
    }
    if (IS_MEMORY_FREED.equals(memberName)) {
        return isMemoryFreed();
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
Example #8
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(final String member) throws UnknownIdentifierException {
    if (WRAPPED_MEMBER.equals(member)) {
        return WrapToSqueakNode.getUncached().executeWrap(wrappedObject);
    }
    final Field field = getFields().get(member);
    if (field != null) {
        try {
            return wrap(field.get(wrappedObject));
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw UnknownIdentifierException.create(member);
        }
    }
    final Method method = getMethods().get(member);
    if (method != null) {
        return new JavaMethodWrapper(wrappedObject, method);
    } else {
        throw UnknownIdentifierException.create(member);
    }
}
 
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: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object readMember(String member) throws UnknownIdentifierException {
    if (frame == null) {
        return HashemPooch.SINGLETON;
    }
    FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        Object value;
        Object info = slot.getInfo();
        if (args != null && info != null) {
            value = args[(Integer) info];
        } else {
            value = frame.getValue(slot);
        }
        return value;
    }
}
 
Example #11
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
void writeMember(String member, Object value) throws UnsupportedMessageException, UnknownIdentifierException {
    if (frame == null) {
        throw UnsupportedMessageException.create();
    }
    FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        Object info = slot.getInfo();
        if (args != null && info != null) {
            args[(Integer) info] = value;
        } else {
            frame.setObject(slot, value);
        }
    }
}
 
Example #12
Source File: HashemToMemberNode.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@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 #13
Source File: HostFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void resolveSymbol() throws UnknownIdentifierException {
    synchronized (this) {
        if (nfiCallable == null) {
            nfiCallable = cudaRuntime.getSymbol(binding);
            assert nfiCallable != null : "NFI callable non-null";
        }
    }
}
 
Example #14
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 #15
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) {
    int index;
    try {
        index = INTEROP.asInt(INTEROP.readMember(argumentSet, name));
    } catch (UnsupportedMessageException | UnknownIdentifierException e) {
        CompilerDirectives.transferToInterpreter();
        throw new MapException("cannot resolve argument index for '" + name + "'");
    }
    return new MapBoundArgObjectArgument(name, index);
}
 
Example #16
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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 #17
Source File: DeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object readMember(String memberName,
                @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException {
    if (MAP.equals(memberProfile.profile(memberName))) {
        return new MapDeviceArrayFunction(runtime);
    }
    CompilerDirectives.transferToInterpreter();
    throw UnknownIdentifierException.create(memberName);
}
 
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: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"member.isByteType()", "lib.isMemberRemovable(object, member.asStringUnsafe())"}, limit = "2")
protected static final Object doRemove(@SuppressWarnings("unused") final Object receiver, final Object object, final NativeObject member,
                @CachedLibrary("object") final InteropLibrary lib) {
    final String identifier = member.asStringUnsafe();
    try {
        lib.removeMember(object, identifier);
        return object;
    } catch (UnknownIdentifierException | UnsupportedMessageException e) {
        throw primitiveFailedInInterpreterCapturing(e);
    }
}
 
Example #20
Source File: ContextObjectInfo.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(final String member) throws UnknownIdentifierException {
    if (frame == null) {
        return NilObject.SINGLETON;
    }
    if (SENDER.equals(member)) {
        return FrameAccess.getSender(frame);
    }
    if (PC.equals(member)) {
        return FrameAccess.getInstructionPointer(frame, FrameAccess.getBlockOrMethod(frame));
    }
    if (STACKP.equals(member)) {
        return FrameAccess.getStackPointer(frame, FrameAccess.getBlockOrMethod(frame));
    }
    if (METHOD.equals(member)) {
        return FrameAccess.getMethod(frame);
    }
    if (CLOSURE_OR_NIL.equals(member)) {
        return NilObject.nullToNil(FrameAccess.getClosure(frame));
    }
    if (RECEIVER.equals(member)) {
        return FrameAccess.getReceiver(frame);
    }
    final FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        return Objects.requireNonNull(frame.getValue(slot));
    }
}
 
Example #21
Source File: AbstractFactory.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: NodeProfJalangi.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@TruffleBoundary
private static Object getProperty(TruffleObject cb, String prop) {
    Object result = null;
    try {
        result = InteropLibrary.getFactory().getUncached().readMember(cb, prop);
    } catch (UnknownIdentifierException | UnsupportedMessageException e) {
        // undefined property is expected
    }
    if (Undefined.instance == result || Null.instance == result) {
        result = null;
    }
    return result;
}
 
Example #23
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"member.isByteType()", "lib.isMemberReadable(object, member.asStringUnsafe())",
                "!lib.hasMemberReadSideEffects(object, member.asStringUnsafe())"}, limit = "2")
protected static final Object doReadMember(@SuppressWarnings("unused") final Object receiver, final Object object, final NativeObject member,
                @Cached final WrapToSqueakNode wrapNode,
                @CachedLibrary("object") final InteropLibrary lib) {
    try {
        return wrapNode.executeWrap(lib.readMember(object, member.asStringUnsafe()));
    } catch (UnknownIdentifierException | UnsupportedMessageException e) {
        throw primitiveFailedInInterpreterCapturing(e);
    }
}
 
Example #24
Source File: SqueakFFIPrims.java    From trufflesqueak with MIT License 5 votes vote down vote up
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 #25
Source File: ClassObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
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 #26
Source File: AbstractOSProcessPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
protected final Object getSysCallObject() {
    assert supportsNFI;
    if (sysCallObject == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        final Object defaultLibrary = SqueakLanguage.getContext().env.parseInternal(Source.newBuilder("nfi", "default", "native").build()).call();
        final InteropLibrary lib = InteropLibrary.getFactory().getUncached();
        try {
            final Object symbol = lib.readMember(defaultLibrary, getFunctionName());
            sysCallObject = lib.invokeMember(symbol, "bind", getFunctionSignature());
        } catch (UnsupportedMessageException | UnknownIdentifierException | ArityException | UnsupportedTypeException e) {
            throw PrimitiveFailed.andTransferToInterpreterWithError(e);
        }
    }
    return sysCallObject;
}
 
Example #27
Source File: ContextObjectInfo.java    From trufflesqueak with MIT License 5 votes vote down vote up
@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 #28
Source File: HashemReadPropertyNode.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@Specialization(guards = "objects.hasMembers(receiver)", limit = "LIBRARY_LIMIT")
protected Object writeObject(Object receiver, Object name,
                             @CachedLibrary("receiver") InteropLibrary objects,
                             @Cached HashemToMemberNode asMember) {
    try {
        return objects.readMember(receiver, asMember.execute(name));
    } catch (UnsupportedMessageException | UnknownIdentifierException e) {
        // read was not successful. In Hashemi we only have basic support for errors.
        throw HashemUndefinedNameException.undefinedProperty(this, name);
    }
}
 
Example #29
Source File: HashemWritePropertyNode.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@Specialization(limit = "LIBRARY_LIMIT")
protected Object write(Object receiver, Object name, Object value,
                @CachedLibrary("receiver") InteropLibrary objectLibrary,
                @Cached HashemToMemberNode asMember) {
    try {
        objectLibrary.writeMember(receiver, asMember.execute(name), value);
    } catch (UnsupportedMessageException | UnknownIdentifierException | UnsupportedTypeException e) {
        // write was not successful. In Hashemi we only have basic support for errors.
        throw HashemUndefinedNameException.undefinedProperty(this, name);
    }
    return value;
}
 
Example #30
Source File: HashemObjectType.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@ExportMessage
static boolean removeMember(DynamicObject receiver, String member) throws UnknownIdentifierException {
    if (receiver.containsKey(member)) {
        return receiver.delete(member);
    } else {
        throw UnknownIdentifierException.create(member);
    }
}