From a7a566616b8daa81671166d0386c251cc0f43461 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 6 Sep 2013 23:36:39 +0400 Subject: [PATCH] Fix collection of objects referenced only from GC_mark_stack_X variables * include/private/gc_pmark.h (mse): Move to gc_priv.h (as used by GC_mark_stack_limit, GC_mark_stack_top, GC_mark_stack). * include/private/gc_pmark.h (GC_mark_stack_limit, GC_mark_stack_top, GC_mark_stack): Remove variable declaration. * include/private/gc_priv.h (_GC_arrays): Add _mark_stack, _mark_stack_limit, _mark_stack_top fields. * include/private/gc_priv.h (GC_mark_stack_limit, GC_mark_stack_top, GC_mark_stack): Define macro (redirecting to the corresponding field of GC_arrays). * mark.c (GC_mark_stack, GC_mark_stack_limit, GC_mark_stack_top): Remove variable; move comment to gc_priv.h. * mark.c (GC_push_marked1, GC_push_marked2, GC_push_marked4): Undefine GC_mark_stack_top and GC_mark_stack_limit macros (before redefining them to local variables) at function start, redefine them back to the corresponding field of GC_arrays at function exit. --- include/private/gc_pmark.h | 16 ---------------- include/private/gc_priv.h | 20 ++++++++++++++++++++ mark.c | 28 ++++++++++++++-------------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/include/private/gc_pmark.h b/include/private/gc_pmark.h index 3aa67a9b..7e302d20 100644 --- a/include/private/gc_pmark.h +++ b/include/private/gc_pmark.h @@ -69,24 +69,8 @@ GC_EXTERN unsigned GC_n_mark_procs; /* Number of mark stack entries to discard on overflow. */ #define GC_MARK_STACK_DISCARDS (INITIAL_MARK_STACK_SIZE/8) -typedef struct GC_ms_entry { - ptr_t mse_start; /* First word of object, word aligned. */ - GC_word mse_descr; /* Descriptor; low order two bits are tags, */ - /* as described in gc_mark.h. */ -} mse; - GC_EXTERN size_t GC_mark_stack_size; -GC_EXTERN mse * GC_mark_stack_limit; - -#ifdef PARALLEL_MARK - GC_EXTERN mse * volatile GC_mark_stack_top; -#else - GC_EXTERN mse * GC_mark_stack_top; -#endif - -GC_EXTERN mse * GC_mark_stack; - #ifdef PARALLEL_MARK /* * Allow multiple threads to participate in the marking process. diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index f0e6cffa..3fdb6874 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -965,6 +965,12 @@ struct roots { # endif #endif /* !MAX_HEAP_SECTS */ +typedef struct GC_ms_entry { + ptr_t mse_start; /* First word of object, word aligned. */ + word mse_descr; /* Descriptor; low order two bits are tags, */ + /* as described in gc_mark.h. */ +} mse; + /* Lists of all heap blocks and free lists */ /* as well as other random data structures */ /* that should not be scanned by the */ @@ -1033,6 +1039,17 @@ struct _GC_arrays { ptr_t _scratch_last_end_ptr; /* Used by headers.c, and can easily appear to point to */ /* heap. */ + mse *_mark_stack; + /* Limits of stack for GC_mark routine. All ranges */ + /* between GC_mark_stack (incl.) and GC_mark_stack_top */ + /* (incl.) still need to be marked from. */ + mse *_mark_stack_limit; +# ifdef PARALLEL_MARK + mse *volatile _mark_stack_top; + /* Updated only with mark lock held, but read asynchronously. */ +# else + mse *_mark_stack_top; +# endif GC_mark_proc _mark_procs[MAX_MARK_PROCS]; /* Table of user-defined mark procedures. There is */ /* a small number of these, which can be referenced */ @@ -1182,6 +1199,9 @@ GC_API_PRIV GC_FAR struct _GC_arrays GC_arrays; #define GC_large_allocd_bytes GC_arrays._large_allocd_bytes #define GC_large_free_bytes GC_arrays._large_free_bytes #define GC_last_heap_addr GC_arrays._last_heap_addr +#define GC_mark_stack GC_arrays._mark_stack +#define GC_mark_stack_limit GC_arrays._mark_stack_limit +#define GC_mark_stack_top GC_arrays._mark_stack_top #define GC_mark_procs GC_arrays._mark_procs #define GC_max_heapsize GC_arrays._max_heapsize #define GC_max_large_allocd_bytes GC_arrays._max_large_allocd_bytes diff --git a/mark.c b/mark.c index d47f4550..825c9c86 100644 --- a/mark.c +++ b/mark.c @@ -96,30 +96,18 @@ GC_INNER unsigned GC_n_kinds = GC_N_KINDS_INITIAL_VALUE; /* grow dynamically. */ # endif -/* - * Limits of stack for GC_mark routine. - * All ranges between GC_mark_stack(incl.) and GC_mark_stack_top(incl.) still - * need to be marked from. - */ - STATIC word GC_n_rescuing_pages = 0; /* Number of dirty pages we marked from */ /* excludes ptrfree pages, etc. */ -GC_INNER mse * GC_mark_stack = NULL; -GC_INNER mse * GC_mark_stack_limit = NULL; GC_INNER size_t GC_mark_stack_size = 0; #ifdef PARALLEL_MARK - GC_INNER mse * volatile GC_mark_stack_top = NULL; - /* Updated only with mark lock held, but read asynchronously. */ STATIC volatile AO_t GC_first_nonempty = 0; /* Lowest entry on mark stack */ /* that may be nonempty. */ /* Updated only by initiating */ /* thread. */ -#else - GC_INNER mse * GC_mark_stack_top = NULL; #endif GC_INNER mark_state_t GC_mark_state = MS_NONE; @@ -1586,6 +1574,9 @@ STATIC void GC_push_marked1(struct hblk *h, hdr *hhdr) ptr_t least_ha = GC_least_plausible_heap_addr; mse * mark_stack_top = GC_mark_stack_top; mse * mark_stack_limit = GC_mark_stack_limit; + +# undef GC_mark_stack_top +# undef GC_mark_stack_limit # define GC_mark_stack_top mark_stack_top # define GC_mark_stack_limit mark_stack_limit # define GC_greatest_plausible_heap_addr greatest_ha @@ -1612,7 +1603,8 @@ STATIC void GC_push_marked1(struct hblk *h, hdr *hhdr) # undef GC_least_plausible_heap_addr # undef GC_mark_stack_top # undef GC_mark_stack_limit - +# define GC_mark_stack_limit GC_arrays._mark_stack_limit +# define GC_mark_stack_top GC_arrays._mark_stack_top GC_mark_stack_top = mark_stack_top; } @@ -1634,6 +1626,8 @@ STATIC void GC_push_marked2(struct hblk *h, hdr *hhdr) mse * mark_stack_top = GC_mark_stack_top; mse * mark_stack_limit = GC_mark_stack_limit; +# undef GC_mark_stack_top +# undef GC_mark_stack_limit # define GC_mark_stack_top mark_stack_top # define GC_mark_stack_limit mark_stack_limit # define GC_greatest_plausible_heap_addr greatest_ha @@ -1661,7 +1655,8 @@ STATIC void GC_push_marked2(struct hblk *h, hdr *hhdr) # undef GC_least_plausible_heap_addr # undef GC_mark_stack_top # undef GC_mark_stack_limit - +# define GC_mark_stack_limit GC_arrays._mark_stack_limit +# define GC_mark_stack_top GC_arrays._mark_stack_top GC_mark_stack_top = mark_stack_top; } @@ -1682,6 +1677,9 @@ STATIC void GC_push_marked4(struct hblk *h, hdr *hhdr) ptr_t least_ha = GC_least_plausible_heap_addr; mse * mark_stack_top = GC_mark_stack_top; mse * mark_stack_limit = GC_mark_stack_limit; + +# undef GC_mark_stack_top +# undef GC_mark_stack_limit # define GC_mark_stack_top mark_stack_top # define GC_mark_stack_limit mark_stack_limit # define GC_greatest_plausible_heap_addr greatest_ha @@ -1710,6 +1708,8 @@ STATIC void GC_push_marked4(struct hblk *h, hdr *hhdr) # undef GC_least_plausible_heap_addr # undef GC_mark_stack_top # undef GC_mark_stack_limit +# define GC_mark_stack_limit GC_arrays._mark_stack_limit +# define GC_mark_stack_top GC_arrays._mark_stack_top GC_mark_stack_top = mark_stack_top; } -- 2.40.0