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());
}
}
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);
}
}
}
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()));
}
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");
}
}
}
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.");
}
}
}
Aggregations