@@ -25,7 +25,6 @@ See the bottom of this file for documentation on the cache system.
2525*/
2626
2727#include "jit-internal.h"
28- #include "jit-cache.h"
2928#include "jit-apply-func.h"
3029
3130#include <stddef.h> /* for offsetof */
@@ -76,7 +75,7 @@ struct jit_cache_page
7675/*
7776 * Structure of the method cache.
7877 */
79- #define JIT_CACHE_DEBUG_SIZE 64
78+ typedef struct jit_cache * jit_cache_t ;
8079struct jit_cache
8180{
8281 struct jit_cache_page * pages ; /* List of pages currently in the cache */
@@ -117,6 +116,8 @@ struct jit_cache
117116#define SetBlack (node ) \
118117 ((node)->left = (jit_cache_method_t)(((jit_nuint)(node)->left) & ~((jit_nuint)1)))
119118
119+ void _jit_cache_destroy (jit_cache_t cache );
120+
120121/*
121122 * Allocate a cache page and add it to the cache.
122123 */
@@ -517,13 +518,13 @@ _jit_cache_start_function(jit_cache_t cache, jit_function_t func)
517518 /* Bail out if there is a started function already */
518519 if (cache -> method )
519520 {
520- return JIT_CACHE_ERROR ;
521+ return JIT_MEMORY_ERROR ;
521522 }
522523
523524 /* Bail out if the cache is already full */
524525 if (!cache -> free_start )
525526 {
526- return JIT_CACHE_TOO_BIG ;
527+ return JIT_MEMORY_TOO_BIG ;
527528 }
528529
529530 /* Save the cache position */
@@ -540,7 +541,7 @@ _jit_cache_start_function(jit_cache_t cache, jit_function_t func)
540541 cache -> method -> left = 0 ;
541542 cache -> method -> right = 0 ;
542543
543- return JIT_CACHE_OK ;
544+ return JIT_MEMORY_OK ;
544545}
545546
546547int
@@ -549,17 +550,17 @@ _jit_cache_end_function(jit_cache_t cache, int result)
549550 /* Bail out if there is no started function */
550551 if (!cache -> method )
551552 {
552- return JIT_CACHE_ERROR ;
553+ return JIT_MEMORY_ERROR ;
553554 }
554555
555556 /* Determine if we ran out of space while writing the function */
556- if (result != JIT_CACHE_OK || cache -> free_start >= cache -> free_end )
557+ if (result != JIT_MEMORY_OK || cache -> free_start >= cache -> free_end )
557558 {
558559 /* Restore the saved cache position */
559560 cache -> free_start = cache -> prev_start ;
560561 cache -> free_end = cache -> prev_end ;
561562 cache -> method = 0 ;
562- return JIT_CACHE_RESTART ;
563+ return JIT_MEMORY_RESTART ;
563564 }
564565
565566 /* Update the method region block and then add it to the lookup tree */
@@ -568,7 +569,7 @@ _jit_cache_end_function(jit_cache_t cache, int result)
568569 cache -> method = 0 ;
569570
570571 /* The method is ready to go */
571- return JIT_CACHE_OK ;
572+ return JIT_MEMORY_OK ;
572573}
573574
574575void *
@@ -797,6 +798,30 @@ _jit_cache_get_function(jit_cache_t cache, void *pc)
797798 return 0 ;
798799}
799800
801+ jit_memory_manager_t
802+ jit_default_memory_manager (void )
803+ {
804+ static const struct jit_memory_manager mm = {
805+ & _jit_cache_create ,
806+ & _jit_cache_destroy ,
807+ & _jit_cache_get_function ,
808+ & _jit_cache_alloc_function ,
809+ & _jit_cache_free_function ,
810+ & _jit_cache_start_function ,
811+ & _jit_cache_end_function ,
812+ & _jit_cache_extend ,
813+ & _jit_cache_get_code_limit ,
814+ & _jit_cache_get_code_break ,
815+ & _jit_cache_set_code_break ,
816+ & _jit_cache_alloc_trampoline ,
817+ & _jit_cache_free_trampoline ,
818+ & _jit_cache_alloc_closure ,
819+ & _jit_cache_free_closure ,
820+ & _jit_cache_alloc_data
821+ };
822+ return & mm ;
823+ }
824+
800825/*
801826
802827Using the cache
0 commit comments