unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-devel@gnu.org
Subject: Re: Opportunistic garbage collection
Date: Thu, 25 Apr 2019 14:18:03 -0400	[thread overview]
Message-ID: <jwvbm0uvtwi.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <b2bab9ee-ba8f-a936-3b07-1de293e72eda@cs.ucla.edu> (Paul Eggert's message of "Wed, 24 Apr 2019 17:17:45 -0700")

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

Thanks.

>> +  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
is:

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

with

    consing_since_gc

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.

Agreed.


        Stefan



  parent reply	other threads:[~2019-04-25 18:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 20:54 Opportunistic garbage collection Stefan Monnier
2019-04-25  0:17 ` Paul Eggert
2019-04-25  6:27   ` Eli Zaretskii
2019-04-25 12:49     ` Stefan Monnier
2019-04-25 18:18   ` Stefan Monnier [this message]
2019-04-25 22:14     ` Paul Eggert
2019-04-26  0:15       ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvbm0uvtwi.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).