From 568036430013b3af5cc358d512e731725a53af76 Mon Sep 17 00:00:00 2001 From: vsc Date: Tue, 15 Nov 2005 00:50:49 +0000 Subject: [PATCH] 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 --- C/absmi.c | 76 ++++++++++++++++++++++++---------------------- C/grow.c | 4 +-- C/heapgc.c | 38 ++++++++++++++++++----- C/tracer.c | 4 ++- H/absmi.h | 1 + OPTYap/tab.insts.i | 3 +- changes-5.1.html | 4 +++ 7 files changed, 81 insertions(+), 49 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 43d71896b..322325230 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -10,8 +10,11 @@ * * * File: absmi.c * * 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 $ +* 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 * get rid of unnecessary ^ in setof * Found bug in comparisons @@ -602,10 +605,9 @@ Yap_absmi(int inp) /* YREG =was pointing to where we were going to build the * next choice-point. The stack shifter will need to know this * to move the local stack */ - if (YREG > (CELL *) B) { - ASP = (CELL *) B; - } - else { + if (YREG > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); + } else { ASP = YREG+E_CB; } saveregs(); @@ -620,8 +622,8 @@ Yap_absmi(int inp) #endif /* OS_HANDLES_TR_OVERFLOW */ BOp(Ystop, e); - if (YREG > (CELL *) B) { - ASP = (CELL *) B; + if (YREG > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); } else { ASP = YREG; @@ -638,8 +640,8 @@ Yap_absmi(int inp) ENDBOp(); BOp(Nstop, e); - if (YREG > (CELL *) B) { - ASP = (CELL *) B; + if (YREG > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); } else { ASP = YREG; @@ -1027,8 +1029,8 @@ Yap_absmi(int inp) /* update ASP before calling IPred */ ASP = YREG+E_CB; - if (ASP > (CELL *) B) { - ASP = (CELL *) B; + if (ASP > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); } saveregs(); #if defined(YAPOR) || defined(THREADS) @@ -2118,8 +2120,8 @@ Yap_absmi(int inp) SREG = (CELL *) PREG->u.p.p; if (ActiveSignals & YAP_CDOVF_SIGNAL) { ASP = YREG+E_CB; - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); goto noheapleft; } if (ActiveSignals) @@ -2296,16 +2298,16 @@ Yap_absmi(int inp) SREG = (CELL *) PREG->u.sla.sla_u.p; if (ActiveSignals & YAP_CDOVF_SIGNAL) { ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s); - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); goto noheapleft; } if (ActiveSignals) { goto creepc; } ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s); - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); saveregs(); if (!Yap_gc(((PredEntry *)SREG)->ArityOfPE, YREG, NEXTOP(PREG, sla))) { 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)); if (ActiveSignals & YAP_CDOVF_SIGNAL) { ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s); - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); goto noheapleft; } if (ActiveSignals) { goto creep_either; } ASP = (CELL *) (((char *) YREG) + PREG->u.sla.s); - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); saveregs(); if (!Yap_gc(0, YREG, NEXTOP(PREG, sla))) { Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage); @@ -2518,8 +2520,8 @@ Yap_absmi(int inp) SREG = (CELL *) PREG->u.p.p; if (ActiveSignals & YAP_CDOVF_SIGNAL) { ASP = YREG+E_CB; - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); goto noheapleft; } if (ActiveSignals) @@ -2527,8 +2529,8 @@ Yap_absmi(int inp) /* try performing garbage collection */ ASP = YREG+E_CB; - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); saveregs(); if (!Yap_gc(((PredEntry *)(SREG))->ArityOfPE, (CELL *)YREG[E_E], (yamop *)YREG[E_CP])) { Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage); @@ -2543,8 +2545,8 @@ Yap_absmi(int inp) /* try performing garbage collection */ ASP = YREG+E_CB; - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); saveregs(); if (!Yap_gc(((PredEntry *)(SREG))->ArityOfPE, ENV, CPREG)) { Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage); @@ -2596,8 +2598,8 @@ Yap_absmi(int inp) if (Yap_PrologMode & InterruptMode) { Yap_PrologMode &= ~InterruptMode; ASP = YREG+E_CB; - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); saveregs(); Yap_ProcessSIGINT(); setregs(); @@ -6992,8 +6994,8 @@ Yap_absmi(int inp) #endif /* update ASP before calling IPred */ ASP = YREG+E_CB; - if (ASP > (CELL *) B) { - ASP = (CELL *) B; + if (ASP > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); } saveregs(); Yap_IPred(ap, 0); @@ -7024,8 +7026,8 @@ Yap_absmi(int inp) /* update ASP before calling IPred */ ASP = YREG+E_CB; - if (ASP > (CELL *) B) { - ASP = (CELL *) B; + if (ASP > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); } #if defined(YAPOR) || defined(THREADS) if (PP == NULL) { @@ -7066,8 +7068,8 @@ Yap_absmi(int inp) /* update ASP before calling IPred */ ASP = YREG+E_CB; - if (ASP > (CELL *) B) { - ASP = (CELL *) B; + if (ASP > (CELL *) PROTECT_FROZEN_B(B)) { + ASP = (CELL *) PROTECT_FROZEN_B(B); } #if defined(YAPOR) || defined(THREADS) if (PP == NULL) { @@ -12570,8 +12572,8 @@ Yap_absmi(int inp) WRITEBACK_Y_AS_ENV(); SREG = (CELL *) pen; ASP = ENV_YREG; - if (ASP > (CELL *)B) - ASP = (CELL *)B; + if (ASP > (CELL *)PROTECT_FROZEN_B(B)) + ASP = (CELL *)PROTECT_FROZEN_B(B); LOCK(SignalLock); UNLOCK(SignalLock); if (ActiveSignals & YAP_CDOVF_SIGNAL) { diff --git a/C/grow.c b/C/grow.c index 1e16a3908..40e657d0e 100644 --- a/C/grow.c +++ b/C/grow.c @@ -841,7 +841,7 @@ fix_tabling_info(void) struct subgoal_frame *sg; df = LOCAL_top_dep_fr; - while (df != NULL) { + while (df) { if (DepFr_backchain_cp(df)) DepFr_backchain_cp(df) = ChoicePtrAdjust(DepFr_backchain_cp(df)); DepFr_leader_cp(df) = ChoicePtrAdjust(DepFr_leader_cp(df)); @@ -849,7 +849,7 @@ fix_tabling_info(void) df = DepFr_next(df); } sg = LOCAL_top_sg_fr; - while (sg != NULL) { + while (sg) { SgFr_gen_cp(sg) = GeneratorChoicePtrAdjust(SgFr_gen_cp(sg)); sg = SgFr_next(sg); } diff --git a/C/heapgc.c b/C/heapgc.c index 90344d89a..4837f505d 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -1738,10 +1738,17 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose) #ifdef TABLING dep_fr_ptr depfr = LOCAL_top_dep_fr; #endif /* TABLING */ + #ifdef EASY_SHUNTING HB = H; #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) { op_numbers opnum; register OPCODE op; @@ -1915,7 +1922,7 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose) nargs = 0; break; case _table_completion: - { + if (rtp) { CELL *vars_ptr, vars; vars_ptr = (CELL *)(GEN_CP(gc_B) + 1); 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; #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) { yamop *rtp = gc_B->cp_ap; register OPCODE op; @@ -2643,7 +2656,7 @@ sweep_choicepoints(choiceptr gc_B) } break; case _table_completion: - { + if (rtp) { int nargs; CELL *vars_ptr, vars; 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 /* make sure we include consumers */ if (depfr && gc_B >= DepFr_cons_cp(depfr)) { - *depfrp = DepFr_next(depfr); + *depfrp = depfr = DepFr_next(depfr); gc_B = DepFr_cons_cp(depfr); } #endif /* TABLING */ @@ -2935,6 +2948,12 @@ compact_heap(void) * 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); dest = (CELL_PTR) H0 + total_marked - 1; @@ -3114,6 +3133,12 @@ adjust_cp_hbs(void) choiceptr gc_B = B; 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) { CELL *gc_H = gc_B->cp_h; CELL_PTR *nbase = base; @@ -3706,8 +3731,6 @@ p_inform_gc(void) } -int vsc_gc_calls; - static int 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) gc_margin = gc_lim; 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); if (effectiveness > 90) { while (gc_margin < H-H0) diff --git a/C/tracer.c b/C/tracer.c index f02c67d16..55b664cea 100644 --- a/C/tracer.c +++ b/C/tracer.c @@ -108,7 +108,9 @@ check_trail_consistency(void) { 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);} struct various_codes *sc; diff --git a/H/absmi.h b/H/absmi.h index 91a4f709e..a179f2b55 100644 --- a/H/absmi.h +++ b/H/absmi.h @@ -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) #endif /* SBA */ #else +#define PROTECT_FROZEN_B(CPTR) (CPTR) #define PROTECT_FROZEN_H(CPTR) (CPTR)->cp_h #endif /* FROZEN_STACKS */ diff --git a/OPTYap/tab.insts.i b/OPTYap/tab.insts.i index f370963a3..fc55cd9de 100644 --- a/OPTYap/tab.insts.i +++ b/OPTYap/tab.insts.i @@ -5,7 +5,7 @@ Copyright: R. Rocha and NCC - University of Porto, Portugal 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 */ - answer_resolution: INIT_PREFETCH() dep_fr_ptr dep_fr; diff --git a/changes-5.1.html b/changes-5.1.html index 676bd1115..d8bfa1d4f 100644 --- a/changes-5.1.html +++ b/changes-5.1.html @@ -16,6 +16,10 @@

Yap-5.1.0: