Exemplo n.º 1
0
        /* move 'dead' udata that need finalization to list 'tobefnz' */
        public static uint luaC_separateudata(lua_State L, int all)
        {
            global_State g       = G(L);
            uint         deadmem = 0; /* total size of all objects to be finalized */
            GCObjectRef  p       = new NextRef(g.mainthread);
            GCObject     curr;
            GCObjectRef  lastnext = new TobefnzRef(g);      //FIXME:??????

            /* find last 'next' field in 'tobefnz' list (to insert elements in its end) */
            while (lastnext.get() != null)
            {
                lastnext = new NextRef(gch(lastnext.get()));
            }
            while ((curr = p.get()) != null)          /* traverse all finalizable objects */
            {
                lua_assert(ttisuserdata(gch(curr)) && !isfinalized(gco2u(curr)));
                lua_assert(testbit(gch(curr).marked, SEPARATED));
                if (!(all != 0 || iswhite(curr)))    /* not being collected? */
                {
                    p = new NextRef(gch(curr));      /* don't bother with it */
                }
                else
                {
                    l_setbit(ref gch(curr).marked, FINALIZEDBIT); /* won't be finalized again */
                    deadmem += sizeudata(gco2u(curr));
                    p.set(gch(curr).next);                        /* remove 'curr' from 'rootgc' list */
                    /* link 'curr' at the end of 'tobefnz' list */
                    gch(curr).next = lastnext.get();
                    lastnext.set(curr);
                    lastnext = new NextRef(gch(curr));
                }
            }
            return(deadmem);
        }
Exemplo n.º 2
0
        /*
        ** move all unreachable objects that need finalization from list 'finobj'
        ** to list 'tobefnz'
        */
        public static void luaC_separateudata(lua_State L, int all)
        {
            global_State g = G(L);
            GCObjectRef  p = new FinobjRef(g);
            GCObject     curr;
            GCObjectRef  lastnext = new TobefnzRef(g);      //FIXME:??????next???

            /* find last 'next' field in 'tobefnz' list (to add elements in its end) */
            while (lastnext.get() != null)
            {
                lastnext = new NextRef(gch(lastnext.get())); //FIXME:next???PtrRef???
            }
            while ((curr = p.get()) != null)                 /* traverse all finalizable objects */
            {
                lua_assert(!isfinalized(curr));
                lua_assert(testbit(gch(curr).marked, SEPARATED));
                if (!(all != 0 || iswhite(curr)))    /* not being collected? */
                {
                    p = new NextRef(gch(curr));      /* don't bother with it */
                }
                else
                {
                    l_setbit(ref gch(curr).marked, FINALIZEDBIT); /* won't be finalized again */
                    p.set(gch(curr).next);                        /* remove 'curr' from 'finobj' list */
                    gch(curr).next = lastnext.get();              /* link at the end of 'tobefnz' list */
                    lastnext.set(curr);
                    lastnext = new NextRef(gch(curr));
                }
            }
        }