Skip to content

Commit

Permalink
Merge pull request snabbco#35 from lukego/rm-vmevent
Browse files Browse the repository at this point in the history
Remove PROFILE and VMEVENT features
  • Loading branch information
lukego authored Mar 16, 2017
2 parents c40e6bf + df45ff5 commit 521a874
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 444 deletions.
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ LJLIB_C= $(LJLIB_O:.o=.c)

LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \
lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \
lj_strfmt.o lj_strfmt_num.o lj_api.o lj_profile.o \
lj_state.o lj_dispatch.o lj_vmmath.o lj_strscan.o \
lj_strfmt.o lj_strfmt_num.o lj_api.o \
lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
Expand Down
327 changes: 149 additions & 178 deletions src/Makefile.dep

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions src/lib_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "lj_trace.h"
#include "lj_dispatch.h"
#include "lj_vm.h"
#include "lj_vmevent.h"
#include "lj_lib.h"

#include "luajit.h"
Expand Down Expand Up @@ -102,7 +101,7 @@ LJLIB_CF(jit_status)

LJLIB_CF(jit_attach)
{
luaL_error(L, "vmevent API disabled");
luaL_error(L, "vmevent API removed");
return 0;
}

Expand Down Expand Up @@ -491,9 +490,6 @@ LJLIB_CF(jit_opt_start)
#include "lj_libdef.h"


/* -- jit.profile module -------------------------------------------------- */


/* -- JIT compiler initialization ----------------------------------------- */

/* Default values for JIT parameters. */
Expand Down
2 changes: 0 additions & 2 deletions src/lj_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@
/* Disable or enable the FFI extension. */
#define LJ_HASFFI 1

#define LJ_HASPROFILE 0

#ifndef LJ_ARCH_HASFPU
#define LJ_ARCH_HASFPU 1
#endif
Expand Down
1 change: 0 additions & 1 deletion src/lj_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,6 @@ static void asm_ir(ASMState *as, IRIns *ir)
case IR_PHI: asm_phi(as, ir); break;
case IR_HIOP: asm_hiop(as, ir); break;
case IR_GCSTEP: asm_gcstep(as, ir); break;
case IR_PROF: asm_prof(as, ir); break;

/* Guarded assertions. */
case IR_LT: case IR_GE: case IR_LE: case IR_GT:
Expand Down
10 changes: 0 additions & 10 deletions src/lj_asm_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -2103,16 +2103,6 @@ static void asm_hiop(ASMState *as, IRIns *ir)
UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused on x64 or without FFI. */
}

/* -- Profiling ----------------------------------------------------------- */

static void asm_prof(ASMState *as, IRIns *ir)
{
UNUSED(ir);
asm_guardcc(as, CC_NE);
emit_i8(as, HOOK_PROFILE);
emit_rma(as, XO_GROUP3b, XOg_TEST, &J2G(as->J)->hookmask);
}

/* -- Stack handling ------------------------------------------------------ */

/* Check Lua stack size for overflow. Use exit handler as fallback. */
Expand Down
8 changes: 3 additions & 5 deletions src/lj_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ void lj_dispatch_init_hotcount(global_State *g)
#define DISPMODE_INS 0x04 /* Override instruction dispatch. */
#define DISPMODE_JIT 0x10 /* JIT compiler on. */
#define DISPMODE_REC 0x20 /* Recording active. */
#define DISPMODE_PROF 0x40 /* Profiling active. */

/* Update dispatch table depending on various flags. */
void lj_dispatch_update(global_State *g)
Expand Down Expand Up @@ -107,7 +106,7 @@ void lj_dispatch_update(global_State *g)
disp[GG_LEN_DDISP+BC_LOOP] = f_loop;

