Branch: Tag:

2013-06-26

2013-06-26 14:25:19 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.

46:    * 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
3470:    init_gc();    gc_generation++;    Pike_in_gc=GC_PASS_PREPARE; +  +  if (!SAFE_IS_ZERO(&gc_pre_cb)) { +  safe_apply_svalue(&gc_pre_cb, 0, 1); +  pop_stack(); +  } +     gc_start_time = get_cpu_time();    gc_start_real_time = get_real_time();   #ifdef GC_DEBUG
3785:    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
3841:    }    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);
4118: 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;   }