Search in sources :

Example 6 with LLVMManagedPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer in project graal by oracle.

the class LLVMGlobalRootNode method executeWithoutFrame.

@SuppressWarnings("try")
@TruffleBoundary
private Object executeWithoutFrame() {
    LLVMStack stack = getContext().getThreadingStack().getStack();
    try {
        Object appPath = new LLVMArgumentBuffer(applicationPath);
        LLVMManagedPointer applicationPathObj = LLVMManagedPointer.create(appPath);
        Object[] realArgs = new Object[] { stack, mainFunctionType, applicationPathObj, getContext().getSymbolUncached(mainFunction) };
        Object result = startFunction.call(realArgs);
        getContext().awaitThreadTermination();
        return (int) result;
    } catch (LLVMExitException e) {
        LLVMContext context = getContext();
        // if any variant of exit or abort was called, we know that all the necessary
        // cleanup was already done
        context.setCleanupNecessary(false);
        context.awaitThreadTermination();
        return e.getExceptionExitStatus();
    } finally {
        // if not done already, we want at least call a shutdown command
        getContext().shutdownThreads();
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) LLVMExitException(com.oracle.truffle.llvm.runtime.LLVMExitException) LLVMArgumentBuffer(com.oracle.truffle.llvm.runtime.LLVMArgumentBuffer) LLVMManagedPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 7 with LLVMManagedPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer in project graal by oracle.

the class LLVMInteropReadNode method doClazzCached.

@Specialization(guards = { "type == cachedType", "offset == 0", "cachedType != null", "cachedType.hasVirtualMethods()" })
Object doClazzCached(@SuppressWarnings("unused") LLVMInteropType.Clazz type, Object foreign, @SuppressWarnings("unused") long offset, @SuppressWarnings("unused") ForeignToLLVMType accessType, @Cached("type") @SuppressWarnings("unused") LLVMInteropType.Clazz cachedType, @Cached("cachedType.getVTable()") LLVMInteropType.VTable vTable) {
    // return an artificially created pointer pointing to vtable and foreign object
    LLVMInteropType.VTableObjectPair vTableObjectPair = LLVMInteropType.VTableObjectPair.create(vTable, foreign);
    LLVMManagedPointer pointer = LLVMManagedPointer.create(vTableObjectPair);
    return pointer;
}
Also used : LLVMManagedPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 8 with LLVMManagedPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer in project graal by oracle.

the class LLVMLookupDispatchTargetNode method doLookupNativeFunctionCachedSymbol.

/*
     * Try to cache the target symbol if it's always the same one, the reverse lookup is much faster
     * and doesn't need a TruffleBoundary.
     */
@Specialization(guards = { "!isAutoDerefHandle(pointer.asNative())", "cachedSymbol != null" }, replaces = { "doHandleCached", "doNativeFunctionCached" }, rewriteOn = LLVMIllegalSymbolIndexException.class)
protected Object doLookupNativeFunctionCachedSymbol(VirtualFrame frame, LLVMNativePointer pointer, @Cached("lookupFunctionSymbol(pointer)") LLVMAccessSymbolNode cachedSymbol) {
    /*
         * The cache will be invalidated if the symbol cannot be found in the symbol table. In which
         * case the entire specialisation will be rewritten when the context throws an
         * LLVMIllegalSymbolIndexException.
         */
    LLVMPointer symbolPointer = cachedSymbol.executeGeneric(frame);
    // guard against uninitialized symbols in multi-context cases
    if (LLVMManagedPointer.isInstance(symbolPointer)) {
        LLVMManagedPointer managedPointer = LLVMManagedPointer.cast(symbolPointer);
        if (managedPointer.getOffset() == 0 && managedPointer.getObject() instanceof LLVMFunctionDescriptor) {
            LLVMFunctionDescriptor descriptor = (LLVMFunctionDescriptor) managedPointer.getObject();
            long nativePointer = descriptor.getNativePointer();
            if (nativePointer != 0 && nativePointer == pointer.asNative()) {
                return descriptor;
            }
        }
    }
    CompilerDirectives.transferToInterpreterAndInvalidate();
    throw new LLVMIllegalSymbolIndexException("mismatching function");
}
Also used : LLVMIllegalSymbolIndexException(com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) LLVMManagedPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 9 with LLVMManagedPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer in project graal by oracle.

the class GraalVMResolveFunction method doNativePointerResolve.

@Specialization(guards = "pointsToLong(pointer)")
protected Object doNativePointerResolve(LLVMPointer pointer) {
    LLVMManagedPointer object = LLVMManagedPointer.cast(pointer);
    Object pointerValue = object.getObject();
    LLVMNativePointer nativePointer = LLVMNativePointer.create((long) pointerValue);
    return LLVMManagedPointer.create(getContext().getFunctionDescriptor(nativePointer));
}
Also used : LLVMNativePointer(com.oracle.truffle.llvm.runtime.pointer.LLVMNativePointer) LLVMManagedPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 10 with LLVMManagedPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer in project graal by oracle.

the class DebugExprFunctionCallNode method getType.

@TruffleBoundary
public DebugExprType getType() {
    InteropLibrary library = InteropLibrary.getFactory().getUncached();
    if (library.isMemberReadable(scope, functionName)) {
        try {
            Object member = library.readMember(scope, functionName);
            if (LLVMManagedPointer.isInstance(member)) {
                LLVMManagedPointer pointer = LLVMManagedPointer.cast(member);
                if (pointer.getOffset() == 0) {
                    member = pointer.getObject();
                }
            }
            if (member instanceof LLVMFunctionDescriptor) {
                LLVMFunctionDescriptor ldv = (LLVMFunctionDescriptor) member;
                Type returnType = ldv.getLLVMFunction().getType().getReturnType();
                DebugExprType t = DebugExprType.getTypeFromLLVMType(returnType);
                return t;
            } else {
                throw DebugExprException.create(this, "variable %s does not point to a function", functionName);
            }
        } catch (UnsupportedMessageException e) {
            throw DebugExprException.create(this, "error while accessing function %s", functionName);
        } catch (UnknownIdentifierException e) {
        // fallthrough
        }
    }
    throw DebugExprException.symbolNotFound(this, functionName, null);
}
Also used : DebugExprType(com.oracle.truffle.llvm.runtime.debug.debugexpr.parser.DebugExprType) Type(com.oracle.truffle.llvm.runtime.types.Type) DebugExprType(com.oracle.truffle.llvm.runtime.debug.debugexpr.parser.DebugExprType) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) LLVMFunctionDescriptor(com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor) LLVMManagedPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

LLVMManagedPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer)10 Specialization (com.oracle.truffle.api.dsl.Specialization)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)3 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)2 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)1 LLVMArgumentBuffer (com.oracle.truffle.llvm.runtime.LLVMArgumentBuffer)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1 LLVMExitException (com.oracle.truffle.llvm.runtime.LLVMExitException)1 DebugExprType (com.oracle.truffle.llvm.runtime.debug.debugexpr.parser.DebugExprType)1 LLVMIllegalSymbolIndexException (com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException)1 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)1 AccessLocation (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropAccessNode.AccessLocation)1 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)1 LLVMNativePointer (com.oracle.truffle.llvm.runtime.pointer.LLVMNativePointer)1 Type (com.oracle.truffle.llvm.runtime.types.Type)1