Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff from LuaJIT commit 716f2daef8019ce53d75d2c376c74b8f478fd5c5 to OpenResty LuaJIT fork v2.1-20161104
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/.gitignore github.com/openresty/luajit2/.gitignore
--- github.com/LuaJIT/LuaJIT/.gitignore 2015-12-09 18:52:43.000000000 +0900
+++ github.com/openresty/luajit2/.gitignore 2016-11-24 17:20:44.000000000 +0900
@@ -9,3 +9,6 @@
*.dmp
*.swp
.tags
+*~
+tags
+*.swo
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/Makefile github.com/openresty/luajit2/Makefile
--- github.com/LuaJIT/LuaJIT/Makefile 2016-11-24 17:27:27.000000000 +0900
+++ github.com/openresty/luajit2/Makefile 2016-11-24 17:20:44.000000000 +0900
@@ -129,13 +129,8 @@
$(RM) $(FILE_PC).tmp
cd src && $(INSTALL_F) $(FILES_INC) $(INSTALL_INC)
cd src/jit && $(INSTALL_F) $(FILES_JITLIB) $(INSTALL_JITLIB)
+ $(SYMLINK) $(INSTALL_TNAME) $(INSTALL_TSYM)
@echo "==== Successfully installed LuaJIT $(VERSION) to $(PREFIX) ===="
- @echo ""
- @echo "Note: the development releases deliberately do NOT install a symlink for luajit"
- @echo "You can do this now by running this command (with sudo):"
- @echo ""
- @echo " $(SYMLINK) $(INSTALL_TNAME) $(INSTALL_TSYM)"
- @echo ""
uninstall:
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/jit/dump.lua github.com/openresty/luajit2/src/jit/dump.lua
--- github.com/LuaJIT/LuaJIT/src/jit/dump.lua 2016-11-24 17:27:27.000000000 +0900
+++ github.com/openresty/luajit2/src/jit/dump.lua 2016-11-24 17:20:44.000000000 +0900
@@ -591,6 +591,9 @@
if pc >= 0 then
line = bcline(func, pc, recprefix)
if dumpmode.H then line = gsub(line, "[<>&]", html_escape) end
+ if pc > 0 then
+ line = sub(line, 1, -2) .. " (" .. fmtfunc(func, pc) .. ")\n"
+ end
else
line = "0000 "..recprefix.." FUNCC \n"
callee = func
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_arch.h github.com/openresty/luajit2/src/lj_arch.h
--- github.com/LuaJIT/LuaJIT/src/lj_arch.h 2016-11-24 17:27:27.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_arch.h 2016-11-24 17:20:44.000000000 +0900
@@ -367,7 +367,7 @@
#error "Need at least GCC 3.4 or newer"
#endif
#elif LJ_TARGET_X64
-#if __GNUC__ < 4
+#if 0 && __GNUC__ < 4
#error "Need at least GCC 4.0 or newer"
#endif
#elif LJ_TARGET_ARM
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_asm_x86.h github.com/openresty/luajit2/src/lj_asm_x86.h
--- github.com/LuaJIT/LuaJIT/src/lj_asm_x86.h 2016-11-24 17:27:27.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_asm_x86.h 2016-11-24 17:20:44.000000000 +0900
@@ -1271,7 +1271,7 @@
int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
Reg dest = ra_used(ir) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
-#if !LJ_64
+#if !LJ_64 || defined(LUAJIT_USE_VALGRIND)
MCLabel l_exit;
#endif
lua_assert(ofs % sizeof(Node) == 0);
@@ -1286,7 +1286,7 @@
}
}
asm_guardcc(as, CC_NE);
-#if LJ_64
+#if LJ_64 && !defined(LUAJIT_USE_VALGRIND)
if (!irt_ispri(irkey->t)) {
Reg key = ra_scratch(as, rset_exclude(RSET_GPR, node));
emit_rmro(as, XO_CMP, key|REX_64, node,
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_debug.c github.com/openresty/luajit2/src/lj_debug.c
--- github.com/LuaJIT/LuaJIT/src/lj_debug.c 2016-11-24 17:22:37.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_debug.c 2016-11-24 17:20:44.000000000 +0900
@@ -697,3 +697,128 @@
lua_concat(L, (int)(L->top - L->base) - top);
}
+#ifdef LUA_USE_TRACE_LOGS
+
+#include "lj_dispatch.h"
+
+#define MAX_TRACE_EVENTS 64
+
+enum {
+ LJ_TRACE_EVENT_ENTER,
+ LJ_TRACE_EVENT_EXIT,
+ LJ_TRACE_EVENT_START
+};
+
+typedef struct {
+ int event;
+ unsigned traceno;
+ unsigned exitno;
+ int directexit;
+ const BCIns *ins;
+ lua_State *thread;
+ GCfunc *fn;
+} lj_trace_event_record_t;
+
+static lj_trace_event_record_t lj_trace_events[MAX_TRACE_EVENTS];
+
+static int rb_start = 0;
+static int rb_end = 0;
+static int rb_full = 0;
+
+static void
+lj_trace_log_event(lj_trace_event_record_t *rec)
+{
+ lj_trace_events[rb_end] = *rec;
+
+ if (rb_full) {
+ rb_end++;
+ if (rb_end == MAX_TRACE_EVENTS) {
+ rb_end = 0;
+ }
+ rb_start = rb_end;
+
+ } else {
+ rb_end++;
+ if (rb_end == MAX_TRACE_EVENTS) {
+ rb_end = 0;
+ rb_full = MAX_TRACE_EVENTS;
+ }
+ }
+}
+
+static GCfunc*
+lj_debug_top_frame_fn(lua_State *L, const BCIns *pc)
+{
+ int size;
+ cTValue *frame;
+
+ frame = lj_debug_frame(L, 0, &size);
+ if (frame == NULL) {
+ return NULL;
+ }
+
+ return frame_func(frame);
+}
+
+LJ_FUNC void LJ_FASTCALL
+lj_log_trace_start_record(lua_State *L, unsigned traceno, const BCIns *pc,
+ GCfunc *fn)
+{
+ lj_trace_event_record_t r;
+
+ r.event = LJ_TRACE_EVENT_START;
+ r.thread = L;
+ r.ins = pc;
+ r.traceno = traceno;
+ r.fn = fn;
+
+ lj_trace_log_event(&r);
+}
+
+LJ_FUNC void LJ_FASTCALL
+lj_log_trace_entry(lua_State *L, unsigned traceno, const BCIns *pc)
+{
+ lj_trace_event_record_t r;
+
+ r.event = LJ_TRACE_EVENT_ENTER;
+ r.thread = L;
+ r.ins = pc;
+ r.traceno = traceno;
+ r.fn = lj_debug_top_frame_fn(L, pc);
+
+ lj_trace_log_event(&r);
+}
+
+static void
+lj_log_trace_exit_helper(lua_State *L, int vmstate, const BCIns *pc, int direct)
+{
+ if (vmstate >= 0) {
+ lj_trace_event_record_t r;
+
+ jit_State *J = L2J(L);
+
+ r.event = LJ_TRACE_EVENT_EXIT;
+ r.thread = L;
+ r.ins = pc;
+ r.traceno = vmstate;
+ r.exitno = J->exitno;
+ r.directexit = direct;
+ r.fn = lj_debug_top_frame_fn(L, pc);
+
+ lj_trace_log_event(&r);
+ }
+}
+
+LJ_FUNC void LJ_FASTCALL
+lj_log_trace_normal_exit(lua_State *L, int vmstate, const BCIns *pc)
+{
+ lj_log_trace_exit_helper(L, vmstate, pc, 0);
+}
+
+LJ_FUNC void LJ_FASTCALL
+lj_log_trace_direct_exit(lua_State *L, int vmstate, const BCIns *pc)
+{
+ lj_log_trace_exit_helper(L, vmstate, pc, 1);
+}
+
+#endif /* LUA_USE_TRACE_LOGS */
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_debug.h github.com/openresty/luajit2/src/lj_debug.h
--- github.com/LuaJIT/LuaJIT/src/lj_debug.h 2016-11-24 17:22:37.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_debug.h 2016-11-24 17:20:44.000000000 +0900
@@ -62,4 +62,15 @@
VARNAME__MAX
};
+#ifdef LUA_USE_TRACE_LOGS
+LJ_FUNC void LJ_FASTCALL lj_log_trace_direct_exit(lua_State *L,
+ int vmstate, const BCIns *pc);
+LJ_FUNC void LJ_FASTCALL lj_log_trace_normal_exit(lua_State *L,
+ int vmstate, const BCIns *pc);
+LJ_FUNC void LJ_FASTCALL lj_log_trace_entry(lua_State *L,
+ unsigned traceno, const BCIns *pc);
+LJ_FUNC void LJ_FASTCALL lj_log_trace_start_record(lua_State *L, unsigned traceno,
+ const BCIns *pc, GCfunc *fn);
+#endif
+
#endif
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_err.c github.com/openresty/luajit2/src/lj_err.c
--- github.com/LuaJIT/LuaJIT/src/lj_err.c 2016-11-24 17:26:52.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_err.c 2016-11-24 17:20:44.000000000 +0900
@@ -508,6 +508,7 @@
{
global_State *g = G(L);
lj_trace_abort(g);
+ g->saved_jit_base = g->jit_base;
setmref(g->jit_base, NULL);
L->status = 0;
#if LJ_UNWIND_EXT
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_jit.h github.com/openresty/luajit2/src/lj_jit.h
--- github.com/LuaJIT/LuaJIT/src/lj_jit.h 2016-11-24 17:26:52.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_jit.h 2016-11-24 17:20:44.000000000 +0900
@@ -102,7 +102,7 @@
_(\012, maxirconst, 500) /* Max. # of IR constants of a trace. */ \
_(\007, maxside, 100) /* Max. # of side traces of a root trace. */ \
_(\007, maxsnap, 500) /* Max. # of snapshots for a trace. */ \
- _(\011, minstitch, 0) /* Min. # of IR ins for a stitched trace. */ \
+ _(\011, minstitch, 1000000) /* Min. # of IR ins for a stitched trace. */ \
\
_(\007, hotloop, 56) /* # of iter. to detect a hot loop/call. */ \
_(\007, hotexit, 10) /* # of taken exits to start a side trace. */ \
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_obj.h github.com/openresty/luajit2/src/lj_obj.h
--- github.com/LuaJIT/LuaJIT/src/lj_obj.h 2016-11-24 17:26:52.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_obj.h 2016-11-24 17:20:44.000000000 +0900
@@ -619,6 +619,7 @@
BCIns bc_cfunc_ext; /* Bytecode for external C function calls. */
GCRef cur_L; /* Currently executing lua_State. */
MRef jit_base; /* Current JIT code L->base or NULL. */
+ MRef saved_jit_base; /* saved jit_base for lj_err_throw */
MRef ctype_state; /* Pointer to C type state. */
GCRef gcroot[GCROOT_MAX]; /* GC roots. */
} global_State;
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_record.c github.com/openresty/luajit2/src/lj_record.c
--- github.com/LuaJIT/LuaJIT/src/lj_record.c 2016-11-24 17:26:52.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_record.c 2016-11-24 17:20:44.000000000 +0900
@@ -581,7 +581,7 @@
if (bc_j(*pc) != -1 && !innerloopleft(J, pc))
lj_trace_err(J, LJ_TRERR_LINNER); /* Root trace hit an inner loop. */
if ((ev != LOOPEV_ENTERLO &&
- J->loopref && J->cur.nins - J->loopref > 24) || --J->loopunroll < 0)
+ J->loopref && J->cur.nins - J->loopref > 100) || --J->loopunroll < 0)
lj_trace_err(J, LJ_TRERR_LUNROLL); /* Limit loop unrolling. */
J->loopref = J->cur.nins;
}
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_str.c github.com/openresty/luajit2/src/lj_str.c
--- github.com/LuaJIT/LuaJIT/src/lj_str.c 2016-11-24 17:22:37.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_str.c 2016-11-24 17:20:44.000000000 +0900
@@ -18,6 +18,15 @@
int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b)
{
MSize i, n = a->len > b->len ? b->len : a->len;
+#ifdef LUAJIT_USE_VALGRIND
+ for (i = 0; i < n; i++) {
+ uint8_t va = *(const uint8_t *)(strdata(a)+i);
+ uint8_t vb = *(const uint8_t *)(strdata(b)+i);
+ if (va != vb) {
+ return va < vb ? -1 : 1;
+ }
+ }
+#else
for (i = 0; i < n; i += 4) {
/* Note: innocuous access up to end of string + 3. */
uint32_t va = *(const uint32_t *)(strdata(a)+i);
@@ -34,6 +43,7 @@
return va < vb ? -1 : 1;
}
}
+#endif
return (int32_t)(a->len - b->len);
}
@@ -149,6 +159,7 @@
h ^= b; h -= lj_rol(b, 16);
/* Check if the string has already been interned. */
o = gcref(g->strhash[h & g->strmask]);
+#ifndef LUAJIT_USE_VALGRIND
if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) {
while (o != NULL) {
GCstr *sx = gco2str(o);
@@ -160,6 +171,7 @@
o = gcnext(o);
}
} else { /* Slow path: end of string is too close to a page boundary. */
+#endif
while (o != NULL) {
GCstr *sx = gco2str(o);
if (sx->len == len && memcmp(str, strdata(sx), len) == 0) {
@@ -169,7 +181,9 @@
}
o = gcnext(o);
}
+#ifndef LUAJIT_USE_VALGRIND
}
+#endif
/* Nope, create a new string. */
s = lj_mem_newt(L, sizeof(GCstr)+len+1, GCstr);
newwhite(g, s);
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/lj_trace.c github.com/openresty/luajit2/src/lj_trace.c
--- github.com/LuaJIT/LuaJIT/src/lj_trace.c 2016-11-24 17:27:27.000000000 +0900
+++ github.com/openresty/luajit2/src/lj_trace.c 2016-11-24 17:20:44.000000000 +0900
@@ -397,6 +397,9 @@
{
lua_State *L;
TraceNo traceno;
+#ifdef LUA_USE_TRACE_LOGS
+ const BCIns *pc = J->pc;
+#endif
if ((J->pt->flags & PROTO_NOJIT)) { /* JIT disabled for this proto? */
if (J->parent == 0 && J->exitno == 0) {
@@ -449,6 +452,9 @@
}
);
lj_record_setup(J);
+#ifdef LUA_USE_TRACE_LOGS
+ lj_log_trace_start_record(L, (unsigned) J->cur.traceno, pc, J->fn);
+#endif
}
/* Stop tracing. */
@@ -855,6 +861,20 @@
pc = exd.pc;
cf = cframe_raw(L->cframe);
setcframe_pc(cf, pc);
+
+#ifdef LUA_USE_ASSERT
+ /*
+ ** DEBUGGING: Check GC objects in current stack.
+ ** NOTE: THIS IS EXPENSIVE -- DON'T LEAVE PERMANENTLY ENABLED!
+ */
+ {
+ TValue *o, *top = L->top;
+ for (o = tvref(L->stack)+1; o < top; o++) {
+ tvchecklive(L, o);
+ }
+ }
+#endif
+
if (LJ_HASPROFILE && (G(L)->hookmask & HOOK_PROFILE)) {
/* Just exit to interpreter. */
} else if (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize) {
@@ -877,6 +897,9 @@
}
}
}
+#ifdef LUA_USE_TRACE_LOGS
+ lj_log_trace_normal_exit(L, (int) T->traceno, pc);
+#endif
/* Return MULTRES or 0. */
ERRNO_RESTORE
switch (bc_op(*pc)) {
diff -ruNb -x .git github.com/LuaJIT/LuaJIT/src/vm_x86.dasc github.com/openresty/luajit2/src/vm_x86.dasc
--- github.com/LuaJIT/LuaJIT/src/vm_x86.dasc 2016-11-24 17:26:52.000000000 +0900
+++ github.com/openresty/luajit2/src/vm_x86.dasc 2016-11-24 17:20:44.000000000 +0900
@@ -2919,6 +2919,21 @@
| mov r13, TMPa
| mov r12, TMPQ
|.endif
+#ifdef LUA_USE_TRACE_LOGS
+ |.if X64
+ | mov FCARG1, SAVE_L
+ | mov L:FCARG1->base, BASE
+ | mov RB, RD // Save RD
+ | mov TMP1, PC // Save PC
+ | mov CARG3d, PC // CARG3d == BASE
+ | mov FCARG2, dword [DISPATCH+DISPATCH_GL(vmstate)]
+ | call extern lj_log_trace_direct_exit@8
+ | mov PC, TMP1
+ | mov RD, RB
+ | mov RB, SAVE_L
+ | mov BASE, L:RB->base
+ |.endif
+#endif
| test RD, RD; js >9 // Check for error from exit.
| mov L:RB, SAVE_L
| mov MULTRES, RD
@@ -5260,6 +5275,19 @@
case BC_JLOOP:
|.if JIT
| ins_AD // RA = base (ignored), RD = traceno
+#ifdef LUA_USE_TRACE_LOGS
+ |.if X64
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Save BASE
+ | mov TMP1, RD // Save RD
+ | mov CARG3d, PC // CARG3d == BASE
+ | mov FCARG2, RD
+ | mov FCARG1, RB
+ | call extern lj_log_trace_entry@8
+ | mov RD, TMP1
+ | mov BASE, L:RB->base
+ |.endif
+#endif
| mov RA, [DISPATCH+DISPATCH_J(trace)]
| mov TRACE:RD, [RA+RD*4]
| mov RDa, TRACE:RD->mcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.