pike.git / src / gc.c

version» Context lines:

pike.git/src/gc.c:14:   #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 "constants.h" + #include "block_alloc.h"      #include "gc.h"   #include "main.h"   #include <math.h>    - RCSID("$Id: gc.c,v 1.41 1999/03/17 21:49:24 hubbe Exp $"); + RCSID("$Id: gc.c,v 1.42 1999/05/02 08:11:41 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:43:   INT32 num_allocs =0;   INT32 alloc_threshold = MIN_ALLOC_THRESHOLD;   static int in_gc = 0;   struct pike_queue gc_mark_queue;      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, + struct callback *debug_add_gc_callback(callback_func call,    void *arg,    callback_func free_func)   {    return add_to_callback(&gc_callbacks, call, arg, free_func);   }      #define GC_REFERENCED 1   #define GC_XREFERENCED 2      struct marker   {    INT32 refs;   #ifdef PIKE_DEBUG    INT32 xrefs;   #endif    INT32 flags;    struct marker *next; -  void *marked; +  void *data;   };    - struct marker_chunk - { -  struct marker_chunk *next; -  struct marker markers[MARKER_CHUNK_SIZE]; - }; -  - static struct marker_chunk *chunk=0; - static int markers_left_in_chunk=0; -  - static struct marker *new_marker(void) - { -  if(!markers_left_in_chunk) -  { -  struct marker_chunk *m; -  m=(struct marker_chunk *)xalloc(sizeof(struct marker_chunk)); -  m->next=chunk; -  chunk=m; -  markers_left_in_chunk=MARKER_CHUNK_SIZE; -  } -  markers_left_in_chunk--; -  -  return chunk->markers + markers_left_in_chunk; - } -  - static struct marker **hash=0; - static unsigned long hashsize=0; -  - static struct marker *getmark(void *a) - { -  unsigned long hashval; -  struct marker *m; -  -  hashval=(unsigned long)a; -  hashval%=hashsize; -  + #undef INIT_BLOCK   #ifdef PIKE_DEBUG -  if(hashval >= hashsize) -  fatal("Compiler has buggy modulo operator.\n"); + #define INIT_BLOCK(X) (X)->flags=(X)->refs=(X)->xrefs=0 + #else + #define INIT_BLOCK(X) (X)->flags=(X)->refs=0   #endif    -  for(m=hash[hashval];m;m=m->next) -  if(m->marked == a) -  return m; + PTR_HASH_ALLOC(marker,MARKER_CHUNK_SIZE)    -  m=new_marker(); -  m->marked=a; -  m->refs=0; +    #ifdef PIKE_DEBUG -  m->xrefs=0; - #endif -  m->flags=0; -  m->next=hash[hashval]; -  hash[hashval]=m; +     -  return m; - } -  - #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);    fprintf(stderr,"Second since last gc() : %ld\n", (long)TIME(0) - (long)last_gc);
pike.git/src/gc.c:458: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(check_for)    {    if(check_for == a)    {    gdb_gc_stop_here(a);    }    return 0;    }   #endif -  return add_ref(getmark(a)); +  return add_ref(get_marker(a));   }      static void init_gc(void)   { -  + #if 0    INT32 tmp3;    /* 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;    if(tmp3>=(long)NELEM(hashprimes)) tmp3=NELEM(hashprimes)-1;    hashsize=hashprimes[tmp3];       hash=(struct marker **)xalloc(sizeof(struct marker **)*hashsize);    MEMSET((char *)hash,0,sizeof(struct marker **)*hashsize);    markers_left_in_chunk=0; -  + #else +  init_marker_hash(); + #endif   }      static void exit_gc(void)   { -  + #if 0    struct marker_chunk *m;    /* Free hash table */    free((char *)hash);    while((m=chunk))    {    chunk=m->next;    free((char *)m);    } -  + #else + #ifdef DO_PIKE_CLEANUP +  int e=0; +  struct marker *h; +  for(e=0;e<marker_hash_table_size;e++) +  while(marker_hash_table[e]) +  remove_marker(marker_hash_table[e]->data); + #endif +  exit_marker_hash(); + #endif   }      #ifdef PIKE_DEBUG   void locate_references(void *a)   {    if(!in_gc)    init_gc();       fprintf(stderr,"**Looking for references:\n");   
pike.git/src/gc.c:530: Inside #if defined(PIKE_DEBUG)
   check_for=0;       if(!in_gc)    exit_gc();   }   #endif      int gc_is_referenced(void *a)   {    struct marker *m; -  m=getmark(a); +  m=get_marker(a);   #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:570: Inside #if defined(PIKE_DEBUG)
   {    char *tmp=found_where;    found_where=" externally";    gdb_gc_stop_here(a);    found_where=tmp;       return 1;    }    return 0;    } -  m=getmark(a); +  m=get_marker(a);    m->xrefs++;    m->flags|=GC_XREFERENCED;    gc_is_referenced(a);    return 0;   }   #endif      int gc_mark(void *a)   {    struct marker *m; -  m=getmark(a); +  m=get_marker(a);       if(m->flags & GC_REFERENCED)    {    return 0;    }else{    m->flags |= GC_REFERENCED;    return 1;    }   }      int gc_do_free(void *a)   {    struct marker *m; -  m=getmark(a); +  m=get_marker(a);   #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);