pike.git / src / gc.c

version» Context lines:

pike.git/src/gc.c:23:   #include "constants.h"   #include "interpret.h"   #include "bignum.h"      #include "gc.h"   #include "main.h"   #include <math.h>      #include "block_alloc.h"    - RCSID("$Id: gc.c,v 1.162 2001/07/01 18:17:30 mast Exp $"); + RCSID("$Id: gc.c,v 1.163 2001/07/01 21:05:08 mast Exp $");      /* Run garbage collect approximately every time    * 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:88: Inside #if defined(GC_VERBOSE) && !defined(PIKE_DEBUG)
     #if defined(GC_VERBOSE) && !defined(PIKE_DEBUG)   #undef GC_VERBOSE   #endif   #ifdef GC_VERBOSE   #define GC_VERBOSE_DO(X) X   #else   #define GC_VERBOSE_DO(X)   #endif    - INT32 num_objects = 3; /* Account for *_empty_array. */ - INT32 num_allocs =0; + int num_objects = 3; /* Account for *_empty_array. */ + int num_allocs =0;   ptrdiff_t alloc_threshold = MIN_ALLOC_THRESHOLD;   PMOD_EXPORT int Pike_in_gc = 0;   int gc_generation = 0;   struct pike_queue gc_mark_queue;   time_t last_gc;      struct gc_frame   {    struct gc_frame *back; /* Previous stack frame. */    void *data;
pike.git/src/gc.c:232:   #undef find_marker   #define find_marker(X) ((struct marker *) debug_malloc_pass(debug_find_marker(X)))      int gc_in_cycle_check = 0;   static unsigned delayed_freed, weak_freed, checked, marked, cycle_checked, live_ref;   static unsigned max_gc_frames, num_gc_frames = 0;   static unsigned gc_extra_refs = 0;      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,"Current number of objects: %d\n",num_objects); +  fprintf(stderr,"Objects allocated total : %d\n",num_allocs); +  fprintf(stderr," threshold for next gc() : %"PRINTPTRDIFFT"d\n",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",    DO_NOT_WARN((long)TIME(0) - (long)last_gc));    fprintf(stderr,"Projected garbage : %f\n", objects_freed * (double) num_allocs / (double) alloc_threshold);    fprintf(stderr,"in_gc : %d\n", Pike_in_gc);   }      TYPE_T attempt_to_identify(void *something)   {
pike.git/src/gc.c:325: Inside #if defined(DEBUG_MALLOC)
   {    extern void *dmalloc_find_memblock_base(void *);    memblock=dmalloc_find_memblock_base(location);    }   #endif       if(type==PIKE_T_UNKNOWN)    type=attempt_to_identify(memblock);       if(memblock) -  fprintf(stderr,"%*s-> from %s %p offset %ld\n", +  fprintf(stderr,"%*s-> from %s %p offset %"PRINTPTRDIFFT"d\n",    indent,"",    get_name_of_type(type),    memblock, -  DO_NOT_WARN((long)((char *)location - (char *)memblock))); +  (char *)location - (char *)memblock);    else    fprintf(stderr,"%*s-> at location %p%s\n",    indent,"",    location,    real_memblock == (void *) -1 ? "" : " in unknown memblock (mmaped?)");       again:    descblock = memblock;    switch(type)    {
