limit check bug

Stephen Weeks MLton@sourcelight.com
Tue, 12 Feb 2002 17:52:45 -0800


> You can't use
>     bytesAllocated > limit - frontier
> because of LIMIT_SLOP, 

In general I agree, but I only used that test after ensuring that

	frontier <= limit

which I think makes the test OK.  As always, it wastes LIMIT_SLOP
amount of space, but who cares.

> but you could use
>     bytesAllocated + LIMIT_SLOP > limit + LIMIT_SLOP - frontier
> assuming  that  we  do not allow either addition to overflow (by now allowing
> one to allocate within LIMIT_SLOP of max int or unsigned and by not  allowing
> the end of a semispace to get within LIMIT_SLOP of the end of addressability.

I don't understand why you want LIMIT_SLOP on the left-hand side.

Keep in mind that we know we are safe if

 	frontier + bytesAllocated <= limit + LIMIT_SLOP

So, if bytesAllocated <= LIMIT_SLOP, then we know we are safe if

(1)	frontier <= limit

OTOH, if we're not sure about bytes allocated, we can use

(2)	bytesAllocated <= (limit + LIMIT_SLOP) - frontier

which cannot overflow and is equivalent to the condition we care about

So, my new proposal is to use tests like (1) when we know
bytesAllocated <= LIMIT_SLOP, and like (2) when we don't know.