make options -T -L -G work as SWI: they impose a maximum size limit

This commit is contained in:
Vitor Santos Costa 2009-05-10 13:36:55 -04:00
parent b177a9e333
commit 39ccbd345d
5 changed files with 79 additions and 10 deletions

View File

@ -1953,14 +1953,26 @@ YAP_Init(YAP_init_args *yap_init)
} }
} }
if (yap_init->TrailSize == 0) { if (yap_init->TrailSize == 0) {
if (Trail == 0) if (yap_init->MaxTrailSize) {
Trail = yap_init->MaxTrailSize;
} else if (Trail == 0)
Trail = DefTrailSpace; Trail = DefTrailSpace;
} else { } else {
Trail = yap_init->TrailSize; Trail = yap_init->TrailSize;
} }
Atts = yap_init->AttsSize; Atts = yap_init->AttsSize;
if (yap_init->StackSize == 0) { if (yap_init->StackSize == 0) {
if (Stack == 0) if (yap_init->MaxStackSize || yap_init->MaxGlobalSize) {
if (yap_init->MaxStackSize) {
if (yap_init->MaxGlobalSize) {
Stack = yap_init->MaxStackSize+yap_init->MaxGlobalSize;
} else {
Stack = yap_init->MaxStackSize+DefStackSpace/2;
}
} else {
Stack = yap_init->MaxGlobalSize+DefStackSpace/2;
}
} else if (Stack == 0)
Stack = DefStackSpace; Stack = DefStackSpace;
} else { } else {
Stack = yap_init->StackSize; Stack = yap_init->StackSize;
@ -1989,6 +2001,21 @@ YAP_Init(YAP_init_args *yap_init)
return YAP_BOOT_FROM_SAVED_ERROR;; return YAP_BOOT_FROM_SAVED_ERROR;;
} }
#endif #endif
if (yap_init->MaxStackSize) {
Yap_AllowLocalExpansion = FALSE;
} else {
Yap_AllowLocalExpansion = TRUE;
}
if (yap_init->MaxGlobalSize) {
Yap_AllowGlobalExpansion = FALSE;
} else {
Yap_AllowGlobalExpansion = TRUE;
}
if (yap_init->MaxTrailSize) {
Yap_AllowTrailExpansion = FALSE;
} else {
Yap_AllowTrailExpansion = TRUE;
}
Yap_InitExStacks (Trail, Stack); Yap_InitExStacks (Trail, Stack);
if (yap_init->QuietMode) { if (yap_init->QuietMode) {
yap_flags[QUIET_MODE_FLAG] = TRUE; yap_flags[QUIET_MODE_FLAG] = TRUE;
@ -2121,6 +2148,11 @@ YAP_FastInit(char saved_state[])
init_args.HeapSize = 0; init_args.HeapSize = 0;
init_args.StackSize = 0; init_args.StackSize = 0;
init_args.TrailSize = 0; init_args.TrailSize = 0;
init_args.MaxAttsSize = 0;
init_args.MaxHeapSize = 0;
init_args.MaxStackSize = 0;
init_args.MaxGlobalSize = 0;
init_args.MaxTrailSize = 0;
init_args.YapLibDir = NULL; init_args.YapLibDir = NULL;
init_args.YapPrologBootFile = NULL; init_args.YapPrologBootFile = NULL;
init_args.YapPrologInitFile = NULL; init_args.YapPrologInitFile = NULL;

View File

@ -765,7 +765,12 @@ static_growglobal(long request, CELL **ptr, CELL *hsplit)
Yap_PrologMode |= GrowStackMode; Yap_PrologMode |= GrowStackMode;
start_growth_time = Yap_cputime(); start_growth_time = Yap_cputime();
if (do_grow) { if (do_grow) {
if (!Yap_ExtendWorkSpace(size)) { if (!Yap_AllowGlobalExpansion) {
Yap_ErrorMessage = "Global Stack crashed against Local Stack";
LeaveGrowMode(GrowStackMode);
return 0;
}
if (!Yap_AllowGlobalExpansion || !Yap_ExtendWorkSpace(size)) {
/* always fails when using malloc */ /* always fails when using malloc */
Yap_ErrorMessage = NULL; Yap_ErrorMessage = NULL;
size += AdjustPageSize(((CELL)Yap_TrailTop-(CELL)Yap_GlobalBase)+MinHeapGap); size += AdjustPageSize(((CELL)Yap_TrailTop-(CELL)Yap_GlobalBase)+MinHeapGap);
@ -1326,6 +1331,10 @@ execute_growstack(long size0, int from_trail, int in_parser, tr_fr_ptr *old_trp,
ADDR old_Yap_GlobalBase = Yap_GlobalBase; ADDR old_Yap_GlobalBase = Yap_GlobalBase;
CurrentDelayTop = (CELL *)DelayTop(); CurrentDelayTop = (CELL *)DelayTop();
if (!Yap_AllowGlobalExpansion) {
Yap_ErrorMessage = "Database crashed against stacks";
return FALSE;
}
if (!Yap_ExtendWorkSpace(size)) { if (!Yap_ExtendWorkSpace(size)) {
/* make sure stacks and trail are contiguous */ /* make sure stacks and trail are contiguous */
@ -1528,6 +1537,10 @@ static int do_growtrail(long size, int contiguous_only, int in_parser, tr_fr_ptr
fprintf(Yap_stderr, "%% growing the trail %ld bytes\n", size); fprintf(Yap_stderr, "%% growing the trail %ld bytes\n", size);
} }
Yap_ErrorMessage = NULL; Yap_ErrorMessage = NULL;
if (!Yap_AllowTrailExpansion) {
Yap_ErrorMessage = "Trail Overflow";
return FALSE;
}
#if USE_SYSTEM_MALLOC #if USE_SYSTEM_MALLOC
execute_growstack(size, TRUE, in_parser, old_trp, tksp, vep); execute_growstack(size, TRUE, in_parser, old_trp, tksp, vep);
#else #else

View File

@ -370,6 +370,7 @@ typedef struct various_codes {
lockvar low_level_trace_lock; lockvar low_level_trace_lock;
#endif #endif
#endif #endif
int allow_local_expansion, allow_global_expansion, allow_trail_expansion;
unsigned int size_of_overflow; unsigned int size_of_overflow;
struct mod_entry *current_modules; struct mod_entry *current_modules;
struct operator_entry *op_list; struct operator_entry *op_list;
@ -753,6 +754,9 @@ extern struct various_codes *Yap_heap_regs;
#define DeadMegaClauses Yap_heap_regs->dead_mega_clauses #define DeadMegaClauses Yap_heap_regs->dead_mega_clauses
#define DBTermsList Yap_heap_regs->dbterms_list #define DBTermsList Yap_heap_regs->dbterms_list
#define DeadStaticIndices Yap_heap_regs->dead_static_indices #define DeadStaticIndices Yap_heap_regs->dead_static_indices
#define Yap_AllowLocalExpansion Yap_heap_regs->allow_local_expansion
#define Yap_AllowGlobalExpansion Yap_heap_regs->allow_global_expansion
#define Yap_AllowTrailExpansion Yap_heap_regs->allow_trail_expansion
#define SizeOfOverflow Yap_heap_regs->size_of_overflow #define SizeOfOverflow Yap_heap_regs->size_of_overflow
#define LastWtimePtr Yap_heap_regs->last_wtime #define LastWtimePtr Yap_heap_regs->last_wtime
#define BGL Yap_heap_regs->bgl #define BGL Yap_heap_regs->bgl

View File

@ -313,6 +313,7 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
char *myddas_temp; char *myddas_temp;
#endif #endif
unsigned long int *ssize; unsigned long int *ssize;
while (--argc > 0) while (--argc > 0)
{ {
p = *++argv; p = *++argv;
@ -453,10 +454,12 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
} }
p++; p++;
break; break;
case 'G':
ssize = &(iap->MaxGlobalSize);
goto GetSize;
break;
case 's': case 's':
case 'S': case 'S':
case 'G':
stack_mode:
ssize = &(iap->StackSize); ssize = &(iap->StackSize);
#if defined(ENV_COPY) || defined(ACOW) || defined(SBA) #if defined(ENV_COPY) || defined(ACOW) || defined(SBA)
if (p[1] == 'l') { if (p[1] == 'l') {
@ -469,8 +472,10 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
case 'A': case 'A':
ssize = &(iap->AttsSize); ssize = &(iap->AttsSize);
goto GetSize; goto GetSize;
case 't':
case 'T': case 'T':
ssize = &(iap->MaxTrailSize);
goto get_trail_size;
case 't':
ssize = &(iap->TrailSize); ssize = &(iap->TrailSize);
#ifdef TABLING #ifdef TABLING
if (p[1] == 's') { if (p[1] == 's') {
@ -478,6 +483,7 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
ssize = &(iap->MaxTableSpaceSize); ssize = &(iap->MaxTableSpaceSize);
} }
#endif /* TABLING */ #endif /* TABLING */
get_trail_size:
if (*++p == '\0') if (*++p == '\0')
{ {
if (argc > 1) if (argc > 1)
@ -500,7 +506,6 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
ch = *p++; ch = *p++;
break; break;
case 'g': case 'g':
case 'G':
i *= 1024*1024; i *= 1024*1024;
ch = *p++; ch = *p++;
break; break;
@ -567,7 +572,10 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
#endif #endif
case 'L': case 'L':
if (p[1] && p[1] >= '0' && p[1] <= '9') /* hack to emulate SWI's L local option */ if (p[1] && p[1] >= '0' && p[1] <= '9') /* hack to emulate SWI's L local option */
goto stack_mode; {
ssize = &(iap->MaxStackSize);
goto GetSize;
}
iap->QuietMode = TRUE; iap->QuietMode = TRUE;
iap->HaltAfterConsult = TRUE; iap->HaltAfterConsult = TRUE;
case 'l': case 'l':
@ -654,11 +662,9 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
++p; ++p;
value=p; value=p;
if ( *value == '\0' ) break; if ( *value == '\0' ) break;
//
++def_c; ++def_c;
def_var[def_c-1]=var; def_var[def_c-1]=var;
def_value[def_c-1]=value; def_value[def_c-1]=value;
//printf("var=value--->%s=%s\n",var,value);
break; break;
} }
/* End preprocessor code */ /* End preprocessor code */
@ -708,6 +714,11 @@ init_standard_system(int argc, char *argv[], YAP_init_args *iap)
iap->StackSize = 0; iap->StackSize = 0;
iap->TrailSize = 0; iap->TrailSize = 0;
iap->AttsSize = 0; iap->AttsSize = 0;
iap->MaxAttsSize = 0;
iap->MaxHeapSize = 0;
iap->MaxStackSize = 0;
iap->MaxGlobalSize = 0;
iap->MaxTrailSize = 0;
iap->YapLibDir = NULL; iap->YapLibDir = NULL;
iap->YapPrologBootFile = NULL; iap->YapPrologBootFile = NULL;
iap->YapPrologInitFile = NULL; iap->YapPrologInitFile = NULL;

View File

@ -74,12 +74,21 @@ typedef struct {
char *SavedState; char *SavedState;
/* if NON-0, minimal size for Heap or Code Area */ /* if NON-0, minimal size for Heap or Code Area */
unsigned long int HeapSize; unsigned long int HeapSize;
/* if NON-0, maximal size for Heap or Code Area */
unsigned long int MaxHeapSize;
/* if NON-0, minimal size for Local+Global Stack */ /* if NON-0, minimal size for Local+Global Stack */
unsigned long int StackSize; unsigned long int StackSize;
/* if NON-0, maximal size for Local+Global Stack */
unsigned long int MaxStackSize;
unsigned long int MaxGlobalSize;
/* if NON-0, minimal size for Trail */ /* if NON-0, minimal size for Trail */
unsigned long int TrailSize; unsigned long int TrailSize;
/* if NON-0, maximal size for Trail */
unsigned long int MaxTrailSize;
/* if NON-0, minimal size for AttributeVarStack */ /* if NON-0, minimal size for AttributeVarStack */
unsigned long int AttsSize; unsigned long int AttsSize;
/* if NON-0, maximal size for AttributeVarStack */
unsigned long int MaxAttsSize;
/* if NON-NULL, value for YAPLIBDIR */ /* if NON-NULL, value for YAPLIBDIR */
char *YapLibDir; char *YapLibDir;
/* if NON-NULL, name for a Prolog file to use when booting */ /* if NON-NULL, name for a Prolog file to use when booting */