pike.git / src / gc.c

version» Context lines:

pike.git/src/gc.c:18:   #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>    - RCSID("$Id: gc.c,v 1.38 1998/04/29 15:06:29 noring Exp $"); + RCSID("$Id: gc.c,v 1.39 1998/11/22 11:02:48 hubbe Exp $");      /* 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
pike.git/src/gc.c:55:   {    return add_to_callback(&gc_callbacks, call, arg, free_func);   }      #define GC_REFERENCED 1   #define GC_XREFERENCED 2      struct marker   {    INT32 refs; - #ifdef DEBUG + #ifdef PIKE_DEBUG    INT32 xrefs;   #endif    INT32 flags;    struct marker *next;    void *marked;   };      struct marker_chunk   {    struct marker_chunk *next;
pike.git/src/gc.c:98:   static unsigned long hashsize=0;      static struct marker *getmark(void *a)   {    unsigned long hashval;    struct marker *m;       hashval=(unsigned long)a;    hashval%=hashsize;    - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(hashval >= hashsize)    fatal("Compiler has buggy modulo operator.\n");   #endif       for(m=hash[hashval];m;m=m->next)    if(m->marked == a)    return m;       m=new_marker();    m->marked=a;    m->refs=0; - #ifdef DEBUG + #ifdef PIKE_DEBUG    m->xrefs=0;   #endif    m->flags=0;    m->next=hash[hashval];    hash[hashval]=m;       return m;   }    - #ifdef DEBUG + #ifdef PIKE_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);
pike.git/src/gc.c:387: Inside #if defined(DEBUG)
     void describe(void *x)   {    describe_something(x, attempt_to_identify(x),1);   }      #endif      INT32 gc_check(void *a)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(check_for)    {    if(check_for == a)    {    gdb_gc_stop_here(a);    }    return 0;    }   #endif    return add_ref(getmark(a));
pike.git/src/gc.c:430:    struct marker_chunk *m;    /* Free hash table */    free((char *)hash);    while((m=chunk))    {    chunk=m->next;    free((char *)m);    }   }    - #ifdef DEBUG + #ifdef PIKE_DEBUG   void locate_references(void *a)   {    if(!in_gc)    init_gc();       fprintf(stderr,"**Looking for references:\n");       check_for=a;       found_where=" in an array";
pike.git/src/gc.c:470: Inside #if defined(DEBUG)
      if(!in_gc)    exit_gc();   }   #endif      int gc_is_referenced(void *a)   {    struct marker *m;    m=getmark(a); - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(m->refs + m->xrefs > *(INT32 *)a ||    (!(m->refs < *(INT32 *)a) && m->xrefs) )    {    INT32 refs=m->refs;    INT32 xrefs=m->xrefs;    TYPE_T t=attempt_to_identify(a);       fprintf(stderr,"**Something has %ld references, while gc() found %ld + %ld external.\n",(long)*(INT32 *)a,(long)refs,(long)xrefs);    describe_something(a, t, 1);   
pike.git/src/gc.c:492: Inside #if defined(DEBUG)
      fatal("Ref counts are wrong (has %d, found %d + %d external)\n",    *(INT32 *)a,    refs,    xrefs);    }   #endif    return m->refs < *(INT32 *)a;   }    - #ifdef DEBUG + #ifdef PIKE_DEBUG   int gc_external_mark(void *a)   {    struct marker *m;    if(check_for)    {    if(a==check_for)    {    char *tmp=found_where;    found_where=" externally";    gdb_gc_stop_here(a);
pike.git/src/gc.c:535:    }else{    m->flags |= GC_REFERENCED;    return 1;    }   }      int gc_do_free(void *a)   {    struct marker *m;    m=getmark(a); - #ifdef DEBUG + #ifdef PIKE_DEBUG    if( !(m->flags & GC_REFERENCED) && m->flags & GC_XREFERENCED )    {    INT32 refs=m->refs;    INT32 xrefs=m->xrefs;    TYPE_T t=attempt_to_identify(a);       fprintf(stderr,"**gc_is_referenced failed, object has %ld references, while gc() found %ld + %ld external.\n",(long)*(INT32 *)a,(long)refs,(long)xrefs);    describe_something(a, t, 1);       locate_references(a);
pike.git/src/gc.c:573:    in_gc=1;       if(gc_evaluator_callback)    {    remove_callback(gc_evaluator_callback);    gc_evaluator_callback=0;    }       tmp2=num_objects;    - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(t_flag)    fprintf(stderr,"Garbage collecting ... ");    if(num_objects < 0)    fatal("Panic, less than zero objects!\n");       last_gc=TIME(0);      #endif       multiplier=pow(MULTIPLIER, (double) num_allocs / (double) alloc_threshold);
pike.git/src/gc.c:645:    }else{    alloc_threshold+=num_allocs;    }       if(alloc_threshold < MIN_ALLOC_THRESHOLD)    alloc_threshold = MIN_ALLOC_THRESHOLD;    if(alloc_threshold > MAX_ALLOC_THRESHOLD)    alloc_threshold = MAX_ALLOC_THRESHOLD;    num_allocs=0;    - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(t_flag)    fprintf(stderr,"done (freed %ld of %ld objects).\n",    (long)(tmp2-num_objects),(long)tmp2);   #endif      #ifdef ALWAYS_GC    ADD_GC_CALLBACK();   #else    if(d_flag > 3) ADD_GC_CALLBACK();   #endif    in_gc=0;   }