improve the support for deterministic tabling (still experimental,

problems mainly with the garbage collector)
This commit is contained in:
Ricardo Rocha 2009-08-07 17:29:53 +01:00
parent cc2c6dbe71
commit fc31e7066e
7 changed files with 105 additions and 49 deletions

View File

@ -1878,7 +1878,12 @@ Yap_absmi(int inp)
case _table_retry:
case _table_trust:
case _table_completion:
low_level_trace(retry_table_generator, GEN_CP(B)->cp_pred_entry, (CELL *)(GEN_CP(B) + 1));
#ifdef DETERMINISTIC_TABLING
if (IS_DET_GEN_CP(B))
low_level_trace(retry_table_generator, DET_GEN_CP(B)->cp_pred_entry, NULL);
else
#endif /* DETERMINISTIC_TABLING */
low_level_trace(retry_table_generator, GEN_CP(B)->cp_pred_entry, (CELL *)(GEN_CP(B) + 1));
break;
case _table_answer_resolution:
low_level_trace(retry_table_consumer, CONS_CP(B)->cp_pred_entry, NULL);

View File

@ -5410,8 +5410,16 @@ p_choicepoint_info(void)
case _table_trust:
case _table_completion:
#ifdef LOW_LEVEL_TRACER
pe = GEN_CP(cptr)->cp_pred_entry;
t = BuildActivePred(pe, (CELL *)(GEN_CP(B) + 1));
#ifdef DETERMINISTIC_TABLING
if (IS_DET_GEN_CP(cptr)) {
pe = DET_GEN_CP(cptr)->cp_pred_entry;
t = MkVarTerm();
} else
#endif /* DETERMINISTIC_TABLING */
{
pe = GEN_CP(cptr)->cp_pred_entry;
t = BuildActivePred(pe, (CELL *)(GEN_CP(B) + 1));
}
#else
pe = UndefCode;
t = MkVarTerm();

View File

