diff options
| -rw-r--r-- | lapi.c | 6 | ||||
| -rw-r--r-- | lgc.c | 34 | ||||
| -rw-r--r-- | lgc.h | 6 | ||||
| -rw-r--r-- | ltable.c | 4 | ||||
| -rw-r--r-- | lvm.c | 6 |
5 files changed, 38 insertions, 18 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.13 2004/06/30 14:15:23 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.14 2004/07/09 14:20:22 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -613,7 +613,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { | |||
| 613 | t = luaA_index(L, idx); | 613 | t = luaA_index(L, idx); |
| 614 | api_check(L, ttistable(t)); | 614 | api_check(L, ttistable(t)); |
| 615 | setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); | 615 | setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); |
| 616 | luaC_barrier(L, hvalue(t), L->top-1); | 616 | luaC_barriert(L, hvalue(t), L->top-1); |
| 617 | L->top -= 2; | 617 | L->top -= 2; |
| 618 | lua_unlock(L); | 618 | lua_unlock(L); |
| 619 | } | 619 | } |
| @@ -626,7 +626,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { | |||
| 626 | o = luaA_index(L, idx); | 626 | o = luaA_index(L, idx); |
| 627 | api_check(L, ttistable(o)); | 627 | api_check(L, ttistable(o)); |
| 628 | setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); | 628 | setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); |
| 629 | luaC_barrier(L, hvalue(o), L->top-1); | 629 | luaC_barriert(L, hvalue(o), L->top-1); |
| 630 | L->top--; | 630 | L->top--; |
| 631 | lua_unlock(L); | 631 | lua_unlock(L); |
| 632 | } | 632 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.6 2004/03/23 12:57:12 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.7 2004/04/30 20:13:38 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -24,9 +24,11 @@ | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | #define GCSTEPSIZE (40*sizeof(TValue)) | 26 | #define GCSTEPSIZE (40*sizeof(TValue)) |
| 27 | #define GCFREECOST (sizeof(TValue)/2) | 27 | #define STEPMUL 2 |
| 28 | #define GCSWEEPCOST sizeof(TValue) | 28 | #define GCFREECOST (sizeof(TValue)/10) |
| 29 | #define GCSWEEPCOST (sizeof(TValue)/20) | ||
| 29 | #define GCFINALIZECOST (10*sizeof(TValue)) | 30 | #define GCFINALIZECOST (10*sizeof(TValue)) |
| 31 | #define WAITNEXTCYCLE (10 * GCSTEPSIZE) | ||
| 30 | 32 | ||
| 31 | 33 | ||
| 32 | #define FIXEDMASK bitmask(FIXEDBIT) | 34 | #define FIXEDMASK bitmask(FIXEDBIT) |
| @@ -531,8 +533,10 @@ static void remarkupvals (global_State *g) { | |||
| 531 | if (iswhite(o)) { | 533 | if (iswhite(o)) { |
| 532 | GCObject *curr; | 534 | GCObject *curr; |
| 533 | for (curr = gco2th(o)->openupval; curr != NULL; curr = curr->gch.next) { | 535 | for (curr = gco2th(o)->openupval; curr != NULL; curr = curr->gch.next) { |
| 534 | if (isgray(curr)) | 536 | if (isgray(curr)) { |
| 535 | markvalue(g, gco2uv(curr)->v); | 537 | UpVal *uv = gco2uv(curr); |
| 538 | markvalue(g, uv->v); | ||
| 539 | } | ||
| 536 | } | 540 | } |
| 537 | } | 541 | } |
| 538 | } | 542 | } |
| @@ -612,14 +616,16 @@ static l_mem singlestep (lua_State *L, l_mem lim) { | |||
| 612 | 616 | ||
| 613 | void luaC_step (lua_State *L) { | 617 | void luaC_step (lua_State *L) { |
| 614 | global_State *g = G(L); | 618 | global_State *g = G(L); |
| 615 | l_mem lim = (g->nblocks - (g->GCthreshold - GCSTEPSIZE)) * 2; | 619 | l_mem lim = (g->nblocks - (g->GCthreshold - GCSTEPSIZE)) * STEPMUL; |
| 616 | do { | 620 | do { |
| 617 | lim = singlestep(L, lim); | 621 | lim = singlestep(L, lim); |
| 618 | if (g->gcstate == GCSfinalize && g->tmudata == NULL) | 622 | if (g->gcstate == GCSfinalize && g->tmudata == NULL) { |
| 623 | lim = -WAITNEXTCYCLE; | ||
| 619 | break; /* do not start new collection */ | 624 | break; /* do not start new collection */ |
| 625 | } | ||
| 620 | } while (lim > 0); | 626 | } while (lim > 0); |
| 621 | g->GCthreshold = g->nblocks + GCSTEPSIZE - lim/2; | 627 | g->GCthreshold = g->nblocks + GCSTEPSIZE - lim/STEPMUL; |
| 622 | lua_assert((long)g->nblocks + (long)GCSTEPSIZE >= lim/2); | 628 | lua_assert((long)g->nblocks + (long)GCSTEPSIZE >= lim/STEPMUL); |
| 623 | } | 629 | } |
| 624 | 630 | ||
| 625 | 631 | ||
| @@ -648,6 +654,16 @@ void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { | |||
| 648 | } | 654 | } |
| 649 | 655 | ||
| 650 | 656 | ||
| 657 | void luaC_barrierback (lua_State *L, GCObject *o, GCObject *v) { | ||
| 658 | global_State *g = G(L); | ||
| 659 | lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); | ||
| 660 | lua_assert(g->gcstate != GCSfinalize); | ||
| 661 | black2gray(o); /* make table gray (again) */ | ||
| 662 | gco2h(o)->gclist = g->grayagain; | ||
| 663 | g->grayagain = o; | ||
| 664 | } | ||
| 665 | |||
| 666 | |||
| 651 | void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { | 667 | void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { |
| 652 | global_State *g = G(L); | 668 | global_State *g = G(L); |
| 653 | o->gch.next = g->rootgc; | 669 | o->gch.next = g->rootgc; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.h,v 2.4 2004/03/09 17:34:35 roberto Exp roberto $ | 2 | ** $Id: lgc.h,v 2.5 2004/03/15 21:04:33 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -77,6 +77,9 @@ | |||
| 77 | #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ | 77 | #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ |
| 78 | luaC_barrierf(L,obj2gco(p),gcvalue(v)); } | 78 | luaC_barrierf(L,obj2gco(p),gcvalue(v)); } |
| 79 | 79 | ||
| 80 | #define luaC_barriert(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ | ||
| 81 | luaC_barrierback(L,obj2gco(p),gcvalue(v)); } | ||
| 82 | |||
| 80 | #define luaC_objbarrier(L,p,o) \ | 83 | #define luaC_objbarrier(L,p,o) \ |
| 81 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ | 84 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ |
| 82 | luaC_barrierf(L,obj2gco(p),obj2gco(o)); } | 85 | luaC_barrierf(L,obj2gco(p),obj2gco(o)); } |
| @@ -89,6 +92,7 @@ void luaC_fullgc (lua_State *L); | |||
| 89 | void luaC_link (lua_State *L, GCObject *o, lu_byte tt); | 92 | void luaC_link (lua_State *L, GCObject *o, lu_byte tt); |
| 90 | void luaC_linkupval (lua_State *L, UpVal *uv); | 93 | void luaC_linkupval (lua_State *L, UpVal *uv); |
| 91 | void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); | 94 | void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); |
| 95 | void luaC_barrierback (lua_State *L, GCObject *o, GCObject *v); | ||
| 92 | 96 | ||
| 93 | 97 | ||
| 94 | #endif | 98 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.2 2004/03/26 14:02:41 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.3 2004/04/30 20:13:38 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -375,7 +375,7 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { | |||
| 375 | } | 375 | } |
| 376 | } | 376 | } |
| 377 | setobj2t(L, gkey(mp), key); | 377 | setobj2t(L, gkey(mp), key); |
| 378 | luaC_barrier(L, t, key); | 378 | luaC_barriert(L, t, key); |
| 379 | lua_assert(ttisnil(gval(mp))); | 379 | lua_assert(ttisnil(gval(mp))); |
| 380 | for (;;) { /* correct `firstfree' */ | 380 | for (;;) { /* correct `firstfree' */ |
| 381 | if (ttisnil(gkey(t->firstfree))) | 381 | if (ttisnil(gkey(t->firstfree))) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.10 2004/06/29 17:05:00 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.11 2004/06/29 18:49:02 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -150,7 +150,7 @@ StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
| 150 | if (!ttisnil(oldval) || /* result is no nil? */ | 150 | if (!ttisnil(oldval) || /* result is no nil? */ |
| 151 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ | 151 | (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ |
| 152 | setobj2t(L, oldval, val); | 152 | setobj2t(L, oldval, val); |
| 153 | luaC_barrier(L, h, val); | 153 | luaC_barriert(L, h, val); |
| 154 | return L->base; | 154 | return L->base; |
| 155 | } | 155 | } |
| 156 | /* else will try the tag method */ | 156 | /* else will try the tag method */ |
| @@ -729,7 +729,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 729 | for (; n > 0; n--) { | 729 | for (; n > 0; n--) { |
| 730 | TValue *val = ra+n; | 730 | TValue *val = ra+n; |
| 731 | setobj2t(L, luaH_setnum(L, h, last--), val); | 731 | setobj2t(L, luaH_setnum(L, h, last--), val); |
| 732 | luaC_barrier(L, h, val); | 732 | luaC_barriert(L, h, val); |
| 733 | } | 733 | } |
| 734 | continue; | 734 | continue; |
| 735 | } | 735 | } |
