aboutsummaryrefslogtreecommitdiff
path: root/src/lj_gc.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lj_gc.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/lj_gc.c b/src/lj_gc.c
index 79f8b720..bc10822f 100644
--- a/src/lj_gc.c
+++ b/src/lj_gc.c
@@ -12,6 +12,7 @@
12#include "lj_obj.h" 12#include "lj_obj.h"
13#include "lj_gc.h" 13#include "lj_gc.h"
14#include "lj_err.h" 14#include "lj_err.h"
15#include "lj_buf.h"
15#include "lj_str.h" 16#include "lj_str.h"
16#include "lj_tab.h" 17#include "lj_tab.h"
17#include "lj_func.h" 18#include "lj_func.h"
@@ -348,15 +349,6 @@ static size_t gc_propagate_gray(global_State *g)
348 349
349/* -- Sweep phase --------------------------------------------------------- */ 350/* -- Sweep phase --------------------------------------------------------- */
350 351
351/* Try to shrink some common data structures. */
352static void gc_shrink(global_State *g, lua_State *L)
353{
354 if (g->strnum <= (g->strmask >> 2) && g->strmask > LJ_MIN_STRTAB*2-1)
355 lj_str_resize(L, g->strmask >> 1); /* Shrink string table. */
356 if (g->tmpbuf.sz > LJ_MIN_SBUF*2)
357 lj_str_resizebuf(L, &g->tmpbuf, g->tmpbuf.sz >> 1); /* Shrink temp buf. */
358}
359
360/* Type of GC free functions. */ 352/* Type of GC free functions. */
361typedef void (LJ_FASTCALL *GCFreeFunc)(global_State *g, GCobj *o); 353typedef void (LJ_FASTCALL *GCFreeFunc)(global_State *g, GCobj *o);
362 354
@@ -483,7 +475,7 @@ static void gc_finalize(lua_State *L)
483 global_State *g = G(L); 475 global_State *g = G(L);
484 GCobj *o = gcnext(gcref(g->gc.mmudata)); 476 GCobj *o = gcnext(gcref(g->gc.mmudata));
485 cTValue *mo; 477 cTValue *mo;
486 lua_assert(gcref(g->jit_L) == NULL); /* Must not be called on trace. */ 478 lua_assert(tvref(g->jit_base) == NULL); /* Must not be called on trace. */
487 /* Unchain from list of userdata to be finalized. */ 479 /* Unchain from list of userdata to be finalized. */
488 if (o == gcref(g->gc.mmudata)) 480 if (o == gcref(g->gc.mmudata))
489 setgcrefnull(g->gc.mmudata); 481 setgcrefnull(g->gc.mmudata);
@@ -591,6 +583,8 @@ static void atomic(global_State *g, lua_State *L)
591 /* All marking done, clear weak tables. */ 583 /* All marking done, clear weak tables. */
592 gc_clearweak(gcref(g->gc.weak)); 584 gc_clearweak(gcref(g->gc.weak));
593 585
586 lj_buf_shrink(L, &g->tmpbuf); /* Shrink temp buffer. */
587
594 /* Prepare for sweep phase. */ 588 /* Prepare for sweep phase. */
595 g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */ 589 g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */
596 g->strempty.marked = g->gc.currentwhite; 590 g->strempty.marked = g->gc.currentwhite;
@@ -612,7 +606,7 @@ static size_t gc_onestep(lua_State *L)
612 g->gc.state = GCSatomic; /* End of mark phase. */ 606 g->gc.state = GCSatomic; /* End of mark phase. */
613 return 0; 607 return 0;
614 case GCSatomic: 608 case GCSatomic:
615 if (gcref(g->jit_L)) /* Don't run atomic phase on trace. */ 609 if (tvref(g->jit_base)) /* Don't run atomic phase on trace. */
616 return LJ_MAX_MEM; 610 return LJ_MAX_MEM;
617 atomic(g, L); 611 atomic(g, L);
618 g->gc.state = GCSsweepstring; /* Start of sweep phase. */ 612 g->gc.state = GCSsweepstring; /* Start of sweep phase. */
@@ -631,7 +625,8 @@ static size_t gc_onestep(lua_State *L)
631 MSize old = g->gc.total; 625 MSize old = g->gc.total;
632 setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX)); 626 setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX));
633 if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) { 627 if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) {
634 gc_shrink(g, L); 628 if (g->strnum <= (g->strmask >> 2) && g->strmask > LJ_MIN_STRTAB*2-1)
629 lj_str_resize(L, g->strmask >> 1); /* Shrink string table. */
635 if (gcref(g->gc.mmudata)) { /* Need any finalizations? */ 630 if (gcref(g->gc.mmudata)) { /* Need any finalizations? */
636 g->gc.state = GCSfinalize; 631 g->gc.state = GCSfinalize;
637 } else { /* Otherwise skip this phase to help the JIT. */ 632 } else { /* Otherwise skip this phase to help the JIT. */
@@ -645,7 +640,7 @@ static size_t gc_onestep(lua_State *L)
645 } 640 }
646 case GCSfinalize: 641 case GCSfinalize:
647 if (gcref(g->gc.mmudata) != NULL) { 642 if (gcref(g->gc.mmudata) != NULL) {
648 if (gcref(g->jit_L)) /* Don't call finalizers on trace. */ 643 if (tvref(g->jit_base)) /* Don't call finalizers on trace. */
649 return LJ_MAX_MEM; 644 return LJ_MAX_MEM;
650 gc_finalize(L); /* Finalize one userdata object. */ 645 gc_finalize(L); /* Finalize one userdata object. */
651 if (g->gc.estimate > GCFINALIZECOST) 646 if (g->gc.estimate > GCFINALIZECOST)
@@ -701,8 +696,8 @@ void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L)
701/* Perform multiple GC steps. Called from JIT-compiled code. */ 696/* Perform multiple GC steps. Called from JIT-compiled code. */
702int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps) 697int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps)
703{ 698{
704 lua_State *L = gco2th(gcref(g->jit_L)); 699 lua_State *L = gco2th(gcref(g->cur_L));
705 L->base = mref(G(L)->jit_base, TValue); 700 L->base = tvref(G(L)->jit_base);
706 L->top = curr_topL(L); 701 L->top = curr_topL(L);
707 while (steps-- > 0 && lj_gc_step(L) == 0) 702 while (steps-- > 0 && lj_gc_step(L) == 0)
708 ; 703 ;