pike.git/src/gc.c:375:    fprintf(stderr,"%*s **In p->next\n",indent,"");       if(location == (void *)&p->parent)    fprintf(stderr,"%*s **In p->parent\n",indent,"");       if(p->inherits &&    ptr >= (char *)p->inherits &&    ptr < (char*)(p->inherits+p->num_inherits))    {    e=((char *)ptr - (char *)(p->inherits)) / sizeof(struct inherit); -  fprintf(stderr,"%*s **In p->inherits[%ld] (%s)\n",indent,"", -  DO_NOT_WARN((long)e), -  p->inherits[e].name ? p->inherits[e].name->str : "no name"); +  fprintf(stderr,"%*s **In p->inherits[%"PRINTPTRDIFFT"d] (%s)\n",indent,"", +  e, p->inherits[e].name ? p->inherits[e].name->str : "no name");    break;    }       if(p->constants &&    ptr >= (char *)p->constants &&    ptr < (char*)(p->constants+p->num_constants))    {    e = ((char *)ptr - (char *)(p->constants)) /    sizeof(struct program_constant); -  fprintf(stderr,"%*s **In p->constants[%ld] (%s)\n",indent,"", -  DO_NOT_WARN((long)e), -  p->constants[e].name ? p->constants[e].name->str : "no name"); +  fprintf(stderr,"%*s **In p->constants[%"PRINTPTRDIFFT"d] (%s)\n",indent,"", +  e, p->constants[e].name ? p->constants[e].name->str : "no name");    break;    }          if(p->identifiers &&    ptr >= (char *)p->identifiers &&    ptr < (char*)(p->identifiers+p->num_identifiers))    {    e = ((char *)ptr - (char *)(p->identifiers)) /    sizeof(struct identifier);    -  fprintf(stderr,"%*s **In p->identifiers[%ld] (%s)\n",indent,"", -  DO_NOT_WARN((long)e), -  p->identifiers[e].name ? +  fprintf(stderr,"%*s **In p->identifiers[%"PRINTPTRDIFFT"d] (%s)\n",indent,"", +  e, p->identifiers[e].name ?    (strlen(p->identifiers[e].name->str)<100 ? p->identifiers[e].name->str : "Name too long or already freed.." )    : "no name");    break;    }      #define FOO(NTYP,TYP,NAME) \    if(location == (void *)&p->NAME) fprintf(stderr,"%*s **In p->" #NAME "\n",indent,""); \    if(ptr >= (char *)p->NAME && ptr<(char*)(p->NAME+p->PIKE_CONCAT(num_,NAME))) \ -  fprintf(stderr,"%*s **In p->" #NAME "[%ld]\n",indent,"", \ -  PTRDIFF_T_TO_LONG(((char *)ptr - (char *)(p->NAME)) / sizeof(TYP))); +  fprintf(stderr,"%*s **In p->" #NAME "[%"PRINTPTRDIFFT"d]\n",indent,"", \ +  ((char *)ptr - (char *)(p->NAME)) / sizeof(TYP));   #include "program_areas.h"       break;    }       case T_OBJECT:    {    struct object *o=(struct object *)memblock;    struct program *p;   
pike.git/src/gc.c:482:    break;    }       case T_MULTISET:    descblock = ((struct multiset *) memblock)->ind;    /* FALL THROUGH */    case T_ARRAY:    {    struct array *a=(struct array *)descblock;    struct svalue *s=(struct svalue *)location; -  fprintf(stderr,"%*s **In index number %ld\n",indent,"", -  DO_NOT_WARN((long)(s-ITEM(a)))); +  fprintf(stderr,"%*s **In index number %"PRINTPTRDIFFT"d\n",indent,"", +  s-ITEM(a));    break;    }       case T_MAPPING:    descblock = ((struct mapping *) memblock)->data;    /* FALL THROUGH */    case T_MAPPING_DATA: {    INT32 e;    struct keypair *k;    NEW_MAPPING_LOOP((struct mapping_data *) descblock)
pike.git/src/gc.c:852:    fprintf(stderr,"%*s**Describing mapping:\n",indent,"");    debug_dump_mapping((struct mapping *)a);    fprintf(stderr,"%*s**Describing mapping data block:\n",indent,"");    describe_something( ((struct mapping *)a)->data, T_MAPPING_DATA,    indent+2,-1,flags);    break;       case T_STRING:    {    struct pike_string *s=(struct pike_string *)a; -  fprintf(stderr, "%*s**String length is %ld:\n", indent, "", -  DO_NOT_WARN((long)s->len)); +  fprintf(stderr, "%*s**String length is %"PRINTPTRDIFFT"d:\n", +  indent, "", s->len);    if(s->len>77)    {    fprintf(stderr,"%*s** \"%60s ...\"\n",indent,"",s->str);    }else{    fprintf(stderr,"%*s** \"%s\"\n",indent,"",s->str);    }    break;    }    }   }
pike.git/src/gc.c:918:   {    describe_something(x, attempt_to_identify(x), 0, 2, 0);   }      void debug_describe_svalue(struct svalue *s)   {    fprintf(stderr,"Svalue at %p is:\n",s);    switch(s->type)    {    case T_INT: -  fprintf(stderr," %ld\n",(long)s->u.integer); +  fprintf(stderr," %"PRINTPIKEINT"d\n",s->u.integer);    break;       case T_FLOAT:    fprintf(stderr," %f\n",s->u.float_number);    break;       case T_FUNCTION:    if(s->subtype == FUNCTION_BUILTIN)    {    fprintf(stderr," Builtin function: %s\n",s->u.efun->name->str);
pike.git/src/gc.c:1691:    /* Only recurse through things already handled; we'll get to the    * other later in the normal recursion. */   #ifdef PIKE_DEBUG    if (m->flags & GC_LIVE_RECURSE)    gc_fatal(x, 0, "Mark live recursion attempted twice into thing.\n");   #endif    goto live_recurse;    }    CYCLE_DEBUG_MSG(m, "gc_cycle_push, no live recurse");    } +     else {    /* We'll get here eventually in the normal recursion. Pop off    * the remaining live recurse frames for the last thing. */    int flags;    CYCLE_DEBUG_MSG(m, "gc_cycle_push, no live recurse");    last->flags &= ~GC_LIVE_RECURSE;    while (1) {    struct gc_frame *l = gc_rec_top;   #ifdef PIKE_DEBUG    if (!gc_rec_top)
pike.git/src/gc.c:2098:    if (!p) break;    }    }       CALL_AND_UNSET_ONERROR(tmp);   }      int do_gc(void)   {    double tmp; -  int objs, pre_kill_objs; +  ptrdiff_t objs, pre_kill_objs;    double multiplier;    struct array *a;    struct multiset *l;    struct mapping *m;    struct program *p;    struct object *o;   #ifdef PIKE_DEBUG   #ifdef HAVE_GETHRTIME    hrtime_t gcstarttime = 0;   #endif
pike.git/src/gc.c:2202: Inside #if defined(PIKE_DEBUG)
   if(builtin_constants)    gc_external_mark2(builtin_constants,0," 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, (void *)0);    -  GC_VERBOSE_DO(fprintf(stderr, "| check: %u references checked, counted %lu weak refs\n", -  checked, SIZE_T_TO_ULONG(gc_ext_weak_refs))); +  GC_VERBOSE_DO(fprintf(stderr, "| check: %u references checked, " +  "counted %"PRINTSIZET"u weak refs\n", +  checked, 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;    gc_internal_multiset = first_multiset;    gc_internal_mapping = first_mapping;    gc_internal_program = first_program;
pike.git/src/gc.c:2235:    gc_mark_all_programs();    run_queue(&gc_mark_queue);    gc_mark_all_objects();    run_queue(&gc_mark_queue);   #ifdef PIKE_DEBUG    if(gc_debug) gc_mark_all_strings();   #endif /* PIKE_DEBUG */       GC_VERBOSE_DO(fprintf(stderr,    "| mark: %u markers referenced, %u weak references freed,\n" -  "| %d things to free, got %lu tricky weak refs\n", -  marked, weak_freed, delayed_freed, -  SIZE_T_TO_ULONG(gc_ext_weak_refs))); +  "| %d things to free, " +  "got %"PRINTSIZET"u tricky weak refs\n", +  marked, weak_freed, delayed_freed, gc_ext_weak_refs));       {   #ifdef PIKE_DEBUG    size_t orig_ext_weak_refs = gc_ext_weak_refs;    obj_count = delayed_freed;    max_gc_frames = 0;   #endif    Pike_in_gc=GC_PASS_CYCLE;       /* Now find all cycles in the internal structures. Note that we can
pike.git/src/gc.c:2265:    gc_cycle_check_all_multisets();    gc_cycle_check_all_mappings();    gc_cycle_check_all_programs();      #ifdef PIKE_DEBUG    if (gc_rec_top)    fatal("gc_rec_top not empty at end of cycle check pass.\n");    if (NEXT(&rec_list) || gc_rec_last != &rec_list || gc_rec_top)    fatal("Recurse list not empty or inconsistent after cycle check pass.\n");    if (gc_ext_weak_refs != orig_ext_weak_refs) -  fatal("gc_ext_weak_refs changed from %lu to %lu in cycle check pass.\n", -  SIZE_T_TO_ULONG(orig_ext_weak_refs), SIZE_T_TO_ULONG(gc_ext_weak_refs)); +  fatal("gc_ext_weak_refs changed from %"PRINTSIZET"u " +  "to %"PRINTSIZET"u in cycle check pass.\n", +  orig_ext_weak_refs, gc_ext_weak_refs);   #endif       GC_VERBOSE_DO(fprintf(stderr,    "| cycle: %u internal things visited, %u cycle ids used,\n"    "| %u weak references freed, %d more things to free,\n"    "| space for %u gc frames used\n",    cycle_checked, last_cycle, weak_freed,    delayed_freed - obj_count, max_gc_frames));    }   
pike.git/src/gc.c:2294:    * doesn't occur very often; only when something have both    * external weak refs and nonweak cyclic refs from internal    * things. */    gc_zap_ext_weak_refs_in_mappings();    gc_zap_ext_weak_refs_in_arrays();    /* Multisets handled as arrays. */    gc_zap_ext_weak_refs_in_objects();    gc_zap_ext_weak_refs_in_programs();    GC_VERBOSE_DO(    fprintf(stderr, -  "| zap weak: freed %ld external weak refs, %lu internal still around,\n" +  "| zap weak: freed %"PRINTPTRDIFFT"d external weak refs, " +  "%"PRINTSIZET"u internal still around,\n"    "| %d more things to free\n", -  PTRDIFF_T_TO_LONG(to_free - gc_ext_weak_refs), -  SIZE_T_TO_ULONG(gc_ext_weak_refs), delayed_freed - obj_count)); +  to_free - gc_ext_weak_refs, gc_ext_weak_refs, +  delayed_freed - obj_count));    }      #ifdef PIKE_DEBUG    if (gc_debug) {    unsigned n;    size_t i;    struct marker *m;    Pike_in_gc=GC_PASS_MIDDLETOUCH;    n = gc_touch_all_arrays();    n += gc_touch_all_multisets();
pike.git/src/gc.c:2495:       alloc_threshold = (ptrdiff_t)tmp;       num_allocs=0;      #ifdef PIKE_DEBUG    UNSET_ONERROR (uwp);    if(GC_VERBOSE_DO(1 ||) t_flag)    {   #ifdef HAVE_GETHRTIME -  fprintf(stderr,"done (freed %ld of %ld things), %ld ms.\n", -  (long)objs,(long)objs + num_objects, -  (long)((gethrtime() - gcstarttime)/1000000)); +  fprintf(stderr, +  "done (freed %"PRINTPTRDIFFT"d of %"PRINTPTRDIFFT"d things), %ld ms.\n", +  objs, objs + num_objects, (long)((gethrtime() - gcstarttime)/1000000));   #else -  fprintf(stderr,"done (freed %ld of %ld things)\n", -  (long)objs,(long)objs + num_objects); +  fprintf(stderr, +  "done (freed %"PRINTPTRDIFFT"d of %"PRINTPTRDIFFT"d things)\n", +  objs, objs + num_objects);   #endif    }   #endif      #ifdef ALWAYS_GC    ADD_GC_CALLBACK();   #else    if(d_flag > 3) ADD_GC_CALLBACK();   #endif