unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Fabrice Popineau <fabrice.popineau@gmail.com>, emacs-devel@gnu.org
Subject: Re: GC and stack marking
Date: Tue, 20 May 2014 09:44:05 -0400	[thread overview]
Message-ID: <jwvbnusio3o.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83a9add91p.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 19 May 2014 19:31:46 +0300")

> The short version of the question is: is it possible that a Lisp
> object which is no longer referenced by anything won't be GC'ed
> because it is marked by mark_stack due to some kind of coincidence?

Yes, of course, it's what makes a conservative marking conservative.

> So the huge hash-table gets dumped into the emacs executable, and

That's bad luck, indeed.

> causes all kinds of trouble in the dumped Emacs.

But it shouldn't cause any trouble (other than extra memory use).

> If this can legitimately happen, then how can we make sure this
> hash-table indeed gets GC'd before we dump Emacs?

First we should make sure that even if this table is not GC'd, Emacs
behaves correctly.  Otherwise, we probably have a bug that can appear in
other situations.

As for ensuring that the table gets' GC'd, there are 2 approaches:
- provide a low-level "free-this-table" function which loadup.el could
  use.  This is dangerous, since it basically says "trust me there are
  no other references to this object".  Even implementing this function
  can be tricky; it would probably be easier to provide it as
  a C function only.
- find where the spurious "reference" is coming from and add code to set
  this reference to some other value (e.g. it might be some variable
  left uninitialized, or a dead variable which we could explicitly set
  back to NULL or something), or to mark this memory location as "not
  a pointer" (like GCPRO but reversed: we'd do a NEGATIVE_GCPRO on the
  var (presumably of a type like int or float)).

The Boehm's GC has developed ways to do this second option
automatically: if during a GC, a memory cell is found to "point to"
unallocated memory, then it is assumed to be of non-pointer type and
this fact is recorded somewhere so that if in subsequent GC's this cell
ends up "pointing" to allocated memory that won't be considered as an
actual pointer.  This can be very important when you get close to using
the whole address space, in which case most addresses are allocated, so
that many/most ints and floats end up spuriously pointing "somewhere".

This doesn't work for us, tho, because we don't know when a stack
location is reused for some other purpose (i.e. when it changes type),
and more importantly because we have the Lisp_Object type which is
a memory cell which can sometimes contain integers and
sometimes pointers.  OTOH, we are only conservative w.r.t stack
scanning, so we're only subject to spurious pointers coming from the
stack, not from the rest of the heap.  And furthermore we have the great
advantage that, as an interactive application, our stack regularly comes
back to "almost empty" (and since we do "opportunistic GC" during idle
time, we often GC at the very moment the stack is almost empty).


        Stefan



  parent reply	other threads:[~2014-05-20 13:44 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-19 16:31 GC and stack marking Eli Zaretskii
2014-05-19 18:47 ` Paul Eggert
2014-05-19 19:14   ` Eli Zaretskii
2014-05-19 19:58     ` Paul Eggert
2014-05-19 20:03       ` Eli Zaretskii
2014-05-19 20:17         ` Paul Eggert
2014-05-20 16:37           ` Eli Zaretskii
2014-05-20 13:44 ` Stefan Monnier [this message]
2014-05-20 16:57   ` Eli Zaretskii
2014-05-20 17:54     ` Stefan Monnier
2014-05-20 19:28       ` Eli Zaretskii
2014-05-20 22:01         ` Stefan Monnier
2014-05-21  2:48           ` Eli Zaretskii
2014-05-21  3:01             ` Stefan Monnier
2014-05-21 15:39               ` Eli Zaretskii
2014-05-21 15:57                 ` Dmitry Antipov
2014-05-21 16:06                   ` Dmitry Antipov
2014-05-21 16:55                     ` Eli Zaretskii
2014-05-21 16:53                   ` Eli Zaretskii
2014-05-21 17:40                 ` Stefan Monnier
2014-05-21 17:58                   ` Eli Zaretskii
2014-05-22 15:20                     ` Eli Zaretskii
2014-05-22 16:14                       ` Stefan Monnier
2014-05-24 12:03                         ` Eli Zaretskii
2014-05-20 19:12     ` Daniel Colascione
2014-05-20 19:43       ` Eli Zaretskii
2014-05-20 22:03         ` Stefan Monnier
2014-05-21  2:51           ` Eli Zaretskii
2014-05-31  6:31   ` Florian Weimer
2014-05-31 14:24     ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2014-05-21 19:31 Barry OReilly
2014-05-21 20:13 ` Eli Zaretskii
2014-05-21 20:49   ` Barry OReilly
2014-05-22  2:43     ` Eli Zaretskii
2014-05-22  3:12       ` Daniel Colascione
2014-05-22  5:37         ` David Kastrup
2014-05-22 13:57           ` Stefan Monnier
2014-05-22 15:49         ` Eli Zaretskii
2014-05-22 14:59       ` Barry OReilly
2014-05-22 17:03         ` Eli Zaretskii

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=jwvbnusio3o.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=fabrice.popineau@gmail.com \
    /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).