From: Paolo Molaro Date: Wed, 16 Feb 2005 21:23:39 +0000 (+0000) Subject: alloc: tune the code to collect instead of expanding the heap if X-Git-Tag: gc7_3alpha2~205 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88e92b418090bea0cfa36f017a52d7a29dd8807e;p=gc alloc: tune the code to collect instead of expanding the heap if there are many finalizers and we reclaimed some memory from cleaning the finalization queue (should fix Mono bugs #71001 and #70701). (Apply commit a43aba7 from 'mono_libgc' branch) * alloc.c (last_fo_entries, last_bytes_finalized): New static variable. * alloc.c (GC_collect_or_expand): Test GC_fo_entries delta (in case of non-zero GC_bytes_finalized value) in the condition of toggling garabage collection; update last_fo_entries and last_bytes_finalized values. * include/private/gc_priv.h (GC_fo_entries): Declare global variable (for use in GC_collect_or_expand). --- diff --git a/alloc.c b/alloc.c index 6ba3151c..24ef042c 100644 --- a/alloc.c +++ b/alloc.c @@ -1199,6 +1199,9 @@ GC_INNER unsigned GC_fail_count = 0; /* How many consecutive GC/expansion failures? */ /* Reset by GC_allochblk. */ +static word last_fo_entries = 0; +static word last_bytes_finalized = 0; + /* Collect or expand heap in an attempt make the indicated number of */ /* free blocks available. Should be called until the blocks are */ /* available (seting retry value to TRUE unless this is the first call */ @@ -1213,7 +1216,10 @@ GC_INNER GC_bool GC_collect_or_expand(word needed_blocks, DISABLE_CANCEL(cancel_state); if (!GC_incremental && !GC_dont_gc && - ((GC_dont_expand && GC_bytes_allocd > 0) || GC_should_collect())) { + ((GC_dont_expand && GC_bytes_allocd > 0) + || (GC_fo_entries > (last_fo_entries + 500) + && (last_bytes_finalized | GC_bytes_finalized) != 0) + || GC_should_collect())) { /* Try to do a full collection using 'default' stop_func (unless */ /* nothing has been allocated since the latest collection or heap */ /* expansion is disabled). */ @@ -1223,6 +1229,8 @@ GC_INNER GC_bool GC_collect_or_expand(word needed_blocks, if (gc_not_stopped == TRUE || !retry) { /* Either the collection hasn't been aborted or this is the */ /* first attempt (in a loop). */ + last_fo_entries = GC_fo_entries; + last_bytes_finalized = GC_bytes_finalized; RESTORE_CANCEL(cancel_state); return(TRUE); } diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 4952d04e..7945f195 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1950,6 +1950,8 @@ void GC_print_static_roots(void); #endif /* void GC_dump(void); - declared in gc.h */ +extern word GC_fo_entries; /* should be visible in extra/MacOS.c */ + #ifdef KEEP_BACK_PTRS GC_INNER void GC_store_back_pointer(ptr_t source, ptr_t dest); GC_INNER void GC_marked_for_finalization(ptr_t dest);