pike.git / src / gc.c

version» Context lines:

pike.git/src/gc.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: gc.c,v 1.211 2003/03/30 01:34:53 mast Exp $ + || $Id: gc.c,v 1.212 2003/03/30 02:08:08 mast Exp $   */      #include "global.h"      struct callback *gc_evaluator_callback=0;      #include "array.h"   #include "multiset.h"   #include "mapping.h"   #include "object.h"
pike.git/src/gc.c:26:   #include "interpret.h"   #include "bignum.h"   #include "pike_threadlib.h"      #include "gc.h"   #include "main.h"   #include <math.h>      #include "block_alloc.h"    - RCSID("$Id: gc.c,v 1.211 2003/03/30 01:34:53 mast Exp $"); + RCSID("$Id: gc.c,v 1.212 2003/03/30 02:08:08 mast Exp $");      int gc_enabled = 1;      /* These defaults are only guesses and hardly tested at all. Please improve. */   double gc_garbage_ratio_low = 0.2;   double gc_time_ratio = 0.05;   double gc_garbage_ratio_high = 0.5;      /* This slowness factor approximately corresponds to the average over    * the last ten gc rounds. (0.9 == 1 - 1/10) */
pike.git/src/gc.c:314:    return PIKE_T_UNKNOWN;   }      void *check_for =0;   static char *found_where="";   static void *found_in=0;   static int found_in_type=0;   void *gc_svalue_location=0;   char *fatal_after_gc=0;    + #ifdef DEBUG_MALLOC +  + /* To keep the markers after the gc. Only used for the dmalloc leak +  * report at exit. */ + int gc_keep_markers = 0; +  + int gc_external_refs_zapped = 0; +  + #endif +    #define DESCRIBE_MEM 1   #define DESCRIBE_NO_REFS 2   #define DESCRIBE_SHORT 4   #define DESCRIBE_NO_DMALLOC 8      /* type == -1 means that memblock is a char* and should be    * really be printed..    */   void describe_location(void *real_memblock,    int type,
pike.git/src/gc.c:1306:    if (m->weak_refs == *(INT32 *) a)    m->weak_refs = -1;       ret=m->refs;    add_ref(m);    if (m->refs == *(INT32 *) a)    m->flags |= GC_NOT_REFERENCED;    return ret;   }    + static void cleanup_markers (void) + { + #ifdef DO_PIKE_CLEANUP +  size_t 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(); + } +  +    static void init_gc(void)   {   #ifdef PIKE_DEBUG    if (!gc_is_watching) {   #endif -  + #ifdef DEBUG_MALLOC +  /* The marker hash table is left around after a previous gc if +  * gc_keep_markers is set. */ +  if (marker_hash_table) cleanup_markers(); + #endif +     low_init_marker_hash(num_objects);    get_marker(rec_list.data); /* Used to simplify fencepost conditions. */   #ifdef PIKE_DEBUG    }   #endif   }      static void exit_gc(void)   { - #ifdef DO_PIKE_CLEANUP -  size_t 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); + #ifdef DEBUG_MALLOC +  if (!gc_keep_markers)   #endif -  +  cleanup_markers(); +  +  free_all_gc_frame_blocks(); +  + #ifdef GC_VERBOSE +  num_gc_frames = 0; + #endif +    #ifdef PIKE_DEBUG    if (gc_is_watching) {    fprintf(stderr, "## Exiting gc and resetting watches for %d things.\n",    gc_is_watching);    gc_is_watching = 0;    }   #endif -  exit_marker_hash(); -  free_all_gc_frame_blocks(); - #ifdef GC_VERBOSE -  num_gc_frames = 0; - #endif +    }      #ifdef PIKE_DEBUG   void locate_references(void *a)   {    int tmp, orig_in_gc = Pike_in_gc;    char *orig_found_where = found_where;    void *orig_check_for=check_for;    int i=0;    if(!marker_blocks)
pike.git/src/gc.c:1410: Inside #if defined(PIKE_DEBUG) and #if defined(DEBUG_MALLOC)
  #endif    }   #endif       fprintf(stderr,"**Done looking for references to %p.\n", a);       Pike_in_gc = orig_in_gc;    if(i) exit_gc();    d_flag=tmp;   } - #endif +     - #ifdef PIKE_DEBUG -  +    void debug_gc_add_extra_ref(void *a)   {    struct marker *m;       if (gc_is_watching && (m = find_marker(a)) && m->flags & GC_WATCHED) {    /* This is useful to set breakpoints on. */    fprintf(stderr, "## Watched thing %p found in "    "gc_add_extra_ref() in pass %d.\n", a, Pike_in_gc);    }   
pike.git/src/gc.c:1529: Inside #if defined(PIKE_DEBUG)
      found_where=tmp;    found_in=tmp2;    }    return 0;    }       if (Pike_in_gc != GC_PASS_CHECK)    Pike_fatal("gc_external_mark() called in invalid gc pass.\n");    + #ifdef DEBUG_MALLOC +  if (gc_external_refs_zapped) { +  fprintf (stderr, "One external ref to %p found%s.\n", +  a, where ? where : ""); +  if (in) describe (in); +  return 0; +  } + #endif +     m=get_marker(a);    m->xrefs++;    m->flags|=GC_XREFERENCED;    if(Pike_in_gc == GC_PASS_CHECK &&    (m->refs + m->xrefs > *(INT32 *)a ||    (m->saved_refs != -1 && m->saved_refs != *(INT32 *)a)))    gc_fatal(a, 1, "Ref counts are wrong.\n");    return 0;   }