[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opportunistic garbage collection

From: Stefan Monnier
Subject: Re: Opportunistic garbage collection
Date: Thu, 25 Apr 2019 14:18:03 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>> +needed to triger automatic allocation took place.  */)
> triger -> trigger


>> +  byte_ct new_csgc = consing_since_gc * fact;
>> +  if (new_csgc / fact != consing_since_gc)
>> +    /* Overflow!  */
>> +    garbage_collect ();
> This assumes byte_ct is not narrower than EMACS_INT, which isn't true on
> 32-bit platforms --with-wide-int.

Does it?  My understanding is that if byte_ct is narrower what happens

1- consing_since_gc is widened to EMACS_INT, preserving the mathematical value.
2- multiplication with `fact`.
3- narrowing the result to byte_ct which will perform the equivalent of
   a "modulo 2^N".  So new_csgc should be mathematically equal to

       (consing_since_gc * fact) mod 2^N

4- widen new_csgs to an EMACS_INT, again without any loss
5- divide by `fact` the result can't be larger than new_csgs.
6- widen consing_since_gc to EMACS_INT
7- compare

So in the end, I believe that we compare

    truncation((consing_since_gc * fact) mod 2^N) / fact



so I believe that the inequality test is a reliable way to detect overflow.
What am I missing?

> It also assumes 'fact' is nonzero,

Indeed, I should probably add a check for it.

> which might not be true. (Two more reasons to hardwire 2.)
>> +      consing_since_gc = new_csgc;
>> +      maybe_gc ();
>> +      consing_since_gc /= fact;
> I'd feel better if we didn't muck with the global variable and passed
> the smaller consing value directly to a variant of maybe_gc.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]