diff options
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 58 |
1 files changed, 20 insertions, 38 deletions
@@ -113,13 +113,7 @@ static void entersweep (lua_State *L); | |||
113 | static size_t objsize (GCObject *o) { | 113 | static size_t objsize (GCObject *o) { |
114 | switch (o->tt) { | 114 | switch (o->tt) { |
115 | case LUA_VTABLE: { | 115 | case LUA_VTABLE: { |
116 | /* Fow now, table size does not consider 'haslastfree' */ | 116 | return luaH_size(gco2t(o)); |
117 | Table *t = gco2t(o); | ||
118 | size_t sz = sizeof(Table) | ||
119 | + luaH_realasize(t) * (sizeof(Value) + 1); | ||
120 | if (!isdummy(t)) | ||
121 | sz += sizenode(t) * sizeof(Node); | ||
122 | return sz; | ||
123 | } | 117 | } |
124 | case LUA_VLCL: { | 118 | case LUA_VLCL: { |
125 | LClosure *cl = gco2lcl(o); | 119 | LClosure *cl = gco2lcl(o); |
@@ -135,26 +129,10 @@ static size_t objsize (GCObject *o) { | |||
135 | return sizeudata(u->nuvalue, u->len); | 129 | return sizeudata(u->nuvalue, u->len); |
136 | } | 130 | } |
137 | case LUA_VPROTO: { | 131 | case LUA_VPROTO: { |
138 | Proto *p = gco2p(o); | 132 | return luaF_protosize(gco2p(o)); |
139 | size_t sz = sizeof(Proto) | ||
140 | + cast_uint(p->sizep) * sizeof(Proto*) | ||
141 | + cast_uint(p->sizek) * sizeof(TValue) | ||
142 | + cast_uint(p->sizelocvars) * sizeof(LocVar) | ||
143 | + cast_uint(p->sizeupvalues) * sizeof(Upvaldesc); | ||
144 | if (!(p->flag & PF_FIXED)) { | ||
145 | sz += cast_uint(p->sizecode) * sizeof(Instruction) | ||
146 | + cast_uint(p->sizelineinfo) * sizeof(lu_byte) | ||
147 | + cast_uint(p->sizeabslineinfo) * sizeof(AbsLineInfo); | ||
148 | } | ||
149 | return sz; | ||
150 | } | 133 | } |
151 | case LUA_VTHREAD: { | 134 | case LUA_VTHREAD: { |
152 | lua_State *L1 = gco2th(o); | 135 | return luaE_statesize(gco2th(o)); |
153 | size_t sz = sizeof(lua_State) + LUA_EXTRASPACE | ||
154 | + cast_uint(L1->nci) * sizeof(CallInfo); | ||
155 | if (L1->stack.p != NULL) | ||
156 | sz += cast_uint(stacksize(L1) + EXTRA_STACK) * sizeof(StackValue); | ||
157 | return sz; | ||
158 | } | 136 | } |
159 | case LUA_VSHRSTR: { | 137 | case LUA_VSHRSTR: { |
160 | TString *ts = gco2ts(o); | 138 | TString *ts = gco2ts(o); |
@@ -164,7 +142,9 @@ static size_t objsize (GCObject *o) { | |||
164 | TString *ts = gco2ts(o); | 142 | TString *ts = gco2ts(o); |
165 | return luaS_sizelngstr(ts->u.lnglen, ts->shrlen); | 143 | return luaS_sizelngstr(ts->u.lnglen, ts->shrlen); |
166 | } | 144 | } |
167 | case LUA_VUPVAL: return sizeof(UpVal); | 145 | case LUA_VUPVAL: { |
146 | return sizeof(UpVal); | ||
147 | } | ||
168 | default: lua_assert(0); return 0; | 148 | default: lua_assert(0); return 0; |
169 | } | 149 | } |
170 | } | 150 | } |
@@ -615,7 +595,7 @@ static l_mem traversetable (global_State *g, Table *h) { | |||
615 | } | 595 | } |
616 | else /* not weak */ | 596 | else /* not weak */ |
617 | traversestrongtable(g, h); | 597 | traversestrongtable(g, h); |
618 | return 1 + sizenode(h) + h->alimit; | 598 | return 1 + 2*sizenode(h) + h->alimit; |
619 | } | 599 | } |
620 | 600 | ||
621 | 601 | ||
@@ -1291,10 +1271,11 @@ static void minor2inc (lua_State *L, global_State *g, lu_byte kind) { | |||
1291 | /* | 1271 | /* |
1292 | ** Decide whether to shift to major mode. It tests two conditions: | 1272 | ** Decide whether to shift to major mode. It tests two conditions: |
1293 | ** 1) Whether the number of added old objects in this collection is more | 1273 | ** 1) Whether the number of added old objects in this collection is more |
1294 | ** than half the number of new objects. ('step' is the number of objects | 1274 | ** than half the number of new objects. ('step' is equal to the debt set |
1295 | ** created between minor collections. Except for forward barriers, it | 1275 | ** to trigger the next minor collection; that is equal to the number |
1296 | ** is the maximum number of objects that can become old in each minor | 1276 | ** of objects created since the previous minor collection. Except for |
1297 | ** collection.) | 1277 | ** forward barriers, it is the maximum number of objects that can become |
1278 | ** old in each minor collection.) | ||
1298 | ** 2) Whether the accumulated number of added old objects is larger | 1279 | ** 2) Whether the accumulated number of added old objects is larger |
1299 | ** than 'minormajor'% of the number of lived objects after the last | 1280 | ** than 'minormajor'% of the number of lived objects after the last |
1300 | ** major collection. (That percentage is computed in 'limit'.) | 1281 | ** major collection. (That percentage is computed in 'limit'.) |
@@ -1678,7 +1659,7 @@ void luaC_runtilstate (lua_State *L, int state, int fast) { | |||
1678 | 1659 | ||
1679 | 1660 | ||
1680 | /* | 1661 | /* |
1681 | ** Performs a basic incremental step. The debt and step size are | 1662 | ** Performs a basic incremental step. The step size is |
1682 | ** converted from bytes to "units of work"; then the function loops | 1663 | ** converted from bytes to "units of work"; then the function loops |
1683 | ** running single steps until adding that many units of work or | 1664 | ** running single steps until adding that many units of work or |
1684 | ** finishing a cycle (pause state). Finally, it sets the debt that | 1665 | ** finishing a cycle (pause state). Finally, it sets the debt that |
@@ -1689,7 +1670,9 @@ static void incstep (lua_State *L, global_State *g) { | |||
1689 | l_mem work2do = applygcparam(g, STEPMUL, stepsize); | 1670 | l_mem work2do = applygcparam(g, STEPMUL, stepsize); |
1690 | l_mem stres; | 1671 | l_mem stres; |
1691 | int fast = (work2do == 0); /* special case: do a full collection */ | 1672 | int fast = (work2do == 0); /* special case: do a full collection */ |
1673 | //printf("\n** %ld %ld %d\n", work2do, stepsize, g->gcstate); | ||
1692 | do { /* repeat until enough work */ | 1674 | do { /* repeat until enough work */ |
1675 | //printf("%d-", g->gcstate); | ||
1693 | stres = singlestep(L, fast); /* perform one single step */ | 1676 | stres = singlestep(L, fast); /* perform one single step */ |
1694 | if (stres == step2minor) /* returned to minor collections? */ | 1677 | if (stres == step2minor) /* returned to minor collections? */ |
1695 | return; /* nothing else to be done here */ | 1678 | return; /* nothing else to be done here */ |
@@ -1716,21 +1699,20 @@ void luaC_step (lua_State *L) { | |||
1716 | if (!gcrunning(g)) /* not running? */ | 1699 | if (!gcrunning(g)) /* not running? */ |
1717 | luaE_setdebt(g, 20000); | 1700 | luaE_setdebt(g, 20000); |
1718 | else { | 1701 | else { |
1719 | // printf("mem: %ld kind: %s ", gettotalbytes(g), | 1702 | //printf("mem: %ld kind: %s ", gettotalbytes(g), |
1720 | // g->gckind == KGC_INC ? "inc" : g->gckind == KGC_GENMAJOR ? "genmajor" : | 1703 | // g->gckind == KGC_INC ? "inc" : g->gckind == KGC_GENMAJOR ? "genmajor" : |
1721 | // "genminor"); | 1704 | // "genminor"); |
1722 | switch (g->gckind) { | 1705 | switch (g->gckind) { |
1723 | case KGC_INC: case KGC_GENMAJOR: | 1706 | case KGC_INC: case KGC_GENMAJOR: |
1724 | // printf("(%d -> ", g->gcstate); | ||
1725 | incstep(L, g); | 1707 | incstep(L, g); |
1726 | // printf("%d) ", g->gcstate); | 1708 | //printf("%d) ", g->gcstate); |
1727 | break; | 1709 | break; |
1728 | case KGC_GENMINOR: | 1710 | case KGC_GENMINOR: |
1729 | youngcollection(L, g); | 1711 | youngcollection(L, g); |
1730 | setminordebt(g); | 1712 | setminordebt(g); |
1731 | break; | 1713 | break; |
1732 | } | 1714 | } |
1733 | // printf("-> mem: %ld debt: %ld\n", gettotalbytes(g), g->GCdebt); | 1715 | //printf("-> mem: %ld debt: %ld\n", gettotalbytes(g), g->GCdebt); |
1734 | } | 1716 | } |
1735 | } | 1717 | } |
1736 | 1718 | ||