aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2010-02-27 19:53:14 +0100
committerMike Pall <mike>2010-02-27 20:18:11 +0100
commitec78d3177e1b24c24a89f0e83c19eb3e3e0f8023 (patch)
tree81d6af7daf9c7fa3e973cc3d8d7861a09880b05c /src
parent52b7651327b2aec4f12ae47f3ce5b56b1fb55996 (diff)
downloadluajit-ec78d3177e1b24c24a89f0e83c19eb3e3e0f8023.tar.gz
luajit-ec78d3177e1b24c24a89f0e83c19eb3e3e0f8023.tar.bz2
luajit-ec78d3177e1b24c24a89f0e83c19eb3e3e0f8023.zip
Correctly align and free allocated machine code areas.
Bump default mcode area size to 64K for x64.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.dep14
-rw-r--r--src/lj_jit.h2
-rw-r--r--src/lj_mcode.c6
-rw-r--r--src/lj_state.c5
4 files changed, 15 insertions, 12 deletions
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 \
110 lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h lj_target_x86.h 110 lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h lj_target_x86.h
111lj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ 111lj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
112 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_meta.h \ 112 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_meta.h \
113 lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \ 113 lj_state.h lj_frame.h lj_bc.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h \
114 lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h 114 lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h
115lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ 115lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
116 lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ctype.h 116 lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ctype.h
117lj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ 117lj_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 \
131 lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h \ 131 lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h \
132 lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c lj_ctype.c \ 132 lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c lj_ctype.c \
133 lj_ctype.h lj_bc.c lj_bcdef.h lj_obj.c lj_str.c lj_tab.c lj_func.c \ 133 lj_ctype.h lj_bc.c lj_bcdef.h lj_obj.c lj_str.c lj_tab.c lj_func.c \
134 lj_udata.c lj_meta.c lj_state.c lj_lex.h lj_alloc.h lj_dispatch.c \ 134 lj_udata.c lj_meta.c lj_state.c lj_mcode.h lj_lex.h lj_alloc.h \
135 lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h lj_api.c \ 135 lj_dispatch.c lj_ff.h lj_ffdef.h luajit.h lj_vmevent.c lj_vmevent.h \
136 lj_parse.h lj_lex.c lj_parse.c lj_lib.c lj_lib.h lj_ir.c lj_iropt.h \ 136 lj_api.c lj_parse.h lj_lex.c lj_parse.c lj_lib.c lj_lib.h lj_ir.c \
137 lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c lj_opt_dce.c \ 137 lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c \
138 lj_opt_loop.c lj_snap.h lj_mcode.c lj_mcode.h lj_snap.c lj_target.h \ 138 lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_mcode.c lj_snap.c lj_target.h \
139 lj_target_x86.h lj_record.c lj_record.h lj_asm.h lj_recdef.h lj_asm.c \ 139 lj_target_x86.h lj_record.c lj_record.h lj_asm.h lj_recdef.h lj_asm.c \
140 lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c \ 140 lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c \
141 lualib.h lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c \ 141 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 @@
53#define JIT_F_OPT_3 (JIT_F_OPT_2|JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_FUSE) 53#define JIT_F_OPT_3 (JIT_F_OPT_2|JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_FUSE)
54#define JIT_F_OPT_DEFAULT JIT_F_OPT_3 54#define JIT_F_OPT_DEFAULT JIT_F_OPT_3
55 55
56#ifdef LUA_USE_WIN 56#if defined(LUA_USE_WIN) || LJ_64
57/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */ 57/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */
58#define JIT_P_sizemcode_DEFAULT 64 58#define JIT_P_sizemcode_DEFAULT 64
59#else 59#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)
110/* Get memory within relative jump distance of our code in 64 bit mode. */ 110/* Get memory within relative jump distance of our code in 64 bit mode. */
111static void *mcode_alloc(jit_State *J, size_t sz, int prot) 111static void *mcode_alloc(jit_State *J, size_t sz, int prot)
112{ 112{
113 /* Target an address in the static assembler code. 113 /* Target an address in the static assembler code (64K aligned).
114 ** Try addresses within a distance of target-1GB+1MB .. target+1GB-1MB. 114 ** Try addresses within a distance of target-1GB+1MB .. target+1GB-1MB.
115 */ 115 */
116 uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler; 116 uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff;
117 const uintptr_t range = (1u<<31) - (1u << 21); 117 const uintptr_t range = (1u<<31) - (1u << 21);
118 int i; 118 int i;
119 /* First try a contiguous area below the last one. */ 119 /* 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)
128 uintptr_t hint; 128 uintptr_t hint;
129 void *p; 129 void *p;
130 do { 130 do {
131 hint = LJ_PRNG_BITS(J, 15) << 16; 131 hint = LJ_PRNG_BITS(J, 15) << 16; /* 64K aligned. */
132 } while (!(hint + sz < range && 132 } while (!(hint + sz < range &&
133 target + hint - (range>>1) < (uintptr_t)1<<47)); 133 target + hint - (range>>1) < (uintptr_t)1<<47));
134 p = mcode_alloc_at(J, target + hint - (range>>1), sz, prot); 134 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 @@
18#include "lj_meta.h" 18#include "lj_meta.h"
19#include "lj_state.h" 19#include "lj_state.h"
20#include "lj_frame.h" 20#include "lj_frame.h"
21#include "lj_mcode.h"
21#include "lj_trace.h" 22#include "lj_trace.h"
22#include "lj_dispatch.h" 23#include "lj_dispatch.h"
23#include "lj_vm.h" 24#include "lj_vm.h"
@@ -143,7 +144,9 @@ static void close_state(lua_State *L)
143 global_State *g = G(L); 144 global_State *g = G(L);
144#ifndef LUAJIT_USE_SYSMALLOC 145#ifndef LUAJIT_USE_SYSMALLOC
145 if (g->allocf == lj_alloc_f) { 146 if (g->allocf == lj_alloc_f) {
146 lj_trace_freestate(g); 147#if LJ_HASJIT
148 lj_mcode_free(G2J(g));
149#endif
147 lj_alloc_destroy(g->allocd); 150 lj_alloc_destroy(g->allocd);
148 } else 151 } else
149#endif 152#endif