@ -361,7 +361,7 @@ gc_lookup_ma_var(CELL *addr, tr_fr_ptr trp) {
gc_ma_hash_table[i].loc = trp;
gc_ma_hash_table[i].more = gc_ma_h_list;
gc_ma_h_list = gc_ma_hash_table+i;
#endif
#endif /* TABLING */
gc_ma_hash_table[i].next = NULL;
return NULL;
}
@ -375,7 +375,7 @@ gc_lookup_ma_var(CELL *addr, tr_fr_ptr trp) {
has the correct new value
*/
TrailVal(nptr->loc+1) = TrailVal(trp+1);
#endif
#endif /* TABLING */
return nptr;
}
nptr = nptr->next;
@ -386,7 +386,7 @@ gc_lookup_ma_var(CELL *addr, tr_fr_ptr trp) {
#if TABLING
nptr->loc = trp;
nptr->more = gc_ma_h_list;
#endif
#endif /* TABLING */
nptr->next = NULL;
gc_ma_h_list = nptr;
return NULL;
@ -1748,7 +1748,7 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
#else
trail_base++;
mark_external_reference(&(TrailTerm(trail_base)));
#endif
#endif /* TABLING */
trail_base ++;
if (HEAP_PTR(trail_cell)) {
/* fool the gc into thinking this is a variable */
@ -1771,7 +1771,7 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
#ifdef FROZEN_STACKS
RESET_VARIABLE(&TrailVal(trail_base));
#endif
#endif /* TABLING */
#endif /* !TABLING */
trail_base++;
RESET_VARIABLE(&TrailTerm(trail_base));
#ifdef FROZEN_STACKS
@ -1794,7 +1794,7 @@ mark_trail(tr_fr_ptr trail_ptr, tr_fr_ptr trail_base, CELL *gc_H, choiceptr gc_B
gl = gl->more;
}
}
#endif
#endif /* TABLING */
#ifdef EASY_SHUNTING
sTR = (tr_fr_ptr)old_cont_top0;
while (begsTR != NULL) {
@ -1877,7 +1877,7 @@ youngest_cp(choiceptr gc_B, dep_fr_ptr *depfrp)
}
return min;
}
#endif
#endif /* TABLING */
static void
@ -1899,14 +1899,17 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose)
#ifdef TABLING
gc_B = youngest_cp(gc_B, &depfr);
#endif
#endif /* TABLING */
while (gc_B != NULL) {
op_numbers opnum;
register OPCODE op;
yamop *rtp = gc_B->cp_ap;
mark_db_fixed((CELL *)rtp);
mark_db_fixed((CELL *)(gc_B->cp_cp));
#ifdef DETERMINISTIC_TABLING
if (!IS_DET_GEN_CP(gc_B))
#endif /* DETERMINISTIC_TABLING */
mark_db_fixed((CELL *)(gc_B->cp_cp));
#ifdef EASY_SHUNTING
current_B = gc_B;
prev_HB = HB;
@ -1933,7 +1936,7 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose)
if (aux_sg_fr && gc_B == SgFr_gen_cp(aux_sg_fr)) {
aux_sg_fr = SgFr_next(aux_sg_fr);
}
#endif
#endif /* TABLING */
if (very_verbose) {
PredEntry *pe = Yap_PredForChoicePt(gc_B);
#if defined(ANALYST) || defined(DEBUG)
@ -1975,9 +1978,12 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose)
EnvSizeInCells,
NULL);
else if (opnum != _trust_fail)
mark_environments((CELL_PTR) gc_B->cp_env,
EnvSize((yamop *) (gc_B->cp_cp)),
EnvBMap((yamop *) (gc_B->cp_cp)));
#ifdef DETERMINISTIC_TABLING
if (!IS_DET_GEN_CP(gc_B))
#endif /* DETERMINISTIC_TABLING */
mark_environments((CELL_PTR) gc_B->cp_env,
EnvSize((yamop *) (gc_B->cp_cp)),
EnvBMap((yamop *) (gc_B->cp_cp)));
/* extended choice point */
restart_cp:
switch (opnum) {
@ -2061,11 +2067,18 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose)
case _table_completion:
{
CELL *vars_ptr, vars;
vars_ptr = (CELL *)(GEN_CP(gc_B) + 1);
nargs = SgFr_arity(GEN_CP(gc_B)->cp_sg_fr);
while (nargs--) {
mark_external_reference(vars_ptr);
vars_ptr++;
#ifdef DETERMINISTIC_TABLING
if (IS_DET_GEN_CP(gc_B))
vars_ptr = (CELL *)(DET_GEN_CP(gc_B) + 1);
else
#endif /* DETERMINISTIC_TABLING */
{
vars_ptr = (CELL *)(GEN_CP(gc_B) + 1);
nargs = SgFr_arity(GEN_CP(gc_B)->cp_sg_fr);
while (nargs--) {
mark_external_reference(vars_ptr);
vars_ptr++;
}
}
vars = *vars_ptr++;
while (vars--) {
@ -2270,7 +2283,7 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose)
gc_B = youngest_cp(gc_B->cp_b, &depfr);
#else
gc_B = gc_B->cp_b;
#endif
#endif /* TABLING */
}
}
@ -2820,7 +2833,7 @@ sweep_choicepoints(choiceptr gc_B)
#ifdef TABLING
gc_B = youngest_cp(gc_B, &depfr);
#endif
#endif /* TABLING */
while (gc_B != NULL) {
yamop *rtp = gc_B->cp_ap;
register OPCODE op;
@ -2844,7 +2857,7 @@ sweep_choicepoints(choiceptr gc_B)
if (aux_sg_fr && gc_B == SgFr_gen_cp(aux_sg_fr)) {
aux_sg_fr = SgFr_next(aux_sg_fr);
}
#endif
#endif /* TABLING */
restart_cp:
/*
@ -2941,18 +2954,25 @@ sweep_choicepoints(choiceptr gc_B)
{
int nargs;
CELL *vars_ptr, vars;
sweep_environments(gc_B->cp_env, EnvSize(gc_B->cp_cp), EnvBMap(gc_B->cp_cp));
vars_ptr = (CELL *)(GEN_CP(gc_B) + 1);
nargs = SgFr_arity(GEN_CP(gc_B)->cp_sg_fr);
while(nargs--) {
CELL cp_cell = *vars_ptr;
if (MARKED_PTR(vars_ptr)) {
UNMARK(vars_ptr);
if (HEAP_PTR(cp_cell)) {
into_relocation_chain(vars_ptr, GET_NEXT(cp_cell));
#ifdef DETERMINISTIC_TABLING
if (IS_DET_GEN_CP(gc_B))
vars_ptr = (CELL *)(DET_GEN_CP(gc_B) + 1);
else
#endif /* DETERMINISTIC_TABLING */
{
sweep_environments(gc_B->cp_env, EnvSize(gc_B->cp_cp), EnvBMap(gc_B->cp_cp));
vars_ptr = (CELL *)(GEN_CP(gc_B) + 1);
nargs = SgFr_arity(GEN_CP(gc_B)->cp_sg_fr);
while(nargs--) {
CELL cp_cell = *vars_ptr;
if (MARKED_PTR(vars_ptr)) {
UNMARK(vars_ptr);
if (HEAP_PTR(cp_cell)) {
into_relocation_chain(vars_ptr, GET_NEXT(cp_cell));
}
}
vars_ptr++;
}
vars_ptr++;
}
vars = *vars_ptr++;
while (vars--) {
@ -3113,7 +3133,7 @@ sweep_choicepoints(choiceptr gc_B)
gc_B = youngest_cp(gc_B->cp_b, &depfr);
#else
gc_B = gc_B->cp_b;
#endif
#endif /* TABLING */
}
}
@ -3146,15 +3166,24 @@ static inline choiceptr
update_B_H( choiceptr gc_B, CELL *current, CELL *dest, CELL *odest
#ifdef TABLING
, dep_fr_ptr *depfrp
#endif
#endif /* TABLING */
) {
/* also make the value of H in a choicepoint
coherent with the new global
*/
#ifdef TABLING
dep_fr_ptr depfr = *depfrp;
#endif
#endif /* TABLING */
#ifdef DETERMINISTIC_TABLING
while (IS_DET_GEN_CP(gc_B))
gc_B = gc_B->cp_b;
/* make sure we include consumers */
if (depfr && gc_B >= DepFr_cons_cp(depfr)) {
gc_B = DepFr_cons_cp(depfr);
*depfrp = depfr = DepFr_next(depfr);
}
#endif /* DETERMINISTIC_TABLING */
while (gc_B && current <= gc_B->cp_h) {
if (gc_B->cp_h == current) {
gc_B->cp_h = dest;
@ -3163,6 +3192,10 @@ update_B_H( choiceptr gc_B, CELL *current, CELL *dest, CELL *odest
}
gc_B = gc_B->cp_b;
#ifdef TABLING
#ifdef DETERMINISTIC_TABLING
while (IS_DET_GEN_CP(gc_B))
gc_B = gc_B->cp_b;
#endif /* DETERMINISTIC_TABLING */
/* make sure we include consumers */
if (depfr && gc_B >= DepFr_cons_cp(depfr)) {
gc_B = DepFr_cons_cp(depfr);
@ -3214,14 +3247,14 @@ compact_heap(void)
gc_B = DepFr_cons_cp(depfr);
depfr = DepFr_next(depfr);
}
#endif
#endif /* TABLING */
next_hb = set_next_hb(gc_B);
dest = H0 + total_marked - 1;
gc_B = update_B_H(gc_B, H, dest+1, dest+2
#ifdef TABLING
, &depfr
#endif
#endif /* TABLING */
);
for (current = H - 1; current >= start_from; current--) {
if (MARKED_PTR(current)) {
@ -3236,7 +3269,7 @@ compact_heap(void)
gc_B = update_B_H(gc_B, current, dest, dest+1
#ifdef TABLING
, &depfr
#endif
#endif /* TABLING */
);
next_hb = set_next_hb(gc_B);
}
@ -3397,13 +3430,13 @@ icompact_heap(void)
gc_B = DepFr_cons_cp(depfr);
depfr = DepFr_next(depfr);
}
#endif
#endif /* TABLING */
next_hb = set_next_hb(gc_B);
dest = (CELL_PTR) H0 + total_marked - 1;
gc_B = update_B_H(gc_B, H, dest+1, dest+2
#ifdef TABLING
, &depfr
#endif
#endif /* TABLING */
);
for (iptr = iptop - 1; iptr >= ibase; iptr--) {
CELL ccell;
@ -3415,7 +3448,7 @@ icompact_heap(void)
gc_B = update_B_H(gc_B, current, dest, dest+1
#ifdef TABLING
, &depfr
#endif
#endif /* TABLING */
);
next_hb = set_next_hb(gc_B);
}

View File

@ -31,12 +31,12 @@
/* ----------------------- **
** default sizes **
** ----------------------- */
#define MAX_TABLE_VARS 100
#define MAX_TABLE_VARS 1000
/* ------------------------------------------ **
** trail freeze scheme (define one) **
** ------------------------------------------ */
#define BFZ_TRAIL_SCHEME 1
#define BFZ_TRAIL_SCHEME 1
/* #define BBREG_TRAIL_SCHEME 1 */
/* ------------------------------------------------ **

View File

@ -811,7 +811,7 @@
sg_fr = GEN_CP(gcp)->cp_sg_fr;
subs_ptr = (CELL *)(GEN_CP(gcp) + 1) + PREG->u.s.s;
}
#ifdef TABLING_ERRORS
#if defined(TABLING_ERRORS) && !defined(DETERMINISTIC_TABLING)
{
int i, j, arity_args, arity_subs;
CELL *aux_args;
@ -831,7 +831,7 @@
TABLING_ERROR_MESSAGE("j == arity_args (table_new_answer)");
}
}
#endif /* TABLING_ERRORS */
#endif /* TABLING_ERRORS && !DETERMINISTIC_TABLING */
#ifdef TABLE_LOCK_AT_ENTRY_LEVEL
LOCK(SgFr_lock(sg_fr));
#endif /* TABLE_LOCK_LEVEL */

View File

@ -938,7 +938,12 @@ void CUT_validate_tg_answers(tg_sol_fr_ptr valid_solutions) {
while (valid_solutions) {
first_answer = last_answer = NULL;
sg_fr = GEN_CP(TgSolFr_gen_cp(valid_solutions))->cp_sg_fr;
#ifdef DETERMINISTIC_TABLING
if (IS_DET_GEN_CP(TgSolFr_gen_cp(valid_solutions)))
sg_fr = DET_GEN_CP(TgSolFr_gen_cp(valid_solutions))->cp_sg_fr;
else
#endif /* DETERMINISTIC_TABLING */
sg_fr = GEN_CP(TgSolFr_gen_cp(valid_solutions))->cp_sg_fr;
ltt_valid_solutions = valid_solutions;
valid_solutions = TgSolFr_next(valid_solutions);
do {

View File

@ -46,7 +46,12 @@ void public_completion(void) {
sg_fr_ptr top_sg_fr;
/* complete subgoals */
top_sg_fr = SgFr_next(GEN_CP(LOCAL_top_cp)->cp_sg_fr);
#ifdef DETERMINISTIC_TABLING
if (IS_DET_GEN_CP(LOCAL_top_cp))
top_sg_fr = SgFr_next(DET_GEN_CP(LOCAL_top_cp)->cp_sg_fr);
else
#endif /* DETERMINISTIC_TABLING */
top_sg_fr = SgFr_next(GEN_CP(LOCAL_top_cp)->cp_sg_fr);
do {
mark_as_completed(LOCAL_top_sg_fr);
LOCAL_top_sg_fr = SgFr_next(LOCAL_top_sg_fr);