[Top][All Lists]

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

GC and stack marking

From: Eli Zaretskii
Subject: GC and stack marking
Date: Mon, 19 May 2014 19:31:46 +0300

I have a question regarding GC and stack marking.

This issue popped up during testing of the new code written by Fabrice
for managing Emacs memory on MS-Windows.  I don't think this issue is
Windows specific, and I don't think the details of the new
implementation matter for what I'm about to ask (but if someone wants
the gory details, please holler).

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?

The specific situation where I think I see something like this is
during dumping.  When temacs loads and runs loadup.el, it does this
near the beginning:

  (if (eq t purify-flag)
      (setq purify-flag (make-hash-table :test 'equal :size 70000)))

This creates a large hash-table and stores its reference in
purify-flag.  Then, after loading all the preloaded packages, temacs
does this:

  ;; Avoid error if user loads some more libraries now and make sure the
  ;; hash-consing hash table is GC'd.
  (setq purify-flag nil)

  (if (null (garbage-collect))
      (setq pure-space-overflow t))

Note the comment: "...and make sure the hash-consing hash table is
GC'd.".  Well, on one machine to which I have access, it isn't GC'd.
Why? because mark_stack happens to find its address somewhere on the
stack.  (I have a backtrace to prove it.)  So the huge hash-table gets
dumped into the emacs executable, and causes all kinds of trouble in
the dumped Emacs.

On another machine (with a different version of the OS and of GCC),
the problem doesn't happen, and the table is indeed GC'd.

My question is: is this a legitimate situation?  Since all mark_stack
does is look for values recorded in the red-black tree, it might find
such a value by sheer luck (or lack thereof).  Right?  Or is this a
bug that needs to be researched further?

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


reply via email to

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