]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
allocate redirector and indirector buffers in the executable code cache
authorAleksey Demakov <ademakov@gmail.com>
Tue, 22 Aug 2006 20:55:25 +0000 (20:55 +0000)
committerAleksey Demakov <ademakov@gmail.com>
Tue, 22 Aug 2006 20:55:25 +0000 (20:55 +0000)
ChangeLog
jit/jit-function.c
jit/jit-internal.h
jit/jit-rules-x86.c

index 44d417f701833e3aa8317d3100a4ef96ca15c1d3..35bfa9558c7222f471574be8a5834e0771c1e462 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,13 @@
-2006-08-22  Klaus treichel  <ktreichel@web.de>
-
-       * 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  <ademakov@gmail.com>
 
+       * 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
        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  <ktreichel@web.de>
+
+       * 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  <linuxgeek@gmail.com>
        * 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.
index 0876f2f71ac71f17b4d6146392969eb9623a5856..3dccad43545ed670bf5489b15e642b5b99179cce 100644 (file)
@@ -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
index 4a30e7d5447e4c87836280e447a47ba9022ec4ee..4ad7183fba5064b0369660f3eb312285014143ad 100644 (file)
@@ -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
 };
 
index 65bfea3a2878a70f527f74aeda057a7695d39ae5..57fcf8ee24266bfe2d302afb1a15b0f91eb52c21 100644 (file)
@@ -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.