From 1a96e40b1d0f9c017e5bd4e1ce9b2f480d8b17aa Mon Sep 17 00:00:00 2001 From: michi Date: Mon, 6 Aug 2007 12:19:01 +0000 Subject: [PATCH] * src/vm/jit/emit-common.c (emit_patcher_traps): Added. * src/vm/jit/emit-common.h (emit_trap): Added prototype. * src/vm/jit/alpha/emit.c (emit_patcher_traps): Removed (moved to emit-common). (emit_trap): Implemented. * src/vm/jit/arm/emit.c: Likewise. * src/vm/jit/powerpc/emit.c: Likewise. * src/vm/jit/s390/emit.c: Likewise. --- src/vm/jit/alpha/emit.c | 44 +++++++++++------------------------ src/vm/jit/arm/emit.c | 41 ++++++++------------------------ src/vm/jit/emit-common.c | 49 +++++++++++++++++++++++++++++++++++++++ src/vm/jit/emit-common.h | 2 ++ src/vm/jit/powerpc/emit.c | 43 ++++++++-------------------------- src/vm/jit/s390/emit.c | 42 +++++++++------------------------ 6 files changed, 95 insertions(+), 126 deletions(-) diff --git a/src/vm/jit/alpha/emit.c b/src/vm/jit/alpha/emit.c index 6a9dabd3d..044a01bd1 100644 --- a/src/vm/jit/alpha/emit.c +++ b/src/vm/jit/alpha/emit.c @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: emit.c 8211 2007-07-18 19:52:23Z michi $ + $Id: emit.c 8260 2007-08-06 12:19:01Z michi $ */ @@ -31,6 +31,7 @@ #include "vm/types.h" #include +#include #include "md-abi.h" @@ -408,45 +409,26 @@ void emit_exception_check(codegendata *cd, instruction *iptr) } -/* emit_patcher_traps ********************************************************** +/* emit_trap ******************************************************************* - Generates the code for the patcher traps. + Emit a trap instruction and return the original machine code. *******************************************************************************/ -void emit_patcher_traps(jitdata *jd) +uint32_t emit_trap(codegendata *cd) { - codegendata *cd; - codeinfo *code; - patchref_t *pr; - u1 *savedmcodeptr; - u1 *tmpmcodeptr; - - /* get required compiler data */ - - cd = jd->cd; - code = jd->code; - - /* generate patcher traps code */ + uint32_t mcode; - for (pr = list_first_unsynced(code->patchers); pr != NULL; pr = list_next_unsynced(code->patchers, pr)) { + /* Get machine code which is patched back in later. The + trap is 1 instruction word long. */ - /* Get machine code which is patched back in later. The - trap is 1 instruction word long. */ + mcode = *((u4 *) cd->mcodeptr); - tmpmcodeptr = (u1 *) (cd->mcodebase + pr->mpc); - pr->mcode = *((u4 *) tmpmcodeptr); + /* Destination register must not be REG_ZERO, because then no + SIGSEGV is thrown. */ + M_ALD_INTERN(REG_RESULT, REG_ZERO, EXCEPTION_HARDWARE_PATCHER); - /* Patch in the trap to call the signal handler (done at - compile time). */ - - savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */ - cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */ - - M_ALD_INTERN(REG_RESULT, REG_ZERO, EXCEPTION_HARDWARE_PATCHER); - - cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */ - } + return mcode; } diff --git a/src/vm/jit/arm/emit.c b/src/vm/jit/arm/emit.c index 2967a7872..ccd5e7402 100644 --- a/src/vm/jit/arm/emit.c +++ b/src/vm/jit/arm/emit.c @@ -30,6 +30,7 @@ #include "config.h" #include +#include #include "vm/types.h" @@ -561,46 +562,24 @@ void emit_exception_check(codegendata *cd, instruction *iptr) } -/* emit_patcher_traps ********************************************************** +/* emit_trap ******************************************************************* - Generates the code for the patcher traps. + Emit a trap instruction and return the original machine code. *******************************************************************************/ -void emit_patcher_traps(jitdata *jd) +uint32_t emit_trap(codegendata *cd) { - codegendata *cd; - codeinfo *code; - patchref_t *pr; - u1 *savedmcodeptr; - u1 *tmpmcodeptr; - - /* get required compiler data */ - - cd = jd->cd; - code = jd->code; - - /* generate patcher traps code */ + uint32_t mcode; - for (pr = list_first_unsynced(code->patchers); pr != NULL; pr = list_next_unsynced(code->patchers, pr)) { + /* Get machine code which is patched back in later. The + trap is 1 instruction word long. */ - /* Get machine code which is patched back in later. The - trap is 1 instruction word long. */ + mcode = *((u4 *) cd->mcodeptr); - tmpmcodeptr = (u1 *) (cd->mcodebase + pr->mpc); + M_TRAP(0, EXCEPTION_HARDWARE_PATCHER); - pr->mcode = *((u4 *) tmpmcodeptr); - - /* Patch in the trap to call the signal handler (done at - compile time). */ - - savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */ - cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */ - - M_TRAP(0, EXCEPTION_HARDWARE_PATCHER); - - cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */ - } + return mcode; } diff --git a/src/vm/jit/emit-common.c b/src/vm/jit/emit-common.c index c02566c53..8e4a72ce9 100644 --- a/src/vm/jit/emit-common.c +++ b/src/vm/jit/emit-common.c @@ -30,6 +30,7 @@ #include "config.h" #include +#include #include "vm/types.h" @@ -38,6 +39,7 @@ #include "vm/jit/emit-common.h" #include "vm/jit/jit.h" +#include "vm/jit/patcher-common.h" #include "vmcore/options.h" #include "vmcore/statistics.h" @@ -247,6 +249,53 @@ void emit_store_dst(jitdata *jd, instruction *iptr, s4 d) } +/* emit_patcher_traps ********************************************************** + + Generates the code for the patcher traps. + +*******************************************************************************/ + +void emit_patcher_traps(jitdata *jd) +{ + codegendata *cd; + codeinfo *code; + patchref_t *pr; + u1 *savedmcodeptr; + u1 *tmpmcodeptr; + uint32_t mcode; + + /* get required compiler data */ + + cd = jd->cd; + code = jd->code; + + /* generate patcher traps code */ + + for (pr = list_first_unsynced(code->patchers); pr != NULL; pr = list_next_unsynced(code->patchers, pr)) { + + /* Calculate the patch position where the original machine + code is located and the trap should be placed. */ + + tmpmcodeptr = (u1 *) (cd->mcodebase + pr->mpc); + + /* Patch in the trap to call the signal handler (done at + compile time). */ + + savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */ + cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */ + + mcode = emit_trap(cd); + + cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */ + + /* Remember the original machine code which is patched + back in later (done at runtime). */ + + pr->mcode = mcode; + } +} + + /* emit_bccz ******************************************************************* Emit conditional and unconditional branch instructions on integer diff --git a/src/vm/jit/emit-common.h b/src/vm/jit/emit-common.h index 99c4b7216..72aeb029a 100644 --- a/src/vm/jit/emit-common.h +++ b/src/vm/jit/emit-common.h @@ -178,6 +178,8 @@ void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 r void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg); void emit_exception_check(codegendata *cd, instruction *iptr); +uint32_t emit_trap(codegendata *cd); + void emit_patcher_stubs(jitdata *jd); void emit_patcher_traps(jitdata *jd); diff --git a/src/vm/jit/powerpc/emit.c b/src/vm/jit/powerpc/emit.c index 5a86e5cec..28c883e37 100644 --- a/src/vm/jit/powerpc/emit.c +++ b/src/vm/jit/powerpc/emit.c @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: emit.c 8216 2007-07-19 13:51:21Z michi $ + $Id: emit.c 8260 2007-08-06 12:19:01Z michi $ */ @@ -51,7 +51,6 @@ #include "vm/jit/dseg.h" #include "vm/jit/emit-common.h" #include "vm/jit/jit.h" -#include "vm/jit/patcher-common.h" #include "vm/jit/replace.h" #include "vmcore/options.h" @@ -507,46 +506,24 @@ void emit_exception_check(codegendata *cd, instruction *iptr) } -/* emit_patcher_traps ********************************************************** +/* emit_trap ******************************************************************* - Generates the code for the patcher stubs. + Emit a trap instruction and return the original machine code. *******************************************************************************/ -void emit_patcher_traps(jitdata *jd) +uint32_t emit_trap(codegendata *cd) { - codegendata *cd; - codeinfo *code; - patchref_t *pr; - u1 *savedmcodeptr; - u1 *tmpmcodeptr; - - /* get required compiler data */ - - cd = jd->cd; - code = jd->code; - - /* generate code patching stub call code */ + uint32_t mcode; - for (pr = list_first_unsynced(code->patchers); pr != NULL; pr = list_next_unsynced(code->patchers, pr)) { + /* Get machine code which is patched back in later. The + trap is 1 instruction word long. */ - /* Get machine code which is patched back in later. The - trap is 1 instruction word long. */ + mcode = *((u4 *) cd->mcodeptr); - tmpmcodeptr = (u1 *) (cd->mcodebase + pr->mpc); + M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_PATCHER); - pr->mcode = *((u4 *) tmpmcodeptr); - - /* Patch in the trap to call the signal handler (done at - compile time). */ - - savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */ - cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */ - - M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_PATCHER); - - cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */ - } + return mcode; } diff --git a/src/vm/jit/s390/emit.c b/src/vm/jit/s390/emit.c index 6b765d63a..d00836281 100644 --- a/src/vm/jit/s390/emit.c +++ b/src/vm/jit/s390/emit.c @@ -22,13 +22,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: emit.c 8251 2007-08-01 15:26:59Z pm $ + $Id: emit.c 8260 2007-08-06 12:19:01Z michi $ */ #include "config.h" #include +#include #include "mm/memory.h" #if defined(ENABLE_THREADS) @@ -205,45 +206,24 @@ void emit_copy(jitdata *jd, instruction *iptr) } } -/* emit_patcher_traps ********************************************************** +/* emit_trap ******************************************************************* - Generates the code for the patcher traps. + Emit a trap instruction and return the original machine code. *******************************************************************************/ -void emit_patcher_traps(jitdata *jd) +uint32_t emit_trap(codegendata *cd) { - codegendata *cd; - codeinfo *code; - patchref_t *pr; - u1 *savedmcodeptr; - u1 *tmpmcodeptr; - - /* get required compiler data */ - - cd = jd->cd; - code = jd->code; - - /* generate patcher traps code */ - - for (pr = list_first_unsynced(code->patchers); pr != NULL; pr = list_next_unsynced(code->patchers, pr)) { + uint32_t mcode; - /* Get machine code which is patched back in later. The - trap is 2 bytes long. */ + /* Get machine code which is patched back in later. The + trap is 2 bytes long. */ - tmpmcodeptr = (u1 *) (cd->mcodebase + pr->mpc); - pr->mcode = *((u2 *) tmpmcodeptr); + mcode = *((u2 *) cd->mcodeptr); - /* Patch in the trap to call the signal handler (done at - compile time). */ + M_ILL(EXCEPTION_HARDWARE_PATCHER); - savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */ - cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */ - - M_ILL(EXCEPTION_HARDWARE_PATCHER); - - cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */ - } + return mcode; } /* emit_replacement_stubs ****************************************************** -- 2.25.1