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
35<SMALL>35<SMALL>
36Copyright &copy; 2011&ndash;2012 Lua.org, PUC-Rio.36Copyright &copy; 2011&ndash;2012 Lua.org, PUC-Rio.
37Freely available under the terms of the37Freely 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>.
39</SMALL>39</SMALL>
40 40
41<H2><A NAME="contents">Contents</A></H2>41<H2><A NAME="contents">Contents</A></H2>
@@ -521,7 +521,7 @@ Freely available under the terms of the · 479 unmodified lines
521<HR>521<HR>
522<SMALL CLASS="footer">522<SMALL CLASS="footer">
523Last update:523Last update:
524Wed May 23 13:28:09 BRT 2012524Sat May 26 08:52:25 BRT 2012
525</SMALL>525</SMALL>
526<!--526<!--
527Last change: revised for Lua 5.2.1527Last 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
21<small>21<small>
22Copyright &copy; 2011&ndash;2012 Lua.org, PUC-Rio.22Copyright &copy; 2011&ndash;2012 Lua.org, PUC-Rio.
23Freely available under the terms of the23Freely 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>.
25</small>25</small>
26<hr>26<hr>
27<p>27<p>
src/lgc.c+29−18
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Garbage Collector3** Garbage Collector
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -24,8 +24,11 @@ · 18 unmodified lines
24 24
25 25
26 26
27/* cost of sweeping one element (half the size of a small object) */27/*
28#define GCSWEEPCOST ((sizeof(TString) + 4) / 2)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)
29 32
30/* maximum number of elements to sweep in each single step */33/* maximum number of elements to sweep in each single step */
31#define GCSWEEPMAX (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))34#define GCSWEEPMAX (cast_int((GCSTEPSIZE / GCSWEEPCOST) / 4))
@@ -33,25 +36,27 @@ · 1 unmodified line
33/* maximum number of finalizers to call in each GC step */36/* maximum number of finalizers to call in each GC step */
34#define GCFINALIZENUM 437#define GCFINALIZENUM 4
35 38
36/* (arbitrary) cost of atomic step */
37#define GCATOMICCOST GCSTEPSIZE
38 39
40/*
41** macro to adjust 'stepmul': 'stepmul' is actually used like
42** 'stepmul / STEPMULADJ' (value chosen by tests)
43*/
44#define STEPMULADJ 200
39 45
40/*46/*
41** macro to apply the "speed" of the garbage collector: the constant47** macro to adjust 'pause': 'pause' is actually used like
42** 80 makes the standard 'stepmul' of 200 results in the GC handling48** 'pause / PAUSEADJ' (value chosen by tests)
43** 80/200 = 1/2.5 = 0.4Kbytes for every 1Kb allocated.
44** (The computation tries to avoid overflows or underflows.)
45*/49*/
46#define workrate(x,mul) \50#define PAUSEADJ 200
47 ((x) < MAX_INT/80 ? ((x) * 80) / mul : ((x) / mul) * 80)51
52
48 53
49 54
50/*55/*
51** standard negative debt for GC; a reasonable "time" to wait before56** standard negative debt for GC; a reasonable "time" to wait before
52** starting a new cycle57** starting a new cycle
53*/58*/
54#define stddebtest(g,e) (-cast(l_mem, (e)/100) * g->gcpause)59#define stddebtest(g,e) (-cast(l_mem, (e)/PAUSEADJ) * g->gcpause)
55#define stddebt(g) stddebtest(g, gettotalbytes(g))60#define stddebt(g) stddebtest(g, gettotalbytes(g))
56 61
57 62
@@ -672,7 +677,7 @@ static void freeobj (lua_State *L, GCObject *o) { · 614 unmodified lines
672 case LUA_TTABLE: luaH_free(L, gco2t(o)); break;677 case LUA_TTABLE: luaH_free(L, gco2t(o)); break;
673 case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;678 case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;
674 case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;679 case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
675 case LUA_TSHRSTR: 680 case LUA_TSHRSTR:
676 G(L)->strt.nuse--;681 G(L)->strt.nuse--;
677 /* go through */682 /* go through */
678 case LUA_TLNGSTR: {683 case LUA_TLNGSTR: {
@@ -955,8 +960,9 @@ void luaC_freeallobjects (lua_State *L) { · 276 unmodified lines
955}960}
956 961
957 962
958static void atomic (lua_State *L) {963static l_mem atomic (lua_State *L) {
959 global_State *g = G(L);964 global_State *g = G(L);
965 l_mem trav = g->GCmemtrav;
960 GCObject *origweak, *origall;966 GCObject *origweak, *origall;
961 lua_assert(!iswhite(obj2gco(g->mainthread)));967 lua_assert(!iswhite(obj2gco(g->mainthread)));
962 markobject(g, L); /* mark running thread */968 markobject(g, L); /* mark running thread */
@@ -976,6 +982,7 @@ static void atomic (lua_State *L) { · 13 unmodified lines
976 separatetobefnz(L, 0); /* separate objects to be finalized */982 separatetobefnz(L, 0); /* separate objects to be finalized */
977 markbeingfnz(g); /* mark userdata that will be finalized */983 markbeingfnz(g); /* mark userdata that will be finalized */
978 propagateall(g); /* remark, to propagate `preserveness' */984 propagateall(g); /* remark, to propagate `preserveness' */
985 trav = g->GCmemtrav - trav; /* avoid adding convergence twice */
979 convergeephemerons(g);986 convergeephemerons(g);
980 /* at this point, all resurrected objects are marked. */987 /* at this point, all resurrected objects are marked. */
981 /* remove dead objects from weak tables */988 /* remove dead objects from weak tables */
@@ -987,6 +994,7 @@ static void atomic (lua_State *L) { · 5 unmodified lines
987 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */994 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
988 entersweep(L); /* prepare to sweep strings */995 entersweep(L); /* prepare to sweep strings */
989 /*lua_checkmemory(L);*/996 /*lua_checkmemory(L);*/
997 return trav; /* reasonable estimate of the work done by 'atomic' */
990}998}
991 999
992 1000
@@ -1012,8 +1020,7 @@ static lu_mem singlestep (lua_State *L) { · 19 unmodified lines
1012 else { /* no more `gray' objects */1020 else { /* no more `gray' objects */
1013 g->gcstate = GCSatomic; /* finish mark phase */1021 g->gcstate = GCSatomic; /* finish mark phase */
1014 g->GCestimate = g->GCmemtrav; /* save what was counted */1022 g->GCestimate = g->GCmemtrav; /* save what was counted */
1015 atomic(L);1023 return atomic(L);
1016 return GCATOMICCOST;
1017 }1024 }
1018 }1025 }
1019 case GCSsweepstring: {1026 case GCSsweepstring: {
@@ -1086,14 +1093,18 @@ static void step (lua_State *L) { · 66 unmodified lines
1086 global_State *g = G(L);1093 global_State *g = G(L);
1087 l_mem debt = g->GCdebt;1094 l_mem debt = g->GCdebt;
1088 int stepmul = g->gcstepmul;1095 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;
1090 do { /* always perform at least one single step */1100 do { /* always perform at least one single step */
1091 lu_mem work = singlestep(L); /* do some work */1101 lu_mem work = singlestep(L); /* do some work */
1092 work = workrate(work, stepmul); /* apply work rate */
1093 debt -= work;1102 debt -= work;
1094 } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);1103 } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
1095 if (g->gcstate == GCSpause)1104 if (g->gcstate == GCSpause)
1096 debt = stddebtest(g, g->GCestimate); /* pause until next cycle */1105 debt = stddebtest(g, g->GCestimate); /* pause until next cycle */
1106 else
1107 debt = (debt / stepmul) * STEPMULADJ; /* convert 'work units' to Kb */
1097 luaE_setdebt(g, debt);1108 luaE_setdebt(g, debt);
1098}1109}
1099 1110
src/llimits.h+3−1
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Limits, basic types, and some other `installation-dependent' definitions3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -31,6 +31,8 @@ typedef unsigned char lu_byte; · 25 unmodified lines
31 31
32#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)32#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
33 33
34#define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))
35
34 36
35#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */37#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
36 38