pike.git / src / gc.c

version» Context lines:

pike.git/src/gc.c:14:   #include "multiset.h"   #include "mapping.h"   #include "object.h"   #include "program.h"   #include "stralloc.h"   #include "stuff.h"   #include "error.h"   #include "pike_memory.h"   #include "pike_macros.h"   #include "pike_types.h" + #include "time_stuff.h"      #include "gc.h"   #include "main.h" -  + #include <math.h>      /* Run garbage collect approximate every time we have    * 20 percent of all arrays, objects and programs is    * garbage.    */      #define GC_CONST 20   #define MIN_ALLOC_THRESHOLD 1000   #define MAX_ALLOC_THRESHOLD 10000000   #define MULTIPLIER 0.9   #define MARKER_CHUNK_SIZE 1023    - INT32 num_objects; - INT32 num_allocs; + INT32 num_objects =0; + INT32 num_allocs =0;   INT32 alloc_threshold = MIN_ALLOC_THRESHOLD; -  + static int in_gc = 0;    - static double objects_alloced; - static double objects_freed; + static double objects_alloced = 0.0; + static double objects_freed = 0.0;      struct callback_list gc_callbacks;      struct callback *add_gc_callback(callback_func call,    void *arg,    callback_func free_func)   {    return add_to_callback(&gc_callbacks, call, arg, free_func);   }   
pike.git/src/gc.c:112:   #endif    m->flags=0;    m->next=hash[hashval];    hash[hashval]=m;       return m;   }      #ifdef DEBUG    + time_t last_gc; +  + void dump_gc_info(void) + { +  fprintf(stderr,"Current number of objects: %ld\n",(long)num_objects); +  fprintf(stderr,"Objects allocated total : %ld\n",(long)num_allocs); +  fprintf(stderr," threshold for next gc() : %ld\n",(long)alloc_threshold); +  fprintf(stderr,"Average allocs per gc() : %f\n",objects_alloced); +  fprintf(stderr,"Average frees per gc() : %f\n",objects_freed); +  fprintf(stderr,"Second since last gc() : %ld\n", (long)TIME(0) - (long)last_gc); +  fprintf(stderr,"Projected garbage : %f\n", objects_freed * (double) num_allocs / (double) alloc_threshold); +  fprintf(stderr,"in_gc : %d\n", in_gc); + } +    TYPE_T attempt_to_identify(void *something)   {    struct array *a;    struct object *o;    struct program *p;       a=&empty_array;    do    {    if(a==(struct array *)something) return T_ARRAY;
pike.git/src/gc.c:404:    67108863, /* ~ 2^26 = 67108864 */    134217727, /* ~ 2^27 = 134217728 */    268435455, /* ~ 2^28 = 268435456 */    536870911, /* ~ 2^29 = 536870912 */    1073741823,/* ~ 2^30 = 1073741824 */    2147483647,/* ~ 2^31 = 2147483648 */   };      void do_gc(void)   { -  static int in_gc = 0; +     double tmp;    INT32 tmp2,tmp3;    struct marker_chunk *m; -  +  double multiplier;       if(in_gc) return;    in_gc=1;       if(gc_evaluator_callback)    {    remove_callback(gc_evaluator_callback);    gc_evaluator_callback=0;    }       tmp2=num_objects;      #ifdef DEBUG    if(t_flag)    fprintf(stderr,"Garbage collecting ... ");    if(num_objects < 0)    fatal("Panic, less than zero objects!\n"); -  +  +  last_gc=TIME(0); +    #endif    -  objects_alloced*=MULTIPLIER; +  multiplier=pow(MULTIPLIER, (double) num_allocs / (double) alloc_threshold); +  objects_alloced*=multiplier;    objects_alloced += (double) num_allocs;    -  objects_freed*=MULTIPLIER; +  objects_freed*=multiplier;    objects_freed += (double) num_objects;          /* init hash , hashsize will be a prime between num_objects/8 and    * num_objects/4, this will assure that no re-hashing is needed.    */    tmp3=my_log2(num_objects);       if(!d_flag) tmp3-=2;    if(tmp3<0) tmp3=0;