handle case where we can expand attributed variable stack

without having to grow stack physically.
This commit is contained in:
Vitor Santos Costa 2008-11-14 14:52:55 +00:00
parent 9296762791
commit 0ef147459a

View File

@ -131,7 +131,10 @@ SetHeapRegs(void)
/* Adjust stack addresses */ /* Adjust stack addresses */
Yap_TrailBase = TrailAddrAdjust(Yap_TrailBase); Yap_TrailBase = TrailAddrAdjust(Yap_TrailBase);
Yap_TrailTop = TrailAddrAdjust(Yap_TrailTop); Yap_TrailTop = TrailAddrAdjust(Yap_TrailTop);
if (!(GDiff==0 && DelayDiff < 0)) {
/* make sure we are not just expanding the delay stack */
Yap_GlobalBase = DelayAddrAdjust(Yap_GlobalBase); Yap_GlobalBase = DelayAddrAdjust(Yap_GlobalBase);
}
Yap_LocalBase = LocalAddrAdjust(Yap_LocalBase); Yap_LocalBase = LocalAddrAdjust(Yap_LocalBase);
#if !USE_SYSTEM_MALLOC && !USE_DL_MALLOC #if !USE_SYSTEM_MALLOC && !USE_DL_MALLOC
AuxSp = PtoDelayAdjust(AuxSp); AuxSp = PtoDelayAdjust(AuxSp);
@ -256,6 +259,18 @@ MoveHalfGlobal(CELL *OldPt)
cpcellsd(NewPt, IntPt, diff); cpcellsd(NewPt, IntPt, diff);
} }
static void
MoveHalfAttrs(CELL *DTop, CELL *OldPt)
{
/*
* cpcellsd(To,From,NOfCells) - copy the cells downwards - in
* absmi.asm
*/
UInt sz = sizeof(CELL)*(OldPt-DTop);
char *base = (char *)DTop+DelayDiff;
cpcellsd((CELL *)base, DTop, sz);
}
static inline CELL static inline CELL
AdjustAppl(register CELL t0) AdjustAppl(register CELL t0)
{ {
@ -724,13 +739,19 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
size0 = size; size0 = size;
if (hsplit) { if (hsplit) {
/* just a little bit of sanity checking */ /* just a little bit of sanity checking */
if (hsplit < (CELL*)omax || if (hsplit < H0 && hsplit > (CELL *)Yap_GlobalBase) {
/* expanding attributed variables */
if (omax - size > Yap_GlobalBase+4096*sizeof(CELL)) {
size = -size;
}
} else if (hsplit < (CELL*)omax ||
hsplit > H) hsplit > H)
return FALSE; return FALSE;
else if (hsplit == (CELL *)omax) else if (hsplit == (CELL *)omax)
hsplit = NULL; hsplit = NULL;
if (size+H < ASP-4096 && if (size < 0 ||
hsplit > H0) { (size+H < ASP-4096 &&
hsplit > H0)) {
/* don't need to expand stacks */ /* don't need to expand stacks */
do_grow = FALSE; do_grow = FALSE;
} }
@ -787,13 +808,23 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
if (do_grow) { if (do_grow) {
DelayDiff = size0; DelayDiff = size0;
TrDiff = LDiff = GDiff = size+size0; TrDiff = LDiff = GDiff = size+size0;
} else {
TrDiff = DelayDiff = LDiff = 0;
GDiff = size;
}
GDiff0 = DelayDiff; GDiff0 = DelayDiff;
} else {
TrDiff = LDiff = 0;
if (size > 0) {
DelayDiff = 0;
GDiff = size;
GDiff0 = DelayDiff;
} else {
DelayDiff = size;
GDiff = 0;
GDiff0 = 0;
}
}
if (hsplit) { if (hsplit) {
if (size > 0) {
GDiff = GDiff0+sz; GDiff = GDiff0+sz;
}
GSplit = hsplit; GSplit = hsplit;
} else { } else {
GSplit = NULL; GSplit = NULL;
@ -802,7 +833,11 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
if (!do_grow) { if (!do_grow) {
TrDiff = DelayDiff = LDiff = 0; TrDiff = DelayDiff = LDiff = 0;
/* don't grow more than what we asked for */ /* don't grow more than what we asked for */
if (size > 0) {
GDiff = size-(size0-sz); GDiff = size-(size0-sz);
} else {
GDiff = 0;
}
} else if (minimal_request) { } else if (minimal_request) {
DelayDiff = size-size0; DelayDiff = size-size0;
TrDiff = LDiff = GDiff = size; TrDiff = LDiff = GDiff = size;
@ -811,7 +846,12 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
DelayDiff = 0; DelayDiff = 0;
} }
if (hsplit) { if (hsplit) {
if (size > 0) {
GDiff0 = GDiff-size0; GDiff0 = GDiff-size0;
} else {
DelayDiff = size;
GDiff0 = 0;
}
GSplit = hsplit; GSplit = hsplit;
} else { } else {
GDiff0 = DelayDiff; GDiff0 = DelayDiff;
@ -840,8 +880,12 @@ static_growglobal(long size, CELL **ptr, CELL *hsplit)
*ptr = PtoLocAdjust(*ptr); *ptr = PtoLocAdjust(*ptr);
} }
if (hsplit) { if (hsplit) {
if (!do_grow && size < 0) {
MoveHalfAttrs(CurrentDelayTop,hsplit);
} else {
MoveHalfGlobal(hsplit); MoveHalfGlobal(hsplit);
} }
}
YAPLeaveCriticalSection(); YAPLeaveCriticalSection();
ASP += 256; ASP += 256;
if (minimal_request) { if (minimal_request) {