* src/vm/jit/powerpc64/patcher.c: Code cleanup.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 12 Sep 2008 08:29:50 +0000 (10:29 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 12 Sep 2008 08:29:50 +0000 (10:29 +0200)
src/vm/jit/powerpc64/patcher.c

index dfedbafda0b39c5bec7a7fa46e9930ab8dbca3c5..85f68441e528e7a92c43aacb3dee2b73fb89f186 100644 (file)
@@ -75,38 +75,26 @@ void patcher_patch_code(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_get_putstatic(patchref_t *pr)
+bool patcher_get_putstatic(patchref_tpr)
 {
-       u1               *ra;
-       u4                mcode;
-       unresolved_field *uf;
-       u1               *datap;
-       fieldinfo        *fi;
+       unresolved_field* uf    = (unresolved_field*) pr->ref;
+       uintptr_t*        datap = (uintptr_t*)        pr->datap;
 
-       /* get stuff from the stack */
+       // Resolve the field.
+       fieldinfo* fi = resolve_field_eager(uf);
 
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       uf    = (unresolved_field *)  pr->ref;
-       datap = (u1 *)                pr->datap;
-
-       /* get the fieldinfo */
-
-       if (!(fi = resolve_field_eager(uf)))
+       if (fi == NULL)
                return false;
 
-       /* check if the field's class is initialized */
-
+       // Check if the field's class is initialized.
        if (!(fi->clazz->state & CLASS_INITIALIZED))
                if (!initialize_class(fi->clazz))
                        return false;
 
-       /* patch the field value's address */
-
-       *((intptr_t *) datap) = (intptr_t) fi->value;
-
-       /* synchronize data cache */
+       // Patch the field value's address.
+       *datap = (uintptr_t) fi->value;
 
+       // Synchronize data cache.
        md_dcacheflush(datap, SIZEOF_VOID_P);
 
        // Patch back the original code.
@@ -125,20 +113,14 @@ bool patcher_get_putstatic(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_get_putfield(patchref_t *pr)
+bool patcher_get_putfield(patchref_tpr)
 {
-       u1               *ra;
-       u4                mcode;
-       unresolved_field *uf;
-       fieldinfo        *fi;
+       unresolved_field* uf = (unresolved_field*) pr->ref;
 
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       uf    = (unresolved_field *)  pr->ref;
+       // Resolve the field.
+       fieldinfo* fi = resolve_field_eager(uf);
 
-       /* get the fieldinfo */
-
-       if (!(fi = resolve_field_eager(uf)))
+       if (fi == NULL)
                return false;
 
        // Patch the field offset in the patcher.  We also need this to
@@ -163,28 +145,19 @@ bool patcher_get_putfield(patchref_t *pr)
 
 ******************************************************************************/
 
-bool patcher_invokestatic_special(patchref_t *pr)
+bool patcher_invokestatic_special(patchref_tpr)
 {
-       u1                *ra;
-       u4                 mcode;
-       unresolved_method *um;
-       u1                *datap;
-       methodinfo        *m;
-
-       /* get stuff from the stack */
-
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       um    = (unresolved_method *) pr->ref;
-       datap = (u1 *)                pr->datap;
+       unresolved_method* um    = (unresolved_method*) pr->ref;
+       uintptr_t*         datap = (uintptr_t*)         pr->datap;
 
-       /* get the fieldinfo */
+       // Resolve the method.
+       methodinfo* m = resolve_method_eager(um);
 
-       if (!(m = resolve_method_eager(um)))
+       if (m == NULL)
                return false;
 
        // Patch stubroutine.
-       *((ptrint *) datap) = (ptrint) m->stubroutine;
+       *datap = (uintptr_t) m->stubroutine;
 
        // Synchronize data cache.
        md_dcacheflush(datap, SIZEOF_VOID_P);
@@ -208,32 +181,24 @@ bool patcher_invokestatic_special(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_invokevirtual(patchref_t *pr)
+bool patcher_invokevirtual(patchref_tpr)
 {
-       u1                *ra;
-       u4                 mcode;
-       unresolved_method *um;
-       methodinfo        *m;
-       s4                 disp;
+       uint32_t*          pc = (uint32_t*)          pr->mpc;
+       unresolved_method* um = (unresolved_method*) pr->ref;
 
-       /* get stuff from the stack */
+       // Resolve the method.
+       methodinfo* m = resolve_method_eager(um);
 
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       um    = (unresolved_method *) pr->ref;
-
-       /* get the fieldinfo */
-
-       if (!(m = resolve_method_eager(um)))
+       if (m == NULL)
                return false;
 
        // Patch vftbl index.
-       disp = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
+       int32_t disp = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
 
-       *((uint32_t*) (ra + 1 * 4)) |= (disp & 0x0000ffff);
+       pc[1] |= (disp & 0x0000ffff);
 
        // Synchronize instruction cache.
-       md_icacheflush(ra, 2 * 4);
+       md_icacheflush(pc + 1, 1 * 4);
 
        // Patch back the original code.
        patcher_patch_code(pr);
@@ -255,40 +220,31 @@ bool patcher_invokevirtual(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_invokeinterface(patchref_t *pr)
+bool patcher_invokeinterface(patchref_tpr)
 {
-       u1                *ra;
-       u4                 mcode;
-       unresolved_method *um;
-       methodinfo        *m;
-       s4                 disp;
-
-       /* get stuff from the stack */
+       uint32_t*          pc = (uint32_t*)          pr->mpc;
+       unresolved_method* um = (unresolved_method*) pr->ref;
 
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       um    = (unresolved_method *) pr->ref;
+       // Resolve the method.
+       methodinfo* m = resolve_method_eager(um);
 
-       /* get the fieldinfo */
-
-       if (!(m = resolve_method_eager(um)))
+       if (m == NULL)
                return false;
 
        // Patch interfacetable index.
-       disp = OFFSET(vftbl_t, interfacetable[0]) -
-               sizeof(methodptr*) * m->clazz->index;
+       int32_t disp = OFFSET(vftbl_t, interfacetable[0]) - sizeof(methodptr*) * m->clazz->index;
 
        // XXX TWISTI: check displacement
-       *((uint32_t*) (ra + 1 * 4)) |= (disp & 0x0000ffff);
+       pc[1] |= (disp & 0x0000ffff);
 
        // Patch method offset.
        disp = sizeof(methodptr) * (m - m->clazz->methods);
 
        // XXX TWISTI: check displacement
-       *((uint32_t*) (ra + 2 * 4)) |= (disp & 0x0000ffff);
+       pc[2] |= (disp & 0x0000ffff);
 
        // Synchronize instruction cache.
-       md_icacheflush(ra, 3 * 4);
+       md_icacheflush(pc + 1, 2 * 4);
 
        // Patch back the original code.
        patcher_patch_code(pr);
@@ -311,33 +267,26 @@ bool patcher_invokeinterface(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_checkcast_interface(patchref_t *pr)
+bool patcher_checkcast_interface(patchref_tpr)
 {
-       u1                *ra;
-       constant_classref *cr;
-       classinfo         *c;
-       s4                 disp;
-       u4                 mcode;
-
-       /* get stuff from stack */
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       cr    = (constant_classref *) pr->ref;
-
-       /* get the fieldinfo */
-       if (!(c = resolve_classref_eager(cr)))  {
+       uint32_t*          pc = (uint32_t*)          pr->mpc;
+       constant_classref* cr = (constant_classref*) pr->ref;
+
+       // Resolve the class.
+       classinfo* c = resolve_classref_eager(cr);
+
+       if (c == NULL)
                return false;
-       }
 
        // Patch super class index.
-       disp = -(c->index);
-       *((uint32_t*) (ra + 2 * 4)) |= (disp & 0x0000ffff);
+       int32_t disp = -(c->index);
+       pc[2] |= (disp & 0x0000ffff);
 
        disp = OFFSET(vftbl_t, interfacetable[0]) - c->index * sizeof(methodptr*);
-       *((uint32_t*) (ra + 5 * 4)) |= (disp & 0x0000ffff);
+       pc[5] |= (disp & 0x0000ffff);
 
        // Synchronize instruction cache.
-       md_icacheflush(ra, 6 * 4);
+       md_icacheflush(pc + 2, 4 * 4);
 
        // Patch back the original code.
        patcher_patch_code(pr);
@@ -359,34 +308,26 @@ bool patcher_checkcast_interface(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_instanceof_interface(patchref_t *pr)
+bool patcher_instanceof_interface(patchref_tpr)
 {
-       u1                *ra;
-       u4                 mcode;
-       constant_classref *cr;
-       classinfo         *c;
-       s4                 disp;
+       uint32_t*          pc = (uint32_t*)          pr->mpc;
+       constant_classref* cr = (constant_classref*) pr->ref;
 
-       /* get stuff from the stack */
+       // Resolve the class.
+       classinfo* c = resolve_classref_eager(cr);
 
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       cr    = (constant_classref *) pr->ref;
-
-       /* get the fieldinfo */
-
-       if (!(c = resolve_classref_eager(cr)))
+       if (c == NULL)
                return false;
 
        // Patch super class index.
-       disp = -(c->index);
-       *((uint32_t*) (ra + 2 * 4)) |= (disp & 0x0000ffff);
+       int32_t disp = -(c->index);
+       pc[2] |= (disp & 0x0000ffff);
 
        disp = OFFSET(vftbl_t, interfacetable[0]) - c->index * sizeof(methodptr*);
-       *((uint32_t*) (ra + 4 * 4)) |= (disp & 0x0000ffff);
+       pc[4] |= (disp & 0x0000ffff);
 
        // Synchronize instruction cache.
-       md_icacheflush(ra, 5 * 4);
+       md_icacheflush(pc + 2, 3 * 4);
 
        // Patch back the original code.
        patcher_patch_code(pr);
@@ -426,27 +367,19 @@ bool patcher_instanceof_interface(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_resolve_classref_to_classinfo(patchref_t *pr)
+bool patcher_resolve_classref_to_classinfo(patchref_tpr)
 {
-       constant_classref *cr;
-       u1                *datap, *ra;
-       u4                 mcode;
-       classinfo         *c;
-
-       /* get stuff from the stack */
+       constant_classref* cr    = (constant_classref*) pr->ref;
+       uintptr_t*         datap = (uintptr_t*)         pr->datap;
 
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       cr    = (constant_classref *) pr->ref;
-       datap = (u1 *)                pr->datap;
+       // Resolve the class.
+       classinfo* c = resolve_classref_eager(cr);
 
-       /* get the classinfo */
-
-       if (!(c = resolve_classref_eager(cr)))
+       if (c == NULL)
                return false;
 
        // Patch the classinfo pointer.
-       *((uintptr_t*) datap) = (uintptr_t) c;
+       *datap = (uintptr_t) c;
 
        // Synchronize data cache.
        md_dcacheflush(datap, SIZEOF_VOID_P);
@@ -476,27 +409,19 @@ bool patcher_resolve_classref_to_classinfo(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_resolve_classref_to_vftbl(patchref_t *pr)
+bool patcher_resolve_classref_to_vftbl(patchref_tpr)
 {
-       constant_classref *cr;
-       u1                *datap, *ra;
-       u4                 mcode;
-       classinfo         *c;
-
-       /* get stuff from the stack */
-
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       cr    = (constant_classref *) pr->ref;
-       datap = (u1 *)                pr->datap;
+       constant_classref* cr    = (constant_classref*) pr->ref;
+       uintptr_t*         datap = (uintptr_t*)         pr->datap;
 
-       /* get the fieldinfo */
+       // Resolve the class.
+       classinfo* c = resolve_classref_eager(cr);
 
-       if (!(c = resolve_classref_eager(cr)))
+       if (c == NULL)
                return false;
 
        // Patch super class' vftbl.
-       *((uintptr_t*) datap) = (uintptr_t) c->vftbl;
+       *datap = (uintptr_t) c->vftbl;
 
        // Synchronize data cache.
        md_dcacheflush(datap, SIZEOF_VOID_P);
@@ -516,27 +441,19 @@ bool patcher_resolve_classref_to_vftbl(patchref_t *pr)
 
 *******************************************************************************/
 
-bool patcher_resolve_classref_to_flags(patchref_t *pr)
+bool patcher_resolve_classref_to_flags(patchref_tpr)
 {
-       constant_classref *cr;
-       u1                *datap, *ra;
-       u4                 mcode;
-       classinfo         *c;
-
-       /* get stuff from the stack */
-
-       ra    = (u1 *)                pr->mpc;
-       mcode =                       pr->mcode;
-       cr    = (constant_classref *) pr->ref;
-       datap = (u1 *)                pr->datap;
+       constant_classref* cr    = (constant_classref*) pr->ref;
+       int32_t*           datap = (int32_t*)           pr->datap;
 
-       /* get the fieldinfo */
+       // Resolve the class.
+       classinfo* c = resolve_classref_eager(cr);
 
-       if (!(c = resolve_classref_eager(cr)))
+       if (c == NULL)
                return false;
 
        // Patch class flags.
-       *((int32_t*) datap) = (int32_t) c->flags;
+       *datap = (int32_t) c->flags;
 
        // Synchronize data cache.
        md_dcacheflush(datap, SIZEOF_VOID_P);