From 61affa1652006322c285f100ada6cdfca94f7fe7 Mon Sep 17 00:00:00 2001 From: vsc Date: Thu, 23 May 2002 03:52:34 +0000 Subject: [PATCH] keep all dynamic arrays linked and garbage collect them. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@481 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/heapgc.c | 25 +++++++++++++++++++++---- C/init.c | 1 + C/save.c | 2 ++ H/Heap.h | 4 +++- m4/Yatom.h.m4 | 7 ++++--- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/C/heapgc.c b/C/heapgc.c index de0b36e01..1e30d8077 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -369,6 +369,14 @@ push_registers(Int num_regs, yamop *nextop) { int i; + /* push array entries first */ + ArrayEntry *al = DynArrayList; + while (al != NULL) { + if (al->ArrayEArity > 0) { + TrailTerm(TR++) = al->ValueOfVE; + } + al = al->NextArrayE; + } #ifdef COROUTINING TrailTerm(TR) = WokenGoals; TrailTerm(TR+1) = MutableList; @@ -411,6 +419,14 @@ pop_registers(Int num_regs, yamop *nextop) int i; tr_fr_ptr ptr = TR; + /* pop array entries first */ + ArrayEntry *al = DynArrayList; + while (al != NULL) { + if (al->ArrayEArity > 0) { + al->ValueOfVE = TrailTerm(ptr++); + } + al = al->NextArrayE; + } #ifdef COROUTINING #ifdef MULTI_ASSIGNMENT_VARIABLES WokenGoals = TrailTerm(ptr++); @@ -1206,11 +1222,12 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B #endif } } else if (IsPairTerm(trail_cell)) { - /* do nothing */ + /* can safely ignore this */ } #if MULTI_ASSIGNMENT_VARIABLES else { tr_fr_ptr *lkp; + CELL *cptr = RepAppl(trail_cell); /* This is a bit complex. The idea is that we may have several trailings for the same mavar in the same trail segment. Essentially, the problem arises because of !. What we want is to ignore all but @@ -1221,14 +1238,14 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B Solution: we keep a list of all found entries and search in the end */ - if (!(lkp = gc_lookup_ma_var(RepAppl(trail_cell), trail_ptr))) { + if (!(lkp = gc_lookup_ma_var(cptr, trail_ptr))) { if (HEAP_PTR(trail_cell)) { /* fool the gc into thinking this is a variable */ - TrailTerm(trail_ptr) = (CELL)RepAppl(trail_cell); + TrailTerm(trail_ptr) = (CELL)cptr; mark_external_reference(&(TrailTerm(trail_ptr))); /* reset the gc to believe the original tag */ TrailTerm(trail_ptr) = AbsAppl((CELL *)TrailTerm(trail_ptr)); - } + } trail_ptr --; } else { tr_fr_ptr trp = (*lkp)-1; diff --git a/C/init.c b/C/init.c index 5b683cb1b..b78c752eb 100644 --- a/C/init.c +++ b/C/init.c @@ -1008,6 +1008,7 @@ InitCodes(void) #endif heap_regs->term_prolog = MkAtomTerm(LookupAtom("prolog")); heap_regs->term_refound_var = MkAtomTerm(LookupAtom("$I_FOUND_THE_VARIABLE_AGAIN")); + heap_regs->dyn_array_list = NULL; heap_regs->n_of_file_aliases = 0; heap_regs->file_aliases = NULL; heap_regs->foreign_code_loaded = NULL; diff --git a/C/save.c b/C/save.c index e9f10a0df..351d6fadf 100644 --- a/C/save.c +++ b/C/save.c @@ -1114,6 +1114,8 @@ restore_codes(void) #endif heap_regs->term_prolog = AtomTermAdjust(heap_regs->term_prolog); heap_regs->term_refound_var = AtomTermAdjust(heap_regs->term_refound_var); + heap_regs->dyn_array_list = + (struct array_entry *)AddrAdjust((ADDR)heap_regs->dyn_array_list); heap_regs->file_aliases = (struct AliasDescS *)AddrAdjust((ADDR)heap_regs->file_aliases); heap_regs->yap_lib_dir = diff --git a/H/Heap.h b/H/Heap.h index 79ade0ae3..7d3382a08 100644 --- a/H/Heap.h +++ b/H/Heap.h @@ -10,7 +10,7 @@ * File: Heap.h * * mods: * * comments: Heap Init Structure * -* version: $Id: Heap.h,v 1.25 2002-05-14 18:24:33 vsc Exp $ * +* version: $Id: Heap.h,v 1.26 2002-05-23 03:52:34 vsc Exp $ * *************************************************************************/ /* information that can be stored in Code Space */ @@ -281,6 +281,7 @@ typedef struct various_codes { PredEntry *pred_dollar_catch; PredEntry *pred_throw; PredEntry *pred_handle_throw; + struct array_entry *dyn_array_list; UInt n_of_file_aliases; UInt sz_of_file_aliases; struct AliasDescS * file_aliases; @@ -472,6 +473,7 @@ typedef struct various_codes { #define PredDollarCatch heap_regs->pred_dollar_catch #define PredThrow heap_regs->pred_throw #define PredHandleThrow heap_regs->pred_handle_throw +#define DynArrayList heap_regs->dyn_array_list #define NOfFileAliases heap_regs->n_of_file_aliases #define SzOfFileAliases heap_regs->sz_of_file_aliases #define FileAliases heap_regs->file_aliases diff --git a/m4/Yatom.h.m4 b/m4/Yatom.h.m4 index 6e2bcabff..f5c01b971 100644 --- a/m4/Yatom.h.m4 +++ b/m4/Yatom.h.m4 @@ -416,14 +416,15 @@ Inline(IsBBProperty, PropFlags, int, flags, (flags == BBProperty)) /* array property entry structure */ /* first case is for dynamic arrays */ -typedef struct { +typedef struct array_entry { Prop NextOfPE; /* used to chain properties */ PropFlags KindOfPE; /* kind of property */ Int ArrayEArity; /* Arity of Array (positive) */ #if defined(YAPOR) || defined(THREADS) rwlock_t ArRWLock; /* a read-write lock to protect the entry */ -#endif - Term ValueOfVE; /* Pointer to the actual array */ +#endif + struct array_entry *NextArrayE; /* Pointer to the actual array */ + Term ValueOfVE; /* Pointer to the actual array */ } ArrayEntry; /* second case is for static arrays */