aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-04-30 15:37:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-04-30 15:37:14 -0300
commit4d871ee973394a0d629894226f2817b3803de205 (patch)
tree86558b21fd480dbec8656224a17edb45967a990d
parentb9e1dec2cbba49c7d6f902080beaf7467231e1fd (diff)
downloadlua-4d871ee973394a0d629894226f2817b3803de205.tar.gz
lua-4d871ee973394a0d629894226f2817b3803de205.tar.bz2
lua-4d871ee973394a0d629894226f2817b3803de205.zip
"gray lists" only need to be valid when 'keepinvariant' is true
-rw-r--r--lgc.c21
-rw-r--r--ltests.c5
2 files changed, 11 insertions, 15 deletions
diff --git a/lgc.c b/lgc.c
index 6eac4f43..43927a93 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.81 2010/04/29 17:32:40 roberto Exp roberto $ 2** $Id: lgc.c,v 2.82 2010/04/29 21:43:36 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*/
@@ -23,6 +23,7 @@
23#include "ltm.h" 23#include "ltm.h"
24 24
25 25
26
26#define GCSTEPSIZE 1024 27#define GCSTEPSIZE 1024
27#define GCSWEEPMAX 40 28#define GCSWEEPMAX 40
28#define GCSWEEPCOST 1 29#define GCSWEEPCOST 1
@@ -288,9 +289,8 @@ static void remarkupvals (global_State *g) {
288*/ 289*/
289static void markroot (lua_State *L) { 290static void markroot (lua_State *L) {
290 global_State *g = G(L); 291 global_State *g = G(L);
291 lua_assert(g->gckind == KGC_GEN || 292 g->gray = g->grayagain = NULL;
292 (g->gray == NULL && g->grayagain == NULL && g->weak == NULL && 293 g->weak = g->allweak = g->ephemeron = NULL;
293 g->allweak == NULL && g->ephemeron == NULL));
294 markobject(g, g->mainthread); 294 markobject(g, g->mainthread);
295 markvalue(g, &g->l_registry); 295 markvalue(g, &g->l_registry);
296 markmt(g); 296 markmt(g);
@@ -793,11 +793,6 @@ static void atomic (lua_State *L) {
793 cleartable(g->allweak); 793 cleartable(g->allweak);
794 lua_checkmemory(L); 794 lua_checkmemory(L);
795 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ 795 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
796 if (g->gckind != KGC_GEN) {
797 g->gray = NULL; /* all gray objects will become white */
798 g->grayagain = NULL;
799 g->weak = g->ephemeron = g->allweak = NULL;
800 }
801} 796}
802 797
803 798
@@ -907,7 +902,10 @@ static void step (lua_State *L) {
907 do { /* always perform at least one single step */ 902 do { /* always perform at least one single step */
908 lim -= singlestep(L); 903 lim -= singlestep(L);
909 } while (lim > 0 && g->gcstate != GCSpause); 904 } while (lim > 0 && g->gcstate != GCSpause);
910 g->GCdebt += (g->gcstate != GCSpause) ? -GCSTEPSIZE : stddebt(g); 905 if (g->gcstate != GCSpause)
906 g->GCdebt -= GCSTEPSIZE;
907 else
908 g->GCdebt = stddebt(g);
911} 909}
912 910
913 911
@@ -931,9 +929,6 @@ void luaC_fullgc (lua_State *L, int isemergency) {
931 (as white has not changed, nothing will be collected) */ 929 (as white has not changed, nothing will be collected) */
932 g->sweepstrgc = 0; 930 g->sweepstrgc = 0;
933 g->gcstate = GCSsweepstring; 931 g->gcstate = GCSsweepstring;
934 g->gray = NULL;
935 g->grayagain = NULL;
936 g->weak = g->ephemeron = g->allweak = NULL;
937 } 932 }
938 /* finish any pending sweep phase */ 933 /* finish any pending sweep phase */
939 luaC_runtilstate(L, bit2mask(GCSpause, GCSfinalize)); 934 luaC_runtilstate(L, bit2mask(GCSpause, GCSfinalize));
diff --git a/ltests.c b/ltests.c
index d302b97b..5764a7fa 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.97 2010/04/29 17:33:51 roberto Exp roberto $ 2** $Id: ltests.c,v 2.98 2010/04/29 21:42:33 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -380,6 +380,7 @@ static void checkgraylist (GCObject *l) {
380 380
381 381
382static void markgrays (global_State *g) { 382static void markgrays (global_State *g) {
383 if (!keepinvariant(g)) return;
383 checkgraylist(g->gray); 384 checkgraylist(g->gray);
384 checkgraylist(g->grayagain); 385 checkgraylist(g->grayagain);
385 checkgraylist(g->weak); 386 checkgraylist(g->weak);
@@ -399,7 +400,7 @@ int lua_checkmemory (lua_State *L) {
399 for (o = g->allgc; o != NULL; o = gch(o)->next) { 400 for (o = g->allgc; o != NULL; o = gch(o)->next) {
400 checkobject(g, o); 401 checkobject(g, o);
401 if (isgray(o)) { 402 if (isgray(o)) {
402 lua_assert(issweepphase(g) || testbit(o->gch.marked, GRAYBIT)); 403 lua_assert(!keepinvariant(g) || testbit(o->gch.marked, GRAYBIT));
403 o->gch.marked = resetbit(o->gch.marked, GRAYBIT); 404 o->gch.marked = resetbit(o->gch.marked, GRAYBIT);
404 } 405 }
405 lua_assert(!testbit(o->gch.marked, SEPARATED)); 406 lua_assert(!testbit(o->gch.marked, SEPARATED));