diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-05-31 18:28:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-05-31 18:28:59 -0300 |
commit | c510d94549c5cb55c7ebdb04b67ae0fc1bf3f790 (patch) | |
tree | e216a17badcddc6f8a1f5b313e3af5a5e1435b59 /lgc.c | |
parent | 4dd0622d0c5f94b46d1e72b75a7c734bfd709e0c (diff) | |
download | lua-c510d94549c5cb55c7ebdb04b67ae0fc1bf3f790.tar.gz lua-c510d94549c5cb55c7ebdb04b67ae0fc1bf3f790.tar.bz2 lua-c510d94549c5cb55c7ebdb04b67ae0fc1bf3f790.zip |
includes counts from 'sweeptolive' in cost of atomic step
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.131 2012/05/30 16:01:10 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.132 2012/05/31 20:26:14 roberto Exp $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -757,11 +757,14 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { | |||
757 | /* | 757 | /* |
758 | ** sweep a list until a live object (or end of list) | 758 | ** sweep a list until a live object (or end of list) |
759 | */ | 759 | */ |
760 | static GCObject **sweeptolive (lua_State *L, GCObject **p) { | 760 | static GCObject **sweeptolive (lua_State *L, GCObject **p, int *n) { |
761 | GCObject ** old = p; | 761 | GCObject ** old = p; |
762 | int i = 0; | ||
762 | do { | 763 | do { |
764 | i++; | ||
763 | p = sweeplist(L, p, 1); | 765 | p = sweeplist(L, p, 1); |
764 | } while (p == old); | 766 | } while (p == old); |
767 | if (n) *n += i; | ||
765 | return p; | 768 | return p; |
766 | } | 769 | } |
767 | 770 | ||
@@ -880,7 +883,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { | |||
880 | GCheader *ho = gch(o); | 883 | GCheader *ho = gch(o); |
881 | if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */ | 884 | if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */ |
882 | lua_assert(issweepphase(g)); | 885 | lua_assert(issweepphase(g)); |
883 | g->sweepgc = sweeptolive(L, g->sweepgc); | 886 | g->sweepgc = sweeptolive(L, g->sweepgc, NULL); |
884 | } | 887 | } |
885 | /* search for pointer pointing to 'o' */ | 888 | /* search for pointer pointing to 'o' */ |
886 | for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ } | 889 | for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ } |
@@ -915,15 +918,18 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { | |||
915 | ** object inside the list (instead of to the header), so that the real | 918 | ** object inside the list (instead of to the header), so that the real |
916 | ** sweep do not need to skip objects created between "now" and the start | 919 | ** sweep do not need to skip objects created between "now" and the start |
917 | ** of the real sweep. | 920 | ** of the real sweep. |
921 | ** Returns how many objects it sweeped. | ||
918 | */ | 922 | */ |
919 | static void entersweep (lua_State *L) { | 923 | static int entersweep (lua_State *L) { |
920 | global_State *g = G(L); | 924 | global_State *g = G(L); |
925 | int n = 0; | ||
921 | g->gcstate = GCSsweepstring; | 926 | g->gcstate = GCSsweepstring; |
922 | lua_assert(g->sweepgc == NULL && g->sweepfin == NULL); | 927 | lua_assert(g->sweepgc == NULL && g->sweepfin == NULL); |
923 | /* prepare to sweep strings, finalizable objects, and regular objects */ | 928 | /* prepare to sweep strings, finalizable objects, and regular objects */ |
924 | g->sweepstrgc = 0; | 929 | g->sweepstrgc = 0; |
925 | g->sweepfin = sweeptolive(L, &g->finobj); | 930 | g->sweepfin = sweeptolive(L, &g->finobj, &n); |
926 | g->sweepgc = sweeptolive(L, &g->allgc); | 931 | g->sweepgc = sweeptolive(L, &g->allgc, &n); |
932 | return n; | ||
927 | } | 933 | } |
928 | 934 | ||
929 | 935 | ||
@@ -1039,12 +1045,13 @@ static lu_mem singlestep (lua_State *L) { | |||
1039 | } | 1045 | } |
1040 | else { /* no more `gray' objects */ | 1046 | else { /* no more `gray' objects */ |
1041 | lu_mem work; | 1047 | lu_mem work; |
1048 | int sw; | ||
1042 | g->gcstate = GCSatomic; /* finish mark phase */ | 1049 | g->gcstate = GCSatomic; /* finish mark phase */ |
1043 | g->GCestimate = g->GCmemtrav; /* save what was counted */; | 1050 | g->GCestimate = g->GCmemtrav; /* save what was counted */; |
1044 | work = atomic(L); /* add what was traversed by 'atomic' */ | 1051 | work = atomic(L); /* add what was traversed by 'atomic' */ |
1045 | g->GCestimate += work; /* estimate of total memory traversed */ | 1052 | g->GCestimate += work; /* estimate of total memory traversed */ |
1046 | entersweep(L); | 1053 | sw = entersweep(L); |
1047 | return work + 2 * GCSWEEPCOST; | 1054 | return work + sw * GCSWEEPCOST; |
1048 | } | 1055 | } |
1049 | } | 1056 | } |
1050 | case GCSsweepstring: { | 1057 | case GCSsweepstring: { |