diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-12-01 16:38:28 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-12-01 16:38:28 -0300 |
| commit | b719ff9399cbc4b19b2b8325417fc5fa0ef3d0e3 (patch) | |
| tree | 99d83abfb2da27d30498f87b9e6b159e73d99812 | |
| parent | 35a2fed2d1e0b95a1bfab364707e469863517085 (diff) | |
| download | lua-b719ff9399cbc4b19b2b8325417fc5fa0ef3d0e3.tar.gz lua-b719ff9399cbc4b19b2b8325417fc5fa0ef3d0e3.tar.bz2 lua-b719ff9399cbc4b19b2b8325417fc5fa0ef3d0e3.zip | |
Removed parameter in 'collectgarbage("step")'
A call to 'collectgarbage("step")' always performs one GC basic step.
| -rw-r--r-- | lapi.c | 18 | ||||
| -rw-r--r-- | testes/gc.lua | 42 |
2 files changed, 3 insertions, 57 deletions
| @@ -1191,25 +1191,11 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { | |||
| 1191 | break; | 1191 | break; |
| 1192 | } | 1192 | } |
| 1193 | case LUA_GCSTEP: { | 1193 | case LUA_GCSTEP: { |
| 1194 | int todo = va_arg(argp, int); /* work to be done */ | ||
| 1195 | int didsomething = 0; | ||
| 1196 | lu_byte oldstp = g->gcstp; | 1194 | lu_byte oldstp = g->gcstp; |
| 1197 | g->gcstp = 0; /* allow GC to run (other bits must be zero here) */ | 1195 | g->gcstp = 0; /* allow GC to run (other bits must be zero here) */ |
| 1198 | if (todo == 0) | 1196 | luaC_step(L); /* run one basic step */ |
| 1199 | todo = 1 << g->gcstepsize; /* standard step size */ | ||
| 1200 | while (todo >= g->GCdebt) { /* enough to run a step? */ | ||
| 1201 | todo -= g->GCdebt; /* decrement 'todo' */ | ||
| 1202 | luaC_step(L); /* run one basic step */ | ||
| 1203 | didsomething = 1; | ||
| 1204 | if (g->gckind == KGC_GEN) /* minor collections? */ | ||
| 1205 | todo = 0; /* doesn't make sense to repeat in this case */ | ||
| 1206 | else if (g->gcstate == GCSpause) | ||
| 1207 | break; /* don't run more than one cycle */ | ||
| 1208 | } | ||
| 1209 | /* remove remaining 'todo' from total debt */ | ||
| 1210 | luaE_setdebt(g, g->GCdebt - todo); | ||
| 1211 | g->gcstp = oldstp; /* restore previous state */ | 1197 | g->gcstp = oldstp; /* restore previous state */ |
| 1212 | if (didsomething && g->gcstate == GCSpause) /* end of cycle? */ | 1198 | if (g->gcstate == GCSpause) /* end of cycle? */ |
| 1213 | res = 1; /* signal it */ | 1199 | res = 1; /* signal it */ |
| 1214 | break; | 1200 | break; |
| 1215 | } | 1201 | } |
diff --git a/testes/gc.lua b/testes/gc.lua index 4cf7d556..d7e0c4ff 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
| @@ -33,8 +33,7 @@ do | |||
| 33 | for j = 1, #t do | 33 | for j = 1, #t do |
| 34 | local m = t[j] | 34 | local m = t[j] |
| 35 | collectgarbage("incremental", p, m) | 35 | collectgarbage("incremental", p, m) |
| 36 | collectgarbage("step", 0) | 36 | collectgarbage("step") |
| 37 | collectgarbage("step", 10000) | ||
| 38 | end | 37 | end |
| 39 | end | 38 | end |
| 40 | -- restore original parameters | 39 | -- restore original parameters |
| @@ -169,45 +168,6 @@ do | |||
| 169 | end | 168 | end |
| 170 | 169 | ||
| 171 | 170 | ||
| 172 | -- | ||
| 173 | -- test the "size" of basic GC steps (whatever they mean...) | ||
| 174 | -- | ||
| 175 | do | ||
| 176 | print("steps") | ||
| 177 | |||
| 178 | print("steps (2)") | ||
| 179 | |||
| 180 | local function dosteps (siz) | ||
| 181 | collectgarbage() | ||
| 182 | local a = {} | ||
| 183 | for i=1,100 do a[i] = {{}}; local b = {} end | ||
| 184 | local x = gcinfo() | ||
| 185 | local i = 0 | ||
| 186 | repeat -- do steps until it completes a collection cycle | ||
| 187 | i = i+1 | ||
| 188 | until collectgarbage("step", siz) | ||
| 189 | assert(gcinfo() < x) | ||
| 190 | return i -- number of steps | ||
| 191 | end | ||
| 192 | |||
| 193 | collectgarbage"stop" | ||
| 194 | |||
| 195 | if not _port then | ||
| 196 | assert(dosteps(10) < dosteps(2)) | ||
| 197 | end | ||
| 198 | |||
| 199 | -- collector should do a full collection with so many steps | ||
| 200 | assert(dosteps(20000) == 1) | ||
| 201 | assert(collectgarbage("step", 20000) == true) | ||
| 202 | assert(collectgarbage("step", 20000) == true) | ||
| 203 | |||
| 204 | assert(not collectgarbage("isrunning")) | ||
| 205 | collectgarbage"restart" | ||
| 206 | assert(collectgarbage("isrunning")) | ||
| 207 | |||
| 208 | end | ||
| 209 | |||
| 210 | |||
| 211 | if not _port then | 171 | if not _port then |
| 212 | -- test the pace of the collector | 172 | -- test the pace of the collector |
| 213 | collectgarbage(); collectgarbage() | 173 | collectgarbage(); collectgarbage() |
