Cleanup exception handling (no need for "By Name" anymore) and fix s390x
authorNeale Ferguson <neale@mono-cvs.ximian.com>
Fri, 18 Jun 2010 20:41:43 +0000 (20:41 -0000)
committerNeale Ferguson <neale@mono-cvs.ximian.com>
Fri, 18 Jun 2010 20:41:43 +0000 (20:41 -0000)
IMT jump logic.

svn path=/trunk/mono/; revision=159151

mono/mini/exceptions-s390x.c
mono/mini/mini-exceptions.c
mono/mini/mini-s390.h
mono/mini/mini-s390x.c
mono/mini/mini-s390x.h
mono/mini/mini.c

index eb98e5830b1d94164683d96ff5794ad94412866b..9e67323b7d15a5626bf1f45b3ef4d4f8a33d1427 100644 (file)
@@ -76,7 +76,6 @@ gboolean mono_arch_handle_exception (void     *ctx,
 
 typedef enum {
        by_none,
-       by_name,
        by_token
 } throwType;
 
@@ -277,36 +276,21 @@ throw_exception (MonoObject *exc, unsigned long ip, unsigned long sp,
 /*------------------------------------------------------------------*/
 
 static gpointer 
-get_throw_exception_generic (guint8 *start, int size
-                            throwType type, gboolean rethrow)
+mono_arch_get_throw_exception_generic (int size, MonoTrampInfo **info
+                               int corlib, gboolean rethrow, gboolean aot)
 {
-       guint8 *code;
+       guint8 *code, *start;
        int alloc_size, pos, i;
 
-       code = start;
+       code = start = mono_global_codeman_reserve(size);
 
        s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
        alloc_size = S390_ALIGN(S390_THROWSTACK_SIZE, S390_STACK_ALIGNMENT);
        s390_lgr  (code, s390_r14, STK_BASE);
        s390_aghi (code, STK_BASE, -alloc_size);
        s390_stg  (code, s390_r14, 0, STK_BASE, 0);
-       switch (type) {
-       case by_name : 
-               s390_lgr  (code, s390_r4, s390_r2);
-               s390_lg   (code, s390_r3, 0, s390_r2, G_STRUCT_OFFSET(MonoException, object));
-               s390_basr (code, s390_r13, 0);
-               s390_j    (code, 10);
-               s390_llong(code, mono_defaults.corlib);
-               s390_llong(code, mono_exception_from_name);
-               s390_lg   (code, s390_r3, 0, s390_r3, G_STRUCT_OFFSET(MonoVTable, klass));
-               s390_lg   (code, s390_r2, 0, s390_r13, 4);
-               s390_lg   (code, s390_r1, 0, s390_r13, 12);
-               s390_lg   (code, s390_r4, 0, s390_r3, G_STRUCT_OFFSET(MonoClass, name));
-               s390_lg   (code, s390_r3, 0, s390_r3, G_STRUCT_OFFSET(MonoClass, name_space));
-               s390_basr (code, s390_r14, s390_r1);
-               break;
-       case by_token : 
-               s390_lgr  (code, s390_r3, s390_r2);
+       s390_lgr  (code, s390_r3, s390_r2);
+       if (corlib) {
                s390_basr (code, s390_r13, 0);
                s390_j    (code, 10);
                s390_llong(code, mono_defaults.exception_class->image);
@@ -314,10 +298,8 @@ get_throw_exception_generic (guint8 *start, int size,
                s390_lg   (code, s390_r2, 0, s390_r13, 4);
                s390_lg   (code, s390_r1, 0, s390_r13, 12);
                s390_basr (code, s390_r14, s390_r1);
-               break;
-       case by_none :
-               break;
        }
+
        /*------------------------------------------------------*/
        /* save the general registers on the stack              */
        /*------------------------------------------------------*/
@@ -386,19 +368,12 @@ get_throw_exception_generic (guint8 *start, int size,
 gpointer
 mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
 {
-       static guint8 *start;
-       static int inited = 0;
 
        g_assert (!aot);
        if (info)
                *info = NULL;
 
-       if (inited)
-               return start;
-       start = mono_global_codeman_reserve (SZ_THROW);
-       get_throw_exception_generic (start, SZ_THROW, by_none, FALSE);
-       inited = 1;
-       return start;
+       return (mono_arch_get_throw_exception_generic (SZ_THROW, info, FALSE, FALSE, aot));
 }
 
 /*========================= End of Function ========================*/
@@ -417,19 +392,11 @@ mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
 gpointer 
 mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
 {
-       static guint8 *start;
-       static int inited = 0;
-
        g_assert (!aot);
        if (info)
                *info = NULL;
 
-       if (inited)
-               return start;
-       start = mono_global_codeman_reserve (SZ_THROW);
-       get_throw_exception_generic (start, SZ_THROW, FALSE, TRUE);
-       inited = 1;
-       return start;
+       return (mono_arch_get_throw_exception_generic (SZ_THROW, info, FALSE, FALSE, aot));
 }
 
 /*========================= End of Function ========================*/
@@ -448,46 +415,11 @@ mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
 gpointer
 mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
 {
-       static guint8 *start;
-       static int inited = 0;
-
        g_assert (!aot);
        if (info)
                *info = NULL;
 
-       if (inited)
-               return start;
-       start = mono_global_codeman_reserve (SZ_THROW);
-       get_throw_exception_generic (start, SZ_THROW, by_token, FALSE);
-       inited = 1;
-       return start;
-}      
-
-/*========================= End of Function ========================*/
-
-/*------------------------------------------------------------------*/
-/*                                                                  */
-/* Name                - arch_get_throw_exception_by_name                  */
-/*                                                                  */
-/* Function    - Return a function pointer which can be used to    */
-/*                raise corlib exceptions. The return function has  */
-/*                the following signature:                          */
-/*                void (*func) (char *exc_name);                    */
-/*                                                                  */
-/*------------------------------------------------------------------*/
-
-gpointer 
-mono_arch_get_throw_exception_by_name (void)
-{
-       static guint8 *start;
-       static int inited = 0;
-
-       if (inited)
-               return start;
-       start = mono_global_codeman_reserve (SZ_THROW);
-       get_throw_exception_generic (start, SZ_THROW, by_name, FALSE);
-       inited = 1;
-       return start;
+       return (mono_arch_get_throw_exception_generic (SZ_THROW, info, TRUE, FALSE, aot));
 }      
 
 /*========================= End of Function ========================*/
@@ -599,6 +531,39 @@ mono_arch_handle_exception (void *uc, gpointer obj, gboolean test_only)
 
 /*========================= End of Function ========================*/
 
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name                - mono_arch_sigctx_to_monoctx.                      */
+/*                                                                  */
+/* Function    - Called from the signal handler to convert signal  */
+/*                context to MonoContext.                           */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+
+void
+mono_arch_sigctx_to_monoctx (void *ctx, MonoContext *mctx)
+{
+       memcpy (mctx, ctx, sizeof(MonoContext));
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name                - mono_arch_monoctx_to_sigctx.                      */
+/*                                                                  */
+/* Function    - Convert MonoContext structure to signal context.  */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+
+void
+mono_arch_monoctx_to_sigctx (MonoContext *mctx, void *ctx)
+{
+       memcpy (ctx, mctx, sizeof(MonoContext));
+}
+
+/*========================= End of Function ========================*/
+
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name                - mono_arch_ip_from_context                         */
index fb59bf5e495b0d1466750f4e73b2cfdd386a1f4f..a8b786b366525b366fbd2570c2fdd75f8ff72f8a 100644 (file)
@@ -117,30 +117,6 @@ mono_get_restore_context (void)
        return restore_context_func;
 }
 
-gpointer
-mono_get_throw_exception_by_name (void)
-{
-#ifdef MONO_ARCH_HAVE_THROW_EXCEPTION_BY_NAME
-       gpointer code = NULL;
-
-       /* This depends on corlib classes so cannot be inited in mono_exceptions_init () */
-       if (throw_exception_by_name_func)
-               return throw_exception_by_name_func;
-
-       code = mono_arch_get_throw_exception_by_name ();
-
-       mono_memory_barrier ();
-
-       throw_exception_by_name_func = code;
-#else
-       throw_exception_by_name_func = NULL;
-
-       g_assert_not_reached ();
-#endif
-
-       return throw_exception_by_name_func;
-}
-
 gpointer
 mono_get_throw_corlib_exception (void)
 {
index eab5ebe8fadeb98e7e14a7e6a62fcac06d1a8cab..dd542f85dfd2365a8b9582931f4ce1aeb285d104 100644 (file)
@@ -59,7 +59,6 @@ typedef struct
 // #define MONO_ARCH_SIGSEGV_ON_ALTSTACK               1
 // #define MONO_ARCH_SIGNAL_STACK_SIZE         65536
 // #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION       1
-#define MONO_ARCH_HAVE_THROW_EXCEPTION_BY_NAME 1
 
 #define MONO_ARCH_USE_SIGACTION        1
 
index 9a8f7cee25190ad4f79a6034d68d3be7de369959..39ed2857dd9a140fc2a235056a9a1a3ba498e0d2 100644 (file)
@@ -1347,8 +1347,7 @@ mono_arch_flush_icache (guint8 *code, gint size)
 /*                                                                  */
 /*------------------------------------------------------------------*/
 
-// static void inline
-static void 
+static void inline
 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
 {
        if (*gr > S390_LAST_ARG_REG) {
@@ -5878,7 +5877,7 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
                                                s390_lg   (code, s390_r1, 0, s390_r1, 0);
                                        }
                                        s390_br   (code, s390_r1);
-                                       target = S390_RELATIVE(item->jmp_code, code);
+                                       target = S390_RELATIVE(code, item->jmp_code);
                                        s390_patch_rel(item->jmp_code+2, target);
                                        s390_basr (code, s390_r13, s390_r0);
                                        s390_j    (code, 6);
index f15de7cfef7cb3964f47d5d77892f3851d39b116..4fcc813e7b5c8d2f9eeaffd5afc8abc43d2f7f37 100644 (file)
@@ -117,7 +117,6 @@ typedef struct
 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION          1
 #define MONO_ARCH_HAVE_IMT                             1
 #define MONO_ARCH_IMT_REG                              s390_r9
-#define MONO_ARCH_HAVE_THROW_EXCEPTION_BY_NAME 1
 
 #define MONO_ARCH_USE_SIGACTION        1
 
index 43eda2ae12a6effcd76d5d76fefec0df63bc3ba3..a7199cdd56ffdbb4cb7013637c1fb1855824098e 100644 (file)
@@ -5863,9 +5863,6 @@ mini_init (const char *filename, const char *runtime_version)
 
        register_icall (mono_get_throw_exception (), "mono_arch_throw_exception", "void object", TRUE);
        register_icall (mono_get_rethrow_exception (), "mono_arch_rethrow_exception", "void object", TRUE);
-#ifdef MONO_ARCH_HAVE_THROW_EXCEPTION_BY_NAME
-       register_icall (mono_get_throw_exception_by_name (), "mono_arch_throw_exception_by_name", "void ptr", TRUE); 
-#endif
 #if MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION
        register_icall (mono_get_throw_corlib_exception (), "mono_arch_throw_corlib_exception", 
                                 "void ptr", TRUE);