aboutsummaryrefslogtreecommitdiff
path: root/src/lj_gc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_gc.c')
-rw-r--r--src/lj_gc.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/lj_gc.c b/src/lj_gc.c
index 79f8b720..c9eaf21a 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
@@ -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;
@@ -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. */