From: Petter Urkedal Date: Sat, 10 Sep 2011 12:03:16 +0000 (+0200) Subject: Fix some issues and avoid warnings in disclaim-related code. X-Git-Tag: gc7_3alpha2~320^2~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e8e9de7d2087523de7815710bafadb34550b739;p=gc Fix some issues and avoid warnings in disclaim-related code. * disclaim.c, include/gc_disclaim.h: Fix prototype. * include/private/gc_priv.h, mark.c: Avoid missing initializer warning. * mark.c: Fix type of a size_t variable in GC_reclaim_block. * misc.c: Initialize ok_mark_unconditionally. * reclaim.c: Tweak and avoid unused label warning. * tests/disclaim_bench.c, tests/disclaim_test.c: Remove or conditionalize unused variables. --- diff --git a/disclaim.c b/disclaim.c index b4f20461..5c866583 100644 --- a/disclaim.c +++ b/disclaim.c @@ -5,9 +5,9 @@ /* Low level interface for reclaim callbacks. */ -int GC_register_disclaim_proc(int kind, - int (*proc)(void *obj, void *cd), void *cd, - int mark_unconditionally) +void GC_register_disclaim_proc(int kind, + int (*proc)(void *obj, void *cd), void *cd, + int mark_unconditionally) { GC_obj_kinds[kind].ok_disclaim_proc = proc; GC_obj_kinds[kind].ok_disclaim_cd = cd; diff --git a/include/gc_disclaim.h b/include/gc_disclaim.h index bf4987a3..d867813e 100644 --- a/include/gc_disclaim.h +++ b/include/gc_disclaim.h @@ -23,9 +23,9 @@ /* will be protected from collection if "mark_from_all" is non-zero, */ /* but at the expense that long chains of objects will take many cycles */ /* to reclaim. */ -int GC_register_disclaim_proc(int kind, - int (*proc)(void *obj, void *cd), void *cd, - int mark_from_all); +void GC_register_disclaim_proc(int kind, + int (*proc)(void *obj, void *cd), void *cd, + int mark_from_all); /* The finalizer closure used by GC_finalized_malloc. */ struct GC_finalizer_closure { diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 77020f16..eaefbd82 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1243,6 +1243,9 @@ GC_EXTERN struct obj_kind { /* is reclaimed, but must also tolerate being */ /* called with object from freelist. Non-zero */ /* exit prevents object from being reclaimed. */ +# define OK_DISCLAIM_INITZ FALSE, NULL, NULL +# else +# define OK_DISCLAIM_INITZ # endif } GC_obj_kinds[MAXOBJKINDS]; diff --git a/mark.c b/mark.c index f706e823..14e6afec 100644 --- a/mark.c +++ b/mark.c @@ -51,21 +51,26 @@ GC_INNER unsigned GC_n_mark_procs = GC_RESERVED_MARK_PROCS; /* It's done here, since we need to deal with mark descriptors. */ GC_INNER struct obj_kind GC_obj_kinds[MAXOBJKINDS] = { /* PTRFREE */ { &GC_aobjfreelist[0], 0 /* filled in dynamically */, - 0 | GC_DS_LENGTH, FALSE, FALSE }, + 0 | GC_DS_LENGTH, FALSE, FALSE, + OK_DISCLAIM_INITZ }, /* NORMAL */ { &GC_objfreelist[0], 0, 0 | GC_DS_LENGTH, /* Adjusted in GC_init for EXTRA_BYTES */ - TRUE /* add length to descr */, TRUE }, + TRUE /* add length to descr */, TRUE, + OK_DISCLAIM_INITZ }, /* UNCOLLECTABLE */ { &GC_uobjfreelist[0], 0, - 0 | GC_DS_LENGTH, TRUE /* add length to descr */, TRUE }, + 0 | GC_DS_LENGTH, TRUE /* add length to descr */, TRUE, + OK_DISCLAIM_INITZ }, # ifdef ATOMIC_UNCOLLECTABLE /* AUNCOLLECTABLE */ { &GC_auobjfreelist[0], 0, - 0 | GC_DS_LENGTH, FALSE /* add length to descr */, FALSE }, + 0 | GC_DS_LENGTH, FALSE /* add length to descr */, FALSE, + OK_DISCLAIM_INITZ }, # endif # ifdef STUBBORN_ALLOC /*STUBBORN*/ { (void **)&GC_sobjfreelist[0], 0, - 0 | GC_DS_LENGTH, TRUE /* add length to descr */, TRUE }, + 0 | GC_DS_LENGTH, TRUE /* add length to descr */, TRUE, + OK_DISCLAIM_INITZ }, # endif }; @@ -1771,8 +1776,8 @@ STATIC void GC_push_marked(struct hblk *h, hdr *hhdr) /* first word. */ void GC_push_unconditionally(struct hblk *h, hdr *hhdr) { - int sz = hhdr -> hb_sz; - int descr = hhdr -> hb_descr; + size_t sz = hhdr -> hb_sz; + word descr = hhdr -> hb_descr; ptr_t p; ptr_t lim; mse * GC_mark_stack_top_reg; diff --git a/misc.c b/misc.c index 1f87c496..10bf1c97 100644 --- a/misc.c +++ b/misc.c @@ -1474,6 +1474,9 @@ GC_API unsigned GC_CALL GC_new_kind_inner(void **fl, GC_word descr, GC_obj_kinds[result].ok_descriptor = descr; GC_obj_kinds[result].ok_relocate_descr = adjust; GC_obj_kinds[result].ok_init = clear; +# ifdef MARK_UNCONDITIONALLY + GC_obj_kinds[result].ok_mark_unconditionally = 0; +# endif # ifdef ENABLE_DISCLAIM GC_obj_kinds[result].ok_disclaim_proc = 0; GC_obj_kinds[result].ok_disclaim_cd = 0; diff --git a/reclaim.c b/reclaim.c index 9e8fd4c6..ef87f078 100644 --- a/reclaim.c +++ b/reclaim.c @@ -382,9 +382,8 @@ STATIC void GC_reclaim_block(struct hblk *hbp, word report_if_found) # ifdef ENABLE_DISCLAIM if (EXPECT(hhdr->hb_flags & HAS_DISCLAIM, 0)) { struct obj_kind *ok = &GC_obj_kinds[hhdr->hb_obj_kind]; - int resurrect; - resurrect = (*ok->ok_disclaim_proc)(hbp, ok->ok_disclaim_cd); - if (resurrect) { + if ((*ok->ok_disclaim_proc)(hbp, ok->ok_disclaim_cd)) { + /* Not disclaimed => resurrect the object. */ set_mark_bit_from_hdr(hhdr, 0); /* excuse me, */ goto in_use; } @@ -397,7 +396,9 @@ STATIC void GC_reclaim_block(struct hblk *hbp, word report_if_found) GC_freehblk(hbp); } } else { +# ifdef ENABLE_DISCLAIM in_use: +# endif if (hhdr -> hb_descr != 0) { GC_composite_in_use += sz; } else { diff --git a/tests/disclaim_bench.c b/tests/disclaim_bench.c index 1c90d839..df67bf4f 100644 --- a/tests/disclaim_bench.c +++ b/tests/disclaim_bench.c @@ -56,7 +56,6 @@ testobj_t testobj_new(int model) int main(int argc, char **argv) { int i; - int repeat; int model; testobj_t *keep_arr; double t; diff --git a/tests/disclaim_test.c b/tests/disclaim_test.c index bc8462a5..6e005ad7 100644 --- a/tests/disclaim_test.c +++ b/tests/disclaim_test.c @@ -113,8 +113,11 @@ void *test(void *data) int main() { +#if THREAD_CNT > 1 pthread_t th[THREAD_CNT]; int i; +#endif + GC_init(); GC_init_finalized_malloc(); #if THREAD_CNT > 1