Branch: Tag:

2014-12-04

2014-12-04 19:23:48 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Pike.gc_parameters(): Added some gc callbacks.

Adds callbacks that are called from the gc to simplify
debugging of memory leaks and similar.

45:    * the last ten gc rounds. (0.9 == 1 - 1/10) */   double gc_average_slowness = 0.9;    + /* High-level callbacks. +  * NB: These are initialized from builtin.cmod. +  */ + /* Callback called when gc() starts. */ + struct svalue gc_pre_cb; +  + /* Callback called when the mark and sweep phase of the gc() is done. */ + struct svalue gc_post_cb; +  + /* Callback called for each object that is to be destructed explicitly +  * by the gc(). +  */ + struct svalue gc_destruct_cb; +  + /* Callback called when the gc() is about to exit. */ + struct svalue gc_done_cb; +    /* The gc will free all things with no external nonweak references    * that isn't referenced by live objects. An object is considered    * "live" if it contains code that must be executed when it is
3465:    return 0;    }    +  if (!SAFE_IS_ZERO(&gc_pre_cb)) { +  safe_apply_svalue(&gc_pre_cb, 0, 1); +  pop_stack(); +  } +    #ifdef DEBUG_MALLOC    if(debug_options & GC_RESET_DMALLOC)    reset_debug_malloc();
3787:    destroy_count = 0;   #endif    +  if (!SAFE_IS_ZERO(&gc_post_cb)) { +  safe_apply_svalue(&gc_post_cb, 0, 1); +  pop_stack(); +  } +     {    enum object_destruct_reason reason =   #ifdef DO_PIKE_CLEANUP
3843:    }    else fputs(", is destructed\n", stderr);    ); +  if (!SAFE_IS_ZERO(&gc_destruct_cb)) { +  ref_push_object(o); +  safe_apply_svalue(&gc_destruct_cb, 1, 1); +  pop_stack(); +  }       destruct_object (o, reason);    free_object(o);
4120: Inside #if defined(DO_PIKE_CLEANUP)
   if (gc_destruct_everything)    return destroy_count;   #endif +  +  if (!SAFE_IS_ZERO(&gc_done_cb)) { +  push_int(unreferenced); +  safe_apply_svalue(&gc_done_cb, 1, 1); +  pop_stack(); +  } +     return unreferenced;   }