Merged revisions 8245-8298 via svnmerge from
[cacao.git] / src / vm / jit / emit-common.c
index dec288b7d3e9fe827a5330b539bc3374fe85dc55..5639853ef8d333c4becb5368bc80a1af78523dc2 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: emitfuncs.c 4398 2006-01-31 23:43:08Z twisti $
+   $Id: emit-common.c 8265 2007-08-06 16:10:42Z twisti $
 
 */
 
@@ -30,6 +30,7 @@
 #include "config.h"
 
 #include <assert.h>
+#include <stdint.h>
 
 #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
@@ -270,6 +319,16 @@ void emit_bccz(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 opt
                branchmpc = cd->mcodeptr - cd->mcodebase;
                disp      = target->mpc - branchmpc;
 
+#if defined(ENABLE_STATISTICS)
+               count_emit_branch++;
+               if ((int8_t)disp == disp)  count_emit_branch_8bit++; 
+               else if ((int16_t)disp == disp) count_emit_branch_16bit++;
+               else if ((int32_t)disp == disp) count_emit_branch_32bit++;
+# if SIZEOF_VOID_P == 8
+               else if ((int64_t)disp == disp) count_emit_branch_64bit++;
+# endif
+#endif
+
                emit_branch(cd, disp, condition, reg, options);
        }
        else {
@@ -481,6 +540,16 @@ void emit_label_bccz(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options
                mpc  = cd->mcodeptr - cd->mcodebase;
                disp = br->mpc - mpc;
 
+#if defined(ENABLE_STATISTICS)
+               count_emit_branch++;
+               if ((int8_t)disp == disp)  count_emit_branch_8bit++; 
+               else if ((int16_t)disp == disp) count_emit_branch_16bit++;
+               else if ((int32_t)disp == disp) count_emit_branch_32bit++;
+# if SIZEOF_VOID_P == 8
+               else if ((int64_t)disp == disp) count_emit_branch_64bit++;
+# endif
+#endif
+
                emit_branch(cd, disp, condition, reg, options);
 
                /* now remove the branch reference */
@@ -542,6 +611,16 @@ void emit_label(codegendata *cd, s4 label)
                mcodeptr     = cd->mcodeptr;
                cd->mcodeptr = cd->mcodebase + br->mpc;
 
+#if defined(ENABLE_STATISTICS)
+               count_emit_branch++;
+               if ((int8_t)disp == disp)  count_emit_branch_8bit++; 
+               else if ((int16_t)disp == disp) count_emit_branch_16bit++;
+               else if ((int32_t)disp == disp) count_emit_branch_32bit++;
+# if SIZEOF_VOID_P == 8
+               else if ((int64_t)disp == disp) count_emit_branch_64bit++;
+# endif
+#endif
+
                emit_branch(cd, disp, br->condition, br->reg, br->options);
 
                /* restore mcodeptr */