From 6efffb9acd65020687627866afe877f0f5071e8e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 29 May 2012 14:52:17 -0300 Subject: only count in 'atomic' objects marked for the first time --- lgc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lgc.c b/lgc.c index 64e8df97..5583d3a1 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.128 2012/05/23 15:43:14 roberto Exp roberto $ +** $Id: lgc.c,v 2.129 2012/05/28 20:41:00 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -962,7 +962,7 @@ void luaC_freeallobjects (lua_State *L) { static l_mem atomic (lua_State *L) { global_State *g = G(L); - l_mem trav = g->GCmemtrav; + l_mem trav = -g->GCmemtrav; /* start counting work */ GCObject *origweak, *origall; lua_assert(!iswhite(obj2gco(g->mainthread))); markobject(g, L); /* mark running thread */ @@ -971,6 +971,8 @@ static l_mem atomic (lua_State *L) { markmt(g); /* mark basic metatables */ /* remark occasional upvalues of (maybe) dead threads */ remarkupvals(g); + propagateall(g); /* propagate changes */ + trav += g->GCmemtrav; /* count work done til now */ /* traverse objects caught by write barrier and by 'remarkupvals' */ retraversegrays(g); convergeephemerons(g); @@ -979,10 +981,11 @@ static l_mem atomic (lua_State *L) { clearvalues(g, g->weak, NULL); clearvalues(g, g->allweak, NULL); origweak = g->weak; origall = g->allweak; + trav -= g->GCmemtrav; /* restart counting work */ separatetobefnz(L, 0); /* separate objects to be finalized */ - markbeingfnz(g); /* mark userdata that will be finalized */ + markbeingfnz(g); /* mark objects that will be finalized */ propagateall(g); /* remark, to propagate `preserveness' */ - trav = g->GCmemtrav - trav; /* avoid adding convergence twice */ + trav += g->GCmemtrav; /* add work done til now */ convergeephemerons(g); /* at this point, all resurrected objects are marked. */ /* remove dead objects from weak tables */ @@ -994,7 +997,7 @@ static l_mem atomic (lua_State *L) { g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ entersweep(L); /* prepare to sweep strings */ /*lua_checkmemory(L);*/ - return trav; /* reasonable estimate of the work done by 'atomic' */ + return trav; /* estimate of the objects marked by 'atomic' */ } -- cgit v1.2.3-55-g6feb