]> granicus.if.org Git - gc/commitdiff
alloc: tune the code to collect instead of expanding the heap if
authorPaolo Molaro <lupus@oddwiz.org>
Wed, 16 Feb 2005 21:23:39 +0000 (21:23 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 20 Jan 2012 21:57:23 +0000 (01:57 +0400)
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).

alloc.c
include/private/gc_priv.h

diff --git a/alloc.c b/alloc.c
index 6ba3151ce13d93366e52c6c8c95d0468093899f7..24ef042c30bf4b810f7304291051052385a4c6a7 100644 (file)
--- 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);
       }
index 4952d04e8f83953a4c43d57589c3fbb534ce3f9d..7945f195f77a2680751bad9a7d2e70805b90be03 100644 (file)
@@ -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);