all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Matt Armstrong <matt@rfc20.org>
Cc: 58639@debbugs.gnu.org
Subject: bug#58639: 29.0.50; [noverlay] Nested overlay iteration in GC
Date: Wed, 19 Oct 2022 13:29:02 -0400	[thread overview]
Message-ID: <jwvfsfjenp1.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87r0z3py0n.fsf@rfc20.org> (Matt Armstrong's message of "Wed, 19 Oct 2022 09:40:40 -0700")

> Stefan, looks like recursive calls to 'mark_buffer' are not only
> possible but common.  For this to be a problem for overlays, all it
> takes is an overlay property to somehow reference a second buffer.
> Boom, you get nested overlay iteration.

Duh, of course!

> Two easy fixes I can think of:
> a) Break the recursion while marking with a queue, rather than a stack.
>    To bound the size of the queue do this only for buffers.

Actually, the alloc.c code already has that, so it's a trivial change.

> b) Add a specialized itree iteration function for gc.  In fact,
>    properties already have one that we can copy:
>
>     extern void traverse_intervals_noorder (
>         INTERVAL,
>         void (*) (INTERVAL, void *), void *);

We even have better: just undo commit b8fbd42f0a7caa4cd9e2d50dd4e4b2101ac78acd

Or use the (100% guaranteed untested) code below.

The good thing about using `ITREE_FOREACH` in the GC is that it checks
that we're not running the GC from within an `ITREE_FOREACH` loop.

Side comment about `traverse_intervals_noorder`: I added this function
back when I played with using splay trees for `intervals.c`, which
worked well except that it occasionally created "pathologically" deep
trees, hence the need for `traverse_intervals_noorder` to keep the
recursion depth in O(log N).

> I like (b) so much I'll work on it now.

Fine by me :-)


        Stefan


diff --git a/src/alloc.c b/src/alloc.c
index 00f2991f250..555df997dfb 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6531,9 +6531,13 @@ mark_buffer (struct buffer *buffer)
   if (!BUFFER_LIVE_P (buffer))
       mark_object (BVAR (buffer, undo_list));
 
-  struct interval_node *node;
-  ITREE_FOREACH (node, buffer->overlays, PTRDIFF_MIN, PTRDIFF_MAX, ASCENDING)
-    mark_object (node->data);
+  {
+    ptrdiff_t sp = mark_stk.sp;
+    struct interval_node *node;
+    ITREE_FOREACH (node, buffer->overlays, PTRDIFF_MIN, PTRDIFF_MAX, ASCENDING)
+      mark_stack_push_value (node->data);
+    process_mark_stack (sp);
+  }
 
   /* If this is an indirect buffer, mark its base buffer.  */
   if (buffer->base_buffer &&






  reply	other threads:[~2022-10-19 17:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19 16:40 bug#58639: 29.0.50; [noverlay] Nested overlay iteration in GC Matt Armstrong
2022-10-19 17:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-10-19 21:49   ` Matt Armstrong
2022-10-19 22:16     ` Matt Armstrong
2022-10-19 23:50       ` Matt Armstrong
2022-10-20  1:55         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-12 20:58           ` Stefan Kangas
2022-11-15 17:47             ` Matt Armstrong

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

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

  git send-email \
    --in-reply-to=jwvfsfjenp1.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=58639@debbugs.gnu.org \
    --cc=matt@rfc20.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.