From efd5d4945a51a73dd9df42fae8a9f8e809287b4e 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 (Apply commit a7a5666 from 'release-7_2' branch.) * 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. Conflicts: include/private/gc_pmark.h --- include/private/gc_pmark.h | 18 ------------------ include/private/gc_priv.h | 22 ++++++++++++++++++++++ mark.c | 28 ++++++++++++++-------------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/include/private/gc_pmark.h b/include/private/gc_pmark.h index 05a7c144..9c3aee54 100644 --- a/include/private/gc_pmark.h +++ b/include/private/gc_pmark.h @@ -69,26 +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. */ - union word_ptr_ao_u 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; - /* FIXME: Use union to avoid casts to AO_t */ -#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 4cbb54d3..f80cd94e 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1063,6 +1063,13 @@ struct roots { # endif #endif /* !MAX_HEAP_SECTS */ +typedef struct GC_ms_entry { + ptr_t mse_start; /* First word of object, word aligned. */ + union word_ptr_ao_u 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 */ @@ -1127,6 +1134,18 @@ 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. */ + /* TODO: Use union to avoid casts to AO_t */ +# 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 */ @@ -1276,6 +1295,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_large_allocd_bytes GC_arrays._max_large_allocd_bytes #define GC_modws_valid_offsets GC_arrays._modws_valid_offsets diff --git a/mark.c b/mark.c index 94c9519d..60a1a1e4 100644 --- a/mark.c +++ b/mark.c @@ -97,30 +97,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; @@ -1582,6 +1570,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 @@ -1608,7 +1599,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; } @@ -1630,6 +1622,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 @@ -1657,7 +1651,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; } @@ -1678,6 +1673,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 @@ -1706,6 +1704,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