[gclist] What wrong with the GC in xemacs
Nick Barnes
nickb@harlequin.co.uk
Tue, 02 Apr 1996 11:20:30 +0100
Emacs uses a stop-and-collect mark/sweep GC. It's unremarkable
stuff. Here is the controlling GC code from alloc.c in Emacs
19.30.
/* Copyright (C) 1985, 86, 88, 93, 94, 95 Free Software Foundation, Inc.
This code was part of GNU Emacs. It has been edited to show
interesting parts of the controlling GC code by Nick Barnes,
on 1996-04-02.
GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", "")
()
{
register struct gcpro *tail;
register struct specbinding *bind;
struct catchtag *catch;
struct handler *handler;
register struct backtrace *backlist;
register Lisp_Object tem;
register int i;
/* In case user calls debug_print during GC,
don't let that cause a recursive GC. */
consing_since_gc = 0;
/* [... Save copy of the stack, for debugging ...NB] */
/* [... trim command history and undo lists ...NB] */
gc_in_progress = 1;
/* In each "large string", set the MARKBIT of the size field.
That enables mark_object to recognize them. */
{
register struct string_block *b;
for (b = large_string_blocks; b; b = b->next)
((struct Lisp_String *)(&b->chars[0]))->size |= MARKBIT;
}
/* Mark all the special slots that serve as the roots of accessibility.
Usually the special slots to mark are contained in particular structures.
Then we know no slot is marked twice because the structures don't overlap.
In some cases, the structures point to the slots to be marked.
For these, we use MARKBIT to avoid double marking of the slot. */
for (i = 0; i < staticidx; i++)
mark_object (staticvec[i]);
for (tail = gcprolist; tail; tail = tail->next)
for (i = 0; i < tail->nvars; i++)
if (!XMARKBIT (tail->var[i]))
{
mark_object (&tail->var[i]);
XMARK (tail->var[i]);
}
for (bind = specpdl; bind != specpdl_ptr; bind++)
{
mark_object (&bind->symbol);
mark_object (&bind->old_value);
}
for (catch = catchlist; catch; catch = catch->next)
{
mark_object (&catch->tag);
mark_object (&catch->val);
}
for (handler = handlerlist; handler; handler = handler->next)
{
mark_object (&handler->handler);
mark_object (&handler->var);
}
for (backlist = backtrace_list; backlist; backlist = backlist->next)
{
if (!XMARKBIT (*backlist->function))
{
mark_object (backlist->function);
XMARK (*backlist->function);
}
if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
i = 0;
else
i = backlist->nargs - 1;
for (; i >= 0; i--)
if (!XMARKBIT (backlist->args[i]))
{
mark_object (&backlist->args[i]);
XMARK (backlist->args[i]);
}
}
mark_kboards ();
gc_sweep ();
/* Clear the mark bits that we set in certain root slots. */
for (tail = gcprolist; tail; tail = tail->next)
for (i = 0; i < tail->nvars; i++)
XUNMARK (tail->var[i]);
for (backlist = backtrace_list; backlist; backlist = backlist->next)
{
XUNMARK (*backlist->function);
if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
i = 0;
else
i = backlist->nargs - 1;
for (; i >= 0; i--)
XUNMARK (backlist->args[i]);
}
XUNMARK (buffer_defaults.name);
XUNMARK (buffer_local_symbols.name);
gc_in_progress = 0;
consing_since_gc = 0;
if (gc_cons_threshold < 10000)
gc_cons_threshold = 10000;
}