lua-users home
lua-l archive

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


1. in incstep function, it miss divide by LUAI_GCMUL  when calculate debt.
static void incstep (lua_State *Lglobal_State *g) {
  int stepmul = (getgcparam(g->gcstepmul) | 1);  /* avoid division by 0 */
  l_mem debt = (g->GCdebt / LUAI_GCMUL) + 1; /*miss this code in lua5.4.3*/
  debt = (debt / WORK2MEM) * stepmul;
  l_mem stepsize = (g->gcstepsize <= log2maxs(l_mem))
                 ? ((cast(l_mem1) << g->gcstepsize) / WORK2MEM) * stepmul
                 : MAX_LMEM;  /* overflow; keep maximum value */

  int oldgcstate = g->gcstate;
  do {  /* repeat until pause or enough "credit" (negative debt) */
    lu_mem work = singlestep(L);  /* perform one single step */
    debt -= work * WORK2MEM;
    singlestep(L);
  } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
  if (g->gcstate == GCSpause && oldgcstate != GCSenterinc)
    setpause(g);  /* pause until next cycle */
  else {
    debt = (debt / stepmul) * WORK2MEM;  /* convert 'work units' to bytes */
    luaE_setdebt(gdebt);
  }
}


2. in luaC_step function, it should be setdebt to avoid being called too often as Lua5.3.5 when gc is stopped

void luaC_step (lua_State *L) {
  global_State *g = G(L);
  lua_assert(!g->gcemergency);
  if (g->gcrunning) {  /* running? */
    if(isdecGCmodegen(g))
      genstep(Lg);
    else
      incstep(Lg);
  }
  else
  {
    if(!isdecGCmodegen(g))
    {
      luaE_setdebt(g, -GCSTEPSIZE * 10);  /* avoid being called too often */
    }
  }
}

-----------------------------------------------------------------------------------------------------------------------
best regard
radlywang