try to avoid doing stack expansion so often on arena overflow

This commit is contained in:
Vitor Santos Costa 2008-10-29 18:21:41 +00:00
parent de043e3ee9
commit 181e122200

View File

@ -43,6 +43,8 @@ static char SccsId[] = "%W% %G%";
#define HEAP_DELAY_ARENA 3 #define HEAP_DELAY_ARENA 3
#define HEAP_START 4 #define HEAP_START 4
#define MIN_ARENA_SIZE 2048
#define Global_MkIntegerTerm(I) MkIntegerTerm(I) #define Global_MkIntegerTerm(I) MkIntegerTerm(I)
static UInt static UInt
@ -458,7 +460,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, CELL *p
pt0_end = ap2 + 1; pt0_end = ap2 + 1;
ptf = H; ptf = H;
H += 2; H += 2;
if (H > ASP - 128) { if (H > ASP - MIN_ARENA_SIZE) {
goto overflow; goto overflow;
} }
} else if (IsApplTerm(d0)) { } else if (IsApplTerm(d0)) {
@ -480,7 +482,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, CELL *p
*ptf++ = d0; *ptf++ = d0;
break; break;
case (CELL)FunctorLongInt: case (CELL)FunctorLongInt:
if (H > ASP - (128+3)) { if (H > ASP - (MIN_ARENA_SIZE+3)) {
goto overflow; goto overflow;
} }
*ptf++ = AbsAppl(H); *ptf++ = AbsAppl(H);
@ -488,12 +490,12 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, CELL *p
H[1] = ap2[1]; H[1] = ap2[1];
H[2] = EndSpecials; H[2] = EndSpecials;
H += 3; H += 3;
if (H > ASP - 128) { if (H > ASP - MIN_ARENA_SIZE) {
goto overflow; goto overflow;
} }
break; break;
case (CELL)FunctorDouble: case (CELL)FunctorDouble:
if (H > ASP - (128+(2+SIZEOF_DOUBLE/sizeof(CELL)))) { if (H > ASP - (MIN_ARENA_SIZE+(2+SIZEOF_DOUBLE/sizeof(CELL)))) {
goto overflow; goto overflow;
} }
*ptf++ = AbsAppl(H); *ptf++ = AbsAppl(H);
@ -513,7 +515,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, CELL *p
/* big int */ /* big int */
UInt sz = ArenaSz(d0), i; UInt sz = ArenaSz(d0), i;
if (H > ASP - (128+sz)) { if (H > ASP - (MIN_ARENA_SIZE+sz)) {
goto overflow; goto overflow;
} }
*ptf++ = AbsAppl(H); *ptf++ = AbsAppl(H);
@ -561,7 +563,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, CELL *p
H[0] = (CELL)f; H[0] = (CELL)f;
ptf = H+1; ptf = H+1;
H += 1+d0; H += 1+d0;
if (H > ASP - 128) { if (H > ASP - MIN_ARENA_SIZE) {
goto overflow; goto overflow;
} }
} else { } else {
@ -599,13 +601,13 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, CELL *p
if (!CopyAttVar(ptd0, bp, ptf, att_arenap)) { if (!CopyAttVar(ptd0, bp, ptf, att_arenap)) {
goto delay_overflow; goto delay_overflow;
} }
if (H > ASP - 128) { if (H > ASP - MIN_ARENA_SIZE) {
goto overflow; goto overflow;
} }
to_visit = bp[0]; to_visit = bp[0];
HB = HLow; HB = HLow;
ptf++; ptf++;
if ((ADDR)TR > Yap_TrailTop-128) if ((ADDR)TR > Yap_TrailTop-MIN_ARENA_SIZE)
goto trail_overflow; goto trail_overflow;
Bind_and_Trail(ptd0, ptf[-1]); Bind_and_Trail(ptd0, ptf[-1]);
} }
@ -613,7 +615,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, CELL *p
#endif #endif
/* first time we met this term */ /* first time we met this term */
RESET_VARIABLE(ptf); RESET_VARIABLE(ptf);
if ((ADDR)TR > Yap_TrailTop-128) if ((ADDR)TR > Yap_TrailTop-MIN_ARENA_SIZE)
goto trail_overflow; goto trail_overflow;
Bind_and_Trail(ptd0, (CELL)ptf); Bind_and_Trail(ptd0, (CELL)ptf);
ptf++; ptf++;
@ -755,7 +757,7 @@ CopyTermToArena(Term t, Term arena, int share, UInt arity, Term *newarena, Term
return t; return t;
} }
tn = MkVarTerm(); tn = MkVarTerm();
if (H > ASP - 128) { if (H > ASP - MIN_ARENA_SIZE) {
res = -1; res = -1;
goto error_handler; goto error_handler;
} }
@ -804,7 +806,7 @@ CopyTermToArena(Term t, Term arena, int share, UInt arity, Term *newarena, Term
CloseArena(oldH, oldHB, oldASP, newarena, old_size); CloseArena(oldH, oldHB, oldASP, newarena, old_size);
return t; return t;
case (CELL)FunctorLongInt: case (CELL)FunctorLongInt:
if (H > ASP - (128+3)) { if (H > ASP - (MIN_ARENA_SIZE+3)) {
res = -1; res = -1;
goto error_handler; goto error_handler;
} }
@ -813,7 +815,7 @@ CopyTermToArena(Term t, Term arena, int share, UInt arity, Term *newarena, Term
H += 3; H += 3;
break; break;
case (CELL)FunctorDouble: case (CELL)FunctorDouble:
if (H > ASP - (128+(2+SIZEOF_DOUBLE/sizeof(CELL)))) { if (H > ASP - (MIN_ARENA_SIZE+(2+SIZEOF_DOUBLE/sizeof(CELL)))) {
res = -1; res = -1;
goto error_handler; goto error_handler;
} }
@ -831,7 +833,7 @@ CopyTermToArena(Term t, Term arena, int share, UInt arity, Term *newarena, Term
{ {
UInt sz = ArenaSz(t), i; UInt sz = ArenaSz(t), i;
if (H > ASP - (128+sz)) { if (H > ASP - (MIN_ARENA_SIZE+sz)) {
res = -1; res = -1;
goto error_handler; goto error_handler;
} }
@ -843,7 +845,7 @@ CopyTermToArena(Term t, Term arena, int share, UInt arity, Term *newarena, Term
} }
} else { } else {
H += 1+ArityOfFunctor(f); H += 1+ArityOfFunctor(f);
if (H > ASP-128) { if (H > ASP-MIN_ARENA_SIZE) {
res = -1; res = -1;
goto error_handler; goto error_handler;
} }
@ -934,7 +936,7 @@ CreateTermInArena(Term arena, Atom Na, UInt Nar, UInt arity, Term *newarena, Ter
tf = AbsAppl(H); tf = AbsAppl(H);
H[0] = (CELL)f; H[0] = (CELL)f;
H += 1+ArityOfFunctor(f); H += 1+ArityOfFunctor(f);
if (H > ASP-128) { if (H > ASP-MIN_ARENA_SIZE) {
/* overflow */ /* overflow */
H = HB; H = HB;
CloseArena(oldH, oldHB, oldASP, newarena, old_size); CloseArena(oldH, oldHB, oldASP, newarena, old_size);
@ -1428,6 +1430,8 @@ p_nb_queue(void)
#endif #endif
Term t = Deref(ARG1); Term t = Deref(ARG1);
UInt arena_sz = (H-H0)/16; UInt arena_sz = (H-H0)/16;
if (arena_sz < MIN_ARENA_SIZE)
arena_sz = MIN_ARENA_SIZE;
if (!IsVarTerm(t)) { if (!IsVarTerm(t)) {
if (!IsApplTerm(t)) { if (!IsApplTerm(t)) {
@ -1594,7 +1598,7 @@ p_nb_queue_enqueue(void)
H = HB = ArenaPt(arena); H = HB = ArenaPt(arena);
old_sz = ArenaSz(arena); old_sz = ArenaSz(arena);
qsize = IntegerOfTerm(qd[QUEUE_SIZE]); qsize = IntegerOfTerm(qd[QUEUE_SIZE]);
while (old_sz < 128) { while (old_sz < MIN_ARENA_SIZE) {
UInt gsiz = H-RepPair(qd[QUEUE_HEAD]); UInt gsiz = H-RepPair(qd[QUEUE_HEAD]);
H = oldH; H = oldH;
HB = oldHB; HB = oldHB;
@ -1927,7 +1931,7 @@ p_nb_heap_add_to_heap(void)
oldHB = HB; oldHB = HB;
H = HB = ArenaPt(arena); H = HB = ArenaPt(arena);
old_sz = ArenaSz(arena); old_sz = ArenaSz(arena);
while (old_sz < 128) { while (old_sz < MIN_ARENA_SIZE) {
UInt gsiz = hsize*2; UInt gsiz = hsize*2;
H = oldH; H = oldH;
@ -2330,7 +2334,7 @@ p_nb_beam_add_to_beam(void)
oldHB = HB; oldHB = HB;
H = HB = ArenaPt(arena); H = HB = ArenaPt(arena);
old_sz = ArenaSz(arena); old_sz = ArenaSz(arena);
while (old_sz < 128) { while (old_sz < MIN_ARENA_SIZE) {
UInt gsiz = hsize*2; UInt gsiz = hsize*2;
H = oldH; H = oldH;