]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
Add JIT_RESULT_CACHE_FULL internal exception;
authorAleksey Demakov <ademakov@gmail.com>
Thu, 29 Oct 2009 22:15:05 +0000 (04:15 +0600)
committerAleksey Demakov <ademakov@gmail.com>
Thu, 29 Oct 2009 22:15:05 +0000 (04:15 +0600)
Add _jit_check_cache_space function.

ChangeLog
include/jit/jit-except.h
jit/jit-cache.c
jit/jit-cache.h

index 1375b0f99247a8e16224d708401b3e9a68d66e93..8e3749c30c9d51c3976174ead462bdb068a0921c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-10-30  Aleksey Demakov  <ademakov@gmail.com>
+
+       * include/jit/jit-except.h (JIT_RESULT_CACHE_FULL): add result code.
+       * jit/jit-cache.h, jit/jit-cache.c (_jit_cache_check_space): add
+       function to check the available cache space.
 
 2009-10-13  Gopal V  <gopalv@php.net>
 
index 07e74396027cf779fd7707b3db7e19a2d257eeca..40104532889a32fd81f9ba9c09f42917e078efbf 100644 (file)
@@ -41,6 +41,7 @@ extern        "C" {
 #define JIT_RESULT_CALLED_NESTED       (-7)
 #define JIT_RESULT_OUT_OF_BOUNDS       (-8)
 #define JIT_RESULT_UNDEFINED_LABEL     (-9)
+#define JIT_RESULT_CACHE_FULL          (-10000)
 
 /*
  * Exception handling function for builtin exceptions.
index 7461756305874f615f9159d3c636bcc92a6bf7d2..0f01485cf0660b1521199bb054608d8aed745ec0 100644 (file)
@@ -726,6 +726,17 @@ int _jit_cache_is_full(jit_cache_t cache, jit_cache_posn *posn)
        return (!cache->freeStart || (posn && posn->ptr >= posn->limit));
 }
 
+void
+_jit_cache_check_space(jit_cache_posn *posn, int space)
+{
+       if(!jit_cache_check_for_n(posn, space))
+       {
+               /* No space left on the current cache page. */
+               jit_cache_mark_full(posn);
+               jit_exception_builtin(JIT_RESULT_CACHE_FULL);
+       }
+}
+
 int _jit_cache_start_method(jit_cache_t cache,
                            jit_cache_posn *posn,
                            int page_factor,
index 1b1d699af80abd83e8301033cab13be843209e03..e0c5dabf302d1372d3c9d564377258750311818f 100644 (file)
@@ -67,6 +67,12 @@ void _jit_cache_destroy(jit_cache_t cache);
  */
 int _jit_cache_is_full(jit_cache_t cache, jit_cache_posn *posn);
 
+/*
+ * Determine if there is sufficient space in the code cache.
+ * If not throws JIT_RESULT_CACHE_FULL exception.
+ */
+void _jit_cache_check_space(jit_cache_posn *posn, int space);
+
 /*
  * Return values for "_jit_cache_start_method" and "_jit_cache_end_method".
  */
@@ -174,8 +180,7 @@ void **_jit_cache_get_method_list(jit_cache_t cache);
  * if the native offset could not be determined.
  */
 #define        JIT_CACHE_NO_OFFSET             (~((unsigned long)0))
-unsigned long _jit_cache_get_native(jit_cache_t cache, void *start,
-                                                                       unsigned long offset, int exact);
+unsigned long _jit_cache_get_native(jit_cache_t cache, void *start, unsigned long offset, int exact);
 
 /*
  * Get the bytecode offset that is associated with a native
@@ -183,8 +188,7 @@ unsigned long _jit_cache_get_native(jit_cache_t cache, void *start,
  * entry point for the method.  Returns JIT_CACHE_NO_OFFSET
  * if the bytecode offset could not be determined.
  */
-unsigned long _jit_cache_get_bytecode(jit_cache_t cache, void *start,
-                                                                         unsigned long offset, int exact);
+unsigned long _jit_cache_get_bytecode(jit_cache_t cache, void *start, unsigned long offset, int exact);
 
 /*
  * Get the number of bytes currently in use in the method cache.
@@ -198,102 +202,78 @@ unsigned long _jit_cache_get_size(jit_cache_t cache);
  * an instruction that falls within a method region.  This
  * macro corrects for the "off by 1" address.
  */
-#define        jit_cache_return_to_pc(addr)    \
-                       ((void *)(((unsigned char *)(addr)) - 1))
+#define jit_cache_return_to_pc(addr)                   \
+       ((void *)(((unsigned char *)(addr)) - 1))
 
 /*
  * Output a single byte to the current method.
  */
-#define        jit_cache_byte(posn,value)      \
-                       do { \
-                               if((posn)->ptr < (posn)->limit) \
-                               { \
-                                       *(((posn)->ptr)++) = (unsigned char)(value); \
-                               } \
-                       } while (0)
+#define jit_cache_byte(posn,value)                                     \
+       do {                                                            \
+               if((posn)->ptr < (posn)->limit)                         \
+               {                                                       \
+                       *(((posn)->ptr)++) = (unsigned char)(value);    \
+               }                                                       \
+       } while (0)
 
 /*
  * Output a 16-bit word to the current method.
  */
-#define        jit_cache_word16(posn,value)    \
-                       do { \
-                               if(((posn)->ptr + 1) < (posn)->limit) \
-                               { \
-                                       *((jit_ushort *)((posn)->ptr)) = (jit_ushort)(value); \
-                                       (posn)->ptr += 2; \
-                               } \
-                               else \
-                               { \
-                                       (posn)->ptr = (posn)->limit; \
-                               } \
-                       } while (0)
+#define jit_cache_word16(posn,value)                                   \
+       do {                                                            \
+               _jit_cache_check_space((posn), 2);                      \
+               *((jit_ushort *)((posn)->ptr)) = (jit_ushort)(value);   \
+               (posn)->ptr += 2;                                       \
+       } while (0)
 
 /*
  * Output a 32-bit word to the current method.
  */
-#define        jit_cache_word32(posn,value)    \
-                       do { \
-                               if(((posn)->ptr + 3) < (posn)->limit) \
-                               { \
-                                       *((jit_uint *)((posn)->ptr)) = (jit_uint)(value); \
-                                       (posn)->ptr += 4; \
-                               } \
-                               else \
-                               { \
-                                       (posn)->ptr = (posn)->limit; \
-                               } \
-                       } while (0)
+#define jit_cache_word32(posn,value)                                   \
+       do {                                                            \
+               _jit_cache_check_space((posn), 4);                      \
+               *((jit_uint *)((posn)->ptr)) = (jit_uint)(value);       \
+               (posn)->ptr += 4;                                       \
+       } while (0)
 
 /*
  * Output a native word to the current method.
  */
-#define        jit_cache_native(posn,value)    \
-                       do { \
-                               if(((posn)->ptr + sizeof(jit_nuint) - 1) < (posn)->limit) \
-                               { \
-                                       *((jit_nuint *)((posn)->ptr)) = (jit_nuint)(value); \
-                                       (posn)->ptr += sizeof(jit_nuint); \
-                               } \
-                               else \
-                               { \
-                                       (posn)->ptr = (posn)->limit; \
-                               } \
-                       } while (0)
+#define jit_cache_native(posn,value)                                   \
+       do {                                                            \
+               _jit_cache_check_space((posn), sizeof(jit_nuint));      \
+               *((jit_nuint *)((posn)->ptr)) = (jit_nuint)(value);     \
+               (posn)->ptr += sizeof(jit_nuint);                       \
+       } while (0)
 
 /*
  * Output a 64-bit word to the current method.
  */
-#define        jit_cache_word64(posn,value)    \
-                       do { \
-                               if(((posn)->ptr + 7) < (posn)->limit) \
-                               { \
-                                       *((jit_ulong *)((posn)->ptr)) = (jit_ulong)(value); \
-                                       (posn)->ptr += 8; \
-                               } \
-                               else \
-                               { \
-                                       (posn)->ptr = (posn)->limit; \
-                               } \
-                       } while (0)
+#define jit_cache_word64(posn,value)                                   \
+       do {                                                            \
+               _jit_cache_check_space((posn), 8);                      \
+               *((jit_ulong *)((posn)->ptr)) = (jit_ulong)(value);     \
+               (posn)->ptr += 8;                                       \
+       } while (0)
 
 /*
  * Get the output position within the current method.
  */
-#define        jit_cache_get_posn(posn)        ((posn)->ptr)
+#define jit_cache_get_posn(posn)       ((posn)->ptr)
 
 /*
  * Determine if there is sufficient space for N bytes in the current method.
  */
-#define        jit_cache_check_for_n(posn,n)   \
-                               (((posn)->ptr + (n)) <= (posn)->limit)
+#define jit_cache_check_for_n(posn,n)          \
+       (((posn)->ptr + (n)) <= (posn)->limit)
 
 /*
  * Mark the cache as full.
  */
-#define        jit_cache_mark_full(posn)       \
-                       do { \
-                               (posn)->ptr = (posn)->limit; \
-                       } while (0)
+#define jit_cache_mark_full(posn)              \
+       do {                                    \
+               (posn)->ptr = (posn)->limit;    \
+       } while (0)
 
 #ifdef __cplusplus
 };