diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-12-20 17:40:07 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-12-20 17:40:07 -0200 |
commit | 551b076f1c7f9b66eecd8f6b7a12b1bd7a78b967 (patch) | |
tree | bde2f0e23706683829e87d4e239793de373444e7 /lgc.c | |
parent | 737f119187aca3c8f6743ec6e3cfc04e83723180 (diff) | |
download | lua-551b076f1c7f9b66eecd8f6b7a12b1bd7a78b967.tar.gz lua-551b076f1c7f9b66eecd8f6b7a12b1bd7a78b967.tar.bz2 lua-551b076f1c7f9b66eecd8f6b7a12b1bd7a78b967.zip |
change in the relationship between totalbytes and GCdebt - luaM_realloc_
is too critical to update two counters
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.105 2010/12/03 11:48:25 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.106 2010/12/20 18:17:46 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 | */ |
@@ -51,7 +51,7 @@ | |||
51 | ** standard negative debt for GC; a reasonable "time" to wait before | 51 | ** standard negative debt for GC; a reasonable "time" to wait before |
52 | ** starting a new cycle | 52 | ** starting a new cycle |
53 | */ | 53 | */ |
54 | #define stddebt(g) (-cast(l_mem, g->totalbytes/100) * g->gcpause) | 54 | #define stddebt(g) (-cast(l_mem, gettotalbytes(g)/100) * g->gcpause) |
55 | 55 | ||
56 | 56 | ||
57 | /* | 57 | /* |
@@ -634,6 +634,7 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { | |||
634 | int ow = otherwhite(g); | 634 | int ow = otherwhite(g); |
635 | int toclear, toset; /* bits to clear and to set in all live objects */ | 635 | int toclear, toset; /* bits to clear and to set in all live objects */ |
636 | int tostop; /* stop sweep when this is true */ | 636 | int tostop; /* stop sweep when this is true */ |
637 | l_mem debt = g->GCdebt; /* current debt */ | ||
637 | if (isgenerational(g)) { /* generational mode? */ | 638 | if (isgenerational(g)) { /* generational mode? */ |
638 | toclear = ~0; /* clear nothing */ | 639 | toclear = ~0; /* clear nothing */ |
639 | toset = bitmask(OLDBIT); /* set the old bit of all surviving objects */ | 640 | toset = bitmask(OLDBIT); /* set the old bit of all surviving objects */ |
@@ -656,13 +657,15 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { | |||
656 | sweepthread(L, gco2th(curr)); /* sweep thread's upvalues */ | 657 | sweepthread(L, gco2th(curr)); /* sweep thread's upvalues */ |
657 | if (testbits(marked, tostop)) { | 658 | if (testbits(marked, tostop)) { |
658 | static GCObject *nullp = NULL; | 659 | static GCObject *nullp = NULL; |
659 | return &nullp; /* stop sweeping this list */ | 660 | p = &nullp; /* stop sweeping this list */ |
661 | break; | ||
660 | } | 662 | } |
661 | /* update marks */ | 663 | /* update marks */ |
662 | gch(curr)->marked = cast_byte((marked & toclear) | toset); | 664 | gch(curr)->marked = cast_byte((marked & toclear) | toset); |
663 | p = &gch(curr)->next; /* go to next element */ | 665 | p = &gch(curr)->next; /* go to next element */ |
664 | } | 666 | } |
665 | } | 667 | } |
668 | luaE_setdebt(g, debt); /* sweeping should not change debt */ | ||
666 | return p; | 669 | return p; |
667 | } | 670 | } |
668 | 671 | ||
@@ -807,7 +810,7 @@ void luaC_changemode (lua_State *L, int mode) { | |||
807 | if (mode == KGC_GEN) { /* change to generational mode */ | 810 | if (mode == KGC_GEN) { /* change to generational mode */ |
808 | /* make sure gray lists are consistent */ | 811 | /* make sure gray lists are consistent */ |
809 | luaC_runtilstate(L, bitmask(GCSpropagate)); | 812 | luaC_runtilstate(L, bitmask(GCSpropagate)); |
810 | g->lastmajormem = g->totalbytes; | 813 | g->lastmajormem = gettotalbytes(g); |
811 | g->gckind = KGC_GEN; | 814 | g->gckind = KGC_GEN; |
812 | } | 815 | } |
813 | else { /* change to incremental mode */ | 816 | else { /* change to incremental mode */ |
@@ -958,15 +961,15 @@ static void generationalcollection (lua_State *L) { | |||
958 | global_State *g = G(L); | 961 | global_State *g = G(L); |
959 | if (g->lastmajormem == 0) { /* signal for another major collection? */ | 962 | if (g->lastmajormem == 0) { /* signal for another major collection? */ |
960 | luaC_fullgc(L, 0); /* perform a full regular collection */ | 963 | luaC_fullgc(L, 0); /* perform a full regular collection */ |
961 | g->lastmajormem = g->totalbytes; /* update control */ | 964 | g->lastmajormem = gettotalbytes(g); /* update control */ |
962 | } | 965 | } |
963 | else { | 966 | else { |
964 | luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */ | 967 | luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */ |
965 | luaC_runtilstate(L, bitmask(GCSpause)); | 968 | luaC_runtilstate(L, bitmask(GCSpause)); |
966 | if (g->totalbytes > g->lastmajormem/100 * g->gcmajorinc) | 969 | if (gettotalbytes(g) > g->lastmajormem/100 * g->gcmajorinc) |
967 | g->lastmajormem = 0; /* signal for a major collection */ | 970 | g->lastmajormem = 0; /* signal for a major collection */ |
968 | } | 971 | } |
969 | g->GCdebt = stddebt(g); | 972 | luaE_setdebt(g, stddebt(g)); |
970 | } | 973 | } |
971 | 974 | ||
972 | 975 | ||
@@ -977,9 +980,9 @@ static void step (lua_State *L) { | |||
977 | lim -= singlestep(L); | 980 | lim -= singlestep(L); |
978 | } while (lim > 0 && g->gcstate != GCSpause); | 981 | } while (lim > 0 && g->gcstate != GCSpause); |
979 | if (g->gcstate != GCSpause) | 982 | if (g->gcstate != GCSpause) |
980 | g->GCdebt -= GCSTEPSIZE; | 983 | luaE_setdebt(g, g->GCdebt - GCSTEPSIZE); |
981 | else | 984 | else |
982 | g->GCdebt = stddebt(g); | 985 | luaE_setdebt(g, stddebt(g)); |
983 | } | 986 | } |
984 | 987 | ||
985 | 988 | ||
@@ -1022,7 +1025,7 @@ void luaC_fullgc (lua_State *L, int isemergency) { | |||
1022 | luaC_runtilstate(L, bitmask(GCSpropagate)); | 1025 | luaC_runtilstate(L, bitmask(GCSpropagate)); |
1023 | } | 1026 | } |
1024 | g->gckind = origkind; | 1027 | g->gckind = origkind; |
1025 | g->GCdebt = stddebt(g); | 1028 | luaE_setdebt(g, stddebt(g)); |
1026 | if (!isemergency) /* do not run finalizers during emergency GC */ | 1029 | if (!isemergency) /* do not run finalizers during emergency GC */ |
1027 | callallpendingfinalizers(L, 1); | 1030 | callallpendingfinalizers(L, 1); |
1028 | } | 1031 | } |