diff options
| -rw-r--r-- | lgc.h | 7 | ||||
| -rw-r--r-- | ltests.c | 25 |
2 files changed, 8 insertions, 24 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.h,v 2.102 2018/02/19 13:55:34 roberto Exp roberto $ | 2 | ** $Id: lgc.h,v 2.102 2018/02/19 20:06:56 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 | */ |
| @@ -69,13 +69,14 @@ | |||
| 69 | 69 | ||
| 70 | /* | 70 | /* |
| 71 | ** Layout for bit use in 'marked' field. First three bits are | 71 | ** Layout for bit use in 'marked' field. First three bits are |
| 72 | ** used for object "age" in generational mode. | 72 | ** used for object "age" in generational mode. Last bit is free |
| 73 | ** to be used by respective objects. | ||
| 73 | */ | 74 | */ |
| 74 | #define WHITE0BIT 3 /* object is white (type 0) */ | 75 | #define WHITE0BIT 3 /* object is white (type 0) */ |
| 75 | #define WHITE1BIT 4 /* object is white (type 1) */ | 76 | #define WHITE1BIT 4 /* object is white (type 1) */ |
| 76 | #define BLACKBIT 5 /* object is black */ | 77 | #define BLACKBIT 5 /* object is black */ |
| 77 | #define FINALIZEDBIT 6 /* object has been marked for finalization */ | 78 | #define FINALIZEDBIT 6 /* object has been marked for finalization */ |
| 78 | #define TESTGRAYBIT 7 /* used by tests (luaL_checkmemory) */ | 79 | |
| 79 | 80 | ||
| 80 | 81 | ||
| 81 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) | 82 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.242 2018/02/23 13:13:31 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.243 2018/03/09 19:24:45 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 | */ |
| @@ -428,8 +428,6 @@ static void checkgraylist (global_State *g, GCObject *o) { | |||
| 428 | ((void)g); /* better to keep it available if we need to print an object */ | 428 | ((void)g); /* better to keep it available if we need to print an object */ |
| 429 | while (o) { | 429 | while (o) { |
| 430 | lua_assert(isgray(o) || getage(o) == G_TOUCHED2); | 430 | lua_assert(isgray(o) || getage(o) == G_TOUCHED2); |
| 431 | lua_assert(!testbit(o->marked, TESTGRAYBIT)); | ||
| 432 | l_setbit(o->marked, TESTGRAYBIT); | ||
| 433 | switch (o->tt) { | 431 | switch (o->tt) { |
| 434 | case LUA_TTABLE: o = gco2t(o)->gclist; break; | 432 | case LUA_TTABLE: o = gco2t(o)->gclist; break; |
| 435 | case LUA_TLCL: o = gco2lcl(o)->gclist; break; | 433 | case LUA_TLCL: o = gco2lcl(o)->gclist; break; |
| @@ -443,10 +441,9 @@ static void checkgraylist (global_State *g, GCObject *o) { | |||
| 443 | 441 | ||
| 444 | 442 | ||
| 445 | /* | 443 | /* |
| 446 | ** mark all objects in gray lists with the TESTGRAYBIT, so that | 444 | ** Check objects in gray lists. |
| 447 | ** 'checkmemory' can check that all gray objects are in a gray list | ||
| 448 | */ | 445 | */ |
| 449 | static void markgrays (global_State *g) { | 446 | static void checkgrays (global_State *g) { |
| 450 | if (!keepinvariant(g)) return; | 447 | if (!keepinvariant(g)) return; |
| 451 | checkgraylist(g, g->gray); | 448 | checkgraylist(g, g->gray); |
| 452 | checkgraylist(g, g->grayagain); | 449 | checkgraylist(g, g->grayagain); |
| @@ -456,17 +453,6 @@ static void markgrays (global_State *g) { | |||
| 456 | } | 453 | } |
| 457 | 454 | ||
| 458 | 455 | ||
| 459 | static void checkgray (global_State *g, GCObject *o) { | ||
| 460 | for (; o != NULL; o = o->next) { | ||
| 461 | if ((isgray(o) && o->tt != LUA_TUPVAL) || getage(o) == G_TOUCHED2) { | ||
| 462 | lua_assert(!keepinvariant(g) || testbit(o->marked, TESTGRAYBIT)); | ||
| 463 | resetbit(o->marked, TESTGRAYBIT); | ||
| 464 | } | ||
| 465 | lua_assert(!testbit(o->marked, TESTGRAYBIT)); | ||
| 466 | } | ||
| 467 | } | ||
| 468 | |||
| 469 | |||
| 470 | static void checklist (global_State *g, int maybedead, int tof, | 456 | static void checklist (global_State *g, int maybedead, int tof, |
| 471 | GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) { | 457 | GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) { |
| 472 | GCObject *o; | 458 | GCObject *o; |
| @@ -499,7 +485,7 @@ int lua_checkmemory (lua_State *L) { | |||
| 499 | } | 485 | } |
| 500 | lua_assert(!isdead(g, gcvalue(&g->l_registry))); | 486 | lua_assert(!isdead(g, gcvalue(&g->l_registry))); |
| 501 | lua_assert(g->sweepgc == NULL || issweepphase(g)); | 487 | lua_assert(g->sweepgc == NULL || issweepphase(g)); |
| 502 | markgrays(g); | 488 | checkgrays(g); |
| 503 | 489 | ||
| 504 | /* check 'fixedgc' list */ | 490 | /* check 'fixedgc' list */ |
| 505 | for (o = g->fixedgc; o != NULL; o = o->next) { | 491 | for (o = g->fixedgc; o != NULL; o = o->next) { |
| @@ -507,16 +493,13 @@ int lua_checkmemory (lua_State *L) { | |||
| 507 | } | 493 | } |
| 508 | 494 | ||
| 509 | /* check 'allgc' list */ | 495 | /* check 'allgc' list */ |
| 510 | checkgray(g, g->allgc); | ||
| 511 | maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpallgc); | 496 | maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpallgc); |
| 512 | checklist(g, maybedead, 0, g->allgc, g->survival, g->old, g->reallyold); | 497 | checklist(g, maybedead, 0, g->allgc, g->survival, g->old, g->reallyold); |
| 513 | 498 | ||
| 514 | /* check 'finobj' list */ | 499 | /* check 'finobj' list */ |
| 515 | checkgray(g, g->finobj); | ||
| 516 | checklist(g, 0, 1, g->finobj, g->finobjsur, g->finobjold, g->finobjrold); | 500 | checklist(g, 0, 1, g->finobj, g->finobjsur, g->finobjold, g->finobjrold); |
| 517 | 501 | ||
| 518 | /* check 'tobefnz' list */ | 502 | /* check 'tobefnz' list */ |
| 519 | checkgray(g, g->tobefnz); | ||
| 520 | for (o = g->tobefnz; o != NULL; o = o->next) { | 503 | for (o = g->tobefnz; o != NULL; o = o->next) { |
| 521 | checkobject(g, o, 0, G_NEW); | 504 | checkobject(g, o, 0, G_NEW); |
| 522 | lua_assert(tofinalize(o)); | 505 | lua_assert(tofinalize(o)); |
