[LLVMdev] Accurate garbage collection

Jon Harrop jonathandeanharrop at googlemail.com
Sun Dec 18 07:29:38 PST 2011

Yes, performing GC checks at allocation can be good too. There are some

Allocations tend to be more common than functions so checking per allocation
is more of a burden and, furthermore, it means you may have more GC safe

HLVM's design is interesting in this regard as well. Specifically, its IR
has no concept of loops or jumps other than tail calls between functions. So
performing a GC check at the beginning of every function guarantees that
checks will be performed regularly. This is necessary because HLVM's GC
allows mutators to run in parallel, replying upon cooperative suspension. So
every mutator thread regularly checks the global GC state to see if another
thread has asked it to suspend itself pending a GC cycle. The only exception
is blocking calls (such as acquiring a lock) which work by temporarily
suspending themselves (making it safe for other threads to do a GC cycle
without them) and resuming when the blocking call returns.

As an optimization, HLVM actually just increments a local counter in its GC
check until the counter exceeds another threshold whereupon it does the
global GC check and resets the counter. All thread-local data are made
accessible via a pointer that is passed around as part of HLVM's calling
convention which, again, is a separate layer on top of LLVM's own fastcc.


> -----Original Message-----
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
> Behalf Of Joachim Durchholz
> Sent: 17 December 2011 09:58
> To: llvmdev at cs.uiuc.edu
> Subject: Re: [LLVMdev] Accurate garbage collection
> Am 16.12.2011 21:06, schrieb Jon Harrop:
> > At regular intervals, check if the heap size has exceeded its quota
> > and, if so, run a GC cycle.
> I have seen people recommend doing this kind of check whenever hitting a
> malloc call.
> I think it nicely scales with the level of heap activity for most
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list