Re[4]: [Gc] Back to "GC Stack problem on Win32"

Ivan Maidanski ivmai at mail.ru
Fri Dec 5 01:05:02 PST 2008


Hi!

"Boehm, Hans" <hans.boehm at hp.com> wrote:
> How about something like this at the end of GC_push_stack_for?
> 
> This will still repeatedly grow the stack for something like your example.  But, as in the last version, I think the total number of VirtualQuery calls is bounded by the final stack depth, plus one for each GC.
>
> Unlike my last version, this should typically avoid the GC_get_stack_min calls in your example.
> 
> I'm not sure I want to introduce very ugly code to handle something like this example a bit better.  The collector already does work in proportion to the root size.  And this seems to be another example where a huge root size causes it to slow down.

Ok. To say the truth, all this code is just for verifying that GetThreadContext and VirtualQuery work (useful only when we porting GC to other arch, or, may be, during debug of an app). It's not good if this code consumes much time in some situations, but if these are rare then it may be acceptable, I think.

> 
> (Warning: completely untested)
> 
>      /* Set stack_min to the lowest address in the thread stack,        */
>       /* or to an address in the thread stack no larger than sp,        */
>       /* taking advantage of the old value to avoid slow traversals     */
>       /* of large stacks.                                               */
>       if (thread -> last_stack_min == ADDR_LIMIT) {
>         stack_min = GC_get_stack_min(thread -> stack_base);

Insert here: thread -> last_stack_min = stack_min;

>       } else {
>         if (sp < thread -> stack_base && sp >= thread -> last_stack_min) {
>             stack_min = sp;
>         } else {
> #         ifdef MSWINCE
>             stack_min = GC_get_stack_min(thread -> stack_base);
> #         else
>             if (GC_may_be_in_stack(thread -> last_stack_min)) {
>               stack_min = GC_get_stack_min(thread -> last_stack_min);
>             } else {
>               /* Stack shrunk?  Is this possible? */

Really not (AFAIK). And what then should we do here? Same thing, I think.

>               stack_min = GC_get_stack_min(thread -> stack_base);
>             }
> #         endif

Insert here: thread -> last_stack_min = stack_min;

>         }
>       }
>       thread -> last_stack_min = stack_min;
Remove it here.

> 
>       if (sp >= stack_min && sp < thread->stack_base) {
> #       ifdef DEBUG_THREADS
>           GC_printf("Pushing thread from %p to %p for 0x%x from 0x%x\n",
>                     sp, thread -> stack_base, (int)thread -> id, (int)me);
> #       endif
>         GC_push_all_stack(sp, thread->stack_base);
>       } else {
>         /* If not current thread then it is possible for sp to point to */
>         /* the guarded (untouched yet) page just below the current      */
>         /* stack_min of the thread.                                     */
>         if (thread -> id == me || sp >= thread->stack_base
>                 || sp + GC_page_size < stack_min)
>           WARN("Thread stack pointer 0x%lx out of range, pushing everything\n",
>                 (unsigned long)(size_t)sp);
>         GC_push_all_stack(stack_min, thread->stack_base);
>       }
>     } /* thread looks live */
> 
> Hans
> 
> > -----Original Message-----
> > ...

Bye.



More information about the Gc mailing list