commit 152b51955aabb9dfb32302569fac810e999eda03
parent ec61be9a7e828bfa366a35658b90f53b1ce39478
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 24 Nov 2022 10:19:48 -0300
Removed GC checks from function calls
Function calls do not create new objects. (It may use memory with
stack reallocation, but now that is irrelevant to the GC.)
Diffstat:
5 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1286,13 +1286,14 @@ LUA_API void lua_toclose (lua_State *L, int idx) {
LUA_API void lua_concat (lua_State *L, int n) {
lua_lock(L);
api_checknelems(L, n);
- if (n > 0)
+ if (n > 0) {
luaV_concat(L, n);
+ luaC_checkGC(L);
+ }
else { /* nothing to concatenate */
setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0)); /* push empty string */
api_incr_top(L);
}
- luaC_checkGC(L);
lua_unlock(L);
}
diff --git a/ldo.c b/ldo.c
@@ -416,7 +416,7 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) {
StkId luaD_tryfuncTM (lua_State *L, StkId func) {
const TValue *tm;
StkId p;
- checkstackGCp(L, 1, func); /* space for metamethod */
+ checkstackp(L, 1, func); /* space for metamethod */
tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */
if (l_unlikely(ttisnil(tm)))
luaG_callerror(L, s2v(func)); /* nothing to call */
@@ -521,7 +521,7 @@ l_sinline int precallC (lua_State *L, StkId func, int nresults,
lua_CFunction f) {
int n; /* number of returns */
CallInfo *ci;
- checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
+ checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
L->ci = ci = prepCallInfo(L, func, nresults, CIST_C,
L->top.p + LUA_MINSTACK);
lua_assert(ci->top.p <= L->stack_last.p);
@@ -557,7 +557,7 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
int fsize = p->maxstacksize; /* frame size */
int nfixparams = p->numparams;
int i;
- checkstackGCp(L, fsize - delta, func);
+ checkstackp(L, fsize - delta, func);
ci->func.p -= delta; /* restore 'func' (if vararg) */
for (i = 0; i < narg1; i++) /* move down function and arguments */
setobjs2s(L, ci->func.p + i, func + i);
@@ -604,7 +604,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
int narg = cast_int(L->top.p - func) - 1; /* number of real arguments */
int nfixparams = p->numparams;
int fsize = p->maxstacksize; /* frame size */
- checkstackGCp(L, fsize, func);
+ checkstackp(L, fsize, func);
L->ci = ci = prepCallInfo(L, func, nresults, 0, func + 1 + fsize);
ci->u.l.savedpc = p->code; /* starting point */
for (; narg < nfixparams; narg++)
diff --git a/ldo.h b/ldo.h
@@ -44,18 +44,6 @@
p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
-/* macro to check stack size and GC, preserving 'p' */
-#define checkstackGCp(L,n,p) \
- luaD_checkstackaux(L, n, \
- ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
- luaC_checkGC(L), /* stack grow uses memory */ \
- p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
-
-
-/* macro to check stack size and GC */
-#define checkstackGC(L,fsize) \
- luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
-
/* type of protected functions, to be ran by 'runprotected' */
typedef void (*Pfunc) (lua_State *L, void *ud);
diff --git a/lgc.c b/lgc.c
@@ -1700,8 +1700,9 @@ static void fullinc (lua_State *L, global_State *g) {
/* finish any pending sweep phase to start a new cycle */
luaC_runtilstate(L, bitmask(GCSpause));
luaC_runtilstate(L, bitmask(GCScallfin)); /* run up to finalizers */
- luaC_runtilstate(L, bitmask(GCSpause)); /* finish collection */
/* estimate must be correct after a full GC cycle */
+ lua_assert(g->marked == gettotalobjs(g));
+ luaC_runtilstate(L, bitmask(GCSpause)); /* finish collection */
setpause(g);
}
diff --git a/ltm.c b/ltm.c
@@ -260,7 +260,7 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) {
int nextra = ci->u.l.nextraargs;
if (wanted < 0) {
wanted = nextra; /* get all extra arguments available */
- checkstackGCp(L, nextra, where); /* ensure stack space */
+ checkstackp(L, nextra, where); /* ensure stack space */
L->top.p = where + nextra; /* next instruction will need top */
}
for (i = 0; i < wanted && i < nextra; i++)