From f9ad74f3e14cbc2de1ca4b10080a7cf2bed48a68 Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Tue, 23 Jan 2007 06:42:33 +0000 Subject: [PATCH] remove the closure_entry field from jit_function_t --- ChangeLog | 10 ++++++++ jit/jit-function.c | 56 +++++++++++++++++------------------------ jit/jit-internal.h | 11 +++----- jit/jit-rules-alpha.ins | 2 +- jit/jit-rules-x86.ins | 4 +-- 5 files changed, 40 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6882e3c..d75a7d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-01-23 Aleksey Demakov + + * jit/jit-internal.h, jit/jit-function.c: remove the closure_entry + field from jit_function_t. Find this value on the fly in + jit_function_to_closure() and jit_function_to_vtable_pointer() + to be equal either to entry_point or indirector fields. + + * jit/jit-rules-alpha.ins, jit/jit-rules-x86.ins: use + jit_function_to_closure() instead of the closure_entry field. + 2007-01-17 Aleksey Demakov * jit/jit-reg-alloc.h, jit/jit-reg-alloc.c: complete special x87 diff --git a/jit/jit-function.c b/jit/jit-function.c index a481513..ffb84bd 100644 --- a/jit/jit-function.c +++ b/jit/jit-function.c @@ -24,6 +24,9 @@ #include "jit-reg-alloc.h" #include "jit-apply-func.h" #include "jit-setjmp.h" +#ifdef _JIT_COMPILE_DEBUG +#include +#endif /*@ * @deftypefun jit_function_t jit_function_create (jit_context_t context, jit_type_t signature) @@ -109,12 +112,10 @@ jit_function_t jit_function_create(jit_context_t context, jit_type_t signature) (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_create_indirector(func->indirector, (void**) &(func->entry_point)); jit_flush_exec(func->indirector, jit_indirector_size); -# else - func->closure_entry = func->entry_point; # endif #endif @@ -496,7 +497,7 @@ static void compile_block(jit_gencode_t gen, jit_function_t func, jit_insn_t insn; #ifdef _JIT_COMPILE_DEBUG - printf("Block: %d\n", func->builder->block_count++); + printf("Block #%d: %d\n", func->builder->block_count++, block->label); #endif /* Iterate over all blocks in the function */ @@ -507,7 +508,7 @@ static void compile_block(jit_gencode_t gen, jit_function_t func, unsigned char *p1, *p2; p1 = gen->posn.ptr; printf("Insn: %5d, Opcode: 0x%04x\n", func->builder->insn_count++, insn->opcode); - printf("Start of binary code: 0x%08x\n", p1); + printf("Start of binary code: 0x%08x\n", p1); #endif switch(insn->opcode) @@ -611,6 +612,7 @@ static void compile_block(jit_gencode_t gen, jit_function_t func, #ifdef _JIT_COMPILE_DEBUG p2 = gen->posn.ptr; printf("Length of binary code: %d\n\n", p2 - p1); + fflush(stdout); #endif } } @@ -648,9 +650,6 @@ int jit_function_compile(jit_function_t func) struct jit_gencode gen; jit_cache_t cache; void *start; -#if !defined(jit_redirector_size) || !defined(jit_indirector_size) || defined(JIT_BACKEND_INTERP) - void *recompilable_start = 0; -#endif void *end; jit_block_t block; int result; @@ -784,12 +783,14 @@ int jit_function_compile(jit_function_t func) } #endif -#if !defined(jit_redirector_size) || !defined(jit_indirector_size) || defined(JIT_BACKEND_INTERP) +#if !defined(jit_redirector_size) || !defined(jit_indirector_size) /* If the function is recompilable, then we need an extra entry point to properly redirect previous references to the function */ - if(func->is_recompilable) + if(func->is_recompilable && !func->indirector) { - recompilable_start = _jit_gen_redirector(&gen, func); + /* TODO: use _jit_create_indirector() instead of + _jit_gen_redirector() as both do the same. */ + func->indirector = _jit_gen_redirector(&gen, func); } #endif @@ -842,22 +843,6 @@ int jit_function_compile(jit_function_t func) /* Record the entry point */ func->entry_point = start; -#if !defined(jit_redirector_size) || !defined(jit_indirector_size) || defined(JIT_BACKEND_INTERP) - if(recompilable_start) - { - func->closure_entry = recompilable_start; - } - else -#else - /* If the function is recompilable, then we keep closure_entry - point to indirector to properly redirect previous references - to the function, otherwise we make it equal to the function - start */ - if(!func->is_recompilable) -#endif - { - func->closure_entry = start; - } func->is_compiled = 1; /* Free the builder structure, which we no longer require */ @@ -1040,7 +1025,11 @@ void *jit_function_to_closure(jit_function_t func) function_closure, (void *)func); #else /* On native platforms, use the closure entry point */ - return func->closure_entry; + if(func->indirector && (!func->is_compiled || func->is_recompilable)) + { + return func->indirector; + } + return func->entry_point; #endif } @@ -1127,14 +1116,15 @@ void *jit_function_to_vtable_pointer(jit_function_t func) return func; #else /* On native platforms, the closure entry point is the vtable pointer */ - if(func) + if(!func) { - return func->closure_entry; + return 0; } - else + if(func->indirector && (!func->is_compiled || func->is_recompilable)) { - return 0; + return func->indirector; } + return func->entry_point; #endif } diff --git a/jit/jit-internal.h b/jit/jit-internal.h index 34f6f5e..409b151 100644 --- a/jit/jit-internal.h +++ b/jit/jit-internal.h @@ -395,9 +395,6 @@ struct _jit_function /* The entry point for the function's compiled code */ void * volatile entry_point; - /* The closure/vtable entry point for the function's compiled code */ - void * volatile closure_entry; - /* The function to call to perform on-demand compilation */ jit_on_demand_func on_demand; @@ -406,12 +403,12 @@ struct _jit_function Redirectors are used to support on-demand compilation */ 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. */ + The indirector jumps to the address that is currently + stored in the entry_point field. Indirectors are used + to support recompilation and on-demand compilation. */ unsigned char *indirector; -#endif }; /* diff --git a/jit/jit-rules-alpha.ins b/jit/jit-rules-alpha.ins index dbb7a8b..ecd48b6 100644 --- a/jit/jit-rules-alpha.ins +++ b/jit/jit-rules-alpha.ins @@ -410,7 +410,7 @@ JIT_OP_ILE_UN: JIT_OP_CALL: [] -> { jit_function_t func = (jit_function_t)(insn->dest); - alpha_call(inst, func->closure_entry); + alpha_call(inst, jit_function_to_closure(func)); } /* TODO: JIT_OP_CALL_TAIL, JIT_OP_CALL_INDIRECT, JIT_OP_CALL_VTABLE_PTR */ diff --git a/jit/jit-rules-x86.ins b/jit/jit-rules-x86.ins index 78717b2..2f80e6f 100644 --- a/jit/jit-rules-x86.ins +++ b/jit/jit-rules-x86.ins @@ -1464,7 +1464,7 @@ JIT_OP_CHECK_NULL: note JIT_OP_CALL: [] -> { jit_function_t func = (jit_function_t)(insn->dest); - x86_call_code(inst, func->closure_entry); + x86_call_code(inst, jit_function_to_closure(func)); } JIT_OP_CALL_TAIL: @@ -1472,7 +1472,7 @@ JIT_OP_CALL_TAIL: jit_function_t func = (jit_function_t)(insn->dest); x86_mov_reg_reg(inst, X86_ESP, X86_EBP, sizeof(void *)); x86_pop_reg(inst, X86_EBP); - x86_jump_code(inst, func->closure_entry); + x86_jump_code(inst, jit_function_to_closure(func)); } JIT_OP_CALL_INDIRECT: -- 2.47.3