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