Merged trunk and subtype.
[cacao.git] / src / vm / jit / i386 / patcher.c
index 13506172df5fc54f99492123794673c7276ebd0c..034ca21ef2239421c87fcad37a950f382a7e9550 100644 (file)
 #include "vm/types.h"
 
 #include "vm/jit/i386/codegen.h"
+#include "vm/jit/i386/md.h"
 
 #include "mm/memory.h"
 
 #include "native/native.h"
 
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
+#include "vm/jit/builtin.hpp"
+#include "vm/class.h"
+#include "vm/field.hpp"
 #include "vm/initialize.h"
-
-#include "vm/jit/patcher-common.h"
-#include "vm/jit/stacktrace.h"
-
-#include "vmcore/class.h"
-#include "vmcore/field.h"
-#include "vmcore/options.h"
+#include "vm/options.h"
+#include "vm/references.h"
 #include "vm/resolve.h"
-#include "vmcore/references.h"
+
+#include "vm/jit/patcher-common.hpp"
 
 
-#define PATCH_BACK_ORIGINAL_MCODE *((u2 *) pr->mpc) = (u2) pr->mcode
+#define PATCH_BACK_ORIGINAL_MCODE                                                      \
+       do {                                                                                                    \
+               *((uint16_t*) pr->mpc) = (uint16_t) pr->mcode;          \
+               md_icacheflush((void*) pr->mpc, PATCHER_CALL_SIZE);     \
+       } while (0)
 
 
 /* patcher_patch_code **********************************************************
@@ -97,11 +99,6 @@ bool patcher_get_putstatic(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch the field value's address */
 
        *((intptr_t *) (ra + 1)) = (intptr_t) fi->value;
@@ -137,11 +134,6 @@ bool patcher_getfield(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch the field's offset */
 
        *((u4 *) (ra + 2)) = (u4) (fi->offset);
@@ -182,11 +174,6 @@ bool patcher_putfield(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch the field's offset */
 
        if (fi->type != TYPE_LNG) {
@@ -234,11 +221,6 @@ bool patcher_putfieldconst(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch the field's offset */
 
        if (!IS_2_WORD_TYPE(fi->type)) {
@@ -287,11 +269,6 @@ bool patcher_aconst(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch the classinfo pointer */
 
        *((ptrint *) (ra + 1)) = (ptrint) c;
@@ -333,11 +310,6 @@ bool patcher_builtin_multianewarray(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch the classinfo pointer */
 
        *((ptrint *) (ra + 7 + 4)) = (ptrint) c;
@@ -375,11 +347,6 @@ bool patcher_builtin_arraycheckcast(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch the classinfo pointer */
 
        *((ptrint *) (ra + 4)) = (ptrint) c;
@@ -420,11 +387,6 @@ bool patcher_invokestatic_special(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch stubroutine */
 
        *((ptrint *) (ra + 1)) = (ptrint) m->stubroutine;
@@ -462,11 +424,6 @@ bool patcher_invokevirtual(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch vftbl index */
 
        *((s4 *) (ra + 2 + 2)) = (s4) (OFFSET(vftbl_t, table[0]) +
@@ -506,11 +463,6 @@ bool patcher_invokeinterface(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch interfacetable index */
 
        *((s4 *) (ra + 2 + 2)) = (s4) (OFFSET(vftbl_t, interfacetable[0]) -
@@ -552,11 +504,6 @@ bool patcher_checkcast_instanceof_flags(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch class flags */
 
        *((s4 *) (ra + 1)) = (s4) c->flags;
@@ -597,11 +544,6 @@ bool patcher_checkcast_interface(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch super class index */
 
        *((s4 *) (ra + 6 + 2)) = (s4) c->index;
@@ -645,11 +587,6 @@ bool patcher_instanceof_interface(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch super class index */
 
        *((s4 *) (ra + 6 + 2)) = (s4) c->index;
@@ -693,11 +630,6 @@ bool patcher_checkcast_class(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch super class' vftbl */
 
        *((ptrint *) (ra + 1)) = (ptrint) c->vftbl;
@@ -736,11 +668,6 @@ bool patcher_instanceof_class(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (opt_shownops)
-               ra = ra + PATCHER_CALL_SIZE;
-
        /* patch super class' vftbl */
 
        *((ptrint *) (ra + 1)) = (ptrint) c->vftbl;