Java / Java 17 Garbage Collection Interview Questions
Define a stop-the-world pause?
A stop-the-world (STW) pause is a period during which the JVM suspends every application ("mutator") thread at a safepoint so the garbage collector can safely inspect and move objects without the program changing references out from under it.
STW pauses are necessary because moving or relocating live objects while application threads are simultaneously reading and writing references would produce a corrupted, inconsistent heap.
Collectors differ mainly in how much of their work happens inside an STW pause versus concurrently alongside the running application: Serial and Parallel GC do almost all their work stop-the-world, G1 confines STW pauses to specific phases (initial mark, remark, evacuation), and ZGC/Shenandoah keep STW pauses down to brief root-scanning steps, doing marking and relocation concurrently.
More Related questions...