GC Bridge: Make merge_cache more aggressive, less exact, faster
[mono.git] / mono / mini / mini-exceptions.c
index b64f4e24e1711001f7198928b5ac0ea442c78a22..d16cee8cee3daa00962ced9e1ed97a12959fc445 100644 (file)
@@ -89,9 +89,6 @@ static gpointer throw_corlib_exception_func;
 static gpointer try_more_restore_tramp = NULL;
 static gpointer restore_stack_protection_tramp = NULL;
 
-static MonoUnhandledExceptionFunc unhandled_exception_hook = NULL;
-static gpointer unhandled_exception_hook_data = NULL;
-
 static void try_more_restore (void);
 static void restore_stack_protection (void);
 static void mono_walk_stack_full (MonoJitStackWalk func, MonoContext *start_ctx, MonoDomain *domain, MonoJitTlsData *jit_tls, MonoLMF *lmf, MonoUnwindOptions unwind_options, gpointer user_data);
@@ -2487,9 +2484,6 @@ mono_print_thread_dump_internal (void *sigctx, MonoContext *start_ctx)
 #endif
        GString* text;
        char *name;
-#ifndef HOST_WIN32
-       char *wapi_desc;
-#endif
        GError *error = NULL;
 
        if (!thread)
@@ -2507,11 +2501,9 @@ mono_print_thread_dump_internal (void *sigctx, MonoContext *start_ctx)
        else
                g_string_append (text, "\n\"<unnamed thread>\"");
 
