Example #1
0
        //private static GCObject nullp = null; //FIXME:see nullp in global_State

        /*
        ** sweep at most 'count' elements from a list of GCObjects erasing dead
        ** objects, where a dead (not alive) object is one marked with the "old"
        ** (non current) white and not fixed.
        ** In non-generational mode, change all non-dead objects back to white,
        ** preparing for next collection cycle.
        ** In generational mode, keep black objects black, and also mark them as
        ** old; stop when hitting an old object, as all objects after that
        ** one will be old too.
        ** When object is a thread, sweep its list of open upvalues too.
        */
        private static GCObjectRef sweeplist(lua_State L, GCObjectRef p, lu_mem count)
        {
            global_State g = G(L);
            int          ow = otherwhite(g);
            int          toclear, toset;   /* bits to clear and to set in all live objects */
            int          tostop;           /* stop sweep when this is true */
            l_mem        debt = g.GCdebt;  /* current debt */

            if (isgenerational(g))         /* generational mode? */
            {
                toclear = ~0;              /* clear nothing */
                toset   = bitmask(OLDBIT); /* set the old bit of all surviving objects */
                tostop  = bitmask(OLDBIT); /* do not sweep old generation */
            }
            else                           /* normal mode */
            {
                toclear = maskcolors;      /* clear all color bits + old bit */
                toset   = luaC_white(g);   /* make object white */
                tostop  = 0;               /* do not stop */
            }
            while (p.get() != null && count-- > 0)
            {
                GCObject curr   = p.get();
                int      marked = gch(curr).marked;
                if (isdeadm(ow, marked))   /* is 'curr' dead? */
                {
                    p.set(gch(curr).next); /* remove 'curr' from list */
                    freeobj(L, curr);      /* erase 'curr' */
                }
                else
                {
                    if (gch(curr).tt == LUA_TTHREAD)
                    {
                        sweepthread(L, gco2th(curr));   /* sweep thread's upvalues */
                    }
                    if (testbits((byte)marked, tostop)) //FIXME:(byte)
                    //static GCObject *nullp = NULL; //FIXME:moved, see upper
                    {
                        p = new NullpRef(g);  /* stop sweeping this list */
                        break;
                    }
                    /* update marks */
                    gch(curr).marked = cast_byte((marked & toclear) | toset);
                    p = new NextRef(gch(curr));    /* go to next element */
                }
            }
            luaE_setdebt(g, debt); /* sweeping should not change debt */
            return(p);
        }