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.236 2003/09/24 01:08:09 mast Exp $ + || $Id: gc.c,v 1.237 2003/09/29 19:41:23 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.236 2003/09/24 01:08:09 mast Exp $"); + RCSID("$Id: gc.c,v 1.237 2003/09/29 19:41:23 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:202:   #endif      /* These are only collected for the sake of gc_status. */   static double last_garbage_ratio = 0.0;   static enum {    GARBAGE_RATIO_LOW, GARBAGE_RATIO_HIGH   } last_garbage_strategy = GARBAGE_RATIO_LOW;      struct callback_list gc_callbacks;    + /* These callbacks are run early in the check pass of the gc and when +  * locate_references is called. They are typically used to mark +  * external references (using gc_mark_external) for debug purposes. */   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);   }      static void init_gc(void);   static void gc_cycle_pop(void *a);   
pike.git/src/gc.c:507:    if(location == (void *)(base + id->func.offset))    {    fprintf(stderr,"%*s **In variable %s\n",indent,"",id->name->str);    }    }       if((char *)location >= base && (char *)location <= base +    ( tmp.prog->storage_needed - tmp.prog->inherits[0].storage_offset ))    {    fprintf(stderr,"%*s **In storage for inherit %d",indent,"",e); -  if(tmp.name) +  if(tmp.name && !tmp.name->size_shift)    fprintf(stderr," (%s)",tmp.name->str);    fprintf(stderr,"\n");    }       }    }    break;    }       case T_STORAGE:
pike.git/src/gc.c:1568: Inside #if defined(PIKE_DEBUG)
  #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   }      #ifdef PIKE_DEBUG + /* This function marks some known externals. The rest are handled by +  * callbacks added with add_gc_callback. */ + static void mark_externals (void) + { +  struct mapping *constants; +  if (master_object) +  gc_mark_external (master_object, " as master_object"); +  if ((constants = get_builtin_constants())) +  gc_mark_external (constants, " as global constants mapping"); + } +    void locate_references(void *a)   {    int tmp, orig_in_gc = Pike_in_gc;    int i=0;    if(!marker_blocks)    {    i=1;    init_gc();    }    Pike_in_gc = GC_PASS_LOCATE;       /* Disable debug, this may help reduce recursion bugs */    tmp=d_flag;    d_flag=0;       fprintf(stderr,"**Looking for references to %p:\n", a);       check_for=a;       GC_ENTER (NULL, PIKE_T_UNKNOWN) { -  +  mark_externals(); +  call_callback(& gc_callbacks, NULL); +     gc_check_all_arrays();    gc_check_all_multisets();    gc_check_all_mappings();    gc_check_all_programs();    gc_check_all_objects(); -  - #ifdef PIKE_DEBUG -  if(master_object) -  gc_mark_external (master_object, " as master_object"); -  { -  extern struct mapping *builtin_constants; -  if(builtin_constants) -  gc_mark_external (builtin_constants, " as builtin_constants"); -  } - #endif -  -  call_callback(& gc_callbacks, NULL); +     } GC_LEAVE;      #ifdef DEBUG_MALLOC    {    extern void dmalloc_find_references_to(void *);   #if 0    fprintf(stderr,"**DMALLOC Looking for references:\n");    dmalloc_find_references_to(a);   #endif    }
pike.git/src/gc.c:2740:    n += gc_touch_all_programs();    n += gc_touch_all_objects();   #ifdef PIKE_DEBUG    gc_touch_all_strings();   #endif    if (n != (unsigned) num_objects)    Pike_fatal("Object count wrong before gc; expected %d, got %d.\n", num_objects, n);    GC_VERBOSE_DO(fprintf(stderr, "| pretouch: %u things\n", n));    }    +  /* First we count internal references */    Pike_in_gc=GC_PASS_CHECK;    gc_ext_weak_refs = 0; -  /* First we count internal references */ +  + #ifdef PIKE_DEBUG +  mark_externals(); + #endif +  call_callback(& gc_callbacks, NULL); +     ACCEPT_UNFINISHED_TYPE_FIELDS {    gc_check_all_arrays();    gc_check_all_multisets();    gc_check_all_mappings();    gc_check_all_programs();    gc_check_all_objects();    } END_ACCEPT_UNFINISHED_TYPE_FIELDS;    - #ifdef PIKE_DEBUG -  if(master_object) -  gc_mark_external (master_object, " as master_object"); -  -  { -  extern struct mapping *builtin_constants; -  if(builtin_constants) -  gc_mark_external (builtin_constants, " as builtin_constants"); -  } - #endif -  -  /* These callbacks are mainly for the check pass, but can also -  * do things that are normally associated with the mark pass -  */ -  call_callback(& gc_callbacks, NULL); -  +     GC_VERBOSE_DO(fprintf(stderr, "| check: %u references in %d things, "    "counted %"PRINTSIZET"u weak refs\n",    checked, num_objects, gc_ext_weak_refs));       Pike_in_gc=GC_PASS_MARK;       /* Anything after and including gc_internal_* in the linked lists    * are considered to lack external references. The mark pass move    * externally referenced things in front of these pointers. */    gc_internal_array = empty_array.next;