Master the fundamental concepts of garbage collection through this focused micro-challenge.
Conservative GC treats stack and register words as possible pointers. If a word points into the heap, keep the object. Boehm-Demers-Weiser GC powers some C/C++ runtimes where precise roots are unavailable.
Walk stack slots; if value looks like heap address and aligns to object boundary, treat as reference. No relocation possible because any word might be a disguised pointer.
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 implement conservative garbage collection root scanning. This exercise requires walking stack words, testing heap likelihood, and marking objects without exact pointer maps.
Implement conservative garbage collection.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github