Exemple #1
0
        public static UpVal luaF_findupval(lua_State L, StkId level)
        {
            global_State g  = G(L);
            GCObjectRef  pp = new OpenValRef(L);
            UpVal        p;
            UpVal        uv;

            while (pp.get() != null && (p = ngcotouv(pp.get())).v >= level)
            {
                lua_assert(p.v != p.u.value);
                if (p.v == level)
                {                                /* found a corresponding upvalue? */
                    if (isdead(g, obj2gco(p)))   /* is it dead? */
                    {
                        changewhite(obj2gco(p)); /* ressurect it */
                    }
                    return(p);
                }
                pp = new NextRef(p);
            }
            uv        = luaM_new <UpVal>(L);        /* not found: create a new one */
            uv.tt     = LUA_TUPVAL;
            uv.marked = luaC_white(g);
            uv.v      = level;               /* current value lives in the stack */
            uv.next   = pp.get();            /* chain it in the proper position */
            pp.set(obj2gco(uv));
            uv.u.l.prev          = g.uvhead; /* double link it in `uvhead' list */
            uv.u.l.next          = g.uvhead.u.l.next;
            uv.u.l.next.u.l.prev = uv;
            g.uvhead.u.l.next    = uv;
            lua_assert(uv.u.l.next.u.l.prev == uv && uv.u.l.prev.u.l.next == uv);
            return(uv);
        }
Exemple #2
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);
        }
Exemple #3
0
 public static UpVal luaF_findupval(lua_State L, StkId level)
 {
     global_State g = G(L);
       GCObjectRef pp = new OpenValRef(L);
       UpVal p;
       UpVal uv;
       while (pp.get() != null && (p = ngcotouv(pp.get())).v >= level) {
     lua_assert(p.v != p.u.value);
     if (p.v == level) {  /* found a corresponding upvalue? */
       if (isdead(g, obj2gco(p)))  /* is it dead? */
         changewhite(obj2gco(p));  /* ressurect it */
       return p;
     }
     pp = new NextRef(p);
       }
       uv = luaM_new<UpVal>(L);  /* not found: create a new one */
       uv.tt = LUA_TUPVAL;
       uv.marked = luaC_white(g);
       uv.v = level;  /* current value lives in the stack */
       uv.next = pp.get();  /* chain it in the proper position */
       pp.set( obj2gco(uv) );
       uv.u.l.prev = g.uvhead;  /* double link it in `uvhead' list */
       uv.u.l.next = g.uvhead.u.l.next;
       uv.u.l.next.u.l.prev = uv;
       g.uvhead.u.l.next = uv;
       lua_assert(uv.u.l.next.u.l.prev == uv && uv.u.l.prev.u.l.next == uv);
       return uv;
 }
Exemple #4
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));
                }
            }
        }
        /* move `dead' udata that need finalization to list `tmudata' */
        public static uint luaC_separateudata(lua_State L, int all)
        {
            global_State g       = G(L);
            uint         deadmem = 0;
            GCObjectRef  p       = new NextRef(g.mainthread);
            GCObject     curr;

            while ((curr = p.get()) != null)
            {
                if (!(iswhite(curr) || (all != 0)) || isfinalized(gco2u(curr)))
                {
                    p = new NextRef(curr.gch);        /* don't bother with them */
                }
                else if (fasttm(L, gco2u(curr).metatable, TMS.TM_GC) == null)
                {
                    markfinalized(gco2u(curr));        /* don't need finalization */
                    p = new NextRef(curr.gch);
                }
                else            /* must call its gc method */
                {
                    deadmem += (uint)sizeudata(gco2u(curr));
                    markfinalized(gco2u(curr));
                    p.set(curr.gch.next);
                    /* link `curr' at the end of `tmudata' list */
                    if (g.tmudata == null)                /* list is empty? */
                    {
                        g.tmudata = curr.gch.next = curr; /* creates a circular list */
                    }
                    else
                    {
                        curr.gch.next      = g.tmudata.gch.next;
                        g.tmudata.gch.next = curr;
                        g.tmudata          = curr;
                    }
                }
            }
            return(deadmem);
        }
Exemple #6
0
 /* move `dead' udata that need finalization to list `tmudata' */
 public static uint luaC_separateudata(lua_State L, int all)
 {
     global_State g = G(L);
       uint deadmem = 0;
       GCObjectRef p = new NextRef(g.mainthread);
       GCObject curr;
       while ((curr = p.get()) != null) {
     if (!(iswhite(curr) || (all!=0)) || isfinalized(gco2u(curr)))
       p = new NextRef(curr.gch);  /* don't bother with them */
     else if (fasttm(L, gco2u(curr).metatable, TMS.TM_GC) == null) {
       markfinalized(gco2u(curr));  /* don't need finalization */
       p = new NextRef(curr.gch);
     }
     else {  /* must call its gc method */
       deadmem += (uint)sizeudata(gco2u(curr));
       markfinalized(gco2u(curr));
       p.set( curr.gch.next );
       /* link `curr' at the end of `tmudata' list */
       if (g.tmudata == null)  /* list is empty? */
         g.tmudata = curr.gch.next = curr;  /* creates a circular list */
       else {
         curr.gch.next = g.tmudata.gch.next;
         g.tmudata.gch.next = curr;
         g.tmudata = curr;
       }
     }
       }
       return deadmem;
 }