lua-users home
lua-l archive

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


> I'm studying the code about gc in lua 5.2. 
> Here is the code in lgc.c: 
> 268     case LUA_TUPVAL: {    
> 269       UpVal *uv = gco2uv(o);
> 270       markvalue(g, uv->v);
> 271       if (uv->v != &uv->u.value)  /* open? */
> 272         return;  /* open upvalues remain gray */
> 273       size = sizeof(UpVal);
> 274       break;              
> 275     }
> Why "open upvalues remain gray", not to black?

Open upvalues point to values in the stack, so these values can change
without passing through the upvalue. Therefore, it is virtually
impossible to ensure the invariant that a black upvalue does not point
to a white value.


> How dose GC process upvalue?

As their values are in a stack, these values are colored when the
stack is traversed. (Stacks also are never black, to avoid the cost of
barriers when writing to the stack; they are kept in the 'grayagain'
list to be re-traversed in the atomic phase.)

-- Roberto