public static void luaS_resize (lua_State L, int newsize) { GCObject[] newhash; stringtable tb; int i; if (G(L).gcstate == GCSsweepstring) return; /* cannot resize during GC traverse */ newhash = new GCObject[newsize]; AddTotalBytes(L, newsize * GetUnmanagedSize(typeof(GCObjectRef))); tb = G(L).strt; for (i=0; i<newsize; i++) newhash[i] = null; /* rehash */ for (i=0; i<tb.size; i++) { GCObject p = tb.hash[i]; while (p != null) { /* for each node in the list */ GCObject next = p.gch.next; /* save next */ uint h = gco2ts(p).hash; int h1 = (int)lmod(h, newsize); /* new position */ lua_assert((int)(h%newsize) == lmod(h, newsize)); p.gch.next = newhash[h1]; /* chain it */ newhash[h1] = p; p = next; } } //luaM_freearray(L, tb.hash); if (tb.hash != null) SubtractTotalBytes(L, tb.hash.Length * GetUnmanagedSize(typeof(GCObjectRef))); tb.size = newsize; tb.hash = newhash; }
//static void reallymarkobject (global_State *g, GCObject *o); /* ** {====================================================== ** Generic functions ** ======================================================= */ private static void linktable(Table h, ref GCObject p) { h.gclist = p; p = obj2gco(h); }
internal static void SetSValue(LuaState L, Lua.LuaTypeValue obj, GCObject x) { obj.value.gc = x; obj.tt = LUA_TSTRING; CheckLiveness(G(L), obj); }
public static void black2gray(GCObject x) { resetbit(ref x.gch.marked, BLACKBIT); }
public static void white2gray(GCObject x) { reset2bits(ref x.gch.marked, WHITE0BIT, WHITE1BIT); }
public static bool iswhite(GCObject x) { return test2bits(x.gch.marked, WHITE0BIT, WHITE1BIT); }
public static void gray2black(GCObject x) { l_setbit(ref x.gch.marked, BLACKBIT); }
/* ** clear collected entries from weaktables */ private static void ClearTable(GCObject l) { while (l != null) { Table h = gco2h(l); int i = h.sizearray; LuaAssert(TestBit(h.marked, VALUEWEAKBIT) || TestBit(h.marked, KEYWEAKBIT)); if (TestBit(h.marked, VALUEWEAKBIT)) { while (i--!= 0) { TValue o = h.array[i]; if (IsCleared(o, false)) /* value was collected? */ SetNilValue(o); /* remove value */ } } i = SizeNode(h); while (i-- != 0) { Node n = gnode(h, i); if (!TTIsNil(gval(n)) && /* non-empty entry? */ (IsCleared(key2tval(n), true) || IsCleared(gval(n), false))) { SetNilValue(gval(n)); /* remove value ... */ RemoveEntry(n); /* remove entry from Table */ } } l = h.gclist; } }
public static void gray2black(GCObject x) { l_setbit(ref x.marked, BLACKBIT); }
public static void changewhite(GCObject x) { x.marked ^= (byte)WHITEBITS; }
public static bool isdead(global_State g, GCObject v) { return(isdeadm(otherwhite(g), v.marked)); }
public static bool tofinalize(GCObject x) { return(testbit(x.marked, FINALIZEDBIT)); }
public static bool isgray(GCObject x) /* neither white nor black */ { return(!testbits(x.marked, WHITEBITS | bitmask(BLACKBIT))); }
public static bool isblack(GCObject x) { return(testbit(x.marked, BLACKBIT)); }
public static bool iswhite(GCObject x) { return(testbits(x.marked, WHITEBITS)); }
public static void LuaCBarrierF(LuaState L, GCObject o, GCObject v) { GlobalState g = G(L); LuaAssert(IsBlack(o) && IsWhite(v) && !IsDead(g, v) && !IsDead(g, o)); LuaAssert(g.gcstate != GCSfinalize && g.gcstate != GCSpause); LuaAssert(TType(o.gch) != LUA_TTABLE); /* must keep invariant? */ if (g.gcstate == GCSpropagate) ReallyMarkObject(g, v); /* restore invariant */ else /* don't mind */ MakeWhite(g, o); /* mark as white just to avoid other barriers */ }
public static void MakeWhite(GlobalState g, GCObject x) { x.gch.marked = (byte)(x.gch.marked & maskmarks | LuaCWhite(g)); }
public static GCheader gch(GCObject o) { return(o.gch); }
private static void ReallyMarkObject(GlobalState g, GCObject o) { LuaAssert(IsWhite(o) && !IsDead(g, o)); White2Gray(o); switch (o.gch.tt) { case LUA_TSTRING: { return; } case LUA_TUSERDATA: { Table mt = gco2u(o).metatable; Gray2Black(o); /* udata are never gray */ if (mt != null) MarkObject(g, mt); MarkObject(g, gco2u(o).env); return; } case LUATUPVAL: { UpVal uv = gco2uv(o); MarkValue(g, uv.v); if (uv.v == uv.u.value) /* closed? */ Gray2Black(o); /* open upvalues are never black */ return; } case LUA_TFUNCTION: { gco2cl(o).c.gclist = g.gray; g.gray = o; break; } case LUA_TTABLE: { gco2h(o).gclist = g.gray; g.gray = o; break; } case LUA_TTHREAD: { gco2th(o).gclist = g.gray; g.gray = o; break; } case LUATPROTO: { gco2p(o).gclist = g.gray; g.gray = o; break; } default: LuaAssert(0); break; } }
public void set(GCObject value) { array_elements[array_index] = value; }
public static bool isdead(global_State g, GCObject v) { return (v.gch.marked & otherwhite(g) & WHITEBITS) != 0; }
public void set(GCObject value) { this.g.allgc = value; }
public static void luaC_link(lua_State L, GCObject o, lu_byte tt) { global_State g = G(L); o.gch.next = g.rootgc; g.rootgc = o; o.gch.marked = luaC_white(g); o.gch.tt = tt; }
public void set(GCObject value) { this.header.next = value; }
private static void freeobj(lua_State L, GCObject o) { switch (o.gch.tt) { case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; case LUA_TTABLE: luaH_free(L, gco2h(o)); break; case LUA_TTHREAD: { lua_assert(gco2th(o) != L && gco2th(o) != G(L).mainthread); luaE_freethread(L, gco2th(o)); break; } case LUA_TSTRING: { G(L).strt.nuse--; SubtractTotalBytes(L, sizestring(gco2ts(o))); luaM_freemem(L, gco2ts(o)); break; } case LUA_TUSERDATA: { SubtractTotalBytes(L, sizeudata(gco2u(o))); luaM_freemem(L, gco2u(o)); break; } default: lua_assert(0); break; } }
public void set(GCObject value) { this.g.finobj = value; }
internal static void setthvalue(lua_State L, TValue obj, GCObject x) { obj.value.gc = x; obj.tt = LUA_TTHREAD; checkliveness(G(L), obj); }
public void set(GCObject value) { this.g.tobefnz = value; }
internal static void SetUValue(LuaState L, TValue obj, GCObject x) { obj.value.gc = x; obj.tt = LUA_TUSERDATA; CheckLiveness(G(L), obj); }
public void set(GCObject value) { this.g.fixedgc = value; }
public static bool IsWhite(GCObject x) { return Test2Bits(x.gch.marked, WHITE0BIT, WHITE1BIT); }
public void set(GCObject value) { this.g.mt_ = value; }
public static void LuaCLink(LuaState L, GCObject o, LuaByteType tt) { GlobalState g = G(L); o.gch.next = g.rootgc; g.rootgc = o; o.gch.marked = LuaCWhite(g); o.gch.tt = tt; }
public void set(GCObject value) { this.g.nullp = value; }
public static void White2Gray(GCObject x) { Reset2Bits(ref x.gch.marked, WHITE0BIT, WHITE1BIT); }
/* macros to convert a GCObject into a specific value */ public static TString rawgco2ts(GCObject o) { return((TString)check_exp(novariant(o.gch.tt) == LUA_TSTRING, o.ts)); }
private static void FreeObj(LuaState L, GCObject o) { switch (o.gch.tt) { case LUATPROTO: LuaFFreeProto(L, gco2p(o)); break; case LUA_TFUNCTION: LuaFFreeClosure(L, gco2cl(o)); break; case LUATUPVAL: LuaFreeUpVal(L, gco2uv(o)); break; case LUA_TTABLE: luaH_free(L, gco2h(o)); break; case LUA_TTHREAD: { LuaAssert(gco2th(o) != L && gco2th(o) != G(L).mainthread); luaE_freethread(L, gco2th(o)); break; } case LUA_TSTRING: { G(L).strt.nuse--; SubtractTotalBytes(L, sizestring(gco2ts(o))); LuaMFreeMem(L, gco2ts(o)); break; } case LUA_TUSERDATA: { SubtractTotalBytes(L, sizeudata(gco2u(o))); LuaMFreeMem(L, gco2u(o)); break; } default: LuaAssert(0); break; } }
public static TString gco2ts(GCObject o) { return((TString)(rawgco2ts(o).tsv)); }
public static void Black2Gray(GCObject x) { ResetBit(ref x.gch.marked, BLACKBIT); }
public static Udata rawgco2u(GCObject o) { return((Udata)check_exp(o.gch.tt == LUA_TUSERDATA, o.u)); }
public static bool isblack(GCObject x) { return testbit(x.gch.marked, BLACKBIT); }
public static Udata gco2u(GCObject o) { return((Udata)(rawgco2u(o).uv)); }
public static bool isgray(GCObject x) { return (!isblack(x) && !iswhite(x)); }
public static LClosure gco2lcl(GCObject o) { return((LClosure)check_exp(o.gch.tt == LUA_TLCL, o.cl.l)); }
public static void luaC_barrierf(lua_State L, GCObject o, GCObject v) { global_State g = G(L); lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); lua_assert(g.gcstate != GCSfinalize && g.gcstate != GCSpause); lua_assert(ttype(o.gch) != LUA_TTABLE); /* must keep invariant? */ if (g.gcstate == GCSpropagate) reallymarkobject(g, v); /* restore invariant */ else /* don't mind */ makewhite(g, o); /* mark as white just to avoid other barriers */ }
public static CClosure gco2ccl(GCObject o) { return((CClosure)check_exp(o.gch.tt == LUA_TCCL, o.cl.c)); }
public static void makewhite(global_State g, GCObject x) { x.gch.marked = (byte)(x.gch.marked & maskmarks | luaC_white(g)); }
public static Closure gco2cl(GCObject o) { return((Closure)check_exp(novariant(o.gch.tt) == LUA_TFUNCTION, o.cl)); }
/* ** clear collected entries from weaktables */ private static void cleartable(GCObject l) { while (l != null) { Table h = gco2h(l); int i = h.sizearray; lua_assert(testbit(h.marked, VALUEWEAKBIT) || testbit(h.marked, KEYWEAKBIT)); if (testbit(h.marked, VALUEWEAKBIT)) { while (i--!= 0) { TValue o = h.array[i]; if (iscleared(o, false)) /* value was collected? */ setnilvalue(o); /* remove value */ } } i = sizenode(h); while (i-- != 0) { Node n = gnode(h, i); if (!ttisnil(gval(n)) && /* non-empty entry? */ (iscleared(key2tval(n), true) || iscleared(gval(n), false))) { setnilvalue(gval(n)); /* remove value ... */ removeentry(n); /* remove entry from Table */ } } l = h.gclist; } }
public static Table gco2t(GCObject o) { return((Table)check_exp(o.gch.tt == LUA_TTABLE, o.h)); }
private static void reallymarkobject(global_State g, GCObject o) { lua_assert(iswhite(o) && !isdead(g, o)); white2gray(o); switch (o.gch.tt) { case LUA_TSTRING: { return; } case LUA_TUSERDATA: { Table mt = gco2u(o).metatable; gray2black(o); /* udata are never gray */ if (mt != null) markobject(g, mt); markobject(g, gco2u(o).env); return; } case LUA_TUPVAL: { UpVal uv = gco2uv(o); markvalue(g, uv.v); if (uv.v == uv.u.value) /* closed? */ gray2black(o); /* open upvalues are never black */ return; } case LUA_TFUNCTION: { gco2cl(o).c.gclist = g.gray; g.gray = o; break; } case LUA_TTABLE: { gco2h(o).gclist = g.gray; g.gray = o; break; } case LUA_TTHREAD: { gco2th(o).gclist = g.gray; g.gray = o; break; } case LUA_TPROTO: { gco2p(o).gclist = g.gray; g.gray = o; break; } default: lua_assert(0); break; } }
public static Proto gco2p(GCObject o) { return((Proto)check_exp(o.gch.tt == LUA_TPROTO, o.p)); }
public static void changewhite(GCObject x) { x.gch.marked ^= (byte)WHITEBITS; }
public static lua_State gco2th(GCObject o) { return((lua_State)check_exp(o.gch.tt == LUA_TTHREAD, o.th)); }
internal static void setuvalue(lua_State L, TValue obj, GCObject x) { obj.value.gc = x; obj.tt = LUA_TUSERDATA; checkliveness(G(L), obj); }
internal static void SetTTHValue(LuaState L, TValue obj, GCObject x) { obj.value.gc = x; obj.tt = LUA_TTHREAD; CheckLiveness(G(L), obj); }
public static bool IsGray(GCObject x) { return (!IsBlack(x) && !IsWhite(x)); }
public static void black2gray(GCObject x) { resetbit(ref gch(x).marked, BLACKBIT); }