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.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/lj_gc.c b/src/lj_gc.c
index c856df4d..376c9d09 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);
@@ -592,6 +584,8 @@ static void atomic(global_State *g, lua_State *L)
592 /* All marking done, clear weak tables. */ 584 /* All marking done, clear weak tables. */
593 gc_clearweak(gcref(g->gc.weak)); 585 gc_clearweak(gcref(g->gc.weak));
594 586
587 lj_buf_shrink(L, &g->tmpbuf); /* Shrink temp buffer. */
588
595 /* Prepare for sweep phase. */ 589 /* Prepare for sweep phase. */
596 g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */ 590 g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */
597 g->strempty.marked = g->gc.currentwhite; 591 g->strempty.marked = g->gc.currentwhite;
@@ -613,7 +607,7 @@ static size_t gc_onestep(lua_State *L)
613 g->gc.state = GCSatomic; /* End of mark phase. */ 607 g->gc.state = GCSatomic; /* End of mark phase. */
614 return 0; 608 return 0;
615 case GCSatomic: 609 case GCSatomic:
616 if (gcref(g->jit_L)) /* Don't run atomic phase on trace. */ 610 if (tvref(g->jit_base)) /* Don't run atomic phase on trace. */
617 return LJ_MAX_MEM; 611 return LJ_MAX_MEM;
618 atomic(g, L); 612 atomic(g, L);
619 g->gc.state = GCSsweepstring; /* Start of sweep phase. */ 613 g->gc.state = GCSsweepstring; /* Start of sweep phase. */
@@ -634,7 +628,8 @@ static size_t gc_onestep(lua_State *L)
634 lua_assert(old >= g->gc.total); 628 lua_assert(old >= g->gc.total);
635 g->gc.estimate -= old - g->gc.total; 629 g->gc.estimate -= old - g->gc.total;
636 if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) { 630 if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) {
637 gc_shrink(g, L); 631 if (g->strnum <= (g->strmask >> 2) && g->strmask > LJ_MIN_STRTAB*2-1)
632 lj_str_resize(L, g->strmask >> 1); /* Shrink string table. */
638 if (gcref(g->gc.mmudata)) { /* Need any finalizations? */ 633 if (gcref(g->gc.mmudata)) { /* Need any finalizations? */
639 g->gc.state = GCSfinalize; 634 g->gc.state = GCSfinalize;
640#if LJ_HASFFI 635#if LJ_HASFFI
@@ -649,7 +644,7 @@ static size_t gc_onestep(lua_State *L)
649 } 644 }
650 case GCSfinalize: 645 case GCSfinalize:
651 if (gcref(g->gc.mmudata) != NULL) { 646 if (gcref(g->gc.mmudata) != NULL) {
652 if (gcref(g->jit_L)) /* Don't call finalizers on trace. */ 647 if (tvref(g->jit_base)) /* Don't call finalizers on trace. */
653 return LJ_MAX_MEM; 648 return LJ_MAX_MEM;
654 gc_finalize(L); /* Finalize one userdata object. */ 649 gc_finalize(L); /* Finalize one userdata object. */
655 if (g->gc.estimate > GCFINALIZECOST) 650 if (g->gc.estimate > GCFINALIZECOST)
@@ -711,8 +706,8 @@ void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L)
711/* Perform multiple GC steps. Called from JIT-compiled code. */ 706/* Perform multiple GC steps. Called from JIT-compiled code. */
712int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps) 707int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps)
713{ 708{
714 lua_State *L = gco2th(gcref(g->jit_L)); 709 lua_State *L = gco2th(gcref(g->cur_L));
715 L->base = mref(G(L)->jit_base, TValue); 710 L->base = tvref(G(L)->jit_base);
716 L->top = curr_topL(L); 711 L->top = curr_topL(L);
717 while (steps-- > 0 && lj_gc_step(L) == 0) 712 while (steps-- > 0 && lj_gc_step(L) == 0)
718 ; 713 ;