use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.
the class GarbageCollectorManagementFactory method blackenStackRoots.
@SuppressWarnings("try")
private void blackenStackRoots() {
final Log trace = Log.noopLog().string("[GCImpl.blackenStackRoots:").newline();
try (Timer bsr = blackenStackRootsTimer.open()) {
Pointer sp = readCallerStackPointer();
trace.string("[blackenStackRoots:").string(" sp: ").hex(sp);
CodePointer ip = readReturnAddress();
trace.string(" ip: ").hex(ip).newline();
JavaStackWalker.walkCurrentThread(sp, ip, frameWalker);
if (SubstrateOptions.MultiThreaded.getValue()) {
/*
* Scan the stacks of all the threads. Other threads will be blocked at a safepoint
* (or in native code) so they will each have a JavaFrameAnchor in their VMThread.
*/
for (IsolateThread vmThread = VMThreads.firstThread(); VMThreads.isNonNullThread(vmThread); vmThread = VMThreads.nextThread(vmThread)) {
if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
/*
* The current thread is already scanned by code above, so we do not have to
* do anything for it here. It might have a JavaFrameAnchor from earlier
* Java-to-C transitions, but certainly not at the top of the stack since it
* is running this code, so just this scan would be incomplete.
*/
continue;
}
JavaStackWalker.walkThread(vmThread, frameWalker);
trace.newline();
}
}
trace.string("]").newline();
}
trace.string("]").newline();
}
use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.
the class StackVerifier method verifyInAllThreads.
public boolean verifyInAllThreads(Pointer currentSp, CodePointer currentIp, String message) {
final Log trace = getTraceLog();
trace.string("[StackVerifier.verifyInAllThreads:").string(message).newline();
// Flush thread-local allocation data.
ThreadLocalAllocation.disableThreadLocalAllocation();
trace.string("Current thread ").hex(CEntryPointContext.getCurrentIsolateThread()).string(": [").newline();
if (!JavaStackWalker.walkCurrentThread(currentSp, currentIp, stackFrameVisitor)) {
return false;
}
trace.string("]").newline();
if (SubstrateOptions.MultiThreaded.getValue()) {
for (IsolateThread vmThread = VMThreads.firstThread(); VMThreads.isNonNullThread(vmThread); vmThread = VMThreads.nextThread(vmThread)) {
if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
continue;
}
trace.string("Thread ").hex(vmThread).string(": [").newline();
if (!JavaStackWalker.walkThread(vmThread, stackFrameVisitor)) {
return false;
}
trace.string("]").newline();
}
}
trace.string("]").newline();
return true;
}
use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.
the class PinnedAllocatorImpl method close.
@Override
public void close() {
log().string("[PinnedAllocatorImpl.close: ").object(this).newline();
ensureOpen();
/* Capture "this", the tlab and the VMThread for the VMOperation. */
final PinnedAllocatorImpl pinnedAllocatorImpl = this;
final ThreadLocalAllocation.Descriptor tlab = ThreadLocalAllocation.pinnedTLAB.getAddress();
final IsolateThread requestingVMThread = CEntryPointContext.getCurrentIsolateThread();
VMOperation.enqueueBlockingSafepoint("PinnedAllocatorImpl.close", () -> {
ThreadLocalAllocation.retireToSpace(tlab, HeapImpl.getHeapImpl().getOldGeneration().getPinnedFromSpace());
assert ThreadLocalAllocation.verifyUninitialized(tlab);
/* Now our TLAB is clean, so we can change the phase. */
openPinnedAllocator.set(requestingVMThread, null);
pinnedAllocatorImpl.phase = LifeCyclePhase.CLOSED;
});
assert phase == LifeCyclePhase.CLOSED : "PinnedAllocatorImpl.close: VMOperation failed to close.";
log().string(" ]").newline();
}
use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.
the class Deoptimizer method deoptimizeInRangeOperation.
/**
* Deoptimize a specific method on all thread stacks.
*/
private static void deoptimizeInRangeOperation(CodePointer fromIp, CodePointer toIp, boolean deoptAll) {
VMOperation.guaranteeInProgress("Deoptimizer.deoptimizeInRangeOperation, but not in VMOperation.");
/* Handle my own thread specially, because I do not have a JavaFrameAnchor. */
StackFrameVisitor currentThreadDeoptVisitor = getStackFrameVisitor((Pointer) fromIp, (Pointer) toIp, deoptAll, CEntryPointContext.getCurrentIsolateThread());
Pointer sp = KnownIntrinsics.readCallerStackPointer();
CodePointer ip = KnownIntrinsics.readReturnAddress();
JavaStackWalker.walkCurrentThread(sp, ip, currentThreadDeoptVisitor);
/* If I am multi-threaded, deoptimize this method on all the other stacks. */
if (SubstrateOptions.MultiThreaded.getValue()) {
for (IsolateThread vmThread = VMThreads.firstThread(); VMThreads.isNonNullThread(vmThread); vmThread = VMThreads.nextThread(vmThread)) {
if (vmThread == CEntryPointContext.getCurrentIsolateThread()) {
continue;
}
StackFrameVisitor deoptVisitor = getStackFrameVisitor((Pointer) fromIp, (Pointer) toIp, deoptAll, vmThread);
JavaStackWalker.walkThread(vmThread, deoptVisitor);
}
}
if (testGCinDeoptimizer) {
Heap.getHeap().getGC().collect("from Deoptimizer.deoptimizeInRange because of testGCinDeoptimizer");
}
}
use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.
the class CInterfaceTutorial method dump.
protected static void dump(MyData data) {
System.out.format("**** In Java ****\n");
System.out.format("primitive: %d\n", data.getPrimitive());
System.out.format("length: %d\n", getDataLength());
for (int i = 0; i < getDataLength(); i++) {
System.out.format("%d ", data.addressOfArray().read(i));
}
System.out.format("\n");
IsolateThread currentThread = CEntryPointContext.getCurrentIsolateThread();
/* Call a C function directly. */
printingInC(currentThread, data.getCString());
/* Call a C function indirectly via function pointer. */
data.getPrintFunction().invoke(currentThread, data.getCString());
}
Aggregations