]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Correctly align and free allocated machine code areas.
authorMike Pall <mike>
Sat, 27 Feb 2010 18:53:14 +0000 (19:53 +0100)
committerMike Pall <mike>
Sat, 27 Feb 2010 19:18:11 +0000 (20:18 +0100)
Bump default mcode area size to 64K for x64.

src/Makefile.dep
src/lj_jit.h
src/lj_mcode.c
src/lj_state.c

index 8af717496344110af5839e187145d92ac521c588..3646349c72ce5467279b5ca1c85233dee3287d95 100644 (file)
@@ -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 \
index ff3492bf58a70116086d23b87aef72ce9ffa2e76..69156218da7c9fb0e104732a81852adf224ce2c0 100644 (file)
@@ -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
index e99216012793a5be2104d458f611c765ca8169d5..be3ea1c0820a2e08a80a1acd264e03c26f4962e9 100644 (file)
@@ -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);
index e690a5d30b3306d11eaceb82dd94a02a7fb2d153..2287efcaf68dc5fd9119b4d4b1c84aef0ebbcf1c 100644 (file)
@@ -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