Get rid of mono_arch_get_vcall_slot ().
authorZoltan Varga <vargaz@gmail.com>
Mon, 2 Aug 2010 21:35:33 +0000 (23:35 +0200)
committerZoltan Varga <vargaz@gmail.com>
Mon, 2 Aug 2010 21:35:33 +0000 (23:35 +0200)
2010-08-02  Zoltan Varga  <vargaz@gmail.com>

* tramp-amd64.c (get_vcall_slot): Move mono_arch_get_vcall_slot () here, since it
is only used by this file.

* tramp-x86.c: Ditto.

* mini-trampolines.c mini-<ARCH>.c: Get rid of mono_arch_get_vcall_slot (), all
architectures should support MONO_ARCH_THIS_AS_FIRST_ARG now.

mono/mini/mini-amd64.c
mono/mini/mini-arm.c
mono/mini/mini-ia64.c
mono/mini/mini-ppc.c
mono/mini/mini-sparc.c
mono/mini/mini-trampolines.c
mono/mini/mini-x86.c
mono/mini/mini.h
mono/mini/tramp-amd64.c
mono/mini/tramp-s390x.c
mono/mini/tramp-x86.c

index 20fa9cd1d092a8915f6785954275e114e4edebbe..2dcd2d0e9d42a54c83208a55d130f65304b6d892 100644 (file)
@@ -6902,41 +6902,6 @@ mono_breakpoint_clean_code (guint8 *method_start, guint8 *code, int offset, guin
        return can_write;
 }
 
-gpointer
-mono_arch_get_vcall_slot (guint8 *code, mgreg_t *regs, int *displacement)
-{
-       guint8 buf [10];
-       gint32 disp;
-       MonoJitInfo *ji = NULL;
-
-#ifdef ENABLE_LLVM
-       /* code - 9 might be before the start of the method */
-       /* FIXME: Avoid this expensive call somehow */
-       ji = mono_jit_info_table_find (mono_domain_get (), (char*)code);
-#endif
-
-       mono_breakpoint_clean_code (ji ? ji->code_start : NULL, code, 9, buf, sizeof (buf));
-       code = buf + 9;
-
-       *displacement = 0;
-
-       code -= 7;
-
-       /*
-        * This function is no longer used, the only caller is
-        * mono_arch_nullify_class_init_trampoline ().
-        */
-       if ((code [0] == 0x41) && (code [1] == 0xff) && (code [2] == 0x15)) {
-               /* call OFFSET(%rip) */
-               g_assert_not_reached ();
-               *displacement = *(guint32*)(code + 3);
-               return (gpointer*)(code + disp + 7);
-       } else {
-               g_assert_not_reached ();
-               return NULL;
-       }
-}
-
 int
 mono_arch_get_this_arg_reg (MonoMethodSignature *sig, MonoGenericSharingContext *gsctx, guint8 *code)
 {
index 7ef17e2f23194f36e9d1489594c712da3f7e3ec4..085e8867a26456ae9dedc190feb5579472fc6836 100644 (file)
@@ -306,15 +306,6 @@ mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJit
        return frame_size;
 }
 
-gpointer
-mono_arch_get_vcall_slot (guint8 *code_ptr, mgreg_t *regs, int *displacement)
-{
-       /* Not used on ARM */
-       g_assert_not_reached ();
-
-       return NULL;
-}
-
 #define MAX_ARCH_DELEGATE_PARAMS 3
 
 static gpointer
index 8a62f88147dbc47bc0bf5f8bb17b7ea9e793c7f9..8c9f7252e83ceafb5e7229804541139eb9be424c 100644 (file)
@@ -4497,14 +4497,6 @@ mono_arch_get_patch_offset (guint8 *code)
        return 0;
 }
 
-gpointer
-mono_arch_get_vcall_slot (guint8* code, mgreg_t *regs, int *displacement)
-{
-       /* Not used on IA64 */
-       g_assert_not_reached ();
-       return NULL;
-}
-
 gpointer*
 mono_arch_get_delegate_method_ptr_addr (guint8* code, mgreg_t *regs)
 {
index 5992b007fdc7832a5407bb3a5f8ae074c58e4fd7..21e23428bec7687a4d1f930858ab7b8cf41254d2 100755 (executable)
@@ -376,16 +376,6 @@ mono_ppc_is_direct_call_sequence (guint32 *code)
 #endif
 }
 