/* Set dynamic instruction dispatch. */
if ((oldmode ^ mode) & (DISPMODE_PROF|DISPMODE_REC|DISPMODE_INS)) {
if ((oldmode ^ mode) & (DISPMODE_REC|DISPMODE_INS)) {
/* Need to update the whole table. */
if (!(mode & DISPMODE_INS)) { /* No ins dispatch? */
/* Copy static dispatch table to dynamic dispatch table. */
Expand All @@ -121,8 +120,7 @@ void lj_dispatch_update(global_State *g)
}
} else {
/* The recording dispatch also checks for hooks. */
ASMFunction f = (mode & DISPMODE_PROF) ? lj_vm_profhook :
(mode & DISPMODE_REC) ? lj_vm_record : lj_vm_inshook;
ASMFunction f = (mode & DISPMODE_REC) ? lj_vm_record : lj_vm_inshook;
uint32_t i;
for (i = 0; i < GG_LEN_SDISP; i++)
disp[i] = f;
Expand Down Expand Up @@ -418,7 +416,7 @@ ASMFunction lj_dispatch_call(lua_State *L, const BCIns *pc)
lua_assert(L->top - L->base == delta);
goto out;
} else if (J->state != LJ_TRACE_IDLE &&
!(g->hookmask & (HOOK_GC|HOOK_VMEVENT))) {
!(g->hookmask & HOOK_GC)) {
#ifdef LUA_USE_ASSERT
ptrdiff_t delta = L->top - L->base;
#endif
Expand Down
1 change: 0 additions & 1 deletion src/lj_ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
_(USE, S , ref, ___) \
_(PHI, S , ref, ref) \
_(RENAME, S , ref, lit) \
_(PROF, S , ___, ___) \
\
/* Constants. */ \
_(KPRI, N , ___, ___) \
Expand Down
5 changes: 1 addition & 4 deletions src/lj_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,10 @@ typedef struct global_State {
#define HOOK_EVENTMASK 0x0f
#define HOOK_ACTIVE 0x10
#define HOOK_ACTIVE_SHIFT 4
#define HOOK_VMEVENT 0x20
#define HOOK_GC 0x40
#define HOOK_PROFILE 0x80
#define HOOK_GC 0x20
#define hook_active(g) ((g)->hookmask & HOOK_ACTIVE)
#define hook_enter(g) ((g)->hookmask |= HOOK_ACTIVE)
#define hook_entergc(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_GC))
#define hook_vmevent(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT))
#define hook_leave(g) ((g)->hookmask &= ~HOOK_ACTIVE)
#define hook_save(g) ((g)->hookmask & ~HOOK_EVENTMASK)
#define hook_restore(g, h) \
Expand Down
11 changes: 0 additions & 11 deletions src/lj_opt_fold.c
Original file line number Diff line number Diff line change
Expand Up @@ -2247,17 +2247,6 @@ LJFOLDF(barrier_tnew_tdup)
return DROPFOLD;
}

/* -- Profiling ----------------------------------------------------------- */

LJFOLD(PROF any any)
LJFOLDF(prof)
{
IRRef ref = J->chain[IR_PROF];
if (ref+1 == J->cur.nins) /* Drop neighbouring IR_PROF. */
return ref;
return EMITFOLD;
}

/* -- Stores and allocations ---------------------------------------------- */

/* Stores and allocations cannot be folded or passed on to CSE in general.
Expand Down
5 changes: 0 additions & 5 deletions src/lj_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "lj_lex.h"
#include "lj_parse.h"
#include "lj_vm.h"
#include "lj_vmevent.h"

/* -- Parser structures and definitions ----------------------------------- */

Expand Down Expand Up @@ -1576,10 +1575,6 @@ static GCproto *fs_finish(LexState *ls, BCLine line)
fs_fixup_line(fs, pt, (void *)((char *)pt + ofsli), numline);
fs_fixup_var(ls, pt, (uint8_t *)((char *)pt + ofsdbg), ofsvar);

lj_vmevent_send(L, BC,
setprotoV(L, L->top++, pt);
);

L->top--; /* Pop table of constants. */
ls->vtop = fs->vbase; /* Reset variable stack. */
ls->fs = fs->prev;
Expand Down
10 changes: 0 additions & 10 deletions src/lj_profile.c

This file was deleted.

12 changes: 0 additions & 12 deletions src/lj_profile.h

This file was deleted.

3 changes: 0 additions & 3 deletions src/lj_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,6 @@ static void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev)
} /* Side trace continues across a loop that's left or not entered. */
}

