diff options
author | Mike Pall <mike> | 2014-12-20 00:17:50 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2014-12-20 00:17:50 +0100 |
commit | 6e9145a882ea70fe438d59959ac4e65481fe5e85 (patch) | |
tree | 98e7c78e5aab6bd0360d9e00e4c82e9f1634c96d /src/lj_gc.c | |
parent | 82e6e5fb5f17e497b3341322998ede75ec29e554 (diff) | |
download | luajit-6e9145a882ea70fe438d59959ac4e65481fe5e85.tar.gz luajit-6e9145a882ea70fe438d59959ac4e65481fe5e85.tar.bz2 luajit-6e9145a882ea70fe438d59959ac4e65481fe5e85.zip |
Cleanup of memory vs. GC sizes. No functional changes.
Diffstat (limited to 'src/lj_gc.c')
-rw-r--r-- | src/lj_gc.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/lj_gc.c b/src/lj_gc.c index 376c9d09..5a7127c2 100644 --- a/src/lj_gc.c +++ b/src/lj_gc.c | |||
@@ -374,7 +374,7 @@ static const GCFreeFunc gc_freefunc[] = { | |||
374 | }; | 374 | }; |
375 | 375 | ||
376 | /* Full sweep of a GC list. */ | 376 | /* Full sweep of a GC list. */ |
377 | #define gc_fullsweep(g, p) gc_sweep(g, (p), LJ_MAX_MEM) | 377 | #define gc_fullsweep(g, p) gc_sweep(g, (p), ~(uint32_t)0) |
378 | 378 | ||
379 | /* Partial sweep of a GC list. */ | 379 | /* Partial sweep of a GC list. */ |
380 | static GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim) | 380 | static GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim) |
@@ -452,7 +452,7 @@ static void gc_call_finalizer(global_State *g, lua_State *L, | |||
452 | { | 452 | { |
453 | /* Save and restore lots of state around the __gc callback. */ | 453 | /* Save and restore lots of state around the __gc callback. */ |
454 | uint8_t oldh = hook_save(g); | 454 | uint8_t oldh = hook_save(g); |
455 | MSize oldt = g->gc.threshold; | 455 | GCSize oldt = g->gc.threshold; |
456 | int errcode; | 456 | int errcode; |
457 | TValue *top; | 457 | TValue *top; |
458 | lj_trace_abort(g); | 458 | lj_trace_abort(g); |
@@ -590,7 +590,7 @@ static void atomic(global_State *g, lua_State *L) | |||
590 | g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */ | 590 | g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */ |
591 | g->strempty.marked = g->gc.currentwhite; | 591 | g->strempty.marked = g->gc.currentwhite; |
592 | setmref(g->gc.sweep, &g->gc.root); | 592 | setmref(g->gc.sweep, &g->gc.root); |
593 | g->gc.estimate = g->gc.total - (MSize)udsize; /* Initial estimate. */ | 593 | g->gc.estimate = g->gc.total - (GCSize)udsize; /* Initial estimate. */ |
594 | } | 594 | } |
595 | 595 | ||
596 | /* GC state machine. Returns a cost estimate for each step performed. */ | 596 | /* GC state machine. Returns a cost estimate for each step performed. */ |
@@ -614,7 +614,7 @@ static size_t gc_onestep(lua_State *L) | |||
614 | g->gc.sweepstr = 0; | 614 | g->gc.sweepstr = 0; |
615 | return 0; | 615 | return 0; |
616 | case GCSsweepstring: { | 616 | case GCSsweepstring: { |
617 | MSize old = g->gc.total; | 617 | GCSize old = g->gc.total; |
618 | gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]); /* Sweep one chain. */ | 618 | gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]); /* Sweep one chain. */ |
619 | if (g->gc.sweepstr > g->strmask) | 619 | if (g->gc.sweepstr > g->strmask) |
620 | g->gc.state = GCSsweep; /* All string hash chains sweeped. */ | 620 | g->gc.state = GCSsweep; /* All string hash chains sweeped. */ |
@@ -623,7 +623,7 @@ static size_t gc_onestep(lua_State *L) | |||
623 | return GCSWEEPCOST; | 623 | return GCSWEEPCOST; |
624 | } | 624 | } |
625 | case GCSsweep: { | 625 | case GCSsweep: { |
626 | MSize old = g->gc.total; | 626 | GCSize old = g->gc.total; |
627 | setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX)); | 627 | setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX)); |
628 | lua_assert(old >= g->gc.total); | 628 | lua_assert(old >= g->gc.total); |
629 | g->gc.estimate -= old - g->gc.total; | 629 | g->gc.estimate -= old - g->gc.total; |
@@ -667,7 +667,7 @@ static size_t gc_onestep(lua_State *L) | |||
667 | int LJ_FASTCALL lj_gc_step(lua_State *L) | 667 | int LJ_FASTCALL lj_gc_step(lua_State *L) |
668 | { | 668 | { |
669 | global_State *g = G(L); | 669 | global_State *g = G(L); |
670 | MSize lim; | 670 | GCSize lim; |
671 | int32_t ostate = g->vmstate; | 671 | int32_t ostate = g->vmstate; |
672 | setvmstate(g, GC); | 672 | setvmstate(g, GC); |
673 | lim = (GCSTEPSIZE/100) * g->gc.stepmul; | 673 | lim = (GCSTEPSIZE/100) * g->gc.stepmul; |
@@ -676,13 +676,13 @@ int LJ_FASTCALL lj_gc_step(lua_State *L) | |||
676 | if (g->gc.total > g->gc.threshold) | 676 | if (g->gc.total > g->gc.threshold) |
677 | g->gc.debt += g->gc.total - g->gc.threshold; | 677 | g->gc.debt += g->gc.total - g->gc.threshold; |
678 | do { | 678 | do { |
679 | lim -= (MSize)gc_onestep(L); | 679 | lim -= (GCSize)gc_onestep(L); |
680 | if (g->gc.state == GCSpause) { | 680 | if (g->gc.state == GCSpause) { |
681 | g->gc.threshold = (g->gc.estimate/100) * g->gc.pause; | 681 | g->gc.threshold = (g->gc.estimate/100) * g->gc.pause; |
682 | g->vmstate = ostate; | 682 | g->vmstate = ostate; |
683 | return 1; /* Finished a GC cycle. */ | 683 | return 1; /* Finished a GC cycle. */ |
684 | } | 684 | } |
685 | } while ((int32_t)lim > 0); | 685 | } while (sizeof(lim) == 8 ? ((int64_t)lim > 0) : ((int32_t)lim > 0)); |
686 | if (g->gc.debt < GCSTEPSIZE) { | 686 | if (g->gc.debt < GCSTEPSIZE) { |
687 | g->gc.threshold = g->gc.total + GCSTEPSIZE; | 687 | g->gc.threshold = g->gc.total + GCSTEPSIZE; |
688 | g->vmstate = ostate; | 688 | g->vmstate = ostate; |
@@ -801,7 +801,7 @@ void lj_gc_barriertrace(global_State *g, uint32_t traceno) | |||
801 | /* -- Allocator ----------------------------------------------------------- */ | 801 | /* -- Allocator ----------------------------------------------------------- */ |
802 | 802 | ||
803 | /* Call pluggable memory allocator to allocate or resize a fragment. */ | 803 | /* Call pluggable memory allocator to allocate or resize a fragment. */ |
804 | void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz) | 804 | void *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz) |
805 | { | 805 | { |
806 | global_State *g = G(L); | 806 | global_State *g = G(L); |
807 | lua_assert((osz == 0) == (p == NULL)); | 807 | lua_assert((osz == 0) == (p == NULL)); |
@@ -809,19 +809,19 @@ void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz) | |||
809 | if (p == NULL && nsz > 0) | 809 | if (p == NULL && nsz > 0) |
810 | lj_err_mem(L); | 810 | lj_err_mem(L); |
811 | lua_assert((nsz == 0) == (p == NULL)); | 811 | lua_assert((nsz == 0) == (p == NULL)); |
812 | lua_assert(checkptr32(p)); | 812 | lua_assert(checkptrGC(p)); |
813 | g->gc.total = (g->gc.total - osz) + nsz; | 813 | g->gc.total = (g->gc.total - osz) + nsz; |
814 | return p; | 814 | return p; |
815 | } | 815 | } |
816 | 816 | ||
817 | /* Allocate new GC object and link it to the root set. */ | 817 | /* Allocate new GC object and link it to the root set. */ |
818 | void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size) | 818 | void * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size) |
819 | { | 819 | { |
820 | global_State *g = G(L); | 820 | global_State *g = G(L); |
821 | GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size); | 821 | GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size); |
822 | if (o == NULL) | 822 | if (o == NULL) |
823 | lj_err_mem(L); | 823 | lj_err_mem(L); |
824 | lua_assert(checkptr32(o)); | 824 | lua_assert(checkptrGC(o)); |
825 | g->gc.total += size; | 825 | g->gc.total += size; |
826 | setgcrefr(o->gch.nextgc, g->gc.root); | 826 | setgcrefr(o->gch.nextgc, g->gc.root); |
827 | setgcref(g->gc.root, o); | 827 | setgcref(g->gc.root, o); |