Skip to content

Commit

Permalink
Fix stack top/bottom print order in GC_push_all_stacks if stack grows up
Browse files Browse the repository at this point in the history
* mark_rts.c [THREADS] (GC_push_all_stack_sections): Add comment for lo
and hi arguments.
* mark_rts.c [!THREADS] (GC_push_all_stack_part_eager_sections):
Likewise.
* pthread_stop_world.c (GC_push_all_stacks): Add comment for lo and hi
local variables.
* pthread_stop_world.c [DEBUG_THREADS && STACK_GROWS_UP]: Print values
of lo and hi variables in reversed order.
  • Loading branch information
ivmai committed May 20, 2023
1 parent 321cf38 commit 761414b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions mark_rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ STATIC void GC_push_conditional_with_exclusions(ptr_t bottom, ptr_t top,

#ifdef THREADS

GC_INNER void GC_push_all_stack_sections(ptr_t lo, ptr_t hi,
GC_INNER void GC_push_all_stack_sections(
ptr_t lo /* top */, ptr_t hi /* bottom */,
struct GC_traced_stack_sect_s *traced_stack_sect)
{
while (traced_stack_sect != NULL) {
Expand Down Expand Up @@ -753,8 +754,9 @@ STATIC void GC_push_all_stack_partially_eager(ptr_t bottom, ptr_t top,
}

/* Similar to GC_push_all_stack_sections() but also uses cold_gc_frame. */
STATIC void GC_push_all_stack_part_eager_sections(ptr_t lo, ptr_t hi,
ptr_t cold_gc_frame, struct GC_traced_stack_sect_s *traced_stack_sect)
STATIC void GC_push_all_stack_part_eager_sections(
ptr_t lo /* top */, ptr_t hi /* bottom */, ptr_t cold_gc_frame,
struct GC_traced_stack_sect_s *traced_stack_sect)
{
GC_ASSERT(traced_stack_sect == NULL || cold_gc_frame == NULL ||
(word)cold_gc_frame HOTTER_THAN (word)traced_stack_sect);
Expand Down
14 changes: 10 additions & 4 deletions pthread_stop_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ GC_INNER void GC_push_all_stacks(void)
size_t nthreads = 0;
int i;
GC_thread p;
ptr_t lo, hi;
ptr_t lo; /* stack top (sp) */
ptr_t hi; /* bottom */
# if defined(E2K) || defined(IA64)
/* We also need to scan the register backing store. */
ptr_t bs_lo, bs_hi;
Expand Down Expand Up @@ -850,8 +851,13 @@ GC_INNER void GC_push_all_stacks(void)
# endif
}
# ifdef DEBUG_THREADS
GC_log_printf("Stack for thread %p is [%p,%p)\n",
(void *)p->id, (void *)lo, (void *)hi);
# ifdef STACK_GROWS_UP
GC_log_printf("Stack for thread %p is (%p,%p]\n",
(void *)(p -> id), (void *)hi, (void *)lo);
# else
GC_log_printf("Stack for thread %p is [%p,%p)\n",
(void *)(p -> id), (void *)lo, (void *)hi);
# endif
# endif
if (0 == lo) ABORT("GC_push_all_stacks: sp not set!");
if (p->altstack != NULL && (word)p->altstack <= (word)lo
Expand Down Expand Up @@ -883,7 +889,7 @@ GC_INNER void GC_push_all_stacks(void)
# if defined(E2K) || defined(IA64)
# ifdef DEBUG_THREADS
GC_log_printf("Reg stack for thread %p is [%p,%p)\n",
(void *)p->id, (void *)bs_lo, (void *)bs_hi);
(void *)(p -> id), (void *)bs_lo, (void *)bs_hi);
# endif
GC_ASSERT(bs_lo != NULL && bs_hi != NULL);
/* FIXME: This (if p->id==self) may add an unbounded number of */
Expand Down

0 comments on commit 761414b

Please sign in to comment.