Search in sources :

Example 1 with BitcodeID

use of com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID in project graal by oracle.

the class LLVMLanguage method parse.

/**
 * If a library has already been parsed, the call target will be retrieved from the language
 * cache.
 *
 * @param request request for parsing
 * @return calltarget of the library
 */
@Override
protected CallTarget parse(ParsingRequest request) {
    if (LLVMContext.get(null).getEnv().isPreInitialization()) {
        throw new UnsupportedOperationException("Parsing not supported during context pre-initialization");
    }
    Source source = request.getSource();
    String path = source.getPath();
    if (source.isCached()) {
        synchronized (libraryCacheLock) {
            CallTarget cached = getCachedLibrary(path);
            if (cached == null) {
                assert !libraryCache.containsKey(path) : "racy insertion despite lock?";
                BitcodeID id = idGenerater.generateID();
                cached = getCapability(Loader.class).load(getContext(), source, id);
                LibraryCacheEntry entry = new LibraryCacheEntry(this, path, cached, id);
                libraryCache.put(path, entry);
            }
            return cached;
        }
    } else {
        // just get the id here and give it to the parserDriver
        return getCapability(Loader.class).load(getContext(), source, idGenerater.generateID());
    }
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) BitcodeID(com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID) Source(com.oracle.truffle.api.source.Source)

Example 2 with BitcodeID

use of com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID 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 3 with BitcodeID

use of com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID in project graal by oracle.

the class LLVMContext method checkSymbol.

/**
 * This method is only intended to be used during initialization of a Sulong library.
 */
@TruffleBoundary
public boolean checkSymbol(LLVMSymbol symbol) {
    assert !symbol.isAlias();
    if (symbol.hasValidIndexAndID()) {
        BitcodeID bitcodeID = symbol.getBitcodeIDUncached();
        int id = bitcodeID.getId();
        if (id < symbolDynamicStorage.length && symbolDynamicStorage[id] != null) {
            LLVMPointer[] symbols = symbolDynamicStorage[id];
            int index = symbol.getSymbolIndexUncached();
            return symbols[index] != null;
        }
    }
    throw new LLVMLinkerException(String.format("External %s %s cannot be found.", symbol.getKind(), symbol.getName()));
}
Also used : 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) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 4 with BitcodeID

use of com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID 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 5 with BitcodeID

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

Aggregations

BitcodeID (com.oracle.truffle.llvm.runtime.IDGenerater.BitcodeID)6 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)4 LLVMIllegalSymbolIndexException (com.oracle.truffle.llvm.runtime.except.LLVMIllegalSymbolIndexException)3 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)3 Assumption (com.oracle.truffle.api.Assumption)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)2 CallTarget (com.oracle.truffle.api.CallTarget)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 Source (com.oracle.truffle.api.source.Source)1