fixes for stack expansion and garbage collection under tabling.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1456 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2005-11-15 00:50:49 +00:00
parent f300bb7cb4
commit 5680364300
7 changed files with 81 additions and 49 deletions

View File

@ -10,8 +10,11 @@
* * * *
* File: absmi.c * * File: absmi.c *
* comments: Portable abstract machine interpreter * * comments: Portable abstract machine interpreter *
* Last rev: $Date: 2005-11-07 15:35:47 $,$Author: vsc $ * * Last rev: $Date: 2005-11-15 00:50:49 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.183 2005/11/07 15:35:47 vsc
* fix bugs in garbage collection of tabling.
*
* Revision 1.182 2005/11/05 03:02:33 vsc * Revision 1.182 2005/11/05 03:02:33 vsc
* get rid of unnecessary ^ in setof * get rid of unnecessary ^ in setof
* Found bug in comparisons * Found bug in comparisons
@ -602,10 +605,9 @@ Yap_absmi(int inp)
/* YREG =was pointing to where we were going to build the /* YREG =was pointing to where we were going to build the
* next choice-point. The stack shifter will need to know this * next choice-point. The stack shifter will need to know this
* to move the local stack */ * to move the local stack */
if (YREG > (CELL *) B) { if (YREG > (CELL *) PROTECT_FROZEN_B(B)) {
ASP = (CELL *) B; ASP = (CELL *) PROTECT_FROZEN_B(B);
} } else {
else {
ASP = YREG+E_CB; ASP = YREG+E_CB;
} }
saveregs(); saveregs();
@ -620,8 +622,8 @@ Yap_absmi(int inp)
#endif /* OS_HANDLES_TR_OVERFLOW */ #endif /* OS_HANDLES_TR_OVERFLOW */
BOp(Ystop, e); BOp(Ystop, e);
if (YREG > (CELL *) B) { if (YREG > (CELL *) PROTECT_FROZEN_B(B)) {
ASP = (CELL *) B; ASP = (CELL *) PROTECT_FROZEN_B(B);
} }
else { else {
ASP = YREG; ASP = YREG;
@ -638,8 +640,8 @@ Yap_absmi(int inp)
ENDBOp(); ENDBOp();
BOp(Nstop, e); BOp(Nstop, e);
if (YREG > (CELL *) B) { if (YREG > (CELL *) PROTECT_FROZEN_B(B)) {
ASP = (CELL *) B; ASP = (CELL *) PROTECT_FROZEN_B(B);
} }
else { else {
ASP = YREG; ASP = YREG;
@ -1027,8 +1029,8 @@ Yap_absmi(int inp)
/* update ASP before calling IPred */ /* update ASP before calling IPred */
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *) B) { if (ASP > (CELL *) PROTECT_FROZEN_B(B)) {
ASP = (CELL *) B; ASP = (CELL *) PROTECT_FROZEN_B(B);
} }
saveregs(); saveregs();
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
@ -2118,8 +2120,8 @@ Yap_absmi(int inp)
SREG = (CELL *) PREG->u.p.p; SREG = (CELL *) PREG->u.p.p;
if (ActiveSignals & YAP_CDOVF_SIGNAL) { if (ActiveSignals & YAP_CDOVF_SIGNAL) {
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
goto noheapleft; goto noheapleft;
} }
if (ActiveSignals) if (ActiveSignals)
@ -2296,16 +2298,16 @@ Yap_absmi(int inp)
SREG = (CELL *) PREG->u.sla.sla_u.p; SREG = (CELL *) PREG->u.sla.sla_u.p;
if (ActiveSignals & YAP_CDOVF_SIGNAL) { if (ActiveSignals & YAP_CDOVF_SIGNAL) {
ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s); ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s);
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
goto noheapleft; goto noheapleft;
} }
if (ActiveSignals) { if (ActiveSignals) {
goto creepc; goto creepc;
} }
ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s); ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s);
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs(); saveregs();
if (!Yap_gc(((PredEntry *)SREG)->ArityOfPE, YREG, NEXTOP(PREG, sla))) { if (!Yap_gc(((PredEntry *)SREG)->ArityOfPE, YREG, NEXTOP(PREG, sla))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage); Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
@ -2404,16 +2406,16 @@ Yap_absmi(int inp)
SREG = (CELL *)RepPredProp(Yap_GetPredPropByFunc(Yap_MkFunctor(AtomRestoreRegs,1),0)); SREG = (CELL *)RepPredProp(Yap_GetPredPropByFunc(Yap_MkFunctor(AtomRestoreRegs,1),0));
if (ActiveSignals & YAP_CDOVF_SIGNAL) { if (ActiveSignals & YAP_CDOVF_SIGNAL) {
ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s); ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s);
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
goto noheapleft; goto noheapleft;
} }
if (ActiveSignals) { if (ActiveSignals) {
goto creep_either; goto creep_either;
} }
ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s); ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s);
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs(); saveregs();
if (!Yap_gc(0, YREG, NEXTOP(PREG, sla))) { if (!Yap_gc(0, YREG, NEXTOP(PREG, sla))) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage); Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
@ -2518,8 +2520,8 @@ Yap_absmi(int inp)
SREG = (CELL *) PREG->u.p.p; SREG = (CELL *) PREG->u.p.p;
if (ActiveSignals & YAP_CDOVF_SIGNAL) { if (ActiveSignals & YAP_CDOVF_SIGNAL) {
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
goto noheapleft; goto noheapleft;
} }
if (ActiveSignals) if (ActiveSignals)
@ -2527,8 +2529,8 @@ Yap_absmi(int inp)
/* try performing garbage collection */ /* try performing garbage collection */
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs(); saveregs();
if (!Yap_gc(((PredEntry *)(SREG))->ArityOfPE, (CELL *)YREG[E_E], (yamop *)YREG[E_CP])) { if (!Yap_gc(((PredEntry *)(SREG))->ArityOfPE, (CELL *)YREG[E_E], (yamop *)YREG[E_CP])) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage); Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
@ -2543,8 +2545,8 @@ Yap_absmi(int inp)
/* try performing garbage collection */ /* try performing garbage collection */
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs(); saveregs();
if (!Yap_gc(((PredEntry *)(SREG))->ArityOfPE, ENV, CPREG)) { if (!Yap_gc(((PredEntry *)(SREG))->ArityOfPE, ENV, CPREG)) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage); Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
@ -2596,8 +2598,8 @@ Yap_absmi(int inp)
if (Yap_PrologMode & InterruptMode) { if (Yap_PrologMode & InterruptMode) {
Yap_PrologMode &= ~InterruptMode; Yap_PrologMode &= ~InterruptMode;
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs(); saveregs();
Yap_ProcessSIGINT(); Yap_ProcessSIGINT();
setregs(); setregs();
@ -6992,8 +6994,8 @@ Yap_absmi(int inp)
#endif #endif
/* update ASP before calling IPred */ /* update ASP before calling IPred */
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *) B) { if (ASP > (CELL *) PROTECT_FROZEN_B(B)) {
ASP = (CELL *) B; ASP = (CELL *) PROTECT_FROZEN_B(B);
} }
saveregs(); saveregs();
Yap_IPred(ap, 0); Yap_IPred(ap, 0);
@ -7024,8 +7026,8 @@ Yap_absmi(int inp)
/* update ASP before calling IPred */ /* update ASP before calling IPred */
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *) B) { if (ASP > (CELL *) PROTECT_FROZEN_B(B)) {
ASP = (CELL *) B; ASP = (CELL *) PROTECT_FROZEN_B(B);
} }
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
if (PP == NULL) { if (PP == NULL) {
@ -7066,8 +7068,8 @@ Yap_absmi(int inp)
/* update ASP before calling IPred */ /* update ASP before calling IPred */
ASP = YREG+E_CB; ASP = YREG+E_CB;
if (ASP > (CELL *) B) { if (ASP > (CELL *) PROTECT_FROZEN_B(B)) {
ASP = (CELL *) B; ASP = (CELL *) PROTECT_FROZEN_B(B);
} }
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
if (PP == NULL) { if (PP == NULL) {
@ -12570,8 +12572,8 @@ Yap_absmi(int inp)
WRITEBACK_Y_AS_ENV(); WRITEBACK_Y_AS_ENV();
SREG = (CELL *) pen; SREG = (CELL *) pen;
ASP = ENV_YREG; ASP = ENV_YREG;
if (ASP > (CELL *)B) if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)B; ASP = (CELL *)PROTECT_FROZEN_B(B);
LOCK(SignalLock); LOCK(SignalLock);
UNLOCK(SignalLock); UNLOCK(SignalLock);
if (ActiveSignals & YAP_CDOVF_SIGNAL) { if (ActiveSignals & YAP_CDOVF_SIGNAL) {

View File

@ -841,7 +841,7 @@ fix_tabling_info(void)
struct subgoal_frame *sg; struct subgoal_frame *sg;
df = LOCAL_top_dep_fr; df = LOCAL_top_dep_fr;
while (df != NULL) { while (df) {
if (DepFr_backchain_cp(df)) if (DepFr_backchain_cp(df))
DepFr_backchain_cp(df) = ChoicePtrAdjust(DepFr_backchain_cp(df)); DepFr_backchain_cp(df) = ChoicePtrAdjust(DepFr_backchain_cp(df));
DepFr_leader_cp(df) = ChoicePtrAdjust(DepFr_leader_cp(df)); DepFr_leader_cp(df) = ChoicePtrAdjust(DepFr_leader_cp(df));
@ -849,7 +849,7 @@ fix_tabling_info(void)
df = DepFr_next(df); df = DepFr_next(df);
} }
sg = LOCAL_top_sg_fr; sg = LOCAL_top_sg_fr;
while (sg != NULL) { while (sg) {
SgFr_gen_cp(sg) = GeneratorChoicePtrAdjust(SgFr_gen_cp(sg)); SgFr_gen_cp(sg) = GeneratorChoicePtrAdjust(SgFr_gen_cp(sg));
sg = SgFr_next(sg); sg = SgFr_next(sg);
} }

View File

@ -1738,10 +1738,17 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose)
#ifdef TABLING #ifdef TABLING
dep_fr_ptr depfr = LOCAL_top_dep_fr; dep_fr_ptr depfr = LOCAL_top_dep_fr;
#endif /* TABLING */ #endif /* TABLING */
#ifdef EASY_SHUNTING #ifdef EASY_SHUNTING
HB = H; HB = H;
#endif #endif
#ifdef TABLING
if (depfr != NULL && gc_B >= DepFr_cons_cp(depfr)) {
gc_B = DepFr_cons_cp(depfr);
depfr = DepFr_next(depfr);
}
#endif
while (gc_B != NULL) { while (gc_B != NULL) {
op_numbers opnum; op_numbers opnum;
register OPCODE op; register OPCODE op;
@ -1915,7 +1922,7 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose)
nargs = 0; nargs = 0;
break; break;
case _table_completion: case _table_completion:
{ if (rtp) {
CELL *vars_ptr, vars; CELL *vars_ptr, vars;
vars_ptr = (CELL *)(GEN_CP(gc_B) + 1); vars_ptr = (CELL *)(GEN_CP(gc_B) + 1);
nargs = SgFr_arity(GEN_CP(gc_B)->cp_sg_fr); nargs = SgFr_arity(GEN_CP(gc_B)->cp_sg_fr);
@ -2521,6 +2528,12 @@ sweep_choicepoints(choiceptr gc_B)
dep_fr_ptr depfr = LOCAL_top_dep_fr; dep_fr_ptr depfr = LOCAL_top_dep_fr;
#endif /* TABLING */ #endif /* TABLING */
#ifdef TABLING
if (depfr != NULL && gc_B >= DepFr_cons_cp(depfr)) {
gc_B = DepFr_cons_cp(depfr);
depfr = DepFr_next(depfr);
}
#endif
while(gc_B != NULL) { while(gc_B != NULL) {
yamop *rtp = gc_B->cp_ap; yamop *rtp = gc_B->cp_ap;
register OPCODE op; register OPCODE op;
@ -2643,7 +2656,7 @@ sweep_choicepoints(choiceptr gc_B)
} }
break; break;
case _table_completion: case _table_completion:
{ if (rtp) {
int nargs; int nargs;
CELL *vars_ptr, vars; CELL *vars_ptr, vars;
sweep_environments(gc_B->cp_env, EnvSize((CELL_PTR) (gc_B->cp_cp)), EnvBMap((CELL_PTR) (gc_B->cp_cp))); sweep_environments(gc_B->cp_env, EnvSize((CELL_PTR) (gc_B->cp_cp)), EnvBMap((CELL_PTR) (gc_B->cp_cp)));
@ -2891,7 +2904,7 @@ update_B_H( choiceptr gc_B, CELL *current, CELL *dest, CELL *odest
#ifdef TABLING #ifdef TABLING
/* make sure we include consumers */ /* make sure we include consumers */
if (depfr && gc_B >= DepFr_cons_cp(depfr)) { if (depfr && gc_B >= DepFr_cons_cp(depfr)) {
*depfrp = DepFr_next(depfr); *depfrp = depfr = DepFr_next(depfr);
gc_B = DepFr_cons_cp(depfr); gc_B = DepFr_cons_cp(depfr);
} }
#endif /* TABLING */ #endif /* TABLING */
@ -2935,6 +2948,12 @@ compact_heap(void)
* objects pointed to * objects pointed to
*/ */
#ifdef TABLING
if (depfr != NULL && gc_B >= DepFr_cons_cp(depfr)) {
gc_B = DepFr_cons_cp(depfr);
depfr = DepFr_next(depfr);
}
#endif
next_hb = set_next_hb(gc_B); next_hb = set_next_hb(gc_B);
dest = (CELL_PTR) H0 + total_marked - 1; dest = (CELL_PTR) H0 + total_marked - 1;
@ -3114,6 +3133,12 @@ adjust_cp_hbs(void)
choiceptr gc_B = B; choiceptr gc_B = B;
CELL_PTR *top = iptop-1, *base = (CELL_PTR *)H; CELL_PTR *top = iptop-1, *base = (CELL_PTR *)H;
#ifdef TABLING
if (depfr != NULL && gc_B >= DepFr_cons_cp(depfr)) {
gc_B = DepFr_cons_cp(depfr);
depfr = DepFr_next(depfr);
}
#endif
while (gc_B != NULL) { while (gc_B != NULL) {
CELL *gc_H = gc_B->cp_h; CELL *gc_H = gc_B->cp_h;
CELL_PTR *nbase = base; CELL_PTR *nbase = base;
@ -3706,8 +3731,6 @@ p_inform_gc(void)
} }
int vsc_gc_calls;
static int static int
call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop) call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
{ {
@ -3742,8 +3765,9 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
if (gc_margin < gc_lim) if (gc_margin < gc_lim)
gc_margin = gc_lim; gc_margin = gc_lim;
GcCalls++; GcCalls++;
vsc_gc_calls = GcCalls; if (gc_on && !(Yap_PrologMode & InErrorMode) &&
if (gc_on && !(Yap_PrologMode & InErrorMode)) { /* make sure there is a point in collecting th eheap */
H-H0 > (LCL0-ASP)/2) {
effectiveness = do_gc(predarity, current_env, nextop); effectiveness = do_gc(predarity, current_env, nextop);
if (effectiveness > 90) { if (effectiveness > 90) {
while (gc_margin < H-H0) while (gc_margin < H-H0)

View File

@ -108,7 +108,9 @@ check_trail_consistency(void) {
CELL old_value = 0L, old_value2 = 0L; CELL old_value = 0L, old_value2 = 0L;
static void void jmp_deb(int);
void
jmp_deb(int i) {if (i) printf("Here we go\n"); else jmp_deb(0);} jmp_deb(int i) {if (i) printf("Here we go\n"); else jmp_deb(0);}
struct various_codes *sc; struct various_codes *sc;

View File

@ -813,6 +813,7 @@ Macros to check the limits of stacks
#define PROTECT_FROZEN_H(CPTR) (((CPTR)->cp_h > H_FZ) ? (CPTR)->cp_h : H_FZ) #define PROTECT_FROZEN_H(CPTR) (((CPTR)->cp_h > H_FZ) ? (CPTR)->cp_h : H_FZ)
#endif /* SBA */ #endif /* SBA */
#else #else
#define PROTECT_FROZEN_B(CPTR) (CPTR)
#define PROTECT_FROZEN_H(CPTR) (CPTR)->cp_h #define PROTECT_FROZEN_H(CPTR) (CPTR)->cp_h
#endif /* FROZEN_STACKS */ #endif /* FROZEN_STACKS */

View File

@ -5,7 +5,7 @@
Copyright: R. Rocha and NCC - University of Porto, Portugal Copyright: R. Rocha and NCC - University of Porto, Portugal
File: tab.insts.i File: tab.insts.i
version: $Id: tab.insts.i,v 1.20 2005-08-05 14:55:03 vsc Exp $ version: $Id: tab.insts.i,v 1.21 2005-11-15 00:50:49 vsc Exp $
**********************************************************************/ **********************************************************************/
@ -969,7 +969,6 @@
} }
#endif /* YAPOR */ #endif /* YAPOR */
answer_resolution: answer_resolution:
INIT_PREFETCH() INIT_PREFETCH()
dep_fr_ptr dep_fr; dep_fr_ptr dep_fr;

View File

@ -16,6 +16,10 @@
<h2>Yap-5.1.0:</h2> <h2>Yap-5.1.0:</h2>
<ul> <ul>
<li> FIXED: in tabling don't look inside cp_ap == NULL and fix recent
bug in walking dependency frames. </li>
<li> FIXED: with tabling ASP sometimes was miscalculated, causing
trouble with stack shifter (obs Kostis Sagonas). </li>
<li> FIXED: ~D should print bignums (obs Jude Shavlik). </li> <li> FIXED: ~D should print bignums (obs Jude Shavlik). </li>
<li> FIXED: format's ~d and ~D were broken (obs Jude Shavlik). </li> <li> FIXED: format's ~d and ~D were broken (obs Jude Shavlik). </li>
<li> FIXED: profiler should not talk about hidden predicates or idb entries. </li> <li> FIXED: profiler should not talk about hidden predicates or idb entries. </li>