This commit is contained in:
Sasha Szpakowski
2026-06-22 18:57:43 -03:00
parent c4192fe9ba
commit 774ba85a81
211 changed files with 1708 additions and 847 deletions
+24 -14
View File
@@ -1,6 +1,6 @@
/*
** Instruction dispatch handling.
** Copyright (C) 2005-2025 Mike Pall. See Copyright Notice in luajit.h
** Copyright (C) 2005-2026 Mike Pall. See Copyright Notice in luajit.h
*/
#define lj_dispatch_c
@@ -103,8 +103,11 @@ void lj_dispatch_init_hotcount(global_State *g)
#define DISPMODE_PROF 0x40 /* Profiling active. */
/* Update dispatch table depending on various flags. */
void lj_dispatch_update(global_State *g)
void LJ_FASTCALL lj_dispatch_update(global_State *g, int nolock)
{
#if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF
int profile_locked = nolock ? 0 : lj_profile_lock();
#endif
uint8_t oldmode = g->dispatchmode;
uint8_t mode = 0;
#if LJ_HASJIT
@@ -208,6 +211,11 @@ void lj_dispatch_update(global_State *g)
lj_dispatch_init_hotcount(g);
#endif
}
#if LJ_HASPROFILE && !LJ_PROFILE_SIGPROF
if (profile_locked) lj_profile_unlock();
#else
UNUSED(nolock);
#endif
}
/* -- JIT mode setting ---------------------------------------------------- */
@@ -260,7 +268,7 @@ int luaJIT_setmode(lua_State *L, int idx, int mode)
G2J(g)->flags &= ~(uint32_t)JIT_F_ON;
else
G2J(g)->flags |= (uint32_t)JIT_F_ON;
lj_dispatch_update(g);
lj_dispatch_update(g, 0);
}
break;
case LUAJIT_MODE_FUNC:
@@ -335,7 +343,7 @@ LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
g->hookcount = g->hookcstart = (int32_t)count;
g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask);
lj_trace_abort(g); /* Abort recording on any hook change. */
lj_dispatch_update(g);
lj_dispatch_update(g, 0);
return 1;
}
@@ -523,16 +531,18 @@ out:
/* Stitch a new trace. */
void LJ_FASTCALL lj_dispatch_stitch(jit_State *J, const BCIns *pc)
{
ERRNO_SAVE
lua_State *L = J->L;
void *cf = cframe_raw(L->cframe);
const BCIns *oldpc = cframe_pc(cf);
setcframe_pc(cf, pc);
/* Before dispatch, have to bias PC by 1. */
L->top = L->base + cur_topslot(curr_proto(L), pc+1, cframe_multres_n(cf));
lj_trace_stitch(J, pc-1); /* Point to the CALL instruction. */
setcframe_pc(cf, oldpc);
ERRNO_RESTORE
if (!(J2G(J)->hookmask & HOOK_VMEVENT)) {
ERRNO_SAVE
lua_State *L = J->L;
void *cf = cframe_raw(L->cframe);
const BCIns *oldpc = cframe_pc(cf);
setcframe_pc(cf, pc);
/* Before dispatch, have to bias PC by 1. */
L->top = L->base + cur_topslot(curr_proto(L), pc+1, cframe_multres_n(cf));
lj_trace_stitch(J, pc-1); /* Point to the CALL instruction. */
setcframe_pc(cf, oldpc);
ERRNO_RESTORE
}
}
#endif