[Gc] Scanning the System Stack

C. Scott Ananian cananian at lesser-magoo.csail.mit.edu
Tue Mar 30 06:41:38 PST 2004


On Tue, 30 Mar 2004, Andrew Begel wrote:

> With pthread-based threaded execution, each stack start could be at a 
> completely unknown location, specifiable at pthread_create(), but not 
> retrievable afterwards. Without this information (except on MacOSX) you 
> can't scan the stack because you don't know where it starts.

Not quite.  The way the BDW collector does this "portably" is by wrapping
the pthread_create() call so that it first invokes a BDW method, which
*then* turns around and calls your thread start method.  The BDW method
knows that there's nothing "important" on the stack yet, so it just looks
at its own stack pointer at that instance and uses that as "start of
stack".  To find your own stack pointer quasi-portably:

void *approx_sp() { int a; return &a; }

The original poster also asked about registers. The collector must
seemingly ensure that all caller-save registers have found their way to
the stack before gc starts.  There's no "portable" way to do this (that I
know of); there's some OS-dependent code which usually finds the registers
somewhere in the thread structure after the thread has been stopped.  You
probably want to look at the source files which start with "pthread" and
in particular at the function GC_push_all_stacks().  A clear example of
pushing registers is in the aix_irix_threads.c version of
GC_push_all_stacks().  Note also that there is a function called
'GC_save_regs_in_stack()' for some architectures.

If it turns out to matter, I'm looking at version 6.2 of the BDW
collector.

Hope this helps!
 --scott

non-violent protest operation SDI General Morwenstow Milosevic AES 
MI5 Seattle Waco, Texas East Timor affinity group Kojarena Columbia 
                         ( http://cscott.net/ )



More information about the Gc mailing list