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

View File

@ -162,7 +162,7 @@ SetHeapRegs(void)
if (B) if (B)
B = ChoicePtrAdjust(B); B = ChoicePtrAdjust(B);
if (CurrentDelayTop) if (CurrentDelayTop)
CurrentDelayTop = PtoGloAdjust(CurrentDelayTop); CurrentDelayTop = PtoDelayAdjust(CurrentDelayTop);
#ifdef CUT_C #ifdef CUT_C
if (Yap_REGS.CUT_C_TOP) if (Yap_REGS.CUT_C_TOP)
Yap_REGS.CUT_C_TOP = (cut_c_str_ptr)ChoicePtrAdjust((choiceptr)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 */ /* expanding attributed variables */
if (omax - size > Yap_GlobalBase+4096*sizeof(CELL)) { if (omax - size > Yap_GlobalBase+4096*sizeof(CELL)) {
size = -size; size = -size;
do_grow = FALSE;
} }
} else if (hsplit < (CELL*)omax || } else if (hsplit < (CELL*)omax ||
hsplit > H) 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) if (gc_margin < gc_lim)
gc_margin = gc_lim; gc_margin = gc_lim;
if (gc_margin < CalculateStackGap())
gc_margin = CalculateStackGap();
GcCalls++; GcCalls++;
HGEN = VarOfTerm(Yap_ReadTimedVar(GcGeneration)); HGEN = VarOfTerm(Yap_ReadTimedVar(GcGeneration));
if (gc_on && !(Yap_PrologMode & InErrorMode) && 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 #endif
ActiveSignals = 0; ActiveSignals = 0;
DoingUndefp = FALSE; DoingUndefp = FALSE;
DelayArenaOverflows = 0;
DBErasedList = NULL; DBErasedList = NULL;
DBErasedIList = NULL; DBErasedIList = NULL;
Yap_heap_regs->IntLUKeys = NULL; Yap_heap_regs->IntLUKeys = NULL;

View File

@ -21,6 +21,7 @@
#include "Yatom.h" #include "Yatom.h"
#include "Heap.h" #include "Heap.h"
#include "attvar.h"
#include "yapio.h" #include "yapio.h"
#include "tracer.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); LOCK(Yap_heap_regs->low_level_trace_lock);
sc = Yap_heap_regs; sc = Yap_heap_regs;
vsc_count++; vsc_count++;
if (vsc_count == 231868LL)
jmp_deb(1);
return;
#ifdef THREADS #ifdef THREADS
Yap_heap_regs->thread_handle[worker_id].thread_inst_count++; Yap_heap_regs->thread_handle[worker_id].thread_inst_count++;
#endif #endif

View File

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

View File

@ -139,9 +139,9 @@ inline EXTERN CELL
GlobalAdjust (CELL val) GlobalAdjust (CELL val)
{ {
if ((CELL *)val < GSplit) { if ((CELL *)val < GSplit) {
return (CELL) ((val + GDiff0)); return (CELL) (val + GDiff0);
} else { } 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 *); inline EXTERN int IsOldGlobalPtr (CELL *);