use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.
the class LLVMRunDestructorFunctions method runDestructorFunctions.
@TruffleBoundary
private void runDestructorFunctions() {
// is only executed once per context so it will be executed in the interpreter only
LLVMContext context = getContextReference().get();
RootCallTarget[] targets = context.getDestructorFunctions().toArray(new RootCallTarget[0]);
for (RootCallTarget target : targets) {
try (StackPointer stackPointer = context.getThreadingStack().getStack().newFrame()) {
callNode.call(target, new Object[] { stackPointer });
}
}
}
use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.
the class LLVMStackRestore method doVoid.
@Specialization
protected Object doVoid(VirtualFrame frame, LLVMAddress addr) {
StackPointer pointer = (StackPointer) FrameUtil.getObjectSafe(frame, getStackPointerSlot());
pointer.set(addr.getVal());
return null;
}
use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.
the class LLVMContext method initialize.
public void initialize() {
assert !initialized && !cleanupNecessary && globalScope.functionExists("@__sulong_init_context");
if (!initialized) {
initialized = true;
cleanupNecessary = true;
LLVMFunctionDescriptor initContextDescriptor = globalScope.getFunctionDescriptor("@__sulong_init_context");
RootCallTarget initContextFunction = initContextDescriptor.getLLVMIRFunction();
try (StackPointer stackPointer = threadingStack.getStack().newFrame()) {
Object[] args = new Object[] { stackPointer, toTruffleObjects(getApplicationArguments()), toTruffleObjects(getEnvironmentVariables()) };
initContextFunction.call(args);
}
}
}
use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.
the class LLVMForeignCallNode method callIndirect.
@Specialization(replaces = "callDirectCached")
protected Object callIndirect(LLVMFunctionDescriptor function, Object[] arguments, @Cached("create()") IndirectCallNode callNode, @Cached("createSlowPackArguments()") SlowPackForeignArgumentsNode slowPack, @Cached("create()") LLVMGetStackNode getStack, @Cached("getLLVMMemory()") LLVMMemory memory) {
assert !(function.getType().getReturnType() instanceof StructureType);
LLVMStack stack = getStack.executeWithTarget(function.getContext().getThreadingStack(), Thread.currentThread());
Object result;
try (StackPointer stackPointer = stack.newFrame()) {
result = callNode.call(getCallTarget(function), slowPack.pack(function, memory, arguments, stackPointer));
}
return prepareValueForEscape.executeWithTarget(result);
}
use of com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer in project sulong by graalvm.
the class LLVMTruffleInvoke method doInvoke.
@ExplodeLoop
private Object doInvoke(VirtualFrame frame, TruffleObject value, String id, ContextReference<LLVMContext> contextReference, LLVMGetStackNode getStack) {
Object[] evaluatedArgs = new Object[args.length];
for (int i = 0; i < args.length; i++) {
evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
}
try {
LLVMContext context = contextReference.get();
LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
Object rawValue;
try (StackPointer save = stack.newFrame()) {
rawValue = ForeignAccess.sendInvoke(foreignInvoke, value, id, evaluatedArgs);
}
return toLLVM.executeWithTarget(rawValue);
} catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
CompilerDirectives.transferToInterpreter();
throw new IllegalStateException(e);
}
}
Aggregations