diff options
author | Mike Pall <mike> | 2010-02-11 01:21:40 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-02-11 01:21:40 +0100 |
commit | ab90b8fc2b516fa38a194844e31c70c106153cdf (patch) | |
tree | 78401446b804b73bcdd0f98161bcc2a7a00e002c /src/lj_gc.c | |
parent | bb0384c36628c94a2232955e0cac5cf45679039f (diff) | |
download | luajit-ab90b8fc2b516fa38a194844e31c70c106153cdf.tar.gz luajit-ab90b8fc2b516fa38a194844e31c70c106153cdf.tar.bz2 luajit-ab90b8fc2b516fa38a194844e31c70c106153cdf.zip |
Switch to pre-initialized stacks. Drop frame clearing in interpreter.
Diffstat (limited to 'src/lj_gc.c')
-rw-r--r-- | src/lj_gc.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/src/lj_gc.c b/src/lj_gc.c index d8221740..d769c0c8 100644 --- a/src/lj_gc.c +++ b/src/lj_gc.c | |||
@@ -261,7 +261,7 @@ static void gc_traverse_proto(global_State *g, GCproto *pt) | |||
261 | } | 261 | } |
262 | 262 | ||
263 | /* Traverse the frame structure of a stack. */ | 263 | /* Traverse the frame structure of a stack. */ |
264 | static TValue *gc_traverse_frames(global_State *g, lua_State *th) | 264 | static MSize gc_traverse_frames(global_State *g, lua_State *th) |
265 | { | 265 | { |
266 | TValue *frame, *top = th->top-1; | 266 | TValue *frame, *top = th->top-1; |
267 | /* Note: extra vararg frame not skipped, marks function twice (harmless). */ | 267 | /* Note: extra vararg frame not skipped, marks function twice (harmless). */ |
@@ -274,32 +274,22 @@ static TValue *gc_traverse_frames(global_State *g, lua_State *th) | |||
274 | } | 274 | } |
275 | top++; /* Correct bias of -1 (frame == base-1). */ | 275 | top++; /* Correct bias of -1 (frame == base-1). */ |
276 | if (top > th->maxstack) top = th->maxstack; | 276 | if (top > th->maxstack) top = th->maxstack; |
277 | return top; | 277 | return (MSize)(top - th->stack); /* Return minimum needed stack size. */ |
278 | } | 278 | } |
279 | 279 | ||
280 | /* Traverse a thread object. */ | 280 | /* Traverse a thread object. */ |
281 | static void gc_traverse_thread(global_State *g, lua_State *th) | 281 | static void gc_traverse_thread(global_State *g, lua_State *th) |
282 | { | 282 | { |
283 | TValue *o, *lim; | 283 | TValue *o, *top = th->top; |
284 | gc_markobj(g, tabref(th->env)); | 284 | for (o = th->stack+1; o < top; o++) |
285 | for (o = th->stack+1; o < th->top; o++) | ||
286 | gc_marktv(g, o); | 285 | gc_marktv(g, o); |
287 | lim = gc_traverse_frames(g, th); | 286 | if (g->gc.state == GCSatomic) { |
288 | /* Extra cleanup required to avoid this marking problem: | 287 | top = th->stack + th->stacksize; |
289 | ** | 288 | for (; o < top; o++) /* Clear unmarked slots. */ |
290 | ** [aa[bb.X| X created. | 289 | setnilV(o); |
291 | ** [aa[cc| GC called from (small) inner frame, X destroyed. | 290 | } |
292 | ** [aa....X.| GC called again in (larger) outer frame, X resurrected (ouch). | 291 | gc_markobj(g, tabref(th->env)); |
293 | ** | 292 | lj_state_shrinkstack(th, gc_traverse_frames(g, th)); |
294 | ** During GC in step 2 the stack must be cleaned up to the max. frame extent: | ||
295 | ** | ||
296 | ** ***| Slots cleaned | ||
297 | ** [cc| from top of last frame | ||
298 | ** [aa......| to max. frame extent. | ||
299 | */ | ||
300 | for (; o <= lim; o++) | ||
301 | setnilV(o); | ||
302 | lj_state_shrinkstack(th, (MSize)(lim - th->stack)); | ||
303 | } | 293 | } |
304 | 294 | ||
305 | /* Propagate one gray object. Traverse it and turn it black. */ | 295 | /* Propagate one gray object. Traverse it and turn it black. */ |
@@ -524,6 +514,7 @@ static void atomic(global_State *g, lua_State *L) | |||
524 | { | 514 | { |
525 | size_t udsize; | 515 | size_t udsize; |
526 | 516 | ||
517 | g->gc.state = GCSatomic; | ||
527 | gc_mark_uv(g); /* Need to remark open upvalues (the thread may be dead). */ | 518 | gc_mark_uv(g); /* Need to remark open upvalues (the thread may be dead). */ |
528 | gc_propagate_gray(g); /* Propagate any left-overs. */ | 519 | gc_propagate_gray(g); /* Propagate any left-overs. */ |
529 | 520 | ||