use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer in project graal by oracle.
the class LLVMGlobalRootNode method executeWithoutFrame.
@SuppressWarnings("try")
@TruffleBoundary
private Object executeWithoutFrame() {
LLVMStack stack = getContext().getThreadingStack().getStack();
try {
Object appPath = new LLVMArgumentBuffer(applicationPath);
LLVMManagedPointer applicationPathObj = LLVMManagedPointer.create(appPath);
Object[] realArgs = new Object[] { stack, mainFunctionType, applicationPathObj, getContext().getSymbolUncached(mainFunction) };
Object result = startFunction.call(realArgs);
getContext().awaitThreadTermination();
return (int) result;
} catch (LLVMExitException e) {
LLVMContext context = getContext();
// if any variant of exit or abort was called, we know that all the necessary
// cleanup was already done
context.setCleanupNecessary(false);
context.awaitThreadTermination();
return e.getExceptionExitStatus();
} finally {
// if not done already, we want at least call a shutdown command
getContext().shutdownThreads();
}
}
use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer in project graal by oracle.
the class LLVMInteropReadNode method doClazzCached.
@Specialization(guards = { "type == cachedType", "offset == 0", "cachedType != null", "cachedType.hasVirtualMethods()" })
Object doClazzCached(@SuppressWarnings("unused") LLVMInteropType.Clazz type, Object foreign, @SuppressWarnings("unused") long offset, @SuppressWarnings("unused") ForeignToLLVMType accessType, @Cached("type") @SuppressWarnings("unused") LLVMInteropType.Clazz cachedType, @Cached("cachedType.getVTable()") LLVMInteropType.VTable vTable) {
// return an artificially created pointer pointing to vtable and foreign object
LLVMInteropType.VTableObjectPair vTableObjectPair = LLVMInteropType.VTableObjectPair.create(vTable, foreign);
LLVMManagedPointer pointer = LLVMManagedPointer.create(vTableObjectPair);
return pointer;
}
use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer 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.LLVMManagedPointer in project graal by oracle.
the class GraalVMResolveFunction method doNativePointerResolve.
@Specialization(guards = "pointsToLong(pointer)")
protected Object doNativePointerResolve(LLVMPointer pointer) {
LLVMManagedPointer object = LLVMManagedPointer.cast(pointer);
Object pointerValue = object.getObject();
LLVMNativePointer nativePointer = LLVMNativePointer.create((long) pointerValue);
return LLVMManagedPointer.create(getContext().getFunctionDescriptor(nativePointer));
}
use of com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer in project graal by oracle.
the class DebugExprFunctionCallNode method getType.
@TruffleBoundary
public DebugExprType getType() {
InteropLibrary library = InteropLibrary.getFactory().getUncached();
if (library.isMemberReadable(scope, functionName)) {
try {
Object member = library.readMember(scope, functionName);
if (LLVMManagedPointer.isInstance(member)) {
LLVMManagedPointer pointer = LLVMManagedPointer.cast(member);
if (pointer.getOffset() == 0) {
member = pointer.getObject();
}
}
if (member instanceof LLVMFunctionDescriptor) {
LLVMFunctionDescriptor ldv = (LLVMFunctionDescriptor) member;
Type returnType = ldv.getLLVMFunction().getType().getReturnType();
DebugExprType t = DebugExprType.getTypeFromLLVMType(returnType);
return t;
} else {
throw DebugExprException.create(this, "variable %s does not point to a function", functionName);
}
} catch (UnsupportedMessageException e) {
throw DebugExprException.create(this, "error while accessing function %s", functionName);
} catch (UnknownIdentifierException e) {
// fallthrough
}
}
throw DebugExprException.symbolNotFound(this, functionName, null);
}
Aggregations