avoid excessive overflows and too large overflows in delay stack.

This commit is contained in:
Vitor Santos Costa 2009-02-26 23:06:27 +00:00
parent d7c2c74acc
commit 51875c627a
7 changed files with 34 additions and 10 deletions

View File

@ -150,11 +150,11 @@ NewDelayArena(UInt size)
UInt howmuch;
while ((ADDR)min < Yap_GlobalBase+1024) {
if ((howmuch = Yap_InsertInGlobal((CELL *)max, size*sizeof(attvar_record)))==0) {
UInt bsize = size*sizeof(attvar_record);
if ((howmuch = Yap_InsertInGlobal((CELL *)max, bsize))==0) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,"No Stack Space for Non-Backtrackable terms");
return TermNil;
}
size = howmuch/sizeof(attvar_record);
max = DelayTop(), min = max-size;
}
out = CreateDelayArena(max, min);
@ -168,6 +168,7 @@ GrowDelayArena(Term *arenap, UInt old_size, UInt size, UInt arity)
Term arena = *arenap;
UInt howmuch;
DelayArenaOverflows++;
if (size == 0) {
if (old_size < 1024) {
size = old_size*2;
@ -1442,11 +1443,14 @@ p_nb_queue(void)
return FALSE;
#if COROUTINING
{
UInt delay_arena_sz = ((attvar_record *)H0- DelayTop())/16;
if (delay_arena_sz <2)
delay_arena_sz = 2;
if (delay_arena_sz > 256)
delay_arena_sz = 256;
UInt delay_arena_sz = 2;
if (DelayArenaOverflows) {
delay_arena_sz = ((attvar_record *)H0- DelayTop())/16;
if (delay_arena_sz <2)
delay_arena_sz = 2;
if (delay_arena_sz > 256)
delay_arena_sz = 256;
}
delay_queue_arena = NewDelayArena(delay_arena_sz);
if (delay_queue_arena == 0L) {
return FALSE;
@ -1514,6 +1518,7 @@ RecoverDelayArena(Term delay_arena)
*max = DelayTop();
if (max == pt-DelayArenaSz(delay_arena)) {
SetDelayTop(pt);
} else {
}
}
#endif

View File

@ -162,7 +162,7 @@ SetHeapRegs(void)
if (B)
B = ChoicePtrAdjust(B);
if (CurrentDelayTop)
CurrentDelayTop = PtoGloAdjust(CurrentDelayTop);
CurrentDelayTop = PtoDelayAdjust(CurrentDelayTop);
#ifdef CUT_C
if (Yap_REGS.CUT_C_TOP)
Yap_REGS.CUT_C_TOP = (cut_c_str_ptr)ChoicePtrAdjust((choiceptr)Yap_REGS.CUT_C_TOP);
@ -743,6 +743,7 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
/* expanding attributed variables */
if (omax - size > Yap_GlobalBase+4096*sizeof(CELL)) {
size = -size;
do_grow = FALSE;
}
} else if (hsplit < (CELL*)omax ||
hsplit > H)

View File

@ -3907,6 +3907,8 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
}
if (gc_margin < gc_lim)
gc_margin = gc_lim;
if (gc_margin < CalculateStackGap())
gc_margin = CalculateStackGap();
GcCalls++;
HGEN = VarOfTerm(Yap_ReadTimedVar(GcGeneration));
if (gc_on && !(Yap_PrologMode & InErrorMode) &&

View File

@ -1415,6 +1415,7 @@ Yap_InitWorkspace(int Heap, int Stack, int Trail, int max_table_size,
#endif
ActiveSignals = 0;
DoingUndefp = FALSE;
DelayArenaOverflows = 0;
DBErasedList = NULL;
DBErasedIList = NULL;
Yap_heap_regs->IntLUKeys = NULL;

View File

@ -21,6 +21,7 @@
#include "Yatom.h"
#include "Heap.h"
#include "attvar.h"
#include "yapio.h"
#include "tracer.h"
@ -171,6 +172,9 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
LOCK(Yap_heap_regs->low_level_trace_lock);
sc = Yap_heap_regs;
vsc_count++;
if (vsc_count == 231868LL)
jmp_deb(1);
return;
#ifdef THREADS
Yap_heap_regs->thread_handle[worker_id].thread_inst_count++;
#endif

View File

@ -105,6 +105,7 @@ extern struct restore_info rinfo;
typedef struct worker_local_struct {
struct format_status *f_info;
Int delay_arena_overflows;
char *scanner_stack;
struct scanner_extra_alloc *scanner_extra_blocks;
#if defined(YAPOR) || defined(THREADS)
@ -688,6 +689,7 @@ extern struct various_codes *Yap_heap_regs;
#define ConsultCapacity Yap_heap_regs->WL.consultcapacity
#define DebugOn Yap_heap_regs->WL.debug_on
#define FormatInfo Yap_heap_regs->WL.f_info
#define DelayArenaOverflows Yap_heap_regs->WL.delay_arena_overflows
#define ScannerStack Yap_heap_regs->WL.scanner_stack
#define ScannerExtraBlocks Yap_heap_regs->WL.scanner_extra_blocks
#define Yap_BigTmp Yap_heap_regs->WL.big_tmp

View File

@ -139,9 +139,9 @@ inline EXTERN CELL
GlobalAdjust (CELL val)
{
if ((CELL *)val < GSplit) {
return (CELL) ((val + GDiff0));
return (CELL) (val + GDiff0);
} else {
return (CELL) ((val + GDiff));
return (CELL) (val + GDiff);
}
}
@ -779,6 +779,15 @@ IsOldGlobal (CELL reg)
}
inline EXTERN int IsOldDelay (CELL);
inline EXTERN int
IsOldDelay (CELL reg)
{
return (int) (IN_BETWEEN (OldGlobalBase, reg, OldH0));
}
inline EXTERN int IsOldGlobalPtr (CELL *);