Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 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));
                }
            }
        }
Exemplo n.º 5
0
        /*
        ** if object 'o' has a finalizer, remove it from 'allgc' list (must
        ** search the list to find it) and link it in 'finobj' list.
        */
        public static void luaC_checkfinalizer(lua_State L, GCObject o, Table mt)
        {
            global_State g = G(L);

            if (testbit(gch(o).marked, SEPARATED) || /* obj. is already separated... */
                isfinalized(o) ||                    /* ... or is finalized... */
                gfasttm(g, mt, TMS.TM_GC) == null)   /* or has no finalizer? */
            {
                return;                              /* nothing to be done */
            }
            else                                     /* move 'o' to 'finobj' list */
            {
                GCObjectRef p;
                for (p = new AllGCRef(g); p.get() != o; p = new NextRef(gch(p.get())))
                {
                    ;
                }
                p.set(gch(o).next);                     /* remove 'o' from root list */
                gch(o).next = g.finobj;                 /* link it in list 'finobj' */
                g.finobj    = o;
                l_setbit(ref gch(o).marked, SEPARATED); /* mark it as such */
                resetoldbit(o);                         /* see MOVE OLD rule */
            }
        }
Exemplo n.º 6
0
        /*
        ** if userdata 'u' has a finalizer, remove it from 'allgc' list (must
        ** search the list to find it) and link it in 'udgc' list.
        */
        public static void luaC_checkfinalizer(lua_State L, Udata u)
        {
            global_State g = G(L);

            if (testbit(u.uv.marked, SEPARATED) ||             /* userdata is already separated... */
                isfinalized(u.uv) ||                           /* ... or is finalized... */
                gfasttm(g, u.uv.metatable, TMS.TM_GC) == null) /* or has no finalization? */
            {
                return;                                        /* nothing to be done */
            }
            else                                               /* move 'u' to 'udgc' list */
            {
                GCObjectRef p;
                for (p = new AllGCRef(g); p.get() != obj2gco(u); p = new NextRef(gch(p.get())))
                {
                    ;
                }
                p.set(u.uv.next);                     /* remove 'u' from root list */
                u.uv.next = g.udgc;                   /* link it in list 'udgc' */
                g.udgc    = obj2gco(u);
                l_setbit(ref u.uv.marked, SEPARATED); /* mark it as such */
                resetoldbit(obj2gco(u));              /* see MOVE OLD rule */
            }
        }