From f3374b526619671fe576d593dcdc6bd048bf5603 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 21 Apr 2014 22:26:46 +0200 Subject: [PATCH 1/3] x64: Allow building with LUAJIT_USE_SYSMALLOC and LUAJIT_USE_VALGRIND. Valgrind 3.9 killed MAP_32BIT support. Ugh. So now we have to rely on undocumented behavior where Valgrind always allocates from the bottom of memory. Alas, such a binary won't run properly without Valgrind. --- src/Makefile | 6 ++++-- src/lib_aux.c | 2 +- src/lj_state.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Makefile b/src/Makefile index 9551781a..c558003c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -122,8 +122,10 @@ XCFLAGS= # # Use the system provided memory allocator (realloc) instead of the # bundled memory allocator. This is slower, but sometimes helpful for -# debugging. It's helpful for Valgrind's memcheck tool, too. This option -# cannot be enabled on x64, since the built-in allocator is mandatory. +# debugging. This option cannot be enabled on x64, since realloc usually +# doesn't return addresses in the right address range. +# OTOH this option is mandatory for Valgrind's memcheck tool on x64 and +# the only way to get useful results from it for all other architectures. #XCFLAGS+= -DLUAJIT_USE_SYSMALLOC # # This define is required to run LuaJIT under Valgrind. The Valgrind diff --git a/src/lib_aux.c b/src/lib_aux.c index 1b01fe07..e88dc7c2 100644 --- a/src/lib_aux.c +++ b/src/lib_aux.c @@ -302,7 +302,7 @@ static int panic(lua_State *L) #ifdef LUAJIT_USE_SYSMALLOC -#if LJ_64 +#if LJ_64 && !defined(LUAJIT_USE_VALGRIND) #error "Must use builtin allocator for 64 bit target" #endif diff --git a/src/lj_state.c b/src/lj_state.c index f972fdce..b9eaef46 100644 --- a/src/lj_state.c +++ b/src/lj_state.c @@ -175,7 +175,7 @@ static void close_state(lua_State *L) g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0); } -#if LJ_64 +#if LJ_64 && !(defined(LUAJIT_USE_VALGRIND) && defined(LUAJIT_USE_SYSMALLOC)) lua_State *lj_state_newstate(lua_Alloc f, void *ud) #else LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud) From 18309b0a25babe1a7d601d2ee92ce1dba1859ef9 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 22 Apr 2014 09:57:39 +0200 Subject: [PATCH 2/3] Prevent adding side traces for stack checks. --- src/lj_trace.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lj_trace.c b/src/lj_trace.c index 9e5e400f..0f48809d 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c @@ -607,6 +607,7 @@ static TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud) } lj_opt_split(J); lj_opt_sink(J); + if (!J->loopref) J->cur.snap[J->cur.nsnap-1].count = SNAPCOUNT_DONE; J->state = LJ_TRACE_ASM; break; From 2715fe3aee7c8202b4b5d04748d1c5faa6d8fd9c Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 22 Apr 2014 11:26:52 +0200 Subject: [PATCH 3/3] Prevent GC estimate miscalculation due to buffer growth. --- src/lj_gc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lj_gc.c b/src/lj_gc.c index c2bc397d..c856df4d 100644 --- a/src/lj_gc.c +++ b/src/lj_gc.c @@ -631,6 +631,8 @@ static size_t gc_onestep(lua_State *L) case GCSsweep: { MSize old = g->gc.total; setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX)); + lua_assert(old >= g->gc.total); + g->gc.estimate -= old - g->gc.total; if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) { gc_shrink(g, L); if (gcref(g->gc.mmudata)) { /* Need any finalizations? */ @@ -643,8 +645,6 @@ static size_t gc_onestep(lua_State *L) g->gc.debt = 0; } } - lua_assert(old >= g->gc.total); - g->gc.estimate -= old - g->gc.total; return GCSWEEPMAX*GCSWEEPCOST; } case GCSfinalize: