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