fix indirect gc when first Heap cell is not collected

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@199 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-11-26 12:33:05 +00:00
parent 88e90c7991
commit 42de8a6f82
6 changed files with 42 additions and 17 deletions

View File

@ -3798,18 +3798,23 @@ p_init_queue(void)
db_queue *dbq; db_queue *dbq;
Term t; Term t;
while ((dbq = (db_queue *)AllocDBSpace(sizeof(db_queue))) == NULL) { if (DBQueuesCache) {
if (!growheap(FALSE)) { dbq = DBQueuesCache;
Abort("[ SYSTEM ERROR: YAP failed to reserve space in growheap ]\n"); DBQueuesCache = dbq->next;
return(FALSE); } else {
while ((dbq = (db_queue *)AllocDBSpace(sizeof(db_queue))) == NULL) {
if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP failed to reserve space in growheap ]\n");
return(FALSE);
}
} }
dbq->id = FunctorDBRef;
dbq->EntryTerm = MkAtomTerm(AbsAtom((AtomEntry *)dbq));
dbq->Flags = DBClMask;
dbq->FirstInQueue = dbq->LastInQueue = NULL;
dbq->next = DBQueues;
dbq->prev = NULL;
} }
dbq->id = FunctorDBRef;
dbq->EntryTerm = MkAtomTerm(AbsAtom((AtomEntry *)dbq));
dbq->Flags = DBClMask;
dbq->FirstInQueue = dbq->LastInQueue = NULL;
dbq->next = DBQueues;
dbq->prev = NULL;
DBQueues = dbq; DBQueues = dbq;
dbq->age = IntOfTerm(GetValue(AtomCatch)); dbq->age = IntOfTerm(GetValue(AtomCatch));
INIT_RWLOCK(dbq->QRWLock); INIT_RWLOCK(dbq->QRWLock);
@ -3899,8 +3904,9 @@ p_dequeue(void)
father_key->prev->next = father_key->next; father_key->prev->next = father_key->next;
if (father_key->next != NULL) if (father_key->next != NULL)
father_key->next->prev = father_key->prev; father_key->next->prev = father_key->prev;
father_key->next = DBQueuesCache;
DBQueuesCache = father_key;
WRITE_UNLOCK(father_key->QRWLock); WRITE_UNLOCK(father_key->QRWLock);
FreeDBSpace((char *) father_key);
return(FALSE); return(FALSE);
} else { } else {
Term TDB; Term TDB;

View File

@ -567,7 +567,7 @@ init_dbtable(tr_fr_ptr trail_ptr) {
#ifdef DEBUG #ifdef DEBUG
#define INSTRUMENT_GC 1 #define INSTRUMENT_GC 1
/*#define CHECK_CHOICEPOINTS 1 */ /* #define CHECK_CHOICEPOINTS 1 */
#ifdef INSTRUMENT_GC #ifdef INSTRUMENT_GC
typedef enum { typedef enum {
@ -803,7 +803,7 @@ mark_variable(CELL_PTR current)
goto begin; goto begin;
} }
#ifdef DEBUG #ifdef DEBUG
else if (next < (CELL *)AtomBase) else if (next < (CELL *)AtomBase || next < (CELL *)HeapTop)
YP_fprintf(YP_stderr, "ooops while marking %lx, %p at %p\n", (unsigned long int)ccur, current, next); YP_fprintf(YP_stderr, "ooops while marking %lx, %p at %p\n", (unsigned long int)ccur, current, next);
#endif #endif
#ifdef INSTRUMENT_GC #ifdef INSTRUMENT_GC
@ -1325,7 +1325,10 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR)
if (pe == NULL) { if (pe == NULL) {
YP_fprintf(YP_stderr,"B %p (%s) with %d\n", gc_B, op_names[opnum], total_marked); YP_fprintf(YP_stderr,"B %p (%s) with %d\n", gc_B, op_names[opnum], total_marked);
} else } else
YP_fprintf(YP_stderr,"B %p (%s for %s/%d) with %d,%d\n", gc_B, op_names[opnum], RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE, gc_B->cp_h-H0, total_marked); if (pe->ArityOfPE)
YP_fprintf(YP_stderr,"B %p (%s for %s/%d) with %d,%d\n", gc_B, op_names[opnum], RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE, pe->ArityOfPE, gc_B->cp_h-H0, total_marked);
else
YP_fprintf(YP_stderr,"B %p (%s for %s) with %d,%d\n", gc_B, op_names[opnum], RepAtom(pe->FunctorOfPred)->StrOfAE, gc_B->cp_h-H0, total_marked);
} }
} }
#endif /* CHECK_CHOICEPOINTS */ #endif /* CHECK_CHOICEPOINTS */
@ -2301,6 +2304,15 @@ adjust_cp_hbs(void)
} else while (TRUE) { } else while (TRUE) {
CELL_PTR *nxt = nbase+(top-nbase)/2; CELL_PTR *nxt = nbase+(top-nbase)/2;
if (nxt[0] > gc_H) { if (nxt[0] > gc_H) {
if (nbase == top) {
if (nbase == base) {
gc_B->cp_h = H0;
break;
} else {
Error(SYSTEM_ERROR,TermNil,"Bug in Garbage collector");
return;
}
}
top = nxt; top = nxt;
} else if (nxt[0] < gc_H && nxt[1] < gc_H) { } else if (nxt[0] < gc_H && nxt[1] < gc_H) {
nbase = nxt+1; nbase = nxt+1;

View File

@ -862,6 +862,7 @@ InitCodes(void)
heap_regs->primitives_module = 0; heap_regs->primitives_module = 0;
heap_regs->user_module = 1; heap_regs->user_module = 1;
heap_regs->db_queues = NULL; heap_regs->db_queues = NULL;
heap_regs->db_queues_cache = NULL;
heap_regs->atom_abol = LookupAtom("$abol"); heap_regs->atom_abol = LookupAtom("$abol");
AtomAltNot = LookupAtom("not"); AtomAltNot = LookupAtom("not");
heap_regs->atom_append = LookupAtom ("append"); heap_regs->atom_append = LookupAtom ("append");

View File

@ -950,10 +950,15 @@ restore_codes(void)
heap_regs->dead_clauses = (Clause *) heap_regs->dead_clauses = (Clause *)
AddrAdjust((ADDR)(heap_regs->dead_clauses)); AddrAdjust((ADDR)(heap_regs->dead_clauses));
} }
/* vsc: FIXME !!!!! */
if (heap_regs->db_queues != NULL) { if (heap_regs->db_queues != NULL) {
heap_regs->db_queues = (struct idb_queue *) heap_regs->db_queues = (struct idb_queue *)
AddrAdjust((ADDR)(heap_regs->db_queues)); AddrAdjust((ADDR)(heap_regs->db_queues));
} }
if (heap_regs->db_queues_cache != NULL) {
heap_regs->db_queues_cache = (struct idb_queue *)
AddrAdjust((ADDR)(heap_regs->db_queues_cache));
}
heap_regs->retry_recorded_code = heap_regs->retry_recorded_code =
PtoOpAdjust(heap_regs->retry_recorded_code); PtoOpAdjust(heap_regs->retry_recorded_code);
heap_regs->retry_recorded_k_code = heap_regs->retry_recorded_k_code =

View File

@ -130,7 +130,7 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
extern int gc_calls; extern int gc_calls;
vsc_count++; vsc_count++;
if (vsc_count < 56514000) return; if (vsc_count < 369599) return;
/* if (vsc_count > 500000) exit(0); */ /* if (vsc_count > 500000) exit(0); */
/* if (gc_calls < 1) return;*/ /* if (gc_calls < 1) return;*/
YP_fprintf(YP_stderr,"%lu ", vsc_count); YP_fprintf(YP_stderr,"%lu ", vsc_count);

View File

@ -10,7 +10,7 @@
* File: Heap.h * * File: Heap.h *
* mods: * * mods: *
* comments: Heap Init Structure * * comments: Heap Init Structure *
* version: $Id: Heap.h,v 1.13 2001-11-15 00:01:40 vsc Exp $ * * version: $Id: Heap.h,v 1.14 2001-11-26 12:33:05 vsc Exp $ *
*************************************************************************/ *************************************************************************/
/* information that can be stored in Code Space */ /* information that can be stored in Code Space */
@ -143,7 +143,7 @@ typedef struct various_codes {
#endif #endif
int primitives_module; int primitives_module;
int user_module; int user_module;
struct idb_queue *db_queues; struct idb_queue *db_queues, *db_queues_cache;
Atom Atom
atom_abol, atom_abol,
atom_alarm, atom_alarm,
@ -333,6 +333,7 @@ typedef struct various_codes {
#define PrimitivesModule heap_regs->primitives_module #define PrimitivesModule heap_regs->primitives_module
#define UserModule heap_regs->user_module #define UserModule heap_regs->user_module
#define DBQueues heap_regs->db_queues #define DBQueues heap_regs->db_queues
#define DBQueuesCache heap_regs->db_queues_cache
#define NoOfModules heap_regs->no_of_modules #define NoOfModules heap_regs->no_of_modules
#define AtomAbol heap_regs->atom_abol #define AtomAbol heap_regs->atom_abol
#define AtomAlarm heap_regs->atom_alarm #define AtomAlarm heap_regs->atom_alarm