Branch: Tag:

1999-05-02

1999-05-02 08:13:05 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

more debug and fixed a memory leak in interpret.c

Rev: src/backend.c:1.41
Rev: src/backend.h:1.7
Rev: src/block_alloc.h:1.11
Rev: src/block_alloc_h.h:1.4
Rev: src/builtin_functions.c:1.168
Rev: src/callback.c:1.17
Rev: src/callback.h:1.8
Rev: src/configure.in:1.281
Rev: src/constants.c:1.18
Rev: src/dmalloc.h:1.11
Rev: src/error.c:1.35
Rev: src/error.h:1.36
Rev: src/gc.c:1.42
Rev: src/gc.h:1.22
Rev: src/interpret.c:1.122
Rev: src/interpret.h:1.31
Rev: src/interpreter.h:1.5
Rev: src/modules/call_out/call_out.c:1.27
Rev: src/modules/files/file.c:1.152
Rev: src/modules/system/system.c:1.70
Rev: src/pike_memory.c:1.37
Rev: src/program.c:1.123
Rev: src/signal_handler.c:1.129
Rev: src/stralloc.c:1.59
Rev: src/threads.c:1.93

21:   #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
50:      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)   {
68:   #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)
465: Inside #if defined(PIKE_DEBUG)
   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.
484:    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);
496:    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
537:   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) )
577: Inside #if defined(PIKE_DEBUG)
   }    return 0;    } -  m=getmark(a); +  m=get_marker(a);    m->xrefs++;    m->flags|=GC_XREFERENCED;    gc_is_referenced(a);
588:   int gc_mark(void *a)   {    struct marker *m; -  m=getmark(a); +  m=get_marker(a);       if(m->flags & GC_REFERENCED)    {
602:   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 )    {