]> granicus.if.org Git - gc/commitdiff
Mon Jan 24 16:39:42 CET 2005 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Mon, 24 Jan 2005 15:29:23 +0000 (15:29 +0000)
committerguest <ivmai@mail.ru>
Fri, 29 Jul 2011 11:24:11 +0000 (15:24 +0400)
* alloc.c, include/gc.h: add event notification, mostly from
a patch by Ben Maurer.

svn path=/trunk/mono/; revision=39416

ChangeLog
alloc.c
include/gc.h

index 0b2a4fcc1203565d54e4f5b0b6c5dc69dd724c17..f0932977d073a91bf7579afbcb08d427a391326f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+
+Mon Jan 24 16:39:42 CET 2005 Paolo Molaro <lupus@ximian.com>
+
+       * alloc.c, include/gc.h: add event notification, mostly from 
+       a patch by Ben Maurer.
+
 2005-01-23  Geoff Norton  <gnorton@customerdna.com>
        
        * os_dir.c: Change GC_task_self to be static everywhere on Darwin.
diff --git a/alloc.c b/alloc.c
index b4b2b1bb77feba4cabe8e4da587eefc34a851391..c1f40635071a15add0dbb31fcf1b506e3aea7c0b 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -260,6 +260,10 @@ void GC_maybe_gc()
     static int n_partial_gcs = 0;
 
     if (GC_should_collect()) {
+       if (GC_notify_event)
+               GC_notify_event (GC_EVENT_START);
+           
+           
         if (!GC_incremental) {
             GC_gcollect_inner();
             n_partial_gcs = 0;
@@ -305,6 +309,10 @@ void GC_maybe_gc()
                GC_n_attempts++;
            }
        }
+       
+
+       if (GC_notify_event)
+               GC_notify_event (GC_EVENT_END);
     }
 }
 
@@ -478,11 +486,16 @@ GC_stop_func stop_func;
 #   if defined(CONDPRINT) && !defined(PRINTTIMES)
        if (GC_print_stats) GET_TIME(start_time);
 #   endif
+       
 #   if defined(REGISTER_LIBRARIES_EARLY)
         GC_cond_register_dynamic_libraries();
 #   endif
     STOP_WORLD();
     IF_THREADS(GC_world_stopped = TRUE);
+       
+       if (GC_notify_event)
+               GC_notify_event (GC_EVENT_MARK_START);
+       
 #   ifdef CONDPRINT
       if (GC_print_stats) {
        GC_printf1("--> Marking for collection %lu ",
@@ -547,6 +560,10 @@ GC_stop_func stop_func;
             (*GC_check_heap)();
         }
     
+
+       if (GC_notify_event)
+               GC_notify_event (GC_EVENT_MARK_END);
+       
     IF_THREADS(GC_world_stopped = FALSE);
     START_WORLD();
 #   ifdef PRINTTIMES
@@ -617,6 +634,9 @@ GC_stop_func stop_func;
    }
 }
 
+void (*GC_notify_event) GC_PROTO((GCEventType e));
+void (*GC_on_heap_resize) GC_PROTO((size_t new_size));
+
 /* Finish up a collection.  Assumes lock is held, signals are disabled,        */
 /* but the world is otherwise running.                                 */
 void GC_finish_collection()
@@ -629,6 +649,10 @@ void GC_finish_collection()
        GET_TIME(start_time);
        finalize_time = start_time;
 #   endif
+       
+
+       if (GC_notify_event)
+               GC_notify_event (GC_EVENT_RECLAIM_START);
 
 #   ifdef GATHERSTATS
         GC_mem_found = 0;
@@ -638,6 +662,7 @@ void GC_finish_collection()
          GC_print_address_map();
        }
 #   endif
+
     COND_DUMP;
     if (GC_find_leak) {
       /* Mark all objects on the free list.  All objects should be */
@@ -740,6 +765,10 @@ void GC_finish_collection()
 #   ifdef USE_MUNMAP
       GC_unmap_old();
 #   endif
+       
+       if (GC_notify_event)
+               GC_notify_event (GC_EVENT_RECLAIM_END);
+       
 #   ifdef PRINTTIMES
        GET_TIME(done_time);
        GC_printf2("Finalize + initiate sweep took %lu + %lu msecs\n",
@@ -960,6 +989,9 @@ word n;
         if (GC_collect_at_heapsize < GC_heapsize /* wrapped */)
          GC_collect_at_heapsize = (word)(-1);
 #     endif
+       if (GC_on_heap_resize)
+               GC_on_heap_resize (GC_heapsize);
+       
     return(TRUE);
 }
 
index 93ede344232fe8c857826c6a3957d66baa559ebb..a60a6560d544c955c2e5431b647334a738784760 100644 (file)
@@ -92,6 +92,22 @@ GC_API GC_PTR (*GC_oom_fn) GC_PROTO((size_t bytes_requested));
                        /* pointer to a previously allocated heap       */
                        /* object.                                      */
 
+typedef enum {
+       GC_EVENT_START,
+       GC_EVENT_MARK_START,
+       GC_EVENT_MARK_END,
+       GC_EVENT_RECLAIM_START,
+       GC_EVENT_RECLAIM_END,
+       GC_EVENT_END
+} GCEventType;
+
+GC_API void (*GC_notify_event) GC_PROTO((GCEventType event_type));
+                       /* Invoked at specific points during every collection.
+                        */
+                        
+GC_API void (*GC_on_heap_resize) GC_PROTO((size_t new_size));
+                       /* Invoked when the heap grows or shrinks        */
+
 GC_API int GC_find_leak;
                        /* Do not actually garbage collect, but simply  */
                        /* report inaccessible memory that was not      */