Branch: Tag:

2001-04-14

2001-04-14 09:44:22 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

Jumbopatch:

Saved 8 bytes per object (for objects that do not use their parent scope),
fixed some memory leaks and
first implementation of constant objects (Gmp.Bignum, Math.Matrix and Image.Colour)

Rev: src/backend.cmod:1.14
Rev: src/builtin.cmod:1.27
Rev: src/builtin_functions.c:1.362
Rev: src/docode.c:1.111
Rev: src/encode.c:1.98
Rev: src/gc.c:1.149
Rev: src/interpret.c:1.191
Rev: src/las.c:1.251
Rev: src/main.c:1.123
Rev: src/modules/Gmp/mpz_glue.c:1.93
Rev: src/modules/Image/colors.c:1.49
Rev: src/modules/Math/math_matrix.c:1.22
Rev: src/modules/Oracle/oracle.c:1.56
Rev: src/modules/files/socket.c:1.54
Rev: src/object.c:1.169
Rev: src/object.h:1.62
Rev: src/program.c:1.314
Rev: src/program.h:1.125
Rev: src/threads.h:1.114
Rev: src/version.h:1.273

5:   \*/   /**/   #include "global.h" - RCSID("$Id: program.c,v 1.313 2001/04/13 20:48:34 grubba Exp $"); + RCSID("$Id: program.c,v 1.314 2001/04/14 09:44:21 hubbe Exp $");   #include "program.h"   #include "object.h"   #include "dynamic_buffer.h"
43:   #define ATTRIBUTE(X)      static void exit_program_struct(struct program *); + static size_t add_xstorage(size_t size, +  size_t alignment, +  ptrdiff_t modulo_orig);      #undef EXIT_BLOCK   #define EXIT_BLOCK(P) exit_program_struct( (P) )
1231:    MEMSET(Pike_compiler->fake_object->storage,0x55,256*sizeof(struct svalue));   #else    Pike_compiler->fake_object=ALLOC_STRUCT(object); -  Pike_compiler->fake_object->storage=0; +  Pike_compiler->fake_object->storage=(char *)malloc(sizeof(struct parent_info));   #endif    /* Can't use GC_ALLOC on fake objects, but still it's good to know    * that they never take over a stale gc marker. */
1240:    Pike_compiler->fake_object->next=Pike_compiler->fake_object;    Pike_compiler->fake_object->prev=Pike_compiler->fake_object;    Pike_compiler->fake_object->refs=1; -  Pike_compiler->fake_object->parent=0; -  Pike_compiler->fake_object->parent_identifier=-1; +     Pike_compiler->fake_object->prog=p;    add_ref(p);   
1258:       if(name)    { -  if((Pike_compiler->fake_object->parent=Pike_compiler->previous->fake_object)) -  add_ref(Pike_compiler->fake_object->parent); -  Pike_compiler->fake_object->parent_identifier=id; +  /* Fake objects have parents regardless of PROGRAM_USE_PARENT */ +  if((((struct parent_info *)Pike_compiler->fake_object->storage)->parent=Pike_compiler->previous->fake_object)) +  add_ref(Pike_compiler->previous->fake_object); +  ((struct parent_info *)Pike_compiler->fake_object->storage)->parent_identifier=id; +  }else{ +  ((struct parent_info *)Pike_compiler->fake_object->storage)->parent=0; +  ((struct parent_info *)Pike_compiler->fake_object->storage)->parent_identifier=0;    }       Pike_compiler->new_program=p;
1508:   {    if(Pike_compiler->fake_object)    { +  if( ((struct parent_info *)Pike_compiler->fake_object->storage)->parent ) +  { +  free_object(((struct parent_info *)Pike_compiler->fake_object->storage)->parent); +  +  ((struct parent_info *)Pike_compiler->fake_object->storage)->parent=0; +  } +     free_program(Pike_compiler->fake_object->prog);    Pike_compiler->fake_object->prog=0;    free_object(Pike_compiler->fake_object);
1799:       Pike_compiler->new_program->flags |= PROGRAM_PASS_1_DONE;    +     if(finish)    { -  +  if(Pike_compiler->new_program->flags & PROGRAM_USES_PARENT) +  { +  Pike_compiler->new_program->parent_info_storage = +  add_xstorage(sizeof(struct parent_info), +  ALIGNOF(struct parent_info), +  0); +  }else{ +  /* Cause errors if used hopefully */ +  Pike_compiler->new_program->parent_info_storage=-1; +  } +     fixate_program();    optimize_program(Pike_compiler->new_program);    Pike_compiler->new_program->flags |= PROGRAM_FINISHED;
1917:    return (size_t) offset;   }    + /* +  * Internal function. +  * Adds object storage that will *not* be inherited. +  */ + static size_t add_xstorage(size_t size, +  size_t alignment, +  ptrdiff_t modulo_orig) + { +  ptrdiff_t offset, modulo, available; +  int e; +  +  if(!size) return Pike_compiler->new_program->xstorage; +  +  modulo=( modulo_orig /* +OFFSETOF(object,storage) */ ) % alignment; +  +  offset=DO_ALIGN(Pike_compiler->new_program->xstorage-modulo,alignment)+modulo; +  +  Pike_compiler->new_program->xstorage = offset + size; +  +  /* Move all inherits to make room */ +  available = Pike_compiler->new_program->inherits[0].storage_offset; +  if(available < offset+size) +  { +  available= +  DO_ALIGN( ((offset + size) - available), +  Pike_compiler->new_program->alignment_needed); +  +  for(e=0;e<Pike_compiler->new_program->num_inherits;e++) +  Pike_compiler->new_program->inherits[e].storage_offset+=available; +  +  Pike_compiler->new_program->storage_needed+=available; +  } +  +  return (size_t) offset; + } +    typedef void (*oldhandlertype)(struct object *);   static void compat_event_handler(enum pike_program_event e)   {
2322:    {    if(parent->next == parent)    { + #if 0    struct object *o;    inherit.parent_offset=0;    for(o=Pike_compiler->fake_object;o!=parent;o=o->parent)
2331:   #endif    inherit.parent_offset++;    } + #else +  struct program_state *state=Pike_compiler; +  inherit.parent_offset=0; +  for(;state->fake_object!=parent;state=state->previous) +  { + #ifdef PIKE_DEBUG +  if(!state->fake_object) +  fatal("low_inherit with odd Pike_compiler->fake_object as parent!\n"); + #endif +  inherit.parent_offset++; +  } + #endif    }else{    inherit.parent=parent;    inherit.parent_identifier=parent_identifier;
2382:    break;       case -18: -  pid = par->parent_identifier; -  par = par->parent; +  if(par->prog->flags & PROGRAM_USES_PARENT) +  { +  pid = PARENT_INFO(par)->parent_identifier; +  par = PARENT_INFO(par)->parent; +  }else{ +  pid=-1; +  par=0;    }    } -  +  }       inherit.parent=par;    inherit.parent_offset=-17;
2903:    dummy.type = get_type_of_svalue(c);    dummy.run_time_type=c->type;    dummy.func.offset=store_constant(c, 0, 0); +  dummy.opt_flags=OPT_SIDE_EFFECT | OPT_EXTERNAL_DEPEND; +  if(c->type == PIKE_T_PROGRAM && (c->u.program->flags & PROGRAM_CONSTANT)) +  dummy.opt_flags=0;    }    else {    copy_pike_type(dummy.type, mixed_type_string);    dummy.run_time_type=T_MIXED;    dummy.func.offset=-1; -  +  dummy.opt_flags=0;    }       ref.id_flags=flags;
4622:    ptrdiff_t offset;    unsigned INT32 hval;    -  if(!o) return 0; +  if(!o) return -1;    oid=o->id;    pid=p->id;    hval=oid*9248339 + pid;