Branch: Tag:

2008-05-02

2008-05-02 04:15:18 by Martin Stjernholm <mast@lysator.liu.se>

Added Pike.count_memory to be able to see the memory consumed by arbitrary
pike structures.

The Gmp classes have been fixed to accurately report sizes, but there's
probably more to do in other modules.

Rev: lib/modules/Pike.pmod/module.pmod:1.17
Rev: src/array.c:1.205
Rev: src/builtin_functions.c:1.659
Rev: src/gc.c:1.305
Rev: src/gc.h:1.131
Rev: src/mapping.c:1.199
Rev: src/modules/Gmp/acconfig.h:1.8
Rev: src/modules/Gmp/configure.in:1.48
Rev: src/modules/Gmp/mpf.cmod:1.35
Rev: src/modules/Gmp/mpq.cmod:1.27
Rev: src/modules/Gmp/mpz_glue.c:1.178
Rev: src/multiset.c:1.107
Rev: src/object.c:1.288
Rev: src/pike_types.c:1.323
Rev: src/program.c:1.681
Rev: src/stralloc.c:1.216
Rev: src/stralloc.h:1.102

2:   || 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: pike_types.c,v 1.322 2008/04/25 13:45:22 grubba Exp $ + || $Id: pike_types.c,v 1.323 2008/05/02 04:15:14 mast Exp $   */      #include "global.h"
7671:   #endif /* DO_PIKE_CLEANUP */   }    - #if defined (PIKE_DEBUG) || defined (DO_PIKE_CLEANUP) -  +    /* This is only enough gc stuff to detect leaking pike_type structs -  * and to locate references to them. More is needed if types are -  * extended to contain pointers to other memory objects or if they -  * might contain cycles. */ +  * and to get _locate_references and Pike.count_memory working. More +  * is needed if types are extended to contain pointers to other memory +  * objects or if they might contain cycles. */    -  + void gc_check_type (struct pike_type *t) + { +  debug_malloc_touch (t); +  +  GC_ENTER (t, T_TYPE) { +  switch (t->type) { +  case T_FUNCTION: +  case T_MANY: +  case T_TUPLE: +  case T_MAPPING: +  case T_OR: +  case T_AND: +  case PIKE_T_RING: +  case PIKE_T_ATTRIBUTE: +  case PIKE_T_NAME: +  debug_gc_check (t->car, " as car in a type"); +  debug_gc_check (t->cdr, " as cdr in a type"); +  break; +  case T_ARRAY: +  case T_MULTISET: +  case T_NOT: +  case T_TYPE: +  case T_PROGRAM: +  case T_STRING: +  debug_gc_check (t->car, " as car in a type"); +  break; +  case T_SCOPE: +  case T_ASSIGN: +  debug_gc_check (t->cdr, " as cdr in a type"); +  break; + #ifdef PIKE_DEBUG +  case '0': +  case '1': +  case '2': +  case '3': +  case '4': +  case '5': +  case '6': +  case '7': +  case '8': +  case '9': +  case T_FLOAT: +  case T_MIXED: +  case T_VOID: +  case T_ZERO: +  case PIKE_T_UNKNOWN: +  case T_INT: +  case T_OBJECT: +  break; +  default: +  Pike_fatal("gc_check_type: " +  "Unhandled type-node: %d\n", t->type); +  break; + #endif /* PIKE_DEBUG */ +  } +  } GC_LEAVE; + } +    void gc_mark_type_as_referenced(struct pike_type *t)   {    if (gc_mark(t)) { -  +  if (Pike_in_gc == GC_PASS_COUNT_MEMORY) { +  gc_counted_bytes += sizeof (struct pike_type); +  gc_check_type (t); +  } +     GC_ENTER(t, PIKE_T_TYPE) {    switch(t->type) {    case PIKE_T_SCOPE:
7710: Inside #if defined (PIKE_DEBUG) || defined (DO_PIKE_CLEANUP)
   }   }    + #if defined (PIKE_DEBUG) || defined (DO_PIKE_CLEANUP) +    #ifdef PIKE_DEBUG   static void gc_mark_external_types(struct callback *cb, void *a, void *b)   {
7766: Inside #if defined (PIKE_DEBUG) || defined (DO_PIKE_CLEANUP)
  }   #endif    - void gc_check_type (struct pike_type *t) - { -  debug_malloc_touch (t); -  -  GC_ENTER (t, T_TYPE) { -  switch (t->type) { -  case T_FUNCTION: -  case T_MANY: -  case T_TUPLE: -  case T_MAPPING: -  case T_OR: -  case T_AND: -  case PIKE_T_RING: -  case PIKE_T_ATTRIBUTE: -  case PIKE_T_NAME: -  debug_gc_check (t->car, " as car in a type"); -  debug_gc_check (t->cdr, " as cdr in a type"); -  break; -  case T_ARRAY: -  case T_MULTISET: -  case T_NOT: -  case T_TYPE: -  case T_PROGRAM: -  case T_STRING: -  debug_gc_check (t->car, " as car in a type"); -  break; -  case T_SCOPE: -  case T_ASSIGN: -  debug_gc_check (t->cdr, " as cdr in a type"); -  break; - #ifdef PIKE_DEBUG -  case '0': -  case '1': -  case '2': -  case '3': -  case '4': -  case '5': -  case '6': -  case '7': -  case '8': -  case '9': -  case T_FLOAT: -  case T_MIXED: -  case T_VOID: -  case T_ZERO: -  case PIKE_T_UNKNOWN: -  case T_INT: -  case T_OBJECT: -  break; -  default: -  Pike_fatal("gc_check_type: " -  "Unhandled type-node: %d\n", t->type); -  break; - #endif /* PIKE_DEBUG */ -  } -  } GC_LEAVE; - } -  +    void gc_check_all_types (void)   {    unsigned INT32 e;