From a71a3c84a54d05179fc9d84f3247acad06767bcd Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 3 Aug 2004 17:16:51 +0000 Subject: [PATCH] Simplified the interface to VG_(translate)(), and merged it with create_translation_for(). Cut about 40 lines of code as a side-effect. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2558 --- coregrind/vg_errcontext.c | 4 +-- coregrind/vg_from_ucode.c | 9 +++-- coregrind/vg_include.h | 7 +--- coregrind/vg_scheduler.c | 38 ++------------------- coregrind/vg_translate.c | 72 ++++++++++++++++++++------------------- 5 files changed, 47 insertions(+), 83 deletions(-) diff --git a/coregrind/vg_errcontext.c b/coregrind/vg_errcontext.c index 4f7fc92546..53e94a4f19 100644 --- a/coregrind/vg_errcontext.c +++ b/coregrind/vg_errcontext.c @@ -665,8 +665,8 @@ void VG_(show_all_errors) ( void ) pp_Error( p_min, False ); if ((i+1 == VG_(clo_dump_error))) { - VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to below NULLs */, - p_min->where->eips[0], NULL, NULL, NULL, NULL ); + VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debugging*/, + p_min->where->eips[0], /*debugging*/True); } p_min->count = 1 << 30; diff --git a/coregrind/vg_from_ucode.c b/coregrind/vg_from_ucode.c index 988448aca1..8dfb4f9bbf 100644 --- a/coregrind/vg_from_ucode.c +++ b/coregrind/vg_from_ucode.c @@ -4510,11 +4510,10 @@ UChar* VG_(emit_code) ( UCodeBlock* cb, vg_assert(!sselive); /* SSE state must be saved by end of BB */ vg_assert(eflags_state != UPD_Real); /* flags can't just be in CPU */ - if (j != NULL) { - vg_assert(jumpidx <= VG_MAX_JUMPS); - for(i = 0; i < jumpidx; i++) - j[i] = jumps[i]; - } + vg_assert(NULL != j); + vg_assert(jumpidx <= VG_MAX_JUMPS); + for(i = 0; i < jumpidx; i++) + j[i] = jumps[i]; /* Returns a pointer to the emitted code. This will have to be copied by the caller into the translation cache, and then freed */ diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h index 501a21be64..ff6735bf9e 100644 --- a/coregrind/vg_include.h +++ b/coregrind/vg_include.h @@ -1151,12 +1151,7 @@ struct _UCodeBlock { extern UCodeBlock* VG_(alloc_UCodeBlock) ( void ); -extern void VG_(translate) ( ThreadId tid, - Addr orig_addr, - UInt* orig_size, - Addr* trans_addr, - UInt* trans_size, - UShort jumps[VG_MAX_JUMPS]); +extern void VG_(translate) ( ThreadId tid, Addr orig_addr, Bool debugging ); extern Bool VG_(saneUInstr) ( Bool beforeRA, Bool beforeLiveness, UInstr* u ); diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index 77f42d8047..3449ebf6e8 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -228,37 +228,6 @@ Char* name_of_sched_event ( UInt event ) } -/* Create a translation of the client basic block beginning at - orig_addr, and add it to the translation cache & translation table. - This probably doesn't really belong here, but, hey ... -*/ -static -void create_translation_for ( ThreadId tid, Addr orig_addr ) -{ - Addr trans_addr; - Int orig_size, trans_size; - UShort jumps[VG_MAX_JUMPS]; - Int i; - - for(i = 0; i < VG_MAX_JUMPS; i++) - jumps[i] = (UShort)-1; - - /* Make a translation, into temporary storage. */ - VG_(translate)( tid, orig_addr, /* in */ - &orig_size, &trans_addr, &trans_size, jumps ); /* out */ - - /* Copy data at trans_addr into the translation cache. */ - /* Since the .orig_size and .trans_size fields are UShort, be paranoid. */ - vg_assert(orig_size > 0 && orig_size < 65536); - vg_assert(trans_size > 0 && trans_size < 65536); - - VG_(add_to_trans_tab)( orig_addr, orig_size, trans_addr, trans_size, jumps ); - - /* Free the intermediary -- was allocated by VG_(emit_code). */ - VG_(arena_free)( VG_AR_JITTER, (void*)trans_addr ); -} - - /* Allocate a completely empty ThreadState record. */ static ThreadId vg_alloc_ThreadState ( void ) @@ -1018,7 +987,7 @@ VgSchedReturnCode VG_(scheduler) ( Int* exitcode ) if (VG_(bbs_done) > 31700000 + 0) { dispatch_ctr_SAVED = VG_(dispatch_ctr) = 2; VG_(translate)(&VG_(threads)[tid], VG_(threads)[tid].m_eip, - NULL,NULL,NULL); + /*debugging*/True); } vg_assert(VG_(threads)[tid].m_eip != 0); # endif @@ -1040,11 +1009,10 @@ VgSchedReturnCode VG_(scheduler) ( Int* exitcode ) /* Trivial event. Miss in the fast-cache. Do a full lookup for it. */ - trans_addr - = VG_(search_transtab) ( VG_(threads)[tid].m_eip ); + trans_addr = VG_(search_transtab) ( VG_(threads)[tid].m_eip ); if (trans_addr == (Addr)0) { /* Not found; we need to request a translation. */ - create_translation_for( tid, VG_(threads)[tid].m_eip ); + VG_(translate)( tid, VG_(threads)[tid].m_eip, /*debug*/False ); trans_addr = VG_(search_transtab) ( VG_(threads)[tid].m_eip ); if (trans_addr == (Addr)0) VG_(core_panic)("VG_TRC_INNER_FASTMISS: missing tt_fast entry"); diff --git a/coregrind/vg_translate.c b/coregrind/vg_translate.c index 716b426466..ededb6ef83 100644 --- a/coregrind/vg_translate.c +++ b/coregrind/vg_translate.c @@ -2396,45 +2396,40 @@ static void vg_realreg_liveness_analysis ( UCodeBlock* cb ) /*--- Main entry point for the JITter. ---*/ /*------------------------------------------------------------*/ -/* Translate the basic block beginning at orig_addr, placing the - translation in a vg_malloc'd block, the address and size of which - are returned in trans_addr and trans_size. Length of the original - block is also returned in orig_size. If the latter three are NULL, - this call is being done for debugging purposes, in which case (a) - throw away the translation once it is made, and (b) produce a load - of debugging output. - - 'tst' is the identity of the thread needing this block. +/* Translate the basic block beginning at orig_addr, and add it to + the translation cache & translation table. Unless 'debugging' is true, + in which case the call is being done for debugging purposes, so + (a) throw away the translation once it is made, and (b) produce a + load of debugging output. + + 'tid' is the identity of the thread needing this block. */ -void VG_(translate) ( /*IN*/ ThreadId tid, - /*IN*/ Addr orig_addr, - /*OUT*/ UInt* orig_size, - /*OUT*/ Addr* trans_addr, - /*OUT*/ UInt* trans_size, - /*OUT*/ UShort jumps[VG_MAX_JUMPS]) +void VG_(translate) ( ThreadId tid, Addr orig_addr, + Bool debugging_translation ) { - Int n_disassembled_bytes, final_code_size; - Bool debugging_translation; - UChar* final_code; + Addr trans_addr, redir, orig_addr0 = orig_addr; + UShort jumps[VG_MAX_JUMPS]; + Int i, orig_size, trans_size; UCodeBlock* cb; Bool notrace_until_done; UInt notrace_until_limit = 0; Segment *seg; - Addr redir; VGP_PUSHCC(VgpTranslate); - debugging_translation - = orig_size == NULL || trans_addr == NULL || trans_size == NULL; + + for (i = 0; i < VG_MAX_JUMPS; i++) + jumps[i] = (UShort)-1; /* Look in the code redirect table to see if we should translate an alternative address for orig_addr. */ redir = VG_(code_redirect)(orig_addr); - if (redir != orig_addr && VG_(clo_verbosity) >= 2) + if (redir != orig_addr && VG_(clo_verbosity) >= 2) { VG_(message)(Vg_UserMsg, "TRANSLATE: %p redirected to %p", orig_addr, redir ); + } orig_addr = redir; /* If codegen tracing, don't start tracing until @@ -2443,8 +2438,7 @@ void VG_(translate) ( /*IN*/ ThreadId tid, few blocks translated prior to a failure. Set notrace_until_limit to be the number of translations to be made before --trace-codegen= style printing takes effect. */ - notrace_until_done - = VG_(overall_in_count) >= notrace_until_limit; + notrace_until_done = VG_(overall_in_count) >= notrace_until_limit; seg = VG_(find_segment)(orig_addr); @@ -2490,7 +2484,7 @@ void VG_(translate) ( /*IN*/ ThreadId tid, /* Disassemble this basic block into cb. */ VG_(print_codegen) = DECIDE_IF_PRINTING_CODEGEN_FOR_PHASE(1); VGP_PUSHCC(VgpToUCode); - n_disassembled_bytes = VG_(disBB) ( cb, orig_addr ); + orig_size = VG_(disBB) ( cb, orig_addr ); VGP_POPCC(VgpToUCode); /* Try and improve the code a bit. */ @@ -2533,26 +2527,34 @@ void VG_(translate) ( /*IN*/ ThreadId tid, /* Emit final code */ VG_(print_codegen) = DECIDE_IF_PRINTING_CODEGEN_FOR_PHASE(5); - VGP_PUSHCC(VgpFromUcode); - final_code = VG_(emit_code)(cb, &final_code_size, jumps ); + trans_addr = (Addr)VG_(emit_code)(cb, &trans_size, jumps ); VGP_POPCC(VgpFromUcode); VG_(free_UCodeBlock)(cb); #undef DECIDE_IF_PRINTING_CODEGEN_FOR_PHASE - if (debugging_translation) { - /* Only done for debugging -- throw away final result. */ - VG_(arena_free)(VG_AR_JITTER, final_code); - } else { - /* Doing it for real -- return values to caller. */ - *orig_size = n_disassembled_bytes; - *trans_addr = (Addr)final_code; - *trans_size = final_code_size; + /* Copy data at trans_addr into the translation cache. */ + /* Since the .orig_size and .trans_size fields are UShort, be paranoid. */ + vg_assert(orig_size > 0 && orig_size < 65536); + vg_assert(trans_size > 0 && trans_size < 65536); + + // If debugging, don't do anything with the translated block; we + // only did this for the debugging output produced along the way. + if (!debugging_translation) { + // Note that we use orig_addr0, not orig_addr, which might have been + // changed by the redirection + VG_(add_to_trans_tab)( orig_addr0, orig_size, trans_addr, trans_size, + jumps ); } + + /* Free the intermediary -- was allocated by VG_(emit_code). */ + VG_(arena_free)( VG_AR_JITTER, (void*)trans_addr ); + VGP_POPCC(VgpTranslate); } + /*--------------------------------------------------------------------*/ /*--- end vg_translate.c ---*/ /*--------------------------------------------------------------------*/ -- 2.47.2