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
This commit is contained in:
vsc 2002-05-23 03:52:34 +00:00
parent a5638757d3
commit 61affa1652
5 changed files with 31 additions and 8 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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 =

View File

@ -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

View File

@ -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 */