Search in sources :

Example 1 with LLVMIllegalSymbolIndexException

use of com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException in project graal by oracle.

the class LLVMContext method setSymbol.

public void setSymbol(LLVMSymbol symbol, LLVMPointer value) {
    CompilerAsserts.neverPartOfCompilation();
    LLVMSymbol target = LLVMAlias.resolveAlias(symbol);
    BitcodeID bitcodeID = symbol.getBitcodeIDUncached();
    int id = bitcodeID.getId();
    LLVMPointer[] symbols = symbolDynamicStorage[id];
    Assumption[] assumptions = symbolAssumptions[id];
    synchronized (symbols) {
        try {
            int index = target.getSymbolIndexUncached();
            symbols[index] = value;
            assumptions[index].invalidate();
            assumptions[index] = Truffle.getRuntime().createAssumption();
            if (target instanceof LLVMFunction) {
                ((LLVMFunction) target).setValue(value);
            }
        } catch (LLVMIllegalSymbolIndexException e) {
            throw CompilerDirectives.shouldNotReachHere("symbol to be replaced was not found: " + target);
        }
    }
}
Also used : LLVMIllegalSymbolIndexException(com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) BitcodeID(com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) Assumption(com.oracle.truffle.api.Assumption)

Example 2 with LLVMIllegalSymbolIndexException

use of com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException in project graal by oracle.

the class LLVMContext method getSymbol.

public LLVMPointer getSymbol(LLVMSymbol symbol, BranchProfile exception) throws LLVMIllegalSymbolIndexException {
    assert !symbol.isAlias();
    BitcodeID bitcodeID = symbol.getBitcodeID(exception);
    int id = bitcodeID.getId();
    int index = symbol.getSymbolIndex(exception);
    if (CompilerDirectives.inCompiledCode() && CompilerDirectives.isPartialEvaluationConstant(this) && CompilerDirectives.isPartialEvaluationConstant(symbol)) {
        if (!symbolAssumptions[id][index].isValid()) {
            CompilerDirectives.transferToInterpreterAndInvalidate();
        }
        try {
            return symbolFinalStorage[id][index];
        } catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
            exception.enter();
            throw new LLVMIllegalSymbolIndexException("cannot find symbol");
        }
    } else {
        try {
            return symbolDynamicStorage[id][index];
        } catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
            exception.enter();
            throw new LLVMIllegalSymbolIndexException("cannot find symbol");
        }
    }
}
Also used : LLVMIllegalSymbolIndexException(com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException) BitcodeID(com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint)

Example 3 with LLVMIllegalSymbolIndexException

use of com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException in project graal by oracle.

the class LLVMContext method initializeSymbol.

/**
 * This method is only intended to be used during initialization of a Sulong library.
 */
@TruffleBoundary
public void initializeSymbol(LLVMSymbol symbol, LLVMPointer value) {
    assert !symbol.isAlias();
    BitcodeID bitcodeID = symbol.getBitcodeIDUncached();
    int id = bitcodeID.getId();
    LLVMPointer[] symbols = symbolDynamicStorage[id];
    Assumption[] assumptions = symbolAssumptions[id];
    synchronized (symbols) {
        try {
            int index = symbol.getSymbolIndexUncached();
            if (symbols[index] != null && symbols[index].isSame(value)) {
                return;
            }
            symbols[index] = value;
            assumptions[index] = Truffle.getRuntime().createAssumption();
            if (symbol instanceof LLVMFunction) {
                ((LLVMFunction) symbol).setValue(value);
            }
        } catch (LLVMIllegalSymbolIndexException e) {
            throw new LLVMLinkerException("Writing symbol into symbol table is inconsistent.");
        }
    }
}
Also used : LLVMIllegalSymbolIndexException(com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException) LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) BitcodeID(com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) Assumption(com.oracle.truffle.api.Assumption) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 4 with LLVMIllegalSymbolIndexException

use of com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException 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)

Aggregations

LLVMIllegalSymbolIndexException (com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException)4 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)3 BitcodeID (com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID)3 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)3 Assumption (com.oracle.truffle.api.Assumption)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Specialization (com.oracle.truffle.api.dsl.Specialization)1 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)1 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)1 LLVMManagedPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer)1