diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-05-07 15:09:23 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-05-07 15:09:23 -0300 |
commit | 9c1347e647a44d5c60d5b1d568204fcffb856911 (patch) | |
tree | cd0ece2a19ef4c5d398ee2092ef8c75bea3e3610 /ltests.c | |
parent | b373a40133800b53f23a7b2df721b7c6892d1797 (diff) | |
download | lua-9c1347e647a44d5c60d5b1d568204fcffb856911.tar.gz lua-9c1347e647a44d5c60d5b1d568204fcffb856911.tar.bz2 lua-9c1347e647a44d5c60d5b1d568204fcffb856911.zip |
more tests in 'lua_checkmemory' + more information in function
'gccolor'
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 46 |
1 files changed, 29 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.101 2010/05/03 17:33:39 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.102 2010/05/06 18:16:57 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 | */ |
@@ -182,7 +182,7 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) { | |||
182 | 182 | ||
183 | static int testobjref1 (global_State *g, GCObject *f, GCObject *t) { | 183 | static int testobjref1 (global_State *g, GCObject *f, GCObject *t) { |
184 | if (isdead(g,t)) return 0; | 184 | if (isdead(g,t)) return 0; |
185 | if (g->gckind == KGC_GEN || !issweepphase(g)) | 185 | if (isgenerational(g) || !issweepphase(g)) |
186 | return !isblack(f) || !iswhite(t); | 186 | return !isblack(f) || !iswhite(t); |
187 | else return 1; | 187 | else return 1; |
188 | } | 188 | } |
@@ -323,7 +323,7 @@ static void checkobject (global_State *g, GCObject *o) { | |||
323 | if (isdead(g, o)) | 323 | if (isdead(g, o)) |
324 | lua_assert(issweepphase(g)); | 324 | lua_assert(issweepphase(g)); |
325 | else { | 325 | else { |
326 | if (g->gcstate == GCSpause) | 326 | if (g->gcstate == GCSpause && !isgenerational(g)) |
327 | lua_assert(iswhite(o)); | 327 | lua_assert(iswhite(o)); |
328 | switch (gch(o)->tt) { | 328 | switch (gch(o)->tt) { |
329 | case LUA_TUPVAL: { | 329 | case LUA_TUPVAL: { |
@@ -396,8 +396,8 @@ static void markgrays (global_State *g) { | |||
396 | static void checkold (global_State *g, GCObject *o) { | 396 | static void checkold (global_State *g, GCObject *o) { |
397 | int isold = 0; | 397 | int isold = 0; |
398 | for (; o != NULL; o = gch(o)->next) { | 398 | for (; o != NULL; o = gch(o)->next) { |
399 | if (testbit(o->gch.marked, OLDBIT)) { /* old generation? */ | 399 | if (isold(o)) { /* old generation? */ |
400 | lua_assert(g->gckind == KGC_GEN); | 400 | lua_assert(isgenerational(g)); |
401 | if (!issweepphase(g)) | 401 | if (!issweepphase(g)) |
402 | isold = 1; | 402 | isold = 1; |
403 | } | 403 | } |
@@ -418,6 +418,10 @@ int lua_checkmemory (lua_State *L) { | |||
418 | checkliveness(g, &g->l_registry); | 418 | checkliveness(g, &g->l_registry); |
419 | checkstack(g, g->mainthread); | 419 | checkstack(g, g->mainthread); |
420 | g->mainthread->marked = resetbit(g->mainthread->marked, TESTGRAYBIT); | 420 | g->mainthread->marked = resetbit(g->mainthread->marked, TESTGRAYBIT); |
421 | if (keepinvariant(g)) { | ||
422 | lua_assert(!iswhite(obj2gco(g->mainthread))); | ||
423 | lua_assert(!iswhite(gcvalue(&g->l_registry))); | ||
424 | } | ||
421 | /* check 'allgc' list */ | 425 | /* check 'allgc' list */ |
422 | markgrays(g); | 426 | markgrays(g); |
423 | checkold(g, g->allgc); | 427 | checkold(g, g->allgc); |
@@ -426,7 +430,7 @@ int lua_checkmemory (lua_State *L) { | |||
426 | lua_assert(!testbit(o->gch.marked, SEPARATED)); | 430 | lua_assert(!testbit(o->gch.marked, SEPARATED)); |
427 | } | 431 | } |
428 | /* check 'udgc' list */ | 432 | /* check 'udgc' list */ |
429 | checkold(g, g->tobefnz); | 433 | checkold(g, g->udgc); |
430 | for (o = g->udgc; o != NULL; o = gch(o)->next) { | 434 | for (o = g->udgc; o != NULL; o = gch(o)->next) { |
431 | lua_assert(gch(o)->tt == LUA_TUSERDATA && | 435 | lua_assert(gch(o)->tt == LUA_TUSERDATA && |
432 | !isdead(g, o) && | 436 | !isdead(g, o) && |
@@ -438,7 +442,7 @@ int lua_checkmemory (lua_State *L) { | |||
438 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { | 442 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { |
439 | lua_assert(gch(o)->tt == LUA_TUSERDATA); | 443 | lua_assert(gch(o)->tt == LUA_TUSERDATA); |
440 | lua_assert(isblack(o)); | 444 | lua_assert(isblack(o)); |
441 | lua_assert(!testbit(o->gch.marked, OLDBIT)); | 445 | lua_assert(!isold(o)); |
442 | lua_assert(testbit(o->gch.marked, SEPARATED)); | 446 | lua_assert(testbit(o->gch.marked, SEPARATED)); |
443 | } | 447 | } |
444 | /* check 'uvhead' list */ | 448 | /* check 'uvhead' list */ |
@@ -602,31 +606,39 @@ static int get_gccolor (lua_State *L) { | |||
602 | if (!iscollectable(o)) | 606 | if (!iscollectable(o)) |
603 | lua_pushstring(L, "no collectable"); | 607 | lua_pushstring(L, "no collectable"); |
604 | else { | 608 | else { |
609 | int n = 1; | ||
605 | lua_pushstring(L, iswhite(gcvalue(o)) ? "white" : | 610 | lua_pushstring(L, iswhite(gcvalue(o)) ? "white" : |
606 | isblack(gcvalue(o)) ? "black" : "grey"); | 611 | isblack(gcvalue(o)) ? "black" : "grey"); |
607 | if (testbit(gcvalue(o)->gch.marked, OLDBIT)) { | 612 | if (testbit(gcvalue(o)->gch.marked, FINALIZEDBIT)) { |
608 | lua_pushliteral(L, "/old"); | 613 | lua_pushliteral(L, "/finalized"); n++; |
609 | lua_concat(L, 2); | 614 | } |
615 | if (testbit(gcvalue(o)->gch.marked, SEPARATED)) { | ||
616 | lua_pushliteral(L, "/separated"); n++; | ||
617 | } | ||
618 | if (testbit(gcvalue(o)->gch.marked, FIXEDBIT)) { | ||
619 | lua_pushliteral(L, "/fixed"); n++; | ||
620 | } | ||
621 | if (isold(gcvalue(o))) { | ||
622 | lua_pushliteral(L, "/old"); n++; | ||
610 | } | 623 | } |
624 | lua_concat(L, n); | ||
611 | } | 625 | } |
612 | return 1; | 626 | return 1; |
613 | } | 627 | } |
614 | 628 | ||
615 | 629 | ||
616 | static int gc_state (lua_State *L) { | 630 | static int gc_state (lua_State *L) { |
617 | static const char *statenames[] = {"", "pause", "propagate", "atomic", | 631 | static const char *statenames[] = {"propagate", "atomic", |
618 | "sweepstring", "sweepudata", "sweep"}; | 632 | "sweepstring", "sweepudata", "sweep", "pause", ""}; |
619 | static const int states[] = {0, GCSpause, GCSpropagate, GCSatomic, | ||
620 | GCSsweepstring, GCSsweepudata, GCSsweep}; | ||
621 | int option = luaL_checkoption(L, 1, "", statenames); | 633 | int option = luaL_checkoption(L, 1, "", statenames); |
622 | if (option == 0) { | 634 | if (option == GCSpause + 1) { |
623 | lua_pushstring(L, statenames[G(L)->gcstate]); | 635 | lua_pushstring(L, statenames[G(L)->gcstate]); |
624 | return 1; | 636 | return 1; |
625 | } | 637 | } |
626 | else { | 638 | else { |
627 | lua_lock(L); | 639 | lua_lock(L); |
628 | luaC_runtilstate(L, bitmask(states[option])); | 640 | luaC_runtilstate(L, bitmask(option)); |
629 | lua_assert(G(L)->gcstate == states[option]); | 641 | lua_assert(G(L)->gcstate == option); |
630 | lua_unlock(L); | 642 | lua_unlock(L); |
631 | return 0; | 643 | return 0; |
632 | } | 644 | } |