-gpointer
-mono_arch_get_vcall_slot (guint8 *code_ptr, mgreg_t *regs, int *displacement)
-{
-       *displacement = 0;
-
-       /* Not used on PPC */
-       g_assert_not_reached ();
-       return NULL;
-}
-
 #define MAX_ARCH_DELEGATE_PARAMS 7
 
 static gpointer
index aefde7dfc14175d376efbb2f4b7c02460a39d8b2..880612013cab77d0135654da13d688eb15b9fb9e 100644 (file)
@@ -2259,19 +2259,6 @@ mono_sparc_is_virtual_call (guint32 *code)
        return FALSE;
 }
 
-/*
- * mono_arch_get_vcall_slot:
- *
- *  Determine the vtable slot used by a virtual call.
- */
-gpointer
-mono_arch_get_vcall_slot (guint8 *code8, mgreg_t *regs, int *displacement)
-{
-       /* Not used on sparc */
-       g_assert_not_reached ();
-       return NULL;
-}
-
 #define CMP_SIZE 3
 #define BR_SMALL_SIZE 2
 #define BR_LARGE_SIZE 2
index 2bb080a05883f3d0b506c624a6096bdc707ce0fa..0cda2932896de5c8cad373a4e0e8e45825c3a530 100644 (file)
@@ -147,17 +147,6 @@ mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr)
 }
 #endif
 
-gpointer*
-mono_get_vcall_slot_addr (guint8* code, mgreg_t *regs)
-{
-       gpointer vt;
-       int displacement;
-       vt = mono_arch_get_vcall_slot (code, regs, &displacement);
-       if (!vt)
-               return NULL;
-       return (gpointer*)((char*)vt + displacement);
-}
-
 #ifdef MONO_ARCH_HAVE_IMT
 
 static gpointer*
@@ -580,9 +569,6 @@ mono_vcall_trampoline (mgreg_t *regs, guint8 *code, int slot, guint8 *tramp)
        MonoMethod *m;
        gboolean need_rgctx_tramp = FALSE;
        gpointer addr;
-#ifndef MONO_ARCH_THIS_AS_FIRST_ARG
-       int displacement;
-#endif
 
        trampoline_calls ++;
 
@@ -593,35 +579,18 @@ mono_vcall_trampoline (mgreg_t *regs, guint8 *code, int slot, guint8 *tramp)
         * We use one vtable trampoline per vtable slot index, so we need only the vtable,
         * the other two can be computed from the vtable + the slot index.
         */
-#ifdef MONO_ARCH_THIS_AS_FIRST_ARG
+#ifndef MONO_ARCH_THIS_AS_FIRST_ARG
+       /* All architectures should support this */
+       g_assert_not_reached ();
+#endif
+
        /*
-        * If the arch passes 'this' as the first arg, obtain the vtable using it.
+        * Obtain the vtable from the 'this' arg.
         */
        this = mono_arch_get_this_arg_from_call (NULL, NULL, regs, code);
        g_assert (this);
 
        vt = this->vtable;
-#else
-       g_assert (!mono_use_llvm);
-       /*
-        * Obtain the vtable pointer in an arch specific manner.
-        */
-       vt = mono_arch_get_vcall_slot (code, regs, &displacement);
-
-       if (!vt) {
-               int i;
-               MonoJitInfo *ji;
-
-               ji = mono_jit_info_table_find (mono_domain_get (), (char*)code);
-               if (ji)
-                       printf ("Caller: %s\n", mono_method_full_name (ji->method, TRUE));
-               /* Print some debug info */
-               for (i = 0; i < 32; ++i)
-                       printf ("0x%x ", code [-32 + i]);
-               printf ("\n");
-               g_assert (vt);
-       }
-#endif
 
        if (slot >= 0) {
                /* Normal virtual call */
@@ -660,9 +629,6 @@ mono_vcall_trampoline (mgreg_t *regs, guint8 *code, int slot, guint8 *tramp)
                need_rgctx_tramp = FALSE;
        }
 
-       // FIXME:
-       // - get rid of mono_arch_get_vcall_slot where possible
-
        return common_call_trampoline (regs, code, m, tramp, vt, vtable_slot, need_rgctx_tramp);
 }
 
