Search in sources :

Example 66 with ExportMessage

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

the class LLVMAarch64VaListStorage 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;
    boolean lookIntoRegSaveArea = true;
    VarArgArea varArgArea = getVarArgArea(type);
    RegSaveArea regSaveArea = null;
    switch(varArgArea) {
        case GP_AREA:
            regSaveOffs = Aarch64BitVarArgs.GP_OFFSET;
            regSaveStep = Aarch64BitVarArgs.GP_STEP;
            regSaveArea = gpSaveArea;
            break;
        case FP_AREA:
            regSaveOffs = Aarch64BitVarArgs.FP_OFFSET;
            regSaveStep = Aarch64BitVarArgs.FP_STEP;
            regSaveArea = fpSaveArea;
            break;
        case OVERFLOW_AREA:
            lookIntoRegSaveArea = false;
            break;
    }
    if (lookIntoRegSaveArea) {
        regAreaProfile.enter();
        int offs = readLib.readI32(this, regSaveOffs);
        if (offs < 0) {
            // The va shift logic for GP/FP regsave areas is done by updating the gp/fp offset
            // field in va_list
            writeLib.writeI32(this, regSaveOffs, offs + regSaveStep);
            assert regSaveArea != null;
            long n = regSaveArea.offsetToIndex(offs);
            if (n >= 0) {
                int i = (int) ((n << 32) >> 32);
                return 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, Aarch64BitVarArgs.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 67 with ExportMessage

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

the class CurrentScopeView method getMembers.

@ExportMessage
Object getMembers(@SuppressWarnings("unused") boolean includeInternal, @CachedLibrary("this.scope") InteropLibrary scopeLib, @CachedLibrary(limit = "5") InteropLibrary parentScopeLib) throws UnsupportedMessageException {
    Object allKeys = scopeLib.getMembers(scope);
    if (scopeLib.hasScopeParent(scope)) {
        Object parentScope = scopeLib.getScopeParent(scope);
        Object parentKeys = parentScopeLib.getMembers(parentScope);
        return new SubtractedKeys(allKeys, parentKeys);
    }
    return allKeys;
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 68 with ExportMessage

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

the class LLVMGlobalContainer method toNative.

@TruffleBoundary
@ExportMessage
public void toNative(@Cached LLVMToNativeNode toNative) {
    if (address == 0) {
        LLVMMemory memory = LLVMLanguage.get(null).getLLVMMemory();
        LLVMNativePointer pointer = memory.allocateMemory(toNative, 8);
        address = pointer.asNative();
        long value;
        Object global = getFallback();
        if (global instanceof Number) {
            value = ((Number) global).longValue();
        } else {
            value = toNative.executeWithTarget(global).asNative();
        }
        memory.putI64(toNative, pointer, value);
    }
}
Also used : LLVMMemory(com.oracle.truffle.llvm.runtime.memory.LLVMMemory) LLVMNativePointer(com.oracle.truffle.llvm.runtime.pointer.LLVMNativePointer) LLVMInternalTruffleObject(com.oracle.truffle.llvm.runtime.interop.LLVMInternalTruffleObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

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