[Gc] Feature Request: Nearly-precise stack tracing

Zach Saw zach.saw at gmail.com
Thu Nov 1 16:02:24 PST 2012


Hi,

I'd like to request a new feature for the GC.

This is a feature that would be useful to implement a nearly precise stack 
trace. Using this, we do not have to trace CPU registers for possible 
pointers.

Note that I've implemented this for my own nearly precise GC a few years ago 
but unfortunately I've only coded it for bcc32 and x86 -- it's therefore not
portable. In my experience (my GC runs 24-7 in a production environment), the
nearly-precise stack tracing method is a lot better at not retaining out of
scope pointers than the conservative one employed by BoehmGC. Out of scope
pointers are extremely rare compared to BoehmGC especially for C++. By out of
scope pointers, I mean pointers that linger in the stack and have not been 
overridden by other info but is already out of scope (e.g. a function call that
declares a char array but never uses it).

Here's what needs to be done for stack tracing:
1) Don't trace CPU registers
2) Tracing stack: treat pointers as possibly valid only if the next GC_word is
equals to a magic number (choose an arbitrary number - preferably one that ends
with an odd number to ensure it won't traced as another pointer)
3) When allocating GC memory, the memory will never get garbage collected 
during the sweep phase, *unless* we tell the GC that it's now ready to be 
collected when untraceable. I haven't looked into your GC code yet but in my 
own implementation, it's merely a single bit in the GC memory block descriptor.

These tweaks should only be enabled via 
GC_set_enable_nearly_precise_stack_tracing.

We also want to be able to tell the GC what that magic number is (e.g. 
GC_set_nearly_precise_stack_trace_magic_number) and another function for 
setting ready-to-be-swept flag -- 
GC_set_nearly_precise_stack_trace_memory_ready.

These features, combined with the stack unwinding of C++ allows us to achieve 
nearly-precise stack tracing.




More information about the Gc mailing list