index f6a7ca4a6b9cdbfbd30f889ec0389e82d5b477da..ee7b48c611a718b50620d6e3e96c2e864fec5404 100644 (file)
@@ -5493,36 +5493,6 @@ mono_breakpoint_clean_code (guint8 *method_start, guint8 *code, int offset, guin
        return can_write;
 }
 
-gpointer
-mono_arch_get_vcall_slot (guint8 *code, mgreg_t *regs, int *displacement)
-{
-       guint8 buf [8];
-       guint8 reg = 0;
-       gint32 disp = 0;
-
-       mono_breakpoint_clean_code (NULL, code, 8, buf, sizeof (buf));
-       code = buf + 8;
-
-       *displacement = 0;
-
-       code -= 6;
-
-       /*
-        * This function is no longer used, the only caller is
-        * mono_arch_nullify_class_init_trampoline ().
-        */
-       if ((code [0] == 0xff) && ((code [1] & 0x18) == 0x10) && ((code [1] >> 6) == 2)) {
-               reg = code [1] & 0x07;
-               disp = *((gint32*)(code + 2));
-       } else {
-               g_assert_not_reached ();
-               return NULL;
-       }
-
-       *displacement = disp;
-       return (gpointer)regs [reg];
-}
-
 /*
  * mono_x86_get_this_arg_offset:
  *
index a8e8cdc6684df1c98e09b000244ba19ea7b50601..efb9e867130e9e9da7d170dc21697ed7aaedda96 100644 (file)
@@ -1688,7 +1688,6 @@ void              mono_monitor_enter_trampoline (mgreg_t *regs, guint8 *code, Mo
 void              mono_monitor_exit_trampoline (mgreg_t *regs, guint8 *code, MonoObject *obj, guint8 *tramp) MONO_INTERNAL;
 gconstpointer     mono_get_trampoline_func (MonoTrampolineType tramp_type);
 gpointer          mini_get_vtable_trampoline (int slot_index) MONO_INTERNAL;
-gpointer*         mono_get_vcall_slot_addr (guint8* code, mgreg_t *regs) MONO_INTERNAL;
 char*             mono_get_generic_trampoline_name (MonoTrampolineType tramp_type) MONO_INTERNAL;
 char*             mono_get_rgctx_fetch_trampoline_name (int slot) MONO_INTERNAL;
 
@@ -1837,7 +1836,6 @@ MonoInst* mono_arch_get_domain_intrinsic        (MonoCompile* cfg) MONO_INTERNAL
 gboolean mono_arch_is_int_overflow              (void *sigctx, void *info) MONO_INTERNAL;
 void     mono_arch_invalidate_method            (MonoJitInfo *ji, void *func, gpointer func_arg) MONO_INTERNAL;
 guint32  mono_arch_get_patch_offset             (guint8 *code) MONO_INTERNAL;
-gpointer mono_arch_get_vcall_slot               (guint8 *code, mgreg_t *regs, int *displacement) MONO_INTERNAL;
 gpointer*mono_arch_get_delegate_method_ptr_addr (guint8* code, mgreg_t *regs) MONO_INTERNAL;
 void     mono_arch_create_vars                  (MonoCompile *cfg) MONO_INTERNAL;
 void     mono_arch_save_unwind_info             (MonoCompile *cfg) MONO_INTERNAL;
index 9bc47ab5bb4bfee984b94023a4f0d64c377bd24b..5467ea606c25d5f93782b8a6d27787f4daeb6db4 100644 (file)
@@ -202,6 +202,48 @@ mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *a
        InterlockedExchangePointer (plt_jump_table_entry, addr);
 }
 
+static gpointer
+get_vcall_slot (guint8 *code, mgreg_t *regs, int *displacement)
+{
+       guint8 buf [10];
+       gint32 disp;
+       MonoJitInfo *ji = NULL;
+
+#ifdef ENABLE_LLVM
+       /* code - 9 might be before the start of the method */
+       /* FIXME: Avoid this expensive call somehow */
+       ji = mono_jit_info_table_find (mono_domain_get (), (char*)code);
+#endif
+
+       mono_breakpoint_clean_code (ji ? ji->code_start : NULL, code, 9, buf, sizeof (buf));
+       code = buf + 9;
+
+       *displacement = 0;
+
+       code -= 7;
+
+       if ((code [0] == 0x41) && (code [1] == 0xff) && (code [2] == 0x15)) {
+               /* call OFFSET(%rip) */
+               g_assert_not_reached ();
+               *displacement = *(guint32*)(code + 3);
+               return (gpointer*)(code + disp + 7);
+       } else {
+               g_assert_not_reached ();
+               return NULL;
+       }
+}
+
+static gpointer*
+get_vcall_slot_addr (guint8* code, mgreg_t *regs)
+{
+       gpointer vt;
+       int displacement;
+       vt = get_vcall_slot (code, regs, &displacement);
+       if (!vt)
+               return NULL;
+       return (gpointer*)((char*)vt + displacement);
+}
+
 void
 mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
 {
@@ -229,7 +271,7 @@ mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
                gpointer *vtable_slot;
 
                /* call *<OFFSET>(%rip) */
-               vtable_slot = mono_get_vcall_slot_addr (code, regs);
+               vtable_slot = get_vcall_slot_addr (code, regs);
                g_assert (vtable_slot);
 
                *vtable_slot = nullified_class_init_trampoline;
index 399ce487dfd37fa4181226365f3e4acc86b26dcc..945ffa31242fa330b1849191aea55818edc1079e 100644 (file)
@@ -205,31 +205,6 @@ mono_arch_nullify_plt_entry (guint8 *code, mgreg_t *regs)
 
 /*========================= End of Function ========================*/
 
-/*------------------------------------------------------------------*/
-/*                                                                  */
-/* Name                - mono_arch_get_vcall_slot                          */
-/*                                                                  */
-/* Function    - This method is called by the arch independent     */
-/*            trampoline code to determine the vtable slot used by  */
-/*            the call which invoked the trampoline.                */
-/*                                                                  */
-/* Parameters   - code   - Pointer into caller code                 */
-/*                regs   - Register state at the point of the call  */
-/*                displacement - Out parameter which will receive   */
-/*                the displacement of the vtable slot               */
-/*                                                                  */
-/*------------------------------------------------------------------*/
-
-gpointer
-mono_arch_get_vcall_slot (guint8 *code, mgreg_t *regs, int *displacement)
-{
-       /* Not used on s390x */
-       g_assert_not_reached ();
-       return NULL;
-}
-
-/*========================= End of Function ========================*/
-
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name                - mono_arch_create_trampoline_code                  */
index 0b871ff9a4aab1e86ddd66fb9203869293624b89..c1e3009bd9410f68ca02a33b76863b6747aa6f88 100644 (file)
@@ -155,6 +155,43 @@ mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *a
        *(guint8**)((guint8*)got + offset) = addr;
 }
 
