Merge from subtype.
[cacao.git] / src / vm / jit / s390 / patcher.c
index 2eb44fe5a6ea4f9988bcbf7d6602402fd5b56944..1add8371907da523544b80c3f0dbe8479616def7 100644 (file)
@@ -1,9 +1,7 @@
-/* src/vm/jit/x86_64/patcher.c - x86_64 code patching functions
+/* src/vm/jit/s390/patcher.c - s390 code patching functions
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
-   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-   J. Wenninger, Institut f. Computersprachen - TU Wien
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Christian Thalinger
-
-   Changes: Peter Molnar
-
-   $Id: patcher.c 8268 2007-08-07 13:24:43Z twisti $
-
 */
 
 
 #include <stdint.h>
 
 #include "mm/memory.h"
-#include "native/native.h"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/initialize.h"
-#include "vm/jit/patcher-common.h"
+#include "native/native.hpp"
+
+#include "vm/jit/builtin.hpp"
+#include "vm/class.hpp"
+#include "vm/field.hpp"
+#include "vm/initialize.hpp"
+#include "vm/options.h"
+#include "vm/references.h"
+#include "vm/resolve.hpp"
+#include "vm/types.h"
+
+#include "vm/jit/patcher-common.hpp"
 #include "vm/jit/s390/codegen.h"
 #include "vm/jit/s390/md-abi.h"
-#include "vm/jit/stacktrace.h"
-#include "vm/resolve.h"
-#include "vm/types.h"
-#include "vmcore/class.h"
-#include "vmcore/field.h"
-#include "vmcore/options.h"
-#include "vmcore/references.h"
+
 
 #define PATCH_BACK_ORIGINAL_MCODE \
        *((u2 *) pr->mpc) = (u2) pr->mcode;
 
 #define PATCHER_TRACE 
 
+
+/* patcher_patch_code **********************************************************
+
+   Just patches back the original machine code.
+
+*******************************************************************************/
+
+void patcher_patch_code(patchref_t *pr)
+{
+       PATCH_BACK_ORIGINAL_MCODE;
+}
+
+
 /* patcher_get_putstatic *******************************************************
 
    Machine code:
@@ -85,8 +89,8 @@ bool patcher_get_putstatic(patchref_t *pr)
 
        /* check if the field's class is initialized */
 
-       if (!(fi->class->state & CLASS_INITIALIZED))
-               if (!initialize_class(fi->class))
+       if (!(fi->clazz->state & CLASS_INITIALIZED))
+               if (!initialize_class(fi->clazz))
                        return false;
 
        PATCH_BACK_ORIGINAL_MCODE;
@@ -127,11 +131,6 @@ bool patcher_get_putfield(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* If NOPs are generated, skip them */
-
-       if (opt_shownops)
-               ra += PATCHER_NOPS_SKIP;
-
        /* If there is an operand load before, skip the load size passed in disp (see ICMD_PUTFIELD) */
 
        ra += disp;
@@ -139,15 +138,15 @@ bool patcher_get_putfield(patchref_t *pr)
        /* patch correct offset */
 
        if (fi->type == TYPE_LNG) {
-               assert(N_VALID_DISP(fi->offset + 4));
+               ASSERT_VALID_DISP(fi->offset + 4);
                /* 2 RX operations, for 2 words; each already contains a 0 or 4 offset. */
-               *((u4 *) ra ) |= (fi->offset + (*((u4 *) ra) & 0xF));
-               ra += 4;
-               *((u4 *) ra ) |= (fi->offset + (*((u4 *) ra) & 0xF));
+               N_RX_SET_DISP(ra, fi->offset + N_RX_GET_DISP(ra));
+               ra += SZ_RX;
+               N_RX_SET_DISP(ra, fi->offset + N_RX_GET_DISP(ra));
        } else {
-               assert(N_VALID_DISP(fi->offset));
+               ASSERT_VALID_DISP(fi->offset);
                /* 1 RX operation */
-               *((u4 *) ra) |= fi->offset;
+               N_RX_SET_DISP(ra, fi->offset);
        }
 
        return true;
@@ -215,20 +214,15 @@ bool patcher_invokevirtual(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* If NOPs are generated, skip them */
-
-       if (opt_shownops)
-               ra += PATCHER_NOPS_SKIP;
-
        /* patch vftbl index */
 
 
        off = (s4) (OFFSET(vftbl_t, table[0]) +
                                                                   sizeof(methodptr) * m->vftblindex);
 
-       assert(N_VALID_DISP(off));
+       ASSERT_VALID_DISP(off);
 
-       *((s4 *)(ra + 4)) |= off;
+       N_RX_SET_DISP(ra + SZ_RX, off);
 
        return true;
 }
@@ -263,28 +257,24 @@ bool patcher_invokeinterface(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* If NOPs are generated, skip them */
-
-       if (opt_shownops)
-               ra += PATCHER_NOPS_SKIP;
-
        /* get interfacetable index */
 
        idx = (s4) (OFFSET(vftbl_t, interfacetable[0]) -
-               sizeof(methodptr) * m->class->index);
+               sizeof(methodptr) * m->clazz->index);
 
        ASSERT_VALID_IMM(idx);
 
        /* get method offset */
 
        off =
-               (s4) (sizeof(methodptr) * (m - m->class->methods));
+               (s4) (sizeof(methodptr) * (m - m->clazz->methods));
+
        ASSERT_VALID_DISP(off);
 
        /* patch them */
 
-       *((s4 *)(ra + 4)) |= (u2)idx;
-       *((s4 *)(ra + 4 + 4 + 4)) |= off;
+       N_RI_SET_IMM(ra + SZ_L, idx);
+       N_RX_SET_DISP(ra + SZ_L + SZ_LHI + SZ_L, off);
 
        return true;
 }
