Skip to content

Commit

Permalink
Free E2K procedure stack in a single function
Browse files Browse the repository at this point in the history
(refactoring)

Issue #413 (bdwgc).

* include/private/gc_priv.h [E2K] (GC_get_procedure_stack): Document
that the function mgiht be called from a signal handler.
* include/private/gc_priv.h [E2K] (GC_free_procedure_stack): New
function prototype.
* mach_dep.c [E2K] (GC_free_procedure_stack): Implement (just call
free() for now).
* mark_rts.c [!THREADS && !IA64 && E2K] (GC_push_current_stack): Call
GC_free_procedure_stack() instead of free().
* pthread_stop_world.c [E2K] (GC_suspend_handler_inner): Likewise.
* pthread_stop_world.c [E2K] (GC_push_all_stacks): Likewise.
* pthread_support.c [E2K] (GC_do_blocking_inner,
GC_call_with_gc_active): Likewise.
* pthread_stop_world.c [E2K] (GC_push_all_stacks): Move stack_size
local variable declaration to the innermost scope of its usage.
  • Loading branch information
ivmai committed Jan 17, 2022
1 parent f2a2e55 commit 8c2f91a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
8 changes: 7 additions & 1 deletion include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1983,8 +1983,14 @@ GC_INNER void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *),

#ifdef E2K
/* Allocate the buffer and copy the full procedure stack to it. */
/* May be called from a signal handler. */
GC_INNER size_t GC_get_procedure_stack(ptr_t *);
#endif

/* Indicate that the given buffer (used to get a procedure stack) */
/* is not need anymore. */
/* May be called from a signal handler. */
GC_INNER void GC_free_procedure_stack(ptr_t);
#endif /* E2K */

#if defined(E2K) && defined(USE_PTR_HWTAG)
/* Load value and get tag of the target memory. */
Expand Down
4 changes: 4 additions & 0 deletions mach_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
>> (63-E2K_PSHTP_SIZE)); \
} while (0)

GC_INNER void GC_free_procedure_stack(ptr_t buf) {
free(buf);
}

GC_INNER size_t GC_get_procedure_stack(ptr_t *buf_ptr) {
word ps;
ptr_t buf = NULL;
Expand Down
16 changes: 8 additions & 8 deletions mark_rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,12 @@ STATIC void GC_push_current_stack(ptr_t cold_gc_frame,
GC_push_all_stack_part_eager_sections(GC_approx_sp(), GC_stackbottom,
cold_gc_frame, GC_traced_stack_sect);
# ifdef IA64
/* We also need to push the register stack backing store. */
/* This should really be done in the same way as the */
/* regular stack. For now we fudge it a bit. */
/* Note that the backing store grows up, so we can't use */
/* GC_push_all_stack_partially_eager. */
{
/* We also need to push the register stack backing store. */
/* This should really be done in the same way as the */
/* regular stack. For now we fudge it a bit. */
/* Note that the backing store grows up, so we can't use */
/* GC_push_all_stack_partially_eager. */
{
ptr_t bsp = GC_save_regs_ret_val;
ptr_t cold_gc_bs_pointer = bsp - 2048;
if (GC_all_interior_pointers
Expand All @@ -832,7 +832,7 @@ STATIC void GC_push_current_stack(ptr_t cold_gc_frame,
}
/* All values should be sufficiently aligned that we */
/* don't have to worry about the boundary. */
}
}
# elif defined(E2K)
/* We also need to push procedure stack store. */
/* Procedure stack grows up. */
Expand All @@ -843,7 +843,7 @@ STATIC void GC_push_current_stack(ptr_t cold_gc_frame,
GC_push_all_register_sections(bs_lo, bs_lo + stack_size,
TRUE /* eager */,
GC_traced_stack_sect);
free(bs_lo);
GC_free_procedure_stack(bs_lo);
}
# endif
# endif /* !THREADS */
Expand Down
11 changes: 6 additions & 5 deletions pthread_stop_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ STATIC void GC_suspend_handler_inner(ptr_t dummy GC_ATTR_UNUSED,
GC_log_printf("Continuing %p\n", (void *)self);
# endif
# ifdef E2K
free(me -> backing_store_end);
GC_free_procedure_stack(me -> backing_store_end);
me -> backing_store_ptr = NULL;
me -> backing_store_end = NULL;
# endif
Expand Down Expand Up @@ -713,9 +713,6 @@ GC_INNER void GC_push_all_stacks(void)
# if defined(E2K) || defined(IA64)
/* We also need to scan the register backing store. */
ptr_t bs_lo, bs_hi;
# ifdef E2K
size_t stack_size;
# endif
# endif
struct GC_traced_stack_sect_s *traced_stack_sect;
pthread_t self = pthread_self();
Expand All @@ -732,6 +729,10 @@ GC_INNER void GC_push_all_stacks(void)
++nthreads;
traced_stack_sect = p -> traced_stack_sect;
if (THREAD_EQUAL(p -> id, self)) {
# ifdef E2K
size_t stack_size;
# endif

GC_ASSERT(!p->thread_blocked);
# ifdef SPARC
lo = GC_save_regs_in_stack();
Expand Down Expand Up @@ -812,7 +813,7 @@ GC_INNER void GC_push_all_stacks(void)
# endif
# ifdef E2K
if (THREAD_EQUAL(p -> id, self))
free(bs_lo);
GC_free_procedure_stack(bs_lo);
# endif
}
}
Expand Down
4 changes: 2 additions & 2 deletions pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ GC_INNER void GC_do_blocking_inner(ptr_t data, void * context GC_ATTR_UNUSED)
# ifdef E2K
GC_ASSERT(me -> backing_store_end != NULL);
/* Note that me->backing_store_end may differ from bs_lo. */
free(me -> backing_store_end);
GC_free_procedure_stack(me -> backing_store_end);
me -> backing_store_ptr = NULL;
me -> backing_store_end = NULL;
# endif
Expand Down Expand Up @@ -1635,7 +1635,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn,
stacksect.saved_backing_store_ptr = me -> backing_store_ptr;
# elif defined(E2K)
GC_ASSERT(me -> backing_store_end != NULL);
free(me -> backing_store_end);
GC_free_procedure_stack(me -> backing_store_end);
me -> backing_store_ptr = NULL;
me -> backing_store_end = NULL;
# endif
Expand Down

0 comments on commit 8c2f91a

Please sign in to comment.