From 4fb1da286191f2216f14662af29a20f184ed37d9 Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Tue, 22 Aug 2006 20:55:25 +0000 Subject: [PATCH] allocate redirector and indirector buffers in the executable code cache --- ChangeLog | 20 ++++++++++++++------ jit/jit-function.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ jit/jit-internal.h | 4 ++-- jit/jit-rules-x86.c | 6 ++++++ 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44d417f..35bfa95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,13 @@ -2006-08-22 Klaus treichel - - * jit/jit-alloc.c: Use mmap and munmap to allocate executable memory - where available because memory allocated with malloc is not executable - on some archs/distros. - 2006-08-23 Aleksey Demakov + * jit/jit-internal.h (struct _jit_function): change the type of + redirector and indirector fields from char array to pointer. + * jit/jit-function.c (jit_function_create): allocate the redirector + and indirector buffers in the code cache. Call jit_flush_exec on + these buffers. + * jit/jit-rules-x86.c (_jit_gen_redirector): ifdef out as this + function is not used with the x86 backend. + * jit/jit-reg-alloc.c: improve handling of three-address op codes. Now the dest register may re-use one of the input registers while previously it was always assigned to a separate register. Also @@ -17,6 +19,12 @@ ops for x86 as three-address. Adjust IREM ops so that they work correctly together with the latest allocator changes. +2006-08-22 Klaus Treichel + + * jit/jit-alloc.c: Use mmap and munmap to allocate executable memory + where available because memory allocated with malloc is not executable + on some archs/distros. + 2006-08-21 Thomas Cort * jit/jit-rules-alpha.c jit/jit-gen-alpha.h: Add macros for int to fp and fp to int conversions. Use _jit_pad_bufer. diff --git a/jit/jit-function.c b/jit/jit-function.c index 0876f2f..3dccad4 100644 --- a/jit/jit-function.c +++ b/jit/jit-function.c @@ -46,6 +46,9 @@ jit_function_t jit_function_create(jit_context_t context, jit_type_t signature) { jit_function_t func; +#if defined(jit_redirector_size) || defined(jit_indirector_size) + jit_cache_t cache; +#endif /* Allocate memory for the function and clear it */ func = jit_cnew(struct _jit_function); @@ -54,6 +57,46 @@ jit_function_t jit_function_create(jit_context_t context, jit_type_t signature) return 0; } +#if defined(jit_redirector_size) || defined(jit_indirector_size) + /* TODO: if the function is destroyed the redirector and indirector memory + is leaked */ + + /* We need the cache lock while we are allocating redirector and indirector */ + jit_mutex_lock(&(context->cache_lock)); + + /* Get the method cache */ + cache = _jit_context_get_cache(context); + if(!cache) + { + jit_mutex_unlock(&(context->cache_lock)); + jit_free(func); + return 0; + } + +# if defined(jit_redirector_size) + /* Allocate redirector buffer */ + func->redirector = _jit_cache_alloc_no_method(cache, jit_redirector_size, 1); + if(!func->redirector) + { + jit_mutex_unlock(&(context->cache_lock)); + jit_free(func); + return 0; + } +# endif +# if defined(jit_indirector_size) + /* Allocate indirector buffer */ + func->indirector = _jit_cache_alloc_no_method(cache, jit_indirector_size, 1); + if(!func->indirector) + { + jit_mutex_unlock(&(context->cache_lock)); + jit_free(func); + return 0; + } +# endif + + jit_mutex_unlock(&(context->cache_lock)); +#endif + /* Initialize the function block */ func->context = context; func->signature = jit_type_copy(signature); @@ -65,9 +108,11 @@ jit_function_t jit_function_create(jit_context_t context, jit_type_t signature) func->entry_point = _jit_create_redirector (func->redirector, (void *)_jit_function_compile_on_demand, func, jit_type_get_abi(signature)); + jit_flush_exec(func->redirector, jit_redirector_size); # if defined(jit_indirector_size) func->closure_entry = _jit_create_indirector (func->indirector, (void**) &(func->entry_point)); + jit_flush_exec(func->indirector, jit_indirector_size); # else func->closure_entry = func->entry_point; # endif diff --git a/jit/jit-internal.h b/jit/jit-internal.h index 4a30e7d..4ad7183 100644 --- a/jit/jit-internal.h +++ b/jit/jit-internal.h @@ -401,13 +401,13 @@ struct _jit_function #ifdef jit_redirector_size /* Buffer that contains the redirector for this function. Redirectors are used to support on-demand compilation */ - unsigned char redirector[jit_redirector_size]; + unsigned char *redirector; #endif #ifdef jit_indirector_size /* Buffer that contains the indirector for this function. The indirector is used to jump either to the function redirector or the compiled function itself. */ - unsigned char indirector[jit_indirector_size]; + unsigned char *indirector; #endif }; diff --git a/jit/jit-rules-x86.c b/jit/jit-rules-x86.c index 65bfea3..57fcf8e 100644 --- a/jit/jit-rules-x86.c +++ b/jit/jit-rules-x86.c @@ -377,6 +377,11 @@ void _jit_gen_epilog(jit_gencode_t gen, jit_function_t func) gen->posn.ptr = inst; } +#if 0 +/* + * The x86 backend does not need this function because it uses + * _jit_create_indirector() instead. + */ void *_jit_gen_redirector(jit_gencode_t gen, jit_function_t func) { void *ptr, *entry; @@ -390,6 +395,7 @@ void *_jit_gen_redirector(jit_gencode_t gen, jit_function_t func) x86_jump_mem(gen->posn.ptr, ptr); return entry; } +#endif /* * Setup or teardown the x86 code output process. -- 2.47.3