@@ -423,36 +413,31 @@ bool patcher_checkcast_instanceof_interface(patchref_t *pr)
 
        PATCH_BACK_ORIGINAL_MCODE;
 
-       /* If NOPs are generated, skip them */
-
-       if (opt_shownops)
-               ra += PATCHER_NOPS_SKIP;
-
        /* patch super class index */
 
        /* From here, split your editor and open codegen.c */
 
-       switch (*(ra + 1) >> 4) {
+       switch (N_RX_GET_REG(ra)) {
                case REG_ITMP1: 
                        /* First M_ALD is into ITMP1 */
                        /* INSTANCEOF code */
 
-                       *(u4 *)(ra + SZ_L + SZ_L) |= (u2)(s2)(- c->index);
-                       *(u4 *)(ra + SZ_L + SZ_L + SZ_AHI + SZ_BRC) |=
-                               (u2)(s2)(OFFSET(vftbl_t, interfacetable[0]) -
-                                       c->index * sizeof(methodptr*));
-
+                       N_RI_SET_IMM(ra + SZ_L + SZ_L, - c->index);
+                       N_RI_SET_IMM(
+                               ra + SZ_L + SZ_L + SZ_AHI + SZ_BRC,
+                               (int16_t)(OFFSET(vftbl_t, interfacetable[0]) - c->index * sizeof(methodptr*))
+                       );
                        break;
 
                case REG_ITMP2:
                        /* First M_ALD is into ITMP2 */
                        /* CHECKCAST code */
 
-                       *(u4 *)(ra + SZ_L + SZ_L) |= (u2)(s2)(- c->index);
-                       *(u4 *)(ra + SZ_L + SZ_L + SZ_AHI + SZ_BRC + SZ_ILL) |=
-                               (u2)(s2)(OFFSET(vftbl_t, interfacetable[0]) -
-                                       c->index * sizeof(methodptr*));
-
+                       N_RI_SET_IMM(ra + SZ_L + SZ_L, - c->index);
+                       N_RI_SET_IMM(
+                               ra + SZ_L + SZ_L + SZ_AHI + SZ_BRC + SZ_ILL,
+                               (int16_t)(OFFSET(vftbl_t, interfacetable[0]) - c->index * sizeof(methodptr*))
+                       );
                        break;
 
                default:
@@ -463,103 +448,6 @@ bool patcher_checkcast_instanceof_interface(patchref_t *pr)
        return true;
 }
 
-/* patcher_clinit **************************************************************
-
-   May be used for GET/PUTSTATIC and in native stub.
-
-   Machine code:
-
-*******************************************************************************/
-
-bool patcher_clinit(patchref_t *pr)
-{
-       classinfo *c;
-
-       PATCHER_TRACE;
-
-       /* get stuff from the stack */
-
-       c     = (classinfo *)pr->ref;
-
-       /* check if the class is initialized */
-
-       if (!(c->state & CLASS_INITIALIZED))
-               if (!initialize_class(c))
-                       return false;
-
-       /* patch back original code */
-
-       PATCH_BACK_ORIGINAL_MCODE;
-
-       return true;
-}
-
-
-/* patcher_athrow_areturn ******************************************************
-
-   Machine code:
-
-   <patched call position>
-
-*******************************************************************************/
-
-#ifdef ENABLE_VERIFIER
-bool patcher_athrow_areturn(patchref_t *pr)
-{
-       unresolved_class *uc;
-
-       PATCHER_TRACE;
-
-       /* get stuff from the stack */
-
-       uc    = (unresolved_class *) pr->ref;
-
-       /* resolve the class and check subtype constraints */
-
-       if (!resolve_class_eager_no_access_check(uc))
-               return false;
-
-       /* patch back original code */
-
-       PATCH_BACK_ORIGINAL_MCODE;
-
-       return true;
-}
-#endif /* ENABLE_VERIFIER */
-
-
-/* patcher_resolve_native ******************************************************
-
-*******************************************************************************/
-
-#if !defined(WITH_STATIC_CLASSPATH)
-bool patcher_resolve_native_function(patchref_t *pr)
-{
-       methodinfo  *m;
-       u1          *datap;
-       functionptr  f;
-
-       PATCHER_TRACE;
-
-       /* get stuff from the stack */
-
-       m     = (methodinfo *) pr->ref;
-       datap = (u1 *)         pr->datap;
-
-       /* resolve native function */
-
-       if (!(f = native_resolve_function(m)))
-               return false;
-
-       PATCH_BACK_ORIGINAL_MCODE;
-
-       /* patch native function pointer */
-
-       *((ptrint *) datap) = (ptrint) f;
-
-       return true;
-}
-#endif /* !defined(WITH_STATIC_CLASSPATH) */
 
 /*
  * These are local overrides for various environment variables in Emacs.