Master the fundamental concepts of garbage collection through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksStop-the-world pauses hurt latency. Concurrent mark-sweep runs marker alongside mutator with write barriers to catch new references. G1, ZGC, and Go's concurrent sweeper reduce pause times to milliseconds or sub-ms.
White: unvisited. Gray: visited, children pending. Black: fully scanned. Barrier ensures black objects do not point to white without gray intervention.
cLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will understand concurrent garbage collection algorithms. This exercise asks you to model tri-color marking, write barriers, and how the collector maintains correctness while the mutator allocates.
Simulate concurrent marking with the tri-color abstraction and see why concurrent collectors need write barriers: interleave collector steps with mutator writes, run the same schedule with no barrier, a Dijkstra insertion barrier and a Yuasa deletion (snapshot-at-the-beginning) barrier, and detect when a live object gets freed.
cLoading…
dijkstra: on link A B, if B is white, shade B grey.satb: on unlink A B, if B is white, shade B grey (the old value is preserved).none: nothing.cLoading…
The classic lost object: the mutator moves the only pointer to c from a grey object into a black one.
Input:
cLoading…
Output:
cLoading…
link/unlink.Hidden tests run the lost-object schedule under both barriers, a schedule where satb retains floating garbage (an object unlinked during marking survives even though it is dead), and objects created unreachable.