+static gpointer
+get_vcall_slot (guint8 *code, mgreg_t *regs, int *displacement)
+{
+       guint8 buf [8];
+       guint8 reg = 0;
+       gint32 disp = 0;
+
+       mono_breakpoint_clean_code (NULL, code, 8, buf, sizeof (buf));
+       code = buf + 8;
+
+       *displacement = 0;
+
+       code -= 6;
+
+       if ((code [0] == 0xff) && ((code [1] & 0x18) == 0x10) && ((code [1] >> 6) == 2)) {
+               reg = code [1] & 0x07;
+               disp = *((gint32*)(code + 2));
+       } else {
+               g_assert_not_reached ();
+               return NULL;
+       }
+
+       *displacement = disp;
+       return (gpointer)regs [reg];
+}
+
+static gpointer*
+get_vcall_slot_addr (guint8* code, mgreg_t *regs)
+{
+       gpointer vt;
+       int displacement;
+       vt = get_vcall_slot (code, regs, &displacement);
+       if (!vt)
+               return NULL;
+       return (gpointer*)((char*)vt + displacement);
+}
+
 void
 mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
 {
@@ -199,7 +236,7 @@ mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
                /* call *<OFFSET>(<REG>) -> Call made from AOT code */
                gpointer *vtable_slot;
 
-               vtable_slot = mono_get_vcall_slot_addr (code + 5, regs);
+               vtable_slot = get_vcall_slot_addr (code + 5, regs);
                g_assert (vtable_slot);
 
                *vtable_slot = nullified_class_init_trampoline;