Branch: Tag:

1996-02-25

1996-02-25 00:25:47 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

`+ optimization done

Rev: doc/builtin/gc:1.1
Rev: doc/simulated/implode:1.2
Rev: lib/master.lpc:1.4
Rev: src/add_efun.h:1.3
Rev: src/backend.c:1.4
Rev: src/backend.h:1.4
Rev: src/builtin_efuns.c:1.12
Rev: src/call_out.h:1.3
Rev: src/configure:1.2
Rev: src/configure.in:1.7
Rev: src/debug.c:1.3(DEAD)
Rev: src/debug.h:1.3(DEAD)
Rev: src/docode.c:1.4
Rev: src/gc.c:1.1
Rev: src/gc.h:1.1
Rev: src/language.y:1.10
Rev: src/las.c:1.5
Rev: src/las.h:1.5
Rev: src/lex.c:1.7
Rev: src/lpc_signal.c:1.8
Rev: src/machine.h.in:1.7
Rev: src/main.c:1.3
Rev: src/modules/files/configure.in:1.4
Rev: src/operators.c:1.3
Rev: src/rusage.c:1.4
Rev: src/test/create_testsuite:1.9

1: + /*\ + ||| This file a part of uLPC, and is copyright by Fredrik Hubinette + ||| uLPC is distributed as GPL (General Public License) + ||| See the files COPYING and DISCLAIMER for more information. + \*/    -  + #include "global.h" +  + #ifdef GC2 + #include "gc.h" + #include "main.h" +  + /* Run garbage collect approximate every time we have +  * 20 percent of all arrays, objects and programs is +  * garbage. +  */ +  + #define GC_CONST 20 + #define MIN_ALLOC_THRESHOLD 1000 + #define MULTIPLIER 0.9 +  + void *gc_ptr; + INT32 gc_refs; + INT32 num_objects; + INT32 num_allocs; + INT32 alloc_threshold = MIN_ALLOC_THRESHOLD; +  + static double objects_alloced; + static double objects_freed; +  + void do_gc() + { +  double tmp; +  INT32 tmp2; +  +  tmp2=num_objects; +  + #ifdef DEBUG +  if(t_flag) +  fprintf(stderr,"Garbage collecting ... "); + #endif +  +  objects_alloced*=MULTIPLIER; +  objects_alloced += (double) num_allocs; +  +  objects_freed*=MULTIPLIER; +  objects_freed += (double) num_objects; +  +  gc_clear_array_marks(); +  gc_clear_object_marks(); +  gc_clear_program_marks(); +  +  gc_check_all_arrays(); +  gc_check_all_programs(); +  gc_check_all_objects(); +  +  objects_freed -= (double) num_objects; +  +  tmp=(double)num_objects; +  tmp=tmp * GC_CONST/100.0 * (objects_alloced+1.0) / (objects_freed+1.0); +  +  if((int)tmp < alloc_threshold + num_allocs) +  { +  alloc_threshold=(int)tmp; +  }else{ +  alloc_threshold+=num_allocs; +  } +  +  if(alloc_threshold < MIN_ALLOC_THRESHOLD) +  alloc_threshold = MIN_ALLOC_THRESHOLD; +  num_allocs=0; +  + #ifdef DEBUG +  if(t_flag) +  fprintf(stderr,"done (freed %ld of %ld objects).\n", +  (long)(tmp2-num_objects),(long)tmp2); + #endif + } + #endif +  +  +  +  +  +  +  +  +  +    Newline at end of file added.