/* -- Record profiler hook checks ----------------------------------------- */


/* -- Record calls and returns -------------------------------------------- */

/* Specialize to the runtime value of the called function or its prototype. */
Expand Down
86 changes: 10 additions & 76 deletions src/lj_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "lj_asm.h"
#include "lj_dispatch.h"
#include "lj_vm.h"
#include "lj_vmevent.h"
#include "lj_target.h"

/* -- Error handling ------------------------------------------------------ */
Expand Down Expand Up @@ -257,9 +256,6 @@ int lj_trace_flushall(lua_State *L)
/* Free the whole machine code and invalidate all exit stub groups. */
lj_mcode_free(J);
memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup));
lj_vmevent_send(L, TRACE,
setstrV(L, L->top++, lj_str_newlit(L, "flush"));
);
return 0;
}

Expand Down Expand Up @@ -366,7 +362,8 @@ static void trace_start(jit_State *J)
}
setgcrefp(J->trace[traceno], &J->cur);

/* Setup enough of the current trace to be able to send the vmevent. */
/* Setup enough of the current trace to be able to send the vmevent.
XXX Still needed with vmevent removed? -lukego */
memset(&J->cur, 0, sizeof(GCtrace));
J->cur.traceno = traceno;
J->cur.nins = J->cur.nk = REF_BASE;
Expand All @@ -384,22 +381,6 @@ static void trace_start(jit_State *J)
setgcref(J->cur.startpt, obj2gco(J->pt));

L = J->L;
lj_vmevent_send(L, TRACE,
setstrV(L, L->top++, lj_str_newlit(L, "start"));
setintV(L->top++, traceno);
setfuncV(L, L->top++, J->fn);
setintV(L->top++, proto_bcpos(J->pt, J->pc));
if (J->parent) {
setintV(L->top++, J->parent);
setintV(L->top++, J->exitno);
} else {
BCOp op = bc_op(*J->pc);
if (op == BC_CALLM || op == BC_CALL || op == BC_ITERC) {
setintV(L->top++, J->exitno); /* Parent of stitched trace. */
setintV(L->top++, -1);
}
}
);
lj_record_setup(J);
}

Expand Down Expand Up @@ -464,11 +445,6 @@ static void trace_stop(jit_State *J)
trace_save(J, T);

L = J->L;
lj_vmevent_send(L, TRACE,
setstrV(L, L->top++, lj_str_newlit(L, "stop"));
setintV(L->top++, traceno);
setfuncV(L, L->top++, J->fn);
);
}

/* Start a new root trace for down-recursion. */
Expand Down Expand Up @@ -525,26 +501,8 @@ static int trace_abort(jit_State *J)
ptrdiff_t errobj = savestack(L, L->top-1); /* Stack may be resized. */
J->cur.link = 0;
J->cur.linktype = LJ_TRLINK_NONE;
lj_vmevent_send(L, TRACE,
TValue *frame;
const BCIns *pc;
GCfunc *fn;
setstrV(L, L->top++, lj_str_newlit(L, "abort"));
setintV(L->top++, traceno);
/* Find original Lua function call to generate a better error message. */
frame = J->L->base-1;
pc = J->pc;
while (!isluafunc(frame_func(frame))) {
pc = (frame_iscont(frame) ? frame_contpc(frame) : frame_pc(frame)) - 1;
frame = frame_prev(frame);
}
fn = frame_func(frame);
setfuncV(L, L->top++, fn);
setintV(L->top++, proto_bcpos(funcproto(fn), pc));
copyTV(L, L->top++, restorestack(L, errobj));
copyTV(L, L->top++, &J->errinfo);
);
/* Drop aborted trace after the vmevent (which may still access it). */
/* Drop aborted trace after the vmevent (which may still access it).
XXX Rethink now that vmevent is removed? -lukego */
setgcrefnull(J->trace[traceno]);
if (traceno < J->freetrace)
J->freetrace = traceno;
Expand Down Expand Up @@ -588,18 +546,6 @@ static TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud)
case LJ_TRACE_RECORD:
trace_pendpatch(J, 0);
setvmstate(J2G(J), RECORD);
lj_vmevent_send_(L, RECORD,
/* Save/restore tmptv state for trace recorder. */
TValue savetv = J2G(J)->tmptv;
TValue savetv2 = J2G(J)->tmptv2;
setintV(L->top++, J->cur.traceno);
setfuncV(L, L->top++, J->fn);
setintV(L->top++, J->pt ? (int32_t)proto_bcpos(J->pt, J->pc) : -1);
setintV(L->top++, J->framedepth);
,
J2G(J)->tmptv = savetv;
J2G(J)->tmptv2 = savetv2;
);
lj_record_ins(J);
break;

