Garbage collector examples wanted (original) (raw)

November 13, 2025, 10:52am 1

I am writing a runtime for a garbage collected language. Obviously this is quite a complex topic, and I am definitely at the novice end of the spectrum. I think my best approach might be to:

It would be really helpful to find an exising project or two that implement garbage collectors and make use of LLVM GCStrategy and associated LLVM features that can assist with GC.

If anyone has any links they would care to share that might be helpful in this regard, do please share them!

zero9178 November 13, 2025, 11:19am 2

Hello!

A key thing to realize when using LLVMs GC facilities is to know/realize what it provides and what it doesn’t. LLVM only provides the bare minimum of metadata and code generation that is required for one to write a GC which mainly comes down to the stack map.

The stack map enables you to find all references (pointers in address space 1) that are alive at a specific program counter in a given frame and tells you how to retrieve them (whether they are in a register or in stack memory).

When implementing a GC you can then:

As far as implementation steps are concerned, you should:

We have previously implemented a very simple relocating GC in a JIT LLVM envrionment in a JVM implementation:
Some useful pointers might be: GitHub - JLLVM/JLLVM: JVM implementation using LLVM as a JIT
JLLVM/src/jllvm/vm/StackMapRegistrationPlugin.cpp at main · JLLVM/JLLVM · GitHub
JLLVM/src/jllvm/vm/Runtime.cpp at main · JLLVM/JLLVM · GitHub
JLLVM/src/jllvm/gc/GarbageCollector.cpp at main · JLLVM/JLLVM · GitHub
https://www.youtube.com/watch?v=g9b_G4ao3PY&pp=ygUSSkxMVk0gbWFya3VzIGJvZWNr

Thank you - in terms of complexity, code size and educational value, I don’t think I could have wished for a better example than your JLLVM code, that will certainly help me a lot.

avadeaux December 17, 2025, 5:23am 4

Hi, I’m working on a programming language project, and last summer I did the first version of the design and implementation of the garbage collector for my runtime. I’m not ready to make my actual garbage collector code public (I haven’t got to the point of testing it yet), but in order to understand how to get started I experimented with the statepoint mechanism in LLVM, and created a small demo to make sure I could get it to work. Perhaps you are already past that level, but in case you find it useful, you can find my demo and a description of it in this blog post:

LLVM garbage collection statepoints demo