lua-users home
lua-l archive

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


> > In udata2finalize(), there is
> >
> > if (issweepphase(g))
> >
> >     makewhite(g, o);  /* "sweep" object */
> >
> > It seems to me that marking "o" as white have it about to go through the
> > "marking" step again rather than "sweeping" it. Should the comment revised?
> 
> Another thing puzzles me is, why calling makewhite() only when
> issweepphase()? In other state, if the object's "__gc" is invoked,
> shouldn't it be marked as current-white for the possible resurrection?

(You did not mention versions, I will refer to 5.3 beta.)

An object is ressurected just after entering the 'tobefnz' list (see
call to 'markbeingfnz' in 'atomic').  That list is part of the root set,
and objects there go through the GC cycles like other objects. (See
GC state 'GCSswptobefnz'.)  When 'udata2finalize' is called, the object
has the correct color (that is, it is alive and consistent with the
GC state), and its color does not need to be changed, except for one
detail. During sweep, the object can be removed from the list 'tobefnz' 
before it has been swept and inserted in list 'allgc' after that
list position has been swept and, therefore, it would skip the sweep
phase and become out-of-sync with the GC state. The line with that
comment corrects that, that is, it sweeps the object if necessary.

-- Roberto