-#ifndef HOST_WIN32
-       wapi_desc = wapi_current_thread_desc ();
-       g_string_append_printf (text, " tid=0x%p this=0x%p %s\n", (gpointer)(gsize)thread->tid, thread,  wapi_desc);
-       free (wapi_desc);
-#endif
+       g_string_append_printf (text, " tid=0x%p this=0x%p ", (gpointer)(gsize)thread->tid, thread);
+       mono_thread_info_describe ((MonoThreadInfo*) thread->thread_info, text);
+       g_string_append (text, "\n");
 
 #ifdef MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX
        if (start_ctx) {
@@ -2645,7 +2637,6 @@ install_handler_block_guard (MonoJitInfo *ji, MonoContext *ctx)
 
 /*
  * Finds the bottom handler block running and install a block guard if needed.
- * FIXME add full-aot support.
  */
 gboolean
 mono_install_handler_block_guard (MonoThreadUnwindState *ctx)
@@ -2654,9 +2645,10 @@ mono_install_handler_block_guard (MonoThreadUnwindState *ctx)
        MonoJitTlsData *jit_tls = (MonoJitTlsData *)ctx->unwind_data [MONO_UNWIND_DATA_JIT_TLS];
        gpointer resume_ip;
 
-       /* FIXME */
+#ifndef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD_AOT
        if (mono_aot_only)
                return FALSE;
+#endif
 
        /* Guard against a null MonoJitTlsData. This can happens if the thread receives the
          * interrupt signal before the JIT has time to initialize its TLS data for the given thread.
@@ -2824,54 +2816,6 @@ mono_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpoint
 #endif
 }
 
-void
-mono_install_unhandled_exception_hook (MonoUnhandledExceptionFunc func, gpointer user_data)
-{
-       unhandled_exception_hook = func;
-       unhandled_exception_hook_data = user_data;
-}
-
-void
-mono_invoke_unhandled_exception_hook (MonoObject *exc)
-{
-       if (unhandled_exception_hook) {
-               unhandled_exception_hook (exc, unhandled_exception_hook_data);
-       } else {
-               MonoError inner_error;
-               MonoObject *other = NULL;
-               MonoString *str = mono_object_try_to_string (exc, &other, &inner_error);
-               char *msg = NULL;
-               
-               if (str && is_ok (&inner_error)) {
-                       msg = mono_string_to_utf8_checked (str, &inner_error);
-               }
-               if (!is_ok (&inner_error)) {
-                       msg = g_strdup_printf ("Nested exception while formatting original exception");
-                       mono_error_cleanup (&inner_error);
-               } else if (other) {
-                       char *original_backtrace = mono_exception_get_managed_backtrace ((MonoException*)exc);
-                       char *nested_backtrace = mono_exception_get_managed_backtrace ((MonoException*)other);
-
-                       msg = g_strdup_printf ("Nested exception detected.\nOriginal Exception: %s\nNested exception:%s\n",
-                               original_backtrace, nested_backtrace);
-
-                       g_free (original_backtrace);
-                       g_free (nested_backtrace);
-               } else {
-                       msg = g_strdup ("Nested exception trying to figure out what went wrong");
-               }
-               mono_runtime_printf_err ("[ERROR] FATAL UNHANDLED EXCEPTION: %s", msg);
-               g_free (msg);
-#if defined(HOST_IOS)
-               g_assertion_message ("Terminating runtime due to unhandled exception");
-#else
-               exit (mono_environment_exitcode_get ());
-#endif
-       }
-
-       g_assert_not_reached ();
-}
-
 /*
  * mono_restore_context:
  *
@@ -2930,6 +2874,7 @@ throw_exception (MonoObject *ex, gboolean rethrow)
                mono_error_assert_ok (&error);
                mono_ex = mono_get_exception_runtime_wrapped_checked (ex, &error);
                mono_error_assert_ok (&error);
+               jit_tls->thrown_non_exc = mono_gchandle_new (ex, FALSE);
        }
        else
                mono_ex = (MonoException*)ex;
@@ -3009,7 +2954,7 @@ mono_llvm_resume_exception (void)
 MonoObject *
 mono_llvm_load_exception (void)
 {
-               MonoError error;
+       MonoError error;
        MonoJitTlsData *jit_tls = mono_get_jit_tls ();
 
        MonoException *mono_ex = (MonoException*)mono_gchandle_get_target (jit_tls->thrown_exc);
@@ -3061,6 +3006,9 @@ mono_llvm_clear_exception (void)
        MonoJitTlsData *jit_tls = mono_get_jit_tls ();
        mono_gchandle_free (jit_tls->thrown_exc);
        jit_tls->thrown_exc = 0;
+       if (jit_tls->thrown_non_exc)
+               mono_gchandle_free (jit_tls->thrown_non_exc);
+       jit_tls->thrown_non_exc = 0;
 
        mono_memory_barrier ();
 }
@@ -3074,13 +3022,22 @@ mono_llvm_clear_exception (void)
 gint32
 mono_llvm_match_exception (MonoJitInfo *jinfo, guint32 region_start, guint32 region_end, gpointer rgctx, MonoObject *this_obj)
 {
-                       MonoError error;
+       MonoError error;
        MonoJitTlsData *jit_tls = mono_get_jit_tls ();
        MonoObject *exc;
        gint32 index = -1;
 
        g_assert (jit_tls->thrown_exc);
        exc = mono_gchandle_get_target (jit_tls->thrown_exc);
+       if (jit_tls->thrown_non_exc) {
+               /*
+                * Have to unwrap RuntimeWrappedExceptions if the
+                * method's assembly doesn't have a RuntimeCompatibilityAttribute.
+                */
+               if (!wrap_non_exception_throws (jinfo_get_method (jinfo)))
+                       exc = mono_gchandle_get_target (jit_tls->thrown_non_exc);
+       }
+
        for (int i = 0; i < jinfo->num_clauses; i++) {
                MonoJitExceptionInfo *ei = &jinfo->clauses [i];
                MonoClass *catch_class;
@@ -3089,7 +3046,7 @@ mono_llvm_match_exception (MonoJitInfo *jinfo, guint32 region_start, guint32 reg
                        continue;
 
                catch_class = ei->data.catch_class;
-               if (catch_class->byval_arg.type == MONO_TYPE_VAR || catch_class->byval_arg.type == MONO_TYPE_MVAR || catch_class->byval_arg.type == MONO_TYPE_GENERICINST) {
+               if (mono_class_is_open_constructed_type (&catch_class->byval_arg)) {
                        MonoGenericContext context;
                        MonoType *inflated_type;