i386 / x86_64: Align patcher trap instruction.
authorStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 6 Jul 2009 15:16:20 +0000 (17:16 +0200)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 6 Jul 2009 15:16:20 +0000 (17:16 +0200)
* src/vm/jit/i386/emit.c: Added emit_patcher_alignment.
* src/vm/jit/x86_64/emit.c: Likewise.
* src/vm/jit/i386/md-trap.h: Added emit_patcher_alignment, defined
ALIGN_PATCHER_TRAP.
* src/vm/jit/x86_64/md-trap.h: Likewise.
* src/vm/jit/patcher-common.cpp (patcher_add_patch_ref): Use
emit_patcher_alignment if requested.

src/vm/jit/i386/emit.c
src/vm/jit/i386/md-trap.h
src/vm/jit/patcher-common.cpp
src/vm/jit/x86_64/emit.c
src/vm/jit/x86_64/md-trap.h

index dfc62a78bac911d47d401cae744dd3011a449981..cfddc22a70f64aeb6934e5de08a063ac1d4f5ba6 100644 (file)
@@ -537,6 +537,19 @@ void emit_trap_countdown(codegendata *cd, s4 *counter)
        M_ALD_MEM(REG_METHODPTR, TRAP_COUNTDOWN);
 }
 
+/* emit_patcher_alignment ******************************************************
+
+   Emit NOP to ensure placement at an even address.
+
+*******************************************************************************/
+
+void emit_patcher_alignment(codegendata *cd)
+{
+       if ((uintptr_t) cd->mcodeptr & 1)
+               M_NOP;
+}
+
+
 /* emit_trap *******************************************************************
 
    Emit a trap instruction and return the original machine code.
index 6cf2bbf20b99acfa7da6d9c3c28d72758f7d93e3..d8bfecbe35a7044f9548a36ac429179f69db03bb 100644 (file)
@@ -80,6 +80,13 @@ enum {
                (xpc) = (void*) (((uintptr_t) (ra)) - 2); \
        } while(0)
 
+/**
+ * Align traps so they don't cross cache line boundaries.
+ */
+#define ALIGN_PATCHER_TRAP
+
+void emit_patcher_alignment(codegendata *cd);
 
 #endif /* _MD_TRAP_H */
 
index 8d3e6dcef9ae5f618d9e8312b2d6d996984fa73d..c96f14808d0a2061db872d7841b75a6052f538fc 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "codegen.h"                   /* for PATCHER_NOPS */
 #include "md.h"
+#include "trap.hpp"
 
 #include "mm/memory.hpp"
 
@@ -175,6 +176,11 @@ void patcher_add_patch_ref(jitdata *jd, functionptr patcher, void* ref, s4 disp)
        code     = jd->code;
        patchmpc = cd->mcodeptr - cd->mcodebase;
 
+#if defined(ALIGN_PATCHER_TRAP)
+       emit_patcher_alignment(cd);
+       patchmpc = cd->mcodeptr - cd->mcodebase;
+#endif
+
 #if !defined(NDEBUG)
        if (patcher_list_find(code, (void*) (intptr_t) patchmpc) != NULL)
                vm_abort("patcher_add_patch_ref: different patchers at same position.");
index 79cd94dd6a422ba7c1912202379bf55a18f68b8b..398d7d05843a96d1fbff1a8a50c7581b302c266d 100644 (file)
@@ -424,6 +424,19 @@ void emit_trap_compiler(codegendata *cd)
 }
 
 
+/* emit_patcher_alignment ******************************************************
+
+   Emit NOP to ensure placement at an even address.
+
+*******************************************************************************/
+
+void emit_patcher_alignment(codegendata *cd)
+{
+       if ((uintptr_t) cd->mcodeptr & 1)
+               M_NOP;
+}
+
+
 /* emit_trap *******************************************************************
 
    Emit a trap instruction and return the original machine code.
index 8b09e3c6e8d50a0e5b2fa21e493d78c5cf4f6ec7..c8d5383329821c5694f460799c58930151f0a6ff 100644 (file)
@@ -81,6 +81,14 @@ enum {
        } while(0)
 
 
+/**
+ * Align traps so they don't cross cache line boundaries.
+ */
+#define ALIGN_PATCHER_TRAP
+
+void emit_patcher_alignment(codegendata *cd);
+
 #endif /* _MD_TRAP_H */