History

Lua 5.2.1-rc2

Lua Team committed 14 years ago

Commit b19ccd41 parent 8626ef24 files · +35 −22Browse files

Unified · Split

4 files
  1. doc/contents.html +2 −2
  2. doc/manual.html +1 −1
  3. src/lgc.c +29 −18
  4. src/llimits.h +3 −1
doc/contents.html+2−2
@@ -35,7 +35,7 @@ For a complete introduction to Lua programming, see the book · 34 unmodified lines
3535 <SMALL>
3636 Copyright &copy; 2011&ndash;2012 Lua.org, PUC-Rio.
3737 Freely available under the terms of the
38−<A HREF="http://www.lua.org/license.html#5">Lua license</A>.
38+<A HREF="http://www.lua.org/license.html">Lua license</A>.
3939 </SMALL>
4040
4141 <H2><A NAME="contents">Contents</A></H2>
@@ -521,7 +521,7 @@ Freely available under the terms of the · 479 unmodified lines
521521 <HR>
522522 <SMALL CLASS="footer">
523523 Last update:
524−Wed May 23 13:28:09 BRT 2012
524+Sat May 26 08:52:25 BRT 2012
525525 </SMALL>
526526 <!--
527527 Last change: revised for Lua 5.2.1
doc/manual.html+1−1
@@ -21,7 +21,7 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 20 unmodified lines
2121 <small>
2222 Copyright &copy; 2011&ndash;2012 Lua.org, PUC-Rio.
2323 Freely available under the terms of the
24−<a href="http://www.lua.org/license.html#5">Lua license</a>.
24+<a href="http://www.lua.org/license.html">Lua license</a>.
2525 </small>
2626 <hr>
2727 <p>
src/lgc.c+29−18
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 2.128 2012/05/23 15:43:14 roberto Exp $
2+** $Id: lgc.c,v 2.129 2012/05/28 20:41:00 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -24,8 +24,11 @@ · 18 unmodified lines
2424
2525
2626
27−/* cost of sweeping one element (half the size of a small object) */
28−#define GCSWEEPCOST ((sizeof(TString) + 4) / 2)
27+/*
28+** cost of sweeping one element (the size of a small object divided
29+** by some adjust for the sweep speed)
30+*/
31+#define GCSWEEPCOST ((sizeof(TString) + 4) / 4)
2932
3033 /* maximum number of elements to sweep in each single step */
3134 #define GCSWEEPMAX (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))
@@ -33,25 +36,27 @@ · 1 unmodified line
3336 /* maximum number of finalizers to call in each GC step */
3437 #define GCFINALIZENUM 4
3538
36−/* (arbitrary) cost of atomic step */
37−#define GCATOMICCOST GCSTEPSIZE
3839
40+/*
41+** macro to adjust 'stepmul': 'stepmul' is actually used like
42+** 'stepmul / STEPMULADJ' (value chosen by tests)
43+*/
44+#define STEPMULADJ 200
3945
4046 /*
41−** macro to apply the "speed" of the garbage collector: the constant
42−** 80 makes the standard 'stepmul' of 200 results in the GC handling
43−** 80/200 = 1/2.5 = 0.4Kbytes for every 1Kb allocated.
44−** (The computation tries to avoid overflows or underflows.)
47+** macro to adjust 'pause': 'pause' is actually used like
48+** 'pause / PAUSEADJ' (value chosen by tests)
4549 */
46−#define workrate(x,mul) \
47− ((x) < MAX_INT/80 ? ((x) * 80) / mul : ((x) / mul) * 80)
50+#define PAUSEADJ 200
51+
52+
4853
4954
5055 /*
5156 ** standard negative debt for GC; a reasonable "time" to wait before
5257 ** starting a new cycle
5358 */
54−#define stddebtest(g,e) (-cast(l_mem, (e)/100) * g->gcpause)
59+#define stddebtest(g,e) (-cast(l_mem, (e)/PAUSEADJ) * g->gcpause)
5560 #define stddebt(g) stddebtest(g, gettotalbytes(g))
5661
5762
@@ -672,7 +677,7 @@ static void freeobj (lua_State *L, GCObject *o) { · 614 unmodified lines
672677 case LUA_TTABLE: luaH_free(L, gco2t(o)); break;
673678 case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;
674679 case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
675− case LUA_TSHRSTR:
680+ case LUA_TSHRSTR:
676681 G(L)->strt.nuse--;
677682 /* go through */
678683 case LUA_TLNGSTR: {
@@ -955,8 +960,9 @@ void luaC_freeallobjects (lua_State *L) { · 276 unmodified lines
955960 }
956961
957962
958−static void atomic (lua_State *L) {
963+static l_mem atomic (lua_State *L) {
959964 global_State *g = G(L);
965+ l_mem trav = g->GCmemtrav;
960966 GCObject *origweak, *origall;
961967 lua_assert(!iswhite(obj2gco(g->mainthread)));
962968 markobject(g, L); /* mark running thread */
@@ -976,6 +982,7 @@ static void atomic (lua_State *L) { · 13 unmodified lines
976982 separatetobefnz(L, 0); /* separate objects to be finalized */
977983 markbeingfnz(g); /* mark userdata that will be finalized */
978984 propagateall(g); /* remark, to propagate `preserveness' */
985+ trav = g->GCmemtrav - trav; /* avoid adding convergence twice */
979986 convergeephemerons(g);
980987 /* at this point, all resurrected objects are marked. */
981988 /* remove dead objects from weak tables */
@@ -987,6 +994,7 @@ static void atomic (lua_State *L) { · 5 unmodified lines
987994 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
988995 entersweep(L); /* prepare to sweep strings */
989996 /*lua_checkmemory(L);*/
997+ return trav; /* reasonable estimate of the work done by 'atomic' */
990998 }
991999
9921000
@@ -1012,8 +1020,7 @@ static lu_mem singlestep (lua_State *L) { · 19 unmodified lines
10121020 else { /* no more `gray' objects */
10131021 g->gcstate = GCSatomic; /* finish mark phase */
10141022 g->GCestimate = g->GCmemtrav; /* save what was counted */
1015− atomic(L);
1016− return GCATOMICCOST;
1023+ return atomic(L);
10171024 }
10181025 }
10191026 case GCSsweepstring: {
@@ -1086,14 +1093,18 @@ static void step (lua_State *L) { · 66 unmodified lines
10861093 global_State *g = G(L);
10871094 l_mem debt = g->GCdebt;
10881095 int stepmul = g->gcstepmul;
1089− if (stepmul <= 0) stepmul = 1;
1096+ if (stepmul < 40) stepmul = 40; /* avoid ridiculous low values */
1097+ /* convert debt from Kb to 'work units' (avoid zero debt and overflows) */
1098+ debt = (debt / STEPMULADJ) + 1;
1099+ debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
10901100 do { /* always perform at least one single step */
10911101 lu_mem work = singlestep(L); /* do some work */
1092− work = workrate(work, stepmul); /* apply work rate */
10931102 debt -= work;
10941103 } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
10951104 if (g->gcstate == GCSpause)
10961105 debt = stddebtest(g, g->GCestimate); /* pause until next cycle */
1106+ else
1107+ debt = (debt / stepmul) * STEPMULADJ; /* convert 'work units' to Kb */
10971108 luaE_setdebt(g, debt);
10981109 }
10991110
src/llimits.h+3−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llimits.h,v 1.98 2012/05/11 14:10:50 roberto Exp $
2+** $Id: llimits.h,v 1.99 2012/05/28 20:32:28 roberto Exp $
33 ** Limits, basic types, and some other `installation-dependent' definitions
44 ** See Copyright Notice in lua.h
55 */
@@ -31,6 +31,8 @@ typedef unsigned char lu_byte; · 25 unmodified lines
3131
3232 #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
3333
34+#define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))
35+
3436
3537 #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
3638