diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-02-13 10:11:34 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-02-13 10:11:34 -0200 |
| commit | 733c58595bb57541e38275103fade1330aeb839d (patch) | |
| tree | 313583474068cdde188d72a876c7883d47b9e863 /ltests.c | |
| parent | 4a1ed6e6e53f8b208fd21d6ac8b0a34331c43ede (diff) | |
| download | lua-733c58595bb57541e38275103fade1330aeb839d.tar.gz lua-733c58595bb57541e38275103fade1330aeb839d.tar.bz2 lua-733c58595bb57541e38275103fade1330aeb839d.zip | |
no more local collection
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 67 |
1 files changed, 18 insertions, 49 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.162 2013/12/30 20:47:58 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.163 2014/02/11 12:18:12 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 | */ |
| @@ -188,41 +188,23 @@ static int testobjref1 (global_State *g, GCObject *f, GCObject *t) { | |||
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | 190 | ||
| 191 | /* | ||
| 192 | ** Check locality | ||
| 193 | */ | ||
| 194 | static int testobjref2 (GCObject *f, GCObject *t) { | ||
| 195 | /* not a local or pointed by a thread? */ | ||
| 196 | if (!islocal(t) || gch(f)->tt == LUA_TTHREAD) | ||
| 197 | return 1; /* ok */ | ||
| 198 | if (gch(f)->tt == LUA_TPROTO && gch(t)->tt == LUA_TLCL) | ||
| 199 | return 1; /* cache from a prototype */ | ||
| 200 | return 0; | ||
| 201 | } | ||
| 202 | |||
| 203 | |||
| 204 | static void printobj (global_State *g, GCObject *o) { | 191 | static void printobj (global_State *g, GCObject *o) { |
| 205 | printf("||%s(%p)-%s-%c(%02X)||", | 192 | printf("||%s(%p)-%c(%02X)||", |
| 206 | ttypename(novariant(gch(o)->tt)), (void *)o, | 193 | ttypename(novariant(gch(o)->tt)), (void *)o, |
| 207 | islocal(o)?"L":"NL", | ||
| 208 | isdead(g,o)?'d':isblack(o)?'b':iswhite(o)?'w':'g', gch(o)->marked); | 194 | isdead(g,o)?'d':isblack(o)?'b':iswhite(o)?'w':'g', gch(o)->marked); |
| 209 | } | 195 | } |
| 210 | 196 | ||
| 211 | 197 | ||
| 212 | static int testobjref (global_State *g, GCObject *f, GCObject *t) { | 198 | static int testobjref (global_State *g, GCObject *f, GCObject *t) { |
| 213 | int r1 = testobjref1(g,f,t); | 199 | int r1 = testobjref1(g, f, t); |
| 214 | int r2 = testobjref2(f,t); | 200 | if (!r1) { |
| 215 | if (!r1 || !r2) { | 201 | printf("%d(%02X) - ", g->gcstate, g->currentwhite); |
| 216 | if (!r1) | ||
| 217 | printf("%d(%02X) - ", g->gcstate, g->currentwhite); | ||
| 218 | else | ||
| 219 | printf("local violation - "); | ||
| 220 | printobj(g, f); | 202 | printobj(g, f); |
| 221 | printf(" -> "); | 203 | printf(" -> "); |
| 222 | printobj(g, t); | 204 | printobj(g, t); |
| 223 | printf("\n"); | 205 | printf("\n"); |
| 224 | } | 206 | } |
| 225 | return r1 && r2; | 207 | return r1; |
| 226 | } | 208 | } |
| 227 | 209 | ||
| 228 | #define checkobjref(g,f,t) lua_assert(testobjref(g,f,obj2gco(t))) | 210 | #define checkobjref(g,f,t) lua_assert(testobjref(g,f,obj2gco(t))) |
| @@ -349,7 +331,6 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) { | |||
| 349 | break; | 331 | break; |
| 350 | } | 332 | } |
| 351 | case LUA_TTHREAD: { | 333 | case LUA_TTHREAD: { |
| 352 | lua_assert(!islocal(o)); | ||
| 353 | checkstack(g, gco2th(o)); | 334 | checkstack(g, gco2th(o)); |
| 354 | break; | 335 | break; |
| 355 | } | 336 | } |
| @@ -366,7 +347,10 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) { | |||
| 366 | break; | 347 | break; |
| 367 | } | 348 | } |
| 368 | case LUA_TSHRSTR: | 349 | case LUA_TSHRSTR: |
| 369 | case LUA_TLNGSTR: break; | 350 | case LUA_TLNGSTR: { |
| 351 | lua_assert(!isgray(o)); /* strings are never gray */ | ||
| 352 | break; | ||
| 353 | } | ||
| 370 | default: lua_assert(0); | 354 | default: lua_assert(0); |
| 371 | } | 355 | } |
| 372 | } | 356 | } |
| @@ -431,28 +415,23 @@ int lua_checkmemory (lua_State *L) { | |||
| 431 | resetbit(g->mainthread->marked, TESTGRAYBIT); | 415 | resetbit(g->mainthread->marked, TESTGRAYBIT); |
| 432 | lua_assert(g->sweepgc == NULL || issweepphase(g)); | 416 | lua_assert(g->sweepgc == NULL || issweepphase(g)); |
| 433 | markgrays(g); | 417 | markgrays(g); |
| 434 | /* check 'localgc' list */ | 418 | /* check 'fixedgc' list */ |
| 435 | checkgray(g, g->localgc); | 419 | for (o = g->fixedgc; o != NULL; o = gch(o)->next) { |
| 436 | maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswplocalgc); | 420 | lua_assert(gch(o)->tt == LUA_TSHRSTR && isgray(o)); |
| 437 | for (o = g->localgc; o != NULL; o = gch(o)->next) { | ||
| 438 | checkobject(g, o, maybedead); | ||
| 439 | lua_assert(!tofinalize(o) && !testbit(o->gch.marked, LOCALMARK)); | ||
| 440 | } | 421 | } |
| 441 | /* check 'allgc' list */ | 422 | /* check 'allgc' list */ |
| 442 | checkgray(g, g->allgc); | 423 | checkgray(g, g->allgc); |
| 443 | maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpallgc); | 424 | maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpallgc); |
| 444 | for (o = g->allgc; o != NULL; o = gch(o)->next) { | 425 | for (o = g->allgc; o != NULL; o = gch(o)->next) { |
| 445 | checkobject(g, o, maybedead); | 426 | checkobject(g, o, maybedead); |
| 446 | lua_assert(!tofinalize(o) && testbit(o->gch.marked, LOCALMARK)); | 427 | lua_assert(!tofinalize(o)); |
| 447 | lua_assert(testbit(o->gch.marked, NOLOCALBIT)); | ||
| 448 | } | 428 | } |
| 449 | /* check thread list */ | 429 | /* check thread list */ |
| 450 | checkgray(g, obj2gco(g->mainthread)); | 430 | checkgray(g, obj2gco(g->mainthread)); |
| 451 | maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpthreads); | 431 | maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpthreads); |
| 452 | for (o = obj2gco(g->mainthread); o != NULL; o = gch(o)->next) { | 432 | for (o = obj2gco(g->mainthread); o != NULL; o = gch(o)->next) { |
| 453 | checkobject(g, o, maybedead); | 433 | checkobject(g, o, maybedead); |
| 454 | lua_assert(!tofinalize(o) && testbit(o->gch.marked, LOCALMARK)); | 434 | lua_assert(!tofinalize(o)); |
| 455 | lua_assert(testbit(o->gch.marked, NOLOCALBIT)); | ||
| 456 | lua_assert(gch(o)->tt == LUA_TTHREAD); | 435 | lua_assert(gch(o)->tt == LUA_TTHREAD); |
| 457 | } | 436 | } |
| 458 | /* check 'finobj' list */ | 437 | /* check 'finobj' list */ |
| @@ -460,7 +439,6 @@ int lua_checkmemory (lua_State *L) { | |||
| 460 | for (o = g->finobj; o != NULL; o = gch(o)->next) { | 439 | for (o = g->finobj; o != NULL; o = gch(o)->next) { |
| 461 | checkobject(g, o, 0); | 440 | checkobject(g, o, 0); |
| 462 | lua_assert(tofinalize(o)); | 441 | lua_assert(tofinalize(o)); |
| 463 | lua_assert(!islocal(o) || !testbit(gch(o)->marked, LOCALMARK)); | ||
| 464 | lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE); | 442 | lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE); |
| 465 | } | 443 | } |
| 466 | /* check 'tobefnz' list */ | 444 | /* check 'tobefnz' list */ |
| @@ -636,21 +614,12 @@ static int gc_color (lua_State *L) { | |||
| 636 | } | 614 | } |
| 637 | 615 | ||
| 638 | 616 | ||
| 639 | static int gc_local (lua_State *L) { | ||
| 640 | TValue *o; | ||
| 641 | luaL_checkany(L, 1); | ||
| 642 | o = obj_at(L, 1); | ||
| 643 | lua_pushboolean(L, !iscollectable(o) || islocal(gcvalue(o))); | ||
| 644 | return 1; | ||
| 645 | } | ||
| 646 | |||
| 647 | |||
| 648 | static int gc_state (lua_State *L) { | 617 | static int gc_state (lua_State *L) { |
| 649 | static const char *statenames[] = {"propagate", "atomic", | 618 | static const char *statenames[] = {"propagate", "atomic", |
| 650 | "sweeplocalgc", "sweepallgc", "sweepthreads", "sweepfinobj", | 619 | "sweepallgc", "sweepthreads", "sweepfinobj", |
| 651 | "sweeptobefnz", "sweepend", "pause", ""}; | 620 | "sweeptobefnz", "sweepend", "pause", ""}; |
| 652 | static const int states[] = {GCSpropagate, GCSatomic, | 621 | static const int states[] = {GCSpropagate, GCSatomic, |
| 653 | GCSswplocalgc, GCSswpallgc, GCSswpthreads, GCSswpfinobj, | 622 | GCSswpallgc, GCSswpthreads, GCSswpfinobj, |
| 654 | GCSswptobefnz, GCSswpend, GCSpause, -1}; | 623 | GCSswptobefnz, GCSswpend, GCSpause, -1}; |
| 655 | int option = states[luaL_checkoption(L, 1, "", statenames)]; | 624 | int option = states[luaL_checkoption(L, 1, "", statenames)]; |
| 656 | if (option == -1) { | 625 | if (option == -1) { |
| @@ -1459,7 +1428,6 @@ static const struct luaL_Reg tests_funcs[] = { | |||
| 1459 | {"doonnewstack", doonnewstack}, | 1428 | {"doonnewstack", doonnewstack}, |
| 1460 | {"doremote", doremote}, | 1429 | {"doremote", doremote}, |
| 1461 | {"gccolor", gc_color}, | 1430 | {"gccolor", gc_color}, |
| 1462 | {"isgclocal", gc_local}, | ||
| 1463 | {"gcstate", gc_state}, | 1431 | {"gcstate", gc_state}, |
| 1464 | {"getref", getref}, | 1432 | {"getref", getref}, |
| 1465 | {"hash", hash_query}, | 1433 | {"hash", hash_query}, |
| @@ -1509,3 +1477,4 @@ int luaB_opentests (lua_State *L) { | |||
| 1509 | } | 1477 | } |
| 1510 | 1478 | ||
| 1511 | #endif | 1479 | #endif |
| 1480 | |||
