From: ivmai Date: Sun, 20 Mar 2011 09:08:55 +0000 (+0000) Subject: 2011-03-20 Ivan Maidanski X-Git-Tag: gc7_2alpha6~88 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2dddb53a10205f986ae782e5b1e7105f0ea80c5;p=gc 2011-03-20 Ivan Maidanski * alloc.c (GC_finish_collection): Remove redundant brackets; adjust code indentation. * blacklst.c (GC_add_to_black_list_normal): Simplify expression (to improve code readability). * blacklst.c (GC_is_black_listed): Join nested "if" (into a single conditional expression); initialize "nblocks" just before the loop beginning. * misc.c (GC_init): Don't compute initial_heap_sz if GC is already initialized. * include/private/gc_priv.h (GC_initialize_offsets): Move the function declaration to misc.c file. * obj_map.c (GC_initialize_offsets): Remove offsets_initialized static variable since the function is called only once. * tests/middle.c: Include "gc.h" instead of ; expand all tabs to spaces; adjust code indentation; replace the K&R-style function definition with the ANSI C one. * tests/smash_test.c: Ditto. * tests/middle.c (main): Use setter for GC_all_interior_pointers; adjust printf format specifier (and cast the value passed to). --- diff --git a/ChangeLog b/ChangeLog index 69f23836..0024cf70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2011-03-20 Ivan Maidanski + + * alloc.c (GC_finish_collection): Remove redundant brackets; + adjust code indentation. + * blacklst.c (GC_add_to_black_list_normal): Simplify expression + (to improve code readability). + * blacklst.c (GC_is_black_listed): Join nested "if" (into a single + conditional expression); initialize "nblocks" just before the loop + beginning. + * misc.c (GC_init): Don't compute initial_heap_sz if GC is already + initialized. + * include/private/gc_priv.h (GC_initialize_offsets): Move the + function declaration to misc.c file. + * obj_map.c (GC_initialize_offsets): Remove offsets_initialized + static variable since the function is called only once. + * tests/middle.c: Include "gc.h" instead of ; expand all + tabs to spaces; adjust code indentation; replace the K&R-style + function definition with the ANSI C one. + * tests/smash_test.c: Ditto. + * tests/middle.c (main): Use setter for GC_all_interior_pointers; + adjust printf format specifier (and cast the value passed to). + 2011-03-15 Ivan Maidanski * doc/README.macros (SMALL_CONFIG, LARGE_CONFIG): Refine the diff --git a/alloc.c b/alloc.c index 2b0c11d2..d18b7710 100644 --- a/alloc.c +++ b/alloc.c @@ -820,22 +820,20 @@ STATIC void GC_finish_collection(void) # endif COND_DUMP; if (GC_find_leak) { - /* Mark all objects on the free list. All objects should be */ - /* marked when we're done. */ - { - word size; /* current object size */ - unsigned kind; - ptr_t q; - - for (kind = 0; kind < GC_n_kinds; kind++) { - for (size = 1; size <= MAXOBJGRANULES; size++) { - q = GC_obj_kinds[kind].ok_freelist[size]; - if (q != 0) GC_set_fl_marks(q); - } - } + /* Mark all objects on the free list. All objects should be */ + /* marked when we're done. */ + word size; /* current object size */ + unsigned kind; + ptr_t q; + + for (kind = 0; kind < GC_n_kinds; kind++) { + for (size = 1; size <= MAXOBJGRANULES; size++) { + q = GC_obj_kinds[kind].ok_freelist[size]; + if (q != 0) GC_set_fl_marks(q); } - GC_start_reclaim(TRUE); - /* The above just checks; it doesn't really reclaim anything. */ + } + GC_start_reclaim(TRUE); + /* The above just checks; it doesn't really reclaim anything. */ } GC_finalize(); @@ -863,40 +861,38 @@ STATIC void GC_finish_collection(void) /* Note that composite objects on free list are cleared. */ /* Thus accidentally marking a free list is not a problem; only */ /* objects on the list itself will be marked, and that's fixed here. */ - { - word size; /* current object size */ - ptr_t q; /* pointer to current object */ - unsigned kind; - - for (kind = 0; kind < GC_n_kinds; kind++) { - for (size = 1; size <= MAXOBJGRANULES; size++) { - q = GC_obj_kinds[kind].ok_freelist[size]; - if (q != 0) GC_clear_fl_marks(q); - } + { + word size; /* current object size */ + ptr_t q; /* pointer to current object */ + unsigned kind; + + for (kind = 0; kind < GC_n_kinds; kind++) { + for (size = 1; size <= MAXOBJGRANULES; size++) { + q = GC_obj_kinds[kind].ok_freelist[size]; + if (q != 0) GC_clear_fl_marks(q); } } - + } if (GC_print_stats == VERBOSE) GC_log_printf("Bytes recovered before sweep - f.l. count = %ld\n", (long)GC_bytes_found); /* Reconstruct free lists to contain everything not marked */ - GC_start_reclaim(FALSE); - if (GC_print_stats) { - GC_log_printf("Heap contains %lu pointer-containing " - "+ %lu pointer-free reachable bytes\n", - (unsigned long)GC_composite_in_use, - (unsigned long)GC_atomic_in_use); - } - if (GC_is_full_gc) { - GC_used_heap_size_after_full = USED_HEAP_SIZE; - GC_need_full_gc = FALSE; - } else { - GC_need_full_gc = - USED_HEAP_SIZE - GC_used_heap_size_after_full - > min_bytes_allocd(); - } + GC_start_reclaim(FALSE); + if (GC_print_stats) { + GC_log_printf("Heap contains %lu pointer-containing " + "+ %lu pointer-free reachable bytes\n", + (unsigned long)GC_composite_in_use, + (unsigned long)GC_atomic_in_use); + } + if (GC_is_full_gc) { + GC_used_heap_size_after_full = USED_HEAP_SIZE; + GC_need_full_gc = FALSE; + } else { + GC_need_full_gc = USED_HEAP_SIZE - GC_used_heap_size_after_full + > min_bytes_allocd(); + } if (GC_print_stats == VERBOSE) { # ifdef USE_MUNMAP @@ -912,14 +908,14 @@ STATIC void GC_finish_collection(void) } /* Reset or increment counters for next cycle */ - GC_n_attempts = 0; - GC_is_full_gc = FALSE; - GC_bytes_allocd_before_gc += GC_bytes_allocd; - GC_non_gc_bytes_at_gc = GC_non_gc_bytes; - GC_bytes_allocd = 0; - GC_bytes_dropped = 0; - GC_bytes_freed = 0; - GC_finalizer_bytes_freed = 0; + GC_n_attempts = 0; + GC_is_full_gc = FALSE; + GC_bytes_allocd_before_gc += GC_bytes_allocd; + GC_non_gc_bytes_at_gc = GC_non_gc_bytes; + GC_bytes_allocd = 0; + GC_bytes_dropped = 0; + GC_bytes_freed = 0; + GC_finalizer_bytes_freed = 0; # ifdef USE_MUNMAP GC_unmap_old(); diff --git a/blacklst.c b/blacklst.c index 25ebea8e..1fb9d00c 100644 --- a/blacklst.c +++ b/blacklst.c @@ -172,24 +172,22 @@ GC_INNER void GC_unpromote_black_lists(void) GC_INNER void GC_add_to_black_list_normal(word p) #endif { - if (!(GC_modws_valid_offsets[p & (sizeof(word)-1)])) return; - { - word index = PHT_HASH((word)p); + if (GC_modws_valid_offsets[p & (sizeof(word)-1)]) { + word index = PHT_HASH((word)p); - if (HDR(p) == 0 || get_pht_entry_from_index(GC_old_normal_bl, index)) { -# ifdef PRINT_BLACK_LIST - if (!get_pht_entry_from_index(GC_incomplete_normal_bl, index)) { - GC_err_printf( - "Black listing (normal) %p referenced from %p ", - (ptr_t) p, source); - GC_print_source_ptr(source); - GC_err_puts("\n"); - } -# endif - set_pht_entry_from_index(GC_incomplete_normal_bl, index); - } /* else this is probably just an interior pointer to an allocated */ - /* object, and isn't worth black listing. */ - } + if (HDR(p) == 0 || get_pht_entry_from_index(GC_old_normal_bl, index)) { +# ifdef PRINT_BLACK_LIST + if (!get_pht_entry_from_index(GC_incomplete_normal_bl, index)) { + GC_err_printf("Black listing (normal) %p referenced from %p ", + (ptr_t)p, source); + GC_print_source_ptr(source); + GC_err_puts("\n"); + } +# endif + set_pht_entry_from_index(GC_incomplete_normal_bl, index); + } /* else this is probably just an interior pointer to an allocated */ + /* object, and isn't worth black listing. */ + } } /* And the same for false pointers from the stack. */ @@ -199,20 +197,19 @@ GC_INNER void GC_unpromote_black_lists(void) GC_INNER void GC_add_to_black_list_stack(word p) #endif { - word index = PHT_HASH((word)p); + word index = PHT_HASH((word)p); - if (HDR(p) == 0 || get_pht_entry_from_index(GC_old_stack_bl, index)) { -# ifdef PRINT_BLACK_LIST - if (!get_pht_entry_from_index(GC_incomplete_stack_bl, index)) { - GC_err_printf( - "Black listing (stack) %p referenced from %p ", - (ptr_t)p, source); - GC_print_source_ptr(source); - GC_err_puts("\n"); - } -# endif - set_pht_entry_from_index(GC_incomplete_stack_bl, index); - } + if (HDR(p) == 0 || get_pht_entry_from_index(GC_old_stack_bl, index)) { +# ifdef PRINT_BLACK_LIST + if (!get_pht_entry_from_index(GC_incomplete_stack_bl, index)) { + GC_err_printf("Black listing (stack) %p referenced from %p ", + (ptr_t)p, source); + GC_print_source_ptr(source); + GC_err_puts("\n"); + } +# endif + set_pht_entry_from_index(GC_incomplete_stack_bl, index); + } } /* @@ -227,20 +224,20 @@ GC_INNER struct hblk * GC_is_black_listed(struct hblk *h, word len) { word index = PHT_HASH((word)h); word i; - word nblocks = divHBLKSZ(len); + word nblocks; - if (!GC_all_interior_pointers) { - if (get_pht_entry_from_index(GC_old_normal_bl, index) - || get_pht_entry_from_index(GC_incomplete_normal_bl, index)) { - return(h+1); - } + if (!GC_all_interior_pointers + && (get_pht_entry_from_index(GC_old_normal_bl, index) + || get_pht_entry_from_index(GC_incomplete_normal_bl, index))) { + return (h+1); } + nblocks = divHBLKSZ(len); for (i = 0;;) { if (GC_old_stack_bl[divWORDSZ(index)] == 0 && GC_incomplete_stack_bl[divWORDSZ(index)] == 0) { /* An easy case */ - i += WORDSZ - modWORDSZ(index); + i += WORDSZ - modWORDSZ(index); } else { if (get_pht_entry_from_index(GC_old_stack_bl, index) || get_pht_entry_from_index(GC_incomplete_stack_bl, index)) { diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 79e95555..c51a0b0f 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1593,11 +1593,6 @@ GC_INNER void GC_register_displacement_inner(size_t offset); /* Version of GC_register_displacement */ /* that assumes lock is already held. */ -GC_INNER void GC_initialize_offsets(void); - /* Initialize GC_valid_offsets, */ - /* depending on current */ - /* GC_all_interior_pointers settings. */ - /* hblk allocation: */ GC_INNER void GC_new_hblk(size_t size_in_granules, int kind); /* Allocate a new heap block, and build */ diff --git a/misc.c b/misc.c index b0582285..75b92b06 100644 --- a/misc.c +++ b/misc.c @@ -630,21 +630,24 @@ STATIC void GC_exit_check(void) STATIC int GC_log = 2; #endif +GC_INNER void GC_initialize_offsets(void); /* defined in obj_map.c */ + GC_API void GC_CALL GC_init(void) { /* LOCK(); -- no longer does anything this early. */ # if !defined(THREADS) && defined(GC_ASSERTIONS) word dummy; # endif -# ifdef GC_INITIAL_HEAP_SIZE - word initial_heap_sz = divHBLKSZ(GC_INITIAL_HEAP_SIZE); -# else - word initial_heap_sz = (word)MINHINCR; -# endif + word initial_heap_sz; IF_CANCEL(int cancel_state;) if (GC_is_initialized) return; +# ifdef GC_INITIAL_HEAP_SIZE + initial_heap_sz = divHBLKSZ(GC_INITIAL_HEAP_SIZE); +# else + initial_heap_sz = (word)MINHINCR; +# endif DISABLE_CANCEL(cancel_state); /* Note that although we are nominally called with the */ /* allocation lock held, the allocation lock is now */ diff --git a/obj_map.c b/obj_map.c index 972ba491..8bd09930 100644 --- a/obj_map.c +++ b/obj_map.c @@ -78,14 +78,9 @@ GC_INNER void GC_register_displacement_inner(size_t offset) GC_INNER void GC_initialize_offsets(void) { - static GC_bool offsets_initialized = FALSE; - - if (!offsets_initialized) { - int i; - if (GC_all_interior_pointers) { - for (i = 0; i < VALID_OFFSET_SZ; ++i) - GC_valid_offsets[i] = TRUE; - } - offsets_initialized = TRUE; - } + int i; + if (GC_all_interior_pointers) { + for (i = 0; i < VALID_OFFSET_SZ; ++i) + GC_valid_offsets[i] = TRUE; + } } diff --git a/tests/middle.c b/tests/middle.c index ebb348c4..ff0a2355 100644 --- a/tests/middle.c +++ b/tests/middle.c @@ -2,25 +2,24 @@ * Test at the boundary between small and large objects. * Inspired by a test case from Zoltan Varga. */ -#include +#include "gc.h" #include -int main () +int main (void) { - int i; + int i; - GC_all_interior_pointers = 0; - GC_INIT(); + GC_set_all_interior_pointers(0); + GC_INIT(); - for (i = 0; i < 20000; ++i) { - GC_malloc_atomic (4096); - GC_malloc (4096); - } - for (i = 0; i < 20000; ++i) { - GC_malloc_atomic (2048); - GC_malloc (2048); - } - printf("Final heap size is %ld\n", GC_get_heap_size()); - return 0; + for (i = 0; i < 20000; ++i) { + GC_malloc_atomic (4096); + GC_malloc (4096); + } + for (i = 0; i < 20000; ++i) { + GC_malloc_atomic (2048); + GC_malloc (2048); + } + printf("Final heap size is %lu\n", (unsigned long)GC_get_heap_size()); + return 0; } - diff --git a/tests/smash_test.c b/tests/smash_test.c index b94af907..86e081bd 100644 --- a/tests/smash_test.c +++ b/tests/smash_test.c @@ -2,7 +2,8 @@ * Test that overwrite error detection works reasonably. */ #define GC_DEBUG -#include +#include "gc.h" + #include #define COUNT 7000 @@ -10,19 +11,18 @@ char * A[COUNT]; -int main () +int main(void) { - int i; - char *p; + int i; + char *p; - GC_INIT(); + GC_INIT(); - for (i = 0; i < COUNT; ++i) { - A[i] = p = GC_MALLOC(SIZE); + for (i = 0; i < COUNT; ++i) { + A[i] = p = GC_MALLOC(SIZE); - if (i%3000 == 0) GC_gcollect(); - if (i%5678 == 0) p[SIZE + i/2000] = 42; - } - return 0; + if (i%3000 == 0) GC_gcollect(); + if (i%5678 == 0) p[SIZE + i/2000] = 42; + } + return 0; } -