diff --git a/src/Makefile.dep b/src/Makefile.dep index 8af71749..3646349c 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep @@ -110,8 +110,8 @@ lj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h lj_target_x86.h lj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_meta.h \ - lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \ - lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h + lj_state.h lj_frame.h lj_bc.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h \ + lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ctype.h lj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ @@ -131,11 +131,11 @@ ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \ lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h \ lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c lj_ctype.c \ lj_ctype.h lj_bc.c lj_bcdef.h lj_obj.c lj_str.c lj_tab.c lj_func.c \ - lj_udata.c lj_meta.c lj_state.c lj_lex.h lj_alloc.h lj_dispatch.c \ - lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h lj_api.c \ - lj_parse.h lj_lex.c lj_parse.c lj_lib.c lj_lib.h lj_ir.c lj_iropt.h \ - lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c lj_opt_dce.c \ - lj_opt_loop.c lj_snap.h lj_mcode.c lj_mcode.h lj_snap.c lj_target.h \ + lj_udata.c lj_meta.c lj_state.c lj_mcode.h lj_lex.h lj_alloc.h \ + lj_dispatch.c lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h \ + lj_api.c lj_parse.h lj_lex.c lj_parse.c lj_lib.c lj_lib.h lj_ir.c \ + lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c \ + lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_mcode.c lj_snap.c lj_target.h \ lj_target_x86.h lj_record.c lj_record.h lj_asm.h lj_recdef.h lj_asm.c \ lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c \ lualib.h lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c \ diff --git a/src/lj_jit.h b/src/lj_jit.h index ff3492bf..69156218 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h @@ -53,7 +53,7 @@ #define JIT_F_OPT_3 (JIT_F_OPT_2|JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_FUSE) #define JIT_F_OPT_DEFAULT JIT_F_OPT_3 -#ifdef LUA_USE_WIN +#if defined(LUA_USE_WIN) || LJ_64 /* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */ #define JIT_P_sizemcode_DEFAULT 64 #else diff --git a/src/lj_mcode.c b/src/lj_mcode.c index e9921601..be3ea1c0 100644 --- a/src/lj_mcode.c +++ b/src/lj_mcode.c @@ -110,10 +110,10 @@ static void mcode_free(jit_State *J, void *p, size_t sz) /* Get memory within relative jump distance of our code in 64 bit mode. */ static void *mcode_alloc(jit_State *J, size_t sz, int prot) { - /* Target an address in the static assembler code. + /* Target an address in the static assembler code (64K aligned). ** Try addresses within a distance of target-1GB+1MB .. target+1GB-1MB. */ - uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler; + uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff; const uintptr_t range = (1u<<31) - (1u << 21); int i; /* First try a contiguous area below the last one. */ @@ -128,7 +128,7 @@ static void *mcode_alloc(jit_State *J, size_t sz, int prot) uintptr_t hint; void *p; do { - hint = LJ_PRNG_BITS(J, 15) << 16; + hint = LJ_PRNG_BITS(J, 15) << 16; /* 64K aligned. */ } while (!(hint + sz < range && target + hint - (range>>1) < (uintptr_t)1<<47)); p = mcode_alloc_at(J, target + hint - (range>>1), sz, prot); diff --git a/src/lj_state.c b/src/lj_state.c index e690a5d3..2287efca 100644 --- a/src/lj_state.c +++ b/src/lj_state.c @@ -18,6 +18,7 @@ #include "lj_meta.h" #include "lj_state.h" #include "lj_frame.h" +#include "lj_mcode.h" #include "lj_trace.h" #include "lj_dispatch.h" #include "lj_vm.h" @@ -143,7 +144,9 @@ static void close_state(lua_State *L) global_State *g = G(L); #ifndef LUAJIT_USE_SYSMALLOC if (g->allocf == lj_alloc_f) { - lj_trace_freestate(g); +#if LJ_HASJIT + lj_mcode_free(G2J(g)); +#endif lj_alloc_destroy(g->allocd); } else #endif