Search in sources :

Example 56 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class LLVMX86_64VaListStorage method shift.

/**
 * This is the implementation of the {@code va_arg} instruction.
 */
@SuppressWarnings("static-method")
@ExportMessage
Object shift(Type type, @SuppressWarnings("unused") Frame frame, @CachedLibrary(limit = "1") LLVMManagedReadLibrary readLib, @CachedLibrary(limit = "1") LLVMManagedWriteLibrary writeLib, @Cached BranchProfile regAreaProfile, @Cached("createBinaryProfile()") ConditionProfile isNativizedProfile) {
    int regSaveOffs = 0;
    int regSaveStep = 0;
    int regSaveLimit = 0;
    boolean lookIntoRegSaveArea = true;
    VarArgArea varArgArea = getVarArgArea(type);
    switch(varArgArea) {
        case GP_AREA:
            regSaveOffs = X86_64BitVarArgs.GP_OFFSET;
            regSaveStep = X86_64BitVarArgs.GP_STEP;
            regSaveLimit = X86_64BitVarArgs.GP_LIMIT;
            break;
        case FP_AREA:
            regSaveOffs = X86_64BitVarArgs.FP_OFFSET;
            regSaveStep = X86_64BitVarArgs.FP_STEP;
            regSaveLimit = X86_64BitVarArgs.FP_LIMIT;
            break;
        case OVERFLOW_AREA:
            lookIntoRegSaveArea = false;
            break;
    }
    if (lookIntoRegSaveArea) {
        regAreaProfile.enter();
        int offs = readLib.readI32(this, regSaveOffs);
        if (offs < regSaveLimit) {
            writeLib.writeI32(this, regSaveOffs, offs + regSaveStep);
            long n = this.regSaveArea.offsetToIndex(offs);
            int i = (int) ((n << 32) >> 32);
            return this.regSaveArea.args[i];
        }
    }
    // overflow area
    if (isNativizedProfile.profile(isNativized())) {
        // Synchronize the managed current argument pointer from the native overflow area
        this.overflowArgArea.setOffset(getArgPtrFromNativePtr(this, readLib));
        Object currentArg = this.overflowArgArea.getCurrentArg();
        // Shift the managed current argument pointer
        this.overflowArgArea.shift(1);
        // Update the new native current argument pointer from the managed one
        long shiftOffs = this.overflowArgArea.getOffset();
        LLVMPointer shiftedOverflowAreaPtr = overflowArgAreaBaseNativePtr.increment(shiftOffs);
        writeLib.writePointer(this, X86_64BitVarArgs.OVERFLOW_ARG_AREA, shiftedOverflowAreaPtr);
        return currentArg;
    } else {
        Object currentArg = this.overflowArgArea.getCurrentArg();
        this.overflowArgArea.shift(1);
        return currentArg;
    }
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 57 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostObject method writeBufferLong.

@ExportMessage
public void writeBufferLong(ByteOrder order, long index, long value, @Shared("isBuffer") @Cached IsBufferNode isBuffer, @Shared("error") @Cached BranchProfile error, @Shared("classProfile") @Cached("createClassProfile()") ValueProfile classProfile) throws InvalidBufferOffsetException, UnsupportedMessageException {
    if (!isBuffer.execute(this)) {
        error.enter();
        throw UnsupportedMessageException.create();
    }
    if (index < 0 || Integer.MAX_VALUE < index) {
        error.enter();
        throw InvalidBufferOffsetException.create(index, Long.BYTES);
    }
    try {
        final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
        final ByteOrder originalOrder = buffer.order();
        buffer.order(order);
        if (isPEFriendlyBuffer(buffer)) {
            buffer.putLong((int) index, value);
        } else {
            putBufferLongBoundary(buffer, (int) index, value);
        }
        buffer.order(originalOrder);
    } catch (IndexOutOfBoundsException e) {
        error.enter();
        throw InvalidBufferOffsetException.create(index, Long.BYTES);
    } catch (ReadOnlyBufferException e) {
        error.enter();
        throw UnsupportedMessageException.create();
    }
}
Also used : ReadOnlyBufferException(java.nio.ReadOnlyBufferException) ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 58 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostObject method isMetaInstance.

@ExportMessage
@TruffleBoundary
boolean isMetaInstance(Object other, @CachedLibrary("this") InteropLibrary library, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
    if (isClass()) {
        Class<?> c = asClass();
        HostLanguage language = context != null ? HostLanguage.get(library) : null;
        if (HostObject.isInstance(language, other)) {
            Object otherHostObj = HostObject.valueOf(language, other);
            if (otherHostObj == null) {
                return false;
            } else {
                return c.isInstance(otherHostObj);
            }
        } else if (HostProxy.isProxyGuestObject(language, other)) {
            Proxy otherHost = HostProxy.toProxyHostObject(language, other);
            return c.isInstance(otherHost);
        } else {
            boolean canConvert = HostToTypeNode.canConvert(other, c, c, HostToTypeNode.allowsImplementation(context, c), context, HostToTypeNode.LOWEST, InteropLibrary.getFactory().getUncached(other), HostTargetMappingNode.getUncached());
            return canConvert;
        }
    } else {
        error.enter();
        throw UnsupportedMessageException.create();
    }
}
Also used : Proxy(org.graalvm.polyglot.proxy.Proxy) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 59 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostObject method invokeMember.

@ExportMessage
Object invokeMember(String name, Object[] args, @Shared("lookupMethod") @Cached LookupMethodNode lookupMethod, @Shared("hostExecute") @Cached HostExecuteNode executeMethod, @Shared("lookupField") @Cached LookupFieldNode lookupField, @Shared("readField") @Cached ReadFieldNode readField, @CachedLibrary(limit = "5") InteropLibrary fieldValues, @Shared("error") @Cached BranchProfile error) throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    if (isNull()) {
        error.enter();
        throw UnsupportedMessageException.create();
    }
    boolean isStatic = isStaticClass();
    Class<?> lookupClass = getLookupClass();
    // (1) look for a method; if found, invoke it on obj.
    HostMethodDesc foundMethod = lookupMethod.execute(this, lookupClass, name, isStatic);
    if (foundMethod != null) {
        return executeMethod.execute(foundMethod, obj, args, context);
    }
    // (2) look for a field; if found, read its value and if that IsExecutable, Execute it.
    HostFieldDesc foundField = lookupField.execute(this, lookupClass, name, isStatic);
    if (foundField != null) {
        Object fieldValue = readField.execute(foundField, this);
        if (fieldValues.isExecutable(fieldValue)) {
            return fieldValues.execute(fieldValue, args);
        }
    }
    error.enter();
    throw UnknownIdentifierException.create(name);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 60 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostObject method readBufferFloat.

@ExportMessage
public float readBufferFloat(ByteOrder order, long index, @Shared("isBuffer") @Cached IsBufferNode isBuffer, @Shared("error") @Cached BranchProfile error, @Shared("classProfile") @Cached("createClassProfile()") ValueProfile classProfile) throws UnsupportedMessageException, InvalidBufferOffsetException {
    if (!isBuffer.execute(this)) {
        error.enter();
        throw UnsupportedMessageException.create();
    }
    if (index < 0 || Integer.MAX_VALUE < index) {
        error.enter();
        throw InvalidBufferOffsetException.create(index, Float.BYTES);
    }
    try {
        final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
        final ByteOrder originalOrder = buffer.order();
        buffer.order(order);
        final float result = isPEFriendlyBuffer(buffer) ? buffer.getFloat((int) index) : getBufferFloatBoundary(buffer, (int) index);
        buffer.order(originalOrder);
        return result;
    } catch (IndexOutOfBoundsException e) {
        error.enter();
        throw InvalidBufferOffsetException.create(index, Float.BYTES);
    }
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Aggregations

ExportMessage (com.oracle.truffle.api.library.ExportMessage)68 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)24 Meta (com.oracle.truffle.espresso.meta.Meta)24 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 Method (com.oracle.truffle.espresso.impl.Method)13 ByteBuffer (java.nio.ByteBuffer)10 ByteOrder (java.nio.ByteOrder)10 Klass (com.oracle.truffle.espresso.impl.Klass)8 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)8 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)8 Value (org.graalvm.polyglot.Value)8 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)8 ArityException (com.oracle.truffle.api.interop.ArityException)7 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)7 ProxyNativeObject (org.graalvm.polyglot.proxy.ProxyNativeObject)7 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)6 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 Field (com.oracle.truffle.espresso.impl.Field)4 ProxyHashMap (org.graalvm.polyglot.proxy.ProxyHashMap)4