Expand Down Expand Up @@ -670,9 +616,8 @@ void lj_trace_hot(jit_State *J, const BCIns *pc)
ERRNO_SAVE
/* Reset hotcount. */
hotcount_set(J2GG(J), pc, J->param[JIT_P_hotloop]*HOTCOUNT_LOOP);
/* Only start a new trace if not recording or inside __gc call or vmevent. */
if (J->state == LJ_TRACE_IDLE &&
!(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) {
/* Only start a new trace if not recording or inside __gc call. */
if (J->state == LJ_TRACE_IDLE && !(J2G(J)->hookmask & HOOK_GC)) {
J->parent = 0; /* Root trace. */
J->exitno = 0;
J->state = LJ_TRACE_START;
Expand All @@ -685,7 +630,7 @@ void lj_trace_hot(jit_State *J, const BCIns *pc)
static void trace_hotside(jit_State *J, const BCIns *pc)
{
SnapShot *snap = &traceref(J, J->parent)->snap[J->exitno];
if (!(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT)) &&
if (!(J2G(J)->hookmask & HOOK_GC) &&
isluafunc(curr_func(J->L)) &&
snap->count != SNAPCOUNT_DONE &&
++snap->count >= J->param[JIT_P_hotexit]) {
Expand All @@ -699,9 +644,8 @@ static void trace_hotside(jit_State *J, const BCIns *pc)
/* Stitch a new trace to the previous trace. */
void lj_trace_stitch(jit_State *J, const BCIns *pc)
{
/* Only start a new trace if not recording or inside __gc call or vmevent. */
if (J->state == LJ_TRACE_IDLE &&
!(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) {
/* Only start a new trace if not recording or inside __gc call. */
if (J->state == LJ_TRACE_IDLE && !(J2G(J)->hookmask & HOOK_GC)) {
J->parent = 0; /* Have to treat it like a root trace. */
/* J->exitno is set to the invoking trace. */
J->state = LJ_TRACE_START;
Expand Down Expand Up @@ -773,20 +717,10 @@ int lj_trace_exit(jit_State *J, void *exptr)
if (errcode)
return -errcode; /* Return negated error code. */

if (!(LJ_HASPROFILE && (G(L)->hookmask & HOOK_PROFILE)))
lj_vmevent_send(L, TEXIT,
lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK);
setintV(L->top++, J->parent);
setintV(L->top++, J->exitno);
trace_exit_regs(L, ex);
);

pc = exd.pc;
cf = cframe_raw(L->cframe);
setcframe_pc(cf, pc);
if (LJ_HASPROFILE && (G(L)->hookmask & HOOK_PROFILE)) {
/* Just exit to interpreter. */
} else if (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize) {
if (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize) {
if (!(G(L)->hookmask & HOOK_GC))
lj_gc_step(L); /* Exited because of GC: drive GC forward. */
} else {
Expand Down
Loading

0 comments on commit 521a874

Please sign in to comment.