diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-08-10 16:17:23 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-08-10 16:17:23 -0300 |
commit | 26ae992129d5566ee973c0ff78fd709cd5d91271 (patch) | |
tree | 81082d5ee1abaf94175d7cc66ae2331853ce24ab /lgc.c | |
parent | f87057690b3afa7812d0ef5251ce103902a37c96 (diff) | |
download | lua-26ae992129d5566ee973c0ff78fd709cd5d91271.tar.gz lua-26ae992129d5566ee973c0ff78fd709cd5d91271.tar.bz2 lua-26ae992129d5566ee973c0ff78fd709cd5d91271.zip |
less conservative write barrier for tables
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -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; |