diff options
Diffstat (limited to '')
-rw-r--r-- | lapi.c | 18 | ||||
-rw-r--r-- | lbaselib.c | 10 | ||||
-rw-r--r-- | lgc.h | 4 | ||||
-rw-r--r-- | lobject.c | 18 | ||||
-rw-r--r-- | lobject.h | 4 | ||||
-rw-r--r-- | manual/manual.of | 69 | ||||
-rw-r--r-- | testes/files.lua | 2 | ||||
-rw-r--r-- | testes/gc.lua | 29 |
8 files changed, 98 insertions, 56 deletions
@@ -416,10 +416,11 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | |||
416 | luaC_checkGC(L); | 416 | luaC_checkGC(L); |
417 | o = index2value(L, idx); /* previous call may reallocate the stack */ | 417 | o = index2value(L, idx); /* previous call may reallocate the stack */ |
418 | } | 418 | } |
419 | if (len != NULL) | ||
420 | *len = tsslen(tsvalue(o)); | ||
421 | lua_unlock(L); | 419 | lua_unlock(L); |
422 | return getstr(tsvalue(o)); | 420 | if (len != NULL) |
421 | return getlstr(tsvalue(o), *len); | ||
422 | else | ||
423 | return getstr(tsvalue(o)); | ||
423 | } | 424 | } |
424 | 425 | ||
425 | 426 | ||
@@ -1174,11 +1175,16 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { | |||
1174 | } | 1175 | } |
1175 | case LUA_GCSTEP: { | 1176 | case LUA_GCSTEP: { |
1176 | lu_byte oldstp = g->gcstp; | 1177 | lu_byte oldstp = g->gcstp; |
1178 | l_obj n = va_arg(argp, int); | ||
1179 | int work = 0; /* true if GC did some work */ | ||
1177 | g->gcstp = 0; /* allow GC to run (other bits must be zero here) */ | 1180 | g->gcstp = 0; /* allow GC to run (other bits must be zero here) */ |
1178 | luaC_step(L); /* run one basic step */ | 1181 | if (n <= 0) |
1179 | g->gcstp = oldstp; /* restore previous state */ | 1182 | n = g->GCdebt; /* force to run one basic step */ |
1180 | if (g->gcstate == GCSpause) /* end of cycle? */ | 1183 | luaE_setdebt(g, g->GCdebt - n); |
1184 | luaC_condGC(L, (void)0, work = 1); | ||
1185 | if (work && g->gcstate == GCSpause) /* end of cycle? */ | ||
1181 | res = 1; /* signal it */ | 1186 | res = 1; /* signal it */ |
1187 | g->gcstp = oldstp; /* restore previous state */ | ||
1182 | break; | 1188 | break; |
1183 | } | 1189 | } |
1184 | case LUA_GCISRUNNING: { | 1190 | case LUA_GCISRUNNING: { |
@@ -213,7 +213,8 @@ static int luaB_collectgarbage (lua_State *L) { | |||
213 | return 1; | 213 | return 1; |
214 | } | 214 | } |
215 | case LUA_GCSTEP: { | 215 | case LUA_GCSTEP: { |
216 | int res = lua_gc(L, o); | 216 | lua_Integer n = luaL_optinteger(L, 2, 0); |
217 | int res = lua_gc(L, o, (int)n); | ||
217 | checkvalres(res); | 218 | checkvalres(res); |
218 | lua_pushboolean(L, res); | 219 | lua_pushboolean(L, res); |
219 | return 1; | 220 | return 1; |
@@ -239,7 +240,7 @@ static int luaB_collectgarbage (lua_State *L) { | |||
239 | LUA_GCPPAUSE, LUA_GCPSTEPMUL, LUA_GCPSTEPSIZE}; | 240 | LUA_GCPPAUSE, LUA_GCPSTEPMUL, LUA_GCPSTEPSIZE}; |
240 | int p = pnum[luaL_checkoption(L, 2, NULL, params)]; | 241 | int p = pnum[luaL_checkoption(L, 2, NULL, params)]; |
241 | lua_Integer value = luaL_checkinteger(L, 3); | 242 | lua_Integer value = luaL_checkinteger(L, 3); |
242 | lua_pushinteger(L, lua_gc(L, o, p, value)); | 243 | lua_pushinteger(L, lua_gc(L, o, p, (int)value)); |
243 | return 1; | 244 | return 1; |
244 | } | 245 | } |
245 | default: { | 246 | default: { |
@@ -337,10 +338,7 @@ static int load_aux (lua_State *L, int status, int envidx) { | |||
337 | 338 | ||
338 | static const char *getmode (lua_State *L, int idx) { | 339 | static const char *getmode (lua_State *L, int idx) { |
339 | const char *mode = luaL_optstring(L, idx, "bt"); | 340 | const char *mode = luaL_optstring(L, idx, "bt"); |
340 | int i = 0; | 341 | if (strchr(mode, 'B') != NULL) /* Lua code cannot use fixed buffers */ |
341 | if (mode[i] == 'b') i++; | ||
342 | if (mode[i] == 't') i++; | ||
343 | if (mode[i] != '\0') | ||
344 | luaL_argerror(L, idx, "invalid mode"); | 342 | luaL_argerror(L, idx, "invalid mode"); |
345 | return mode; | 343 | return mode; |
346 | } | 344 | } |
@@ -171,13 +171,13 @@ | |||
171 | ** Major collections will shift to minor ones after a collection | 171 | ** Major collections will shift to minor ones after a collection |
172 | ** collects at least LUAI_MAJORMINOR% of the new objects. | 172 | ** collects at least LUAI_MAJORMINOR% of the new objects. |
173 | */ | 173 | */ |
174 | #define LUAI_MAJORMINOR 80 | 174 | #define LUAI_MAJORMINOR 50 |
175 | 175 | ||
176 | /* | 176 | /* |
177 | ** A young (minor) collection will run after creating LUAI_GENMINORMUL% | 177 | ** A young (minor) collection will run after creating LUAI_GENMINORMUL% |
178 | ** new objects. | 178 | ** new objects. |
179 | */ | 179 | */ |
180 | #define LUAI_GENMINORMUL 20 | 180 | #define LUAI_GENMINORMUL 25 |
181 | 181 | ||
182 | 182 | ||
183 | /* incremental */ | 183 | /* incremental */ |
@@ -50,22 +50,22 @@ int luaO_ceillog2 (unsigned int x) { | |||
50 | } | 50 | } |
51 | 51 | ||
52 | /* | 52 | /* |
53 | ** Encodes 'p'% as a floating-point byte, represented as (eeeeexxx). | 53 | ** Encodes 'p'% as a floating-point byte, represented as (eeeexxxx). |
54 | ** The exponent is represented using excess-7. Mimicking IEEE 754, the | 54 | ** The exponent is represented using excess-7. Mimicking IEEE 754, the |
55 | ** representation normalizes the number when possible, assuming an extra | 55 | ** representation normalizes the number when possible, assuming an extra |
56 | ** 1 before the mantissa (xxx) and adding one to the exponent (eeeeexxx) | 56 | ** 1 before the mantissa (xxxx) and adding one to the exponent (eeee) |
57 | ** to signal that. So, the real value is (1xxx) * 2^(eeeee - 8) if | 57 | ** to signal that. So, the real value is (1xxxx) * 2^(eeee - 7 - 1) if |
58 | ** eeeee != 0, and (xxx) * 2^-7 otherwise. | 58 | ** eeee != 0, and (xxxx) * 2^-7 otherwise (subnormal numbers). |
59 | */ | 59 | */ |
60 | unsigned int luaO_codeparam (unsigned int p) { | 60 | unsigned int luaO_codeparam (unsigned int p) { |
61 | if (p >= (cast(lu_mem, 0xF) << 0xF) / 128 * 100) /* overflow? */ | 61 | if (p >= (cast(lu_mem, 0x1F) << (0xF - 7 - 1)) * 100u) /* overflow? */ |
62 | return 0xFF; /* return maximum value */ | 62 | return 0xFF; /* return maximum value */ |
63 | else { | 63 | else { |
64 | p = (p * 128u) / 100; | 64 | p = (cast(l_uint32, p) * 128 + 99) / 100; /* round up the division */ |
65 | if (p <= 0xF) | 65 | if (p < 0x10) /* subnormal number? */ |
66 | return p; | 66 | return p; /* exponent bits are already zero; nothing else to do */ |
67 | else { | 67 | else { |
68 | int log = luaO_ceillog2(p + 1) - 5; | 68 | int log = luaO_ceillog2(p + 1) - 5; /* preserve 5 bits */ |
69 | return ((p >> log) - 0x10) | ((log + 1) << 4); | 69 | return ((p >> log) - 0x10) | ((log + 1) << 4); |
70 | } | 70 | } |
71 | } | 71 | } |
@@ -427,8 +427,8 @@ typedef struct TString { | |||
427 | ** Get string and length */ | 427 | ** Get string and length */ |
428 | #define getlstr(ts, len) \ | 428 | #define getlstr(ts, len) \ |
429 | (strisshr(ts) \ | 429 | (strisshr(ts) \ |
430 | ? (cast_void(len = (ts)->shrlen), rawgetshrstr(ts)) \ | 430 | ? (cast_void((len) = (ts)->shrlen), rawgetshrstr(ts)) \ |
431 | : (cast_void(len = (ts)->u.lnglen), (ts)->contents)) | 431 | : (cast_void((len) = (ts)->u.lnglen), (ts)->contents)) |
432 | 432 | ||
433 | /* }================================================================== */ | 433 | /* }================================================================== */ |
434 | 434 | ||
diff --git a/manual/manual.of b/manual/manual.of index 92d408e5..6fd0df6d 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -666,18 +666,6 @@ A value of 200 means that the collector waits for | |||
666 | the total number of objects to double before starting a new cycle. | 666 | the total number of objects to double before starting a new cycle. |
667 | The default value is 300; the maximum value is 1000. | 667 | The default value is 300; the maximum value is 1000. |
668 | 668 | ||
669 | The garbage-collector step multiplier | ||
670 | controls the speed of the collector relative to | ||
671 | object creation, | ||
672 | that is, | ||
673 | how many objects it marks or sweeps for each object created. | ||
674 | Larger values make the collector more aggressive. | ||
675 | Beware that values too small can | ||
676 | make the collector too slow to ever finish a cycle. | ||
677 | The default value is 200; the maximum value is 1000. | ||
678 | As a special case, a zero value means unlimited work, | ||
679 | effectively producing a non-incremental, stop-the-world collector. | ||
680 | |||
681 | The garbage-collector step size controls the | 669 | The garbage-collector step size controls the |
682 | size of each incremental step, | 670 | size of each incremental step, |
683 | specifically how many objects the interpreter creates | 671 | specifically how many objects the interpreter creates |
@@ -686,6 +674,17 @@ A value of @M{n} means the interpreter will create | |||
686 | approximately @M{n} objects between steps. | 674 | approximately @M{n} objects between steps. |
687 | The default value is 250. | 675 | The default value is 250. |
688 | 676 | ||
677 | The garbage-collector step multiplier | ||
678 | controls the size of each GC step. | ||
679 | A value of @M{n} means the interpreter will mark or sweep, | ||
680 | in each step, @M{n%} objects for each created object. | ||
681 | Larger values make the collector more aggressive. | ||
682 | Beware that values too small can | ||
683 | make the collector too slow to ever finish a cycle. | ||
684 | The default value is 200; the maximum value is 1000. | ||
685 | As a special case, a zero value means unlimited work, | ||
686 | effectively producing a non-incremental, stop-the-world collector. | ||
687 | |||
689 | } | 688 | } |
690 | 689 | ||
691 | @sect3{genmode| @title{Generational Garbage Collection} | 690 | @sect3{genmode| @title{Generational Garbage Collection} |
@@ -707,11 +706,12 @@ and the @def{major-minor multiplier}. | |||
707 | The minor multiplier controls the frequency of minor collections. | 706 | The minor multiplier controls the frequency of minor collections. |
708 | For a minor multiplier @M{x}, | 707 | For a minor multiplier @M{x}, |
709 | a new minor collection will be done when the number of objects | 708 | a new minor collection will be done when the number of objects |
710 | grows @M{x%} larger than the number in use just after the last collection. | 709 | grows @M{x%} larger than the number in use just |
710 | after the last major collection. | ||
711 | For instance, for a multiplier of 20, | 711 | For instance, for a multiplier of 20, |
712 | the collector will do a minor collection when the number of objects | 712 | the collector will do a minor collection when the number of objects |
713 | gets 20% larger than the total after the last major collection. | 713 | gets 20% larger than the total after the last major collection. |
714 | The default value is 20. | 714 | The default value is 25. |
715 | 715 | ||
716 | The minor-major multiplier controls the shift to major collections. | 716 | The minor-major multiplier controls the shift to major collections. |
717 | For a multiplier @M{x}, | 717 | For a multiplier @M{x}, |
@@ -728,11 +728,10 @@ For a multiplier @M{x}, | |||
728 | the collector will shift back to minor collections | 728 | the collector will shift back to minor collections |
729 | after a major collection collects at least @M{x%} | 729 | after a major collection collects at least @M{x%} |
730 | of the objects allocated during the last cycle. | 730 | of the objects allocated during the last cycle. |
731 | |||
732 | In particular, for a multiplier of 0, | 731 | In particular, for a multiplier of 0, |
733 | the collector will immediately shift back to minor collections | 732 | the collector will immediately shift back to minor collections |
734 | after doing one cycle of major collections. | 733 | after doing one cycle of major collections. |
735 | The default value is 80. | 734 | The default value is 50. |
736 | 735 | ||
737 | } | 736 | } |
738 | 737 | ||
@@ -3327,7 +3326,7 @@ Returns the remainder of dividing the current amount of bytes of | |||
3327 | memory in use by Lua by 1024. | 3326 | memory in use by Lua by 1024. |
3328 | } | 3327 | } |
3329 | 3328 | ||
3330 | @item{@defid{LUA_GCSTEP}| | 3329 | @item{@defid{LUA_GCSTEP} (int n)| |
3331 | Performs a step of garbage collection. | 3330 | Performs a step of garbage collection. |
3332 | } | 3331 | } |
3333 | 3332 | ||
@@ -3686,9 +3685,12 @@ Moreover, for a fixed buffer, | |||
3686 | the reader function should return the entire chunk in the first read. | 3685 | the reader function should return the entire chunk in the first read. |
3687 | (As an example, @Lid{luaL_loadbufferx} does that.) | 3686 | (As an example, @Lid{luaL_loadbufferx} does that.) |
3688 | 3687 | ||
3689 | @id{lua_load} uses the stack internally, | 3688 | The function @Lid{lua_load} fully preserves the Lua stack |
3690 | so the reader function must always leave the stack | 3689 | through the calls to the reader function, |
3691 | unmodified when returning. | 3690 | except that it may push some values for internal use |
3691 | before the first call, | ||
3692 | and it restores the stack size to its original size plus one | ||
3693 | (for the pushed result) after the last call. | ||
3692 | 3694 | ||
3693 | @id{lua_load} can return | 3695 | @id{lua_load} can return |
3694 | @Lid{LUA_OK}, @Lid{LUA_ERRSYNTAX}, or @Lid{LUA_ERRMEM}. | 3696 | @Lid{LUA_OK}, @Lid{LUA_ERRSYNTAX}, or @Lid{LUA_ERRMEM}. |
@@ -6344,13 +6346,24 @@ gives the exact number of bytes in use by Lua. | |||
6344 | 6346 | ||
6345 | @item{@St{step}| | 6347 | @item{@St{step}| |
6346 | Performs a garbage-collection step. | 6348 | Performs a garbage-collection step. |
6349 | This option may be followed by an extra argument, | ||
6350 | an integer with the step size. | ||
6351 | The default for this argument is zero. | ||
6352 | |||
6353 | If the size is a positive @id{n}, | ||
6354 | the collector acts as if @id{n} new objects have been created. | ||
6355 | If the size is zero, | ||
6356 | the collector performs a basic step. | ||
6347 | In incremental mode, | 6357 | In incremental mode, |
6348 | that step corresponds to the current step size; | 6358 | a basic step corresponds to the current step size. |
6349 | the function returns @true if the step finished a collection cycle. | ||
6350 | In generational mode, | 6359 | In generational mode, |
6351 | the step performs a full minor collection or | 6360 | a basic step performs a full minor collection or |
6352 | a major collection, | 6361 | a major collection, |
6353 | if the collector has scheduled one; | 6362 | if the collector has scheduled one. |
6363 | |||
6364 | In incremental mode, | ||
6365 | the function returns @true if the step finished a collection cycle. | ||
6366 | In generational mode, | ||
6354 | the function returns @true if the step performed a major collection. | 6367 | the function returns @true if the step performed a major collection. |
6355 | } | 6368 | } |
6356 | 6369 | ||
@@ -6382,13 +6395,9 @@ The argument @id{param} must have one of the following values: | |||
6382 | @item{@St{stepmul}| The step multiplier. } | 6395 | @item{@St{stepmul}| The step multiplier. } |
6383 | @item{@St{stepsize}| The step size. } | 6396 | @item{@St{stepsize}| The step size. } |
6384 | } | 6397 | } |
6385 | To be able to divide by 100 | 6398 | Lua rounds these values before storing them; |
6386 | (as most parameters are given as percentages) | ||
6387 | without using floating-point arithmetic, | ||
6388 | Lua stores these parameters encoded. | ||
6389 | This encoding approximates the real value; | ||
6390 | so, the value returned as the previous value may not be | 6399 | so, the value returned as the previous value may not be |
6391 | equal to the last value set. | 6400 | exactly the last value set. |
6392 | } | 6401 | } |
6393 | 6402 | ||
6394 | } | 6403 | } |
diff --git a/testes/files.lua b/testes/files.lua index 2582406f..4f925f50 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
@@ -74,6 +74,8 @@ io.input(io.stdin); io.output(io.stdout); | |||
74 | 74 | ||
75 | os.remove(file) | 75 | os.remove(file) |
76 | assert(not loadfile(file)) | 76 | assert(not loadfile(file)) |
77 | -- Lua code cannot use chunks with fixed buffers | ||
78 | checkerr("invalid mode", load, "", "", "B") | ||
77 | checkerr("", dofile, file) | 79 | checkerr("", dofile, file) |
78 | assert(not io.open(file)) | 80 | assert(not io.open(file)) |
79 | io.output(file) | 81 | io.output(file) |
diff --git a/testes/gc.lua b/testes/gc.lua index 8bacffa0..c26de406 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
@@ -35,7 +35,7 @@ do | |||
35 | collectgarbage("setparam", "pause", t[i]) | 35 | collectgarbage("setparam", "pause", t[i]) |
36 | for j = 1, #t do | 36 | for j = 1, #t do |
37 | collectgarbage("setparam", "stepmul", t[j]) | 37 | collectgarbage("setparam", "stepmul", t[j]) |
38 | collectgarbage("step") | 38 | collectgarbage("step", t[j]) |
39 | end | 39 | end |
40 | end | 40 | end |
41 | -- restore original parameters | 41 | -- restore original parameters |
@@ -45,6 +45,33 @@ do | |||
45 | end | 45 | end |
46 | 46 | ||
47 | 47 | ||
48 | -- | ||
49 | -- test the "size" of basic GC steps (whatever they mean...) | ||
50 | -- | ||
51 | do print("steps") | ||
52 | |||
53 | local function dosteps (siz) | ||
54 | collectgarbage() | ||
55 | local a = {} | ||
56 | for i=1,100 do a[i] = {{}}; local b = {} end | ||
57 | local x = gcinfo() | ||
58 | local i = 0 | ||
59 | repeat -- do steps until it completes a collection cycle | ||
60 | i = i+1 | ||
61 | until collectgarbage("step", siz) | ||
62 | assert(gcinfo() < x) | ||
63 | return i -- number of steps | ||
64 | end | ||
65 | |||
66 | collectgarbage"stop" | ||
67 | |||
68 | if not _port then | ||
69 | assert(dosteps(10) < dosteps(2)) | ||
70 | end | ||
71 | |||
72 | end | ||
73 | |||
74 | |||
48 | _G["while"] = 234 | 75 | _G["while"] = 234 |
49 | 76 | ||
50 | 77 | ||