[Gc] Scanning the System Stack

Boehm, Hans hans.boehm at hp.com
Tue Mar 30 10:06:46 PST 2004


There definitely is no portable way to do this.  Sometimes it works to call setjmp
to save the registers, and then scan from the stack base (if you can find it)
to top-of-stack.  Sometimes it doesn't.

In addition to the issues that Andrew and Scott point out (I think Scott meant
"callee-save" registers?), some register stack architectures (notably Itanium)
have two stacks per thread, and it's important to scan both of them.  And ...

Hans

> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com
> [mailto:gc-bounces at napali.hpl.hp.com]On Behalf Of C. Scott Ananian
> Sent: Tuesday, March 30, 2004 6:42 AM
> To: Andrew Begel
> Cc: wlight at weatherlight.com; gc at napali.hpl.hp.com
> Subject: Re: [Gc] Scanning the System Stack
> 
> 
> 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/ )
> 
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> 


More information about the Gc mailing list