Next: mark_object, Previous: Invocation, Up: Garbage Collection - Step by Step [Contents][Index]
garbage_collect_1
We can now describe exactly what happens after the invocation takes place.
gc_in_progress
), when
the garbage collection is somehow forbidden
(gc_currently_forbidden
), when we are currently displaying something
(in_display
) or when we are preparing for the armageddon of the
whole system (preparing_for_armageddon
).
pre_gc_cursor
and cursor_changed
take
care of that.
gc_currently_forbidden
must be restored after
the garbage collection, no matter what happens during the process. We
accomplish this by record_unwind_protect
ing the suitable function
restore_gc_inhibit
together with the current value of
gc_currently_forbidden
.
gc_in_progress
is set.
clear_event_resource
) and for specifiers
(cleanup_specifiers
).
mark_object
is called for each root individually to go out from
there to mark all reachable objects. All roots that are traversed are
shown in their processed order:
staticpro
in the dynarr staticpros
.
See Adding Global Lisp Variables.
gcprolist
.
See GCPROing.
symbol
and old
values old_values
) that are bound during the evaluation by the Lisp
engine. They are stored in specbinding
structs pushed on a stack
called specpdl
.
See Dynamic Binding; The specbinding Stack; Unwind-Protects.
catchtag
inserted in the list
catchlist
. Their tag (tag
) and value (val
fields
are freshly created objects and therefore have to be marked.
See Catch and Throw.
backtrace
on the call stack of the Lisp engine (backtrace_list
). The unique
parts that have to be marked are the fields for each function
(function
) and all their arguments (args
).
See Evaluation.
mark_redisplay
(in
redisplay.c
).
mark_profiling_info
make-hash-table
.
Because there are complicated dependency rules about when and what to
mark while processing weak hash tables, the standard marker
method is only active if it is marking non-weak hash tables. As soon as
a weak component is in the table, the hash table entries are ignored
while marking. Instead their marking is done each separately by the
function finish_marking_weak_hash_tables
. This function iterates
over each hash table entry hentries
for each weak hash table in
Vall_weak_hash_tables
. Depending on the type of a table, the
appropriate action is performed.
If a table is acting as HASH_TABLE_KEY_WEAK
, and a key already marked,
everything reachable from the value
component is marked. If it is
acting as a HASH_TABLE_VALUE_WEAK
and the value component is
already marked, the marking starts beginning only from the
key
component.
If it is a HASH_TABLE_KEY_CAR_WEAK
and the car
of the key entry is already marked, we mark both the key
and
value
components.
Finally, if the table is of the type HASH_TABLE_VALUE_CAR_WEAK
and the car of the value components is already marked, again both the
key
and the value
components get marked.
Again, there are lists with comparable properties called weak
lists. There exist different peculiarities of their types called
simple
, assoc
, key-assoc
and
value-assoc
. You can find further details about them in the
description to the function make-weak-list
. The scheme of their
marking is similar: all weak lists are listed in Qall_weak_lists
,
therefore we iterate over them. The marking is advanced until we hit an
already marked pair. Then we know that during a former run all
the rest has been marked completely. Again, depending on the special
type of the weak list, our jobs differ. If it is a WEAK_LIST_SIMPLE
and the elem is marked, we mark the cons
part. If it is a
WEAK_LIST_ASSOC
and not a pair or a pair with both marked car and
cdr, we mark the cons
and the elem
. If it is a
WEAK_LIST_KEY_ASSOC
and not a pair or a pair with a marked car of
the elem, we mark the cons
and the elem
. Finally, if it is
a WEAK_LIST_VALUE_ASSOC
and not a pair or a pair with a marked
cdr of the elem, we mark both the cons
and the elem
.
Since, by marking objects in reach from weak hash tables and weak lists, other objects could get marked, this perhaps implies further marking of other weak objects, both finishing functions are redone as long as yet unmarked objects get freshly marked.
The function prune_weak_hash_tables
does the job for weak hash
tables. Totally unmarked hash tables are removed from the list
Vall_weak_hash_tables
. The other ones are treated more carefully
by scanning over all entries and removing one as soon as one of
the components key
and value
is unmarked.
The same idea applies to the weak lists. It is accomplished by
prune_weak_lists
: An unmarked list is pruned from
Vall_weak_lists
immediately. A marked list is treated more
carefully by going over it and removing just the unmarked pairs.
prune_specifiers
checks all listed specifiers held
in Vall_specifiers
and removes the ones from the lists that are
unmarked.
Vall_syntax_tables
. The function prune_syntax_tables
walks
through it and unlinks the tables that are unmarked.
gc_sweep
which holds the predominance.
consing_since_gc
- the counter of the created cells since
the last garbage collection - is set back to 0, and
gc_in_progress
is not true
anymore.
gc_inhibit
is restored to the former value by
unwinding the stack.
breathing_space
. If nothing more is left, we create a new reserve
and exit.
Next: mark_object, Previous: Invocation, Up: Garbage Collection - Step by Step [Contents][Index]