Search in sources :

Example 31 with LLVMPointer

use of com.oracle.truffle.llvm.runtime.pointer.LLVMPointer 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 32 with LLVMPointer

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

the class LLVMSignal method setSignalHandler.

@TruffleBoundary
private static LLVMPointer setSignalHandler(LLVMContext context, Signal signal, LLVMNativePointer function) {
    int signalId = signal.getNumber();
    LLVMPointer returnFunction = context.getSigDfl();
    try {
        LLVMSignalHandler newSignalHandler = new LLVMSignalHandler(context, signal, function);
        synchronized (registeredSignals) {
            if (registeredSignals.containsKey(signalId)) {
                LLVMSignalHandler currentFunction = registeredSignals.get(signalId);
                if (currentFunction.isRunning()) {
                    returnFunction = currentFunction.getFunction();
                    /*
                         * the new signal handler already manages this signal, so we can safely
                         * deactivate the old one.
                         */
                    currentFunction.setStopped();
                }
            }
            registeredSignals.put(signalId, newSignalHandler);
        }
    } catch (IllegalArgumentException e) {
        return context.getSigErr();
    }
    return returnFunction;
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 33 with LLVMPointer

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

the class LLVMLandingpadNode method doLandingpad.

@Specialization
public Object doLandingpad(VirtualFrame frame) {
    try {
        LLVMUserException exception = (LLVMUserException) frame.getObject(exceptionSlot);
        LLVMPointer unwindHeader = exception.getUnwindHeader();
        LLVMStack stack = (LLVMStack) getStack.executeGeneric(frame);
        int clauseId = getEntryIdentifier(frame, stack, unwindHeader);
        if (clauseId == 0 && !cleanup) {
            throw exception;
        } else {
            LLVMPointer landingPadValue = allocateLandingPadValue.executeLLVMPointer(frame);
            writePointer.executeWithTarget(landingPadValue, unwindHeader);
            writeI32.executeWithTarget(landingPadValue, ADDRESS_SIZE_IN_BYTES, clauseId);
            return landingPadValue;
        }
    } catch (FrameSlotTypeException | UnexpectedResultException e) {
        throw CompilerDirectives.shouldNotReachHere(e);
    }
}
Also used : FrameSlotTypeException(com.oracle.truffle.api.frame.FrameSlotTypeException) UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMUserException(com.oracle.truffle.llvm.runtime.except.LLVMUserException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) Specialization(com.oracle.truffle.api.dsl.Specialization)

Aggregations

LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)33 Specialization (com.oracle.truffle.api.dsl.Specialization)12 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5 LLVMGlobal (com.oracle.truffle.llvm.runtime.global.LLVMGlobal)4 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)3 ExportMessage (com.oracle.truffle.api.library.ExportMessage)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)3 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)3 BitcodeID (com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID)3 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)3 LLVMIllegalSymbolIndexException (com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException)3 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)3 Assumption (com.oracle.truffle.api.Assumption)2 LLVMFunction (com.oracle.truffle.llvm.runtime.LLVMFunction)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 LLVMScopeChain (com.oracle.truffle.llvm.runtime.LLVMScopeChain)2 LLVM80BitFloat (com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat)2 LLVMForeignGetSuperElemPtrNode (com.oracle.truffle.llvm.runtime.interop.export.LLVMForeignGetSuperElemPtrNode)2 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)2 LLVMManagedPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer)2