Fixes PR84 for alpha.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Mon, 15 Sep 2008 11:43:45 +0000 (13:43 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Mon, 15 Sep 2008 11:43:45 +0000 (13:43 +0200)
* src/vm/jit/alpha/patcher.c: Reordered data and code patching.

src/vm/jit/alpha/patcher.c

index 4490f2549391e2c753768ad8e0a19446af6b1d03..71368b63e07b3cc79d832905818adc8d4b16818d 100644 (file)
 #include "vm/jit/methodheader.h"
 
 
-#define PATCH_BACK_ORIGINAL_MCODE \
-       *((u4 *) pr->mpc) = (u4) pr->mcode; \
-    md_icacheflush(NULL, 0);
-
-
 /* patcher_patch_code **********************************************************
 
    Just patches back the original machine code.
 
 *******************************************************************************/
 
-void patcher_patch_code(patchref_t *pr)
+void patcher_patch_code(patchref_tpr)
 {
-       PATCH_BACK_ORIGINAL_MCODE;
+       // Patch back original code.
+       *((uint32_t*) pr->mpc) = pr->mcode;
+
+       // Synchronize instruction cache.
+    md_icacheflush(NULL, 0);
 }
 
 
@@ -105,12 +104,13 @@ bool patcher_resolve_classref_to_classinfo(patchref_t *pr)
        if (!(c = resolve_classref_eager(cr)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch the classinfo pointer */
 
        *((ptrint *) datap) = (ptrint) c;
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }
 
@@ -142,12 +142,13 @@ bool patcher_resolve_classref_to_vftbl(patchref_t *pr)
        if (!(c = resolve_classref_eager(cr)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch super class' vftbl */
 
        *((ptrint *) datap) = (ptrint) c->vftbl;
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }
 
@@ -176,12 +177,13 @@ bool patcher_resolve_classref_to_flags(patchref_t *pr)
        if (!(c = resolve_classref_eager(cr)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch class flags */
 
        *((s4 *) datap) = (s4) c->flags;
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }
 
@@ -218,12 +220,13 @@ bool patcher_get_putstatic(patchref_t *pr)
                if (!initialize_class(fi->clazz))
                        return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch the field value's address */
 
        *((intptr_t *) datap) = (intptr_t) fi->value;
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }
 
@@ -239,11 +242,9 @@ bool patcher_get_putstatic(patchref_t *pr)
 
 bool patcher_get_putfield(patchref_t *pr)
 {
-       u1               *ra;
        unresolved_field *uf;
        fieldinfo        *fi;
 
-       ra    = (u1 *)               pr->mpc;
        uf    = (unresolved_field *) pr->ref;
 
        /* get the fieldinfo */
@@ -251,13 +252,12 @@ bool patcher_get_putfield(patchref_t *pr)
        if (!(fi = resolve_field_eager(uf)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch the field's offset into the instruction */
 
-       *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
+       pr->mcode |= (s2) (fi->offset & 0x0000ffff);
 
-       md_icacheflush(NULL, 0);
+       // Patch back the original code.
+       patcher_patch_code(pr);
 
        return true;
 }
@@ -289,12 +289,13 @@ bool patcher_invokestatic_special(patchref_t *pr)
        if (!(m = resolve_method_eager(um)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch stubroutine */
 
        *((ptrint *) datap) = (ptrint) m->stubroutine;
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }
 
@@ -326,8 +327,6 @@ bool patcher_invokevirtual(patchref_t *pr)
        if (!(m = resolve_method_eager(um)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch vftbl index */
 
        *((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
@@ -335,6 +334,9 @@ bool patcher_invokevirtual(patchref_t *pr)
 
        md_icacheflush(NULL, 0);
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }
 
@@ -367,8 +369,6 @@ bool patcher_invokeinterface(patchref_t *pr)
        if (!(m = resolve_method_eager(um)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch interfacetable index */
 
        *((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
@@ -381,6 +381,9 @@ bool patcher_invokeinterface(patchref_t *pr)
 
        md_icacheflush(NULL, 0);
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }
 
@@ -414,8 +417,6 @@ bool patcher_checkcast_interface(patchref_t *pr)
        if (!(c = resolve_classref_eager(cr)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch super class index */
 
        *((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
@@ -425,6 +426,9 @@ bool patcher_checkcast_interface(patchref_t *pr)
 
        md_icacheflush(NULL, 0);
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }
 
@@ -458,8 +462,6 @@ bool patcher_instanceof_interface(patchref_t *pr)
        if (!(c = resolve_classref_eager(cr)))
                return false;
 
-       PATCH_BACK_ORIGINAL_MCODE;
-
        /* patch super class index */
 
        *((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
@@ -469,6 +471,9 @@ bool patcher_instanceof_interface(patchref_t *pr)
 
        md_icacheflush(NULL, 0);
 
+       // Patch back the original code.
+       patcher_patch_code(pr);
+
        return true;
 }