From b3f17f0e9fc796a6cb64fc5089d2fa3b2a6caca7 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 13 Sep 2021 09:42:42 +0200 Subject: [PATCH 1/4] Convert couple of checks to g_assertf --- src/mono/mono/utils/mono-threads-coop.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/utils/mono-threads-coop.c b/src/mono/mono/utils/mono-threads-coop.c index 44d1ee8681df8..4aa0d35dc6b8d 100644 --- a/src/mono/mono/utils/mono-threads-coop.c +++ b/src/mono/mono/utils/mono-threads-coop.c @@ -95,12 +95,9 @@ coop_tls_pop (gpointer received_cookie) static void check_info (MonoThreadInfo *info, const gchar *action, const gchar *state, const char *func) { - if (!info) - g_error ("%s Cannot %s GC %s region if the thread is not attached", func, action, state); - if (!mono_thread_info_is_current (info)) - g_error ("%s [%p] Cannot %s GC %s region on a different thread", func, mono_thread_info_get_tid (info), action, state); - if (!mono_thread_info_is_live (info)) - g_error ("%s [%p] Cannot %s GC %s region if the thread is not live", func, mono_thread_info_get_tid (info), action, state); + g_assertf (info, "%s Cannot %s GC %s region if the thread is not attached", func, action, state); + g_assertf (mono_thread_info_is_current (info), "%s [%p] Cannot %s GC %s region on a different thread", func, mono_thread_info_get_tid (info), action, state); + g_assertf (mono_thread_info_is_live (info), "%s [%p] Cannot %s GC %s region if the thread is not live", func, mono_thread_info_get_tid (info), action, state); } static int coop_reset_blocking_count; From 3584334d56215e0883a4f7a829f39849adfd7c8f Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 13 Sep 2021 09:47:45 +0200 Subject: [PATCH 2/4] Wrap checks in check_info with ENABLE_CHECKED_BUILD_GC --- src/mono/mono/utils/mono-threads-coop.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mono/mono/utils/mono-threads-coop.c b/src/mono/mono/utils/mono-threads-coop.c index 4aa0d35dc6b8d..752eb5c082791 100644 --- a/src/mono/mono/utils/mono-threads-coop.c +++ b/src/mono/mono/utils/mono-threads-coop.c @@ -95,9 +95,11 @@ coop_tls_pop (gpointer received_cookie) static void check_info (MonoThreadInfo *info, const gchar *action, const gchar *state, const char *func) { +#ifdef ENABLE_CHECKED_BUILD_GC g_assertf (info, "%s Cannot %s GC %s region if the thread is not attached", func, action, state); g_assertf (mono_thread_info_is_current (info), "%s [%p] Cannot %s GC %s region on a different thread", func, mono_thread_info_get_tid (info), action, state); g_assertf (mono_thread_info_is_live (info), "%s [%p] Cannot %s GC %s region if the thread is not live", func, mono_thread_info_get_tid (info), action, state); +#endif } static int coop_reset_blocking_count; From 46e71b9fc39ab8ac3ae11683e118dd1b57ce8319 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 13 Sep 2021 12:10:19 +0200 Subject: [PATCH 3/4] Wrap check_thread_state in ENABLE_CHECKED_BUILD_THREAD --- src/mono/mono/utils/mono-threads-state-machine.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mono/mono/utils/mono-threads-state-machine.c b/src/mono/mono/utils/mono-threads-state-machine.c index 2d9a06cd76f61..ada6d8e21d02d 100644 --- a/src/mono/mono/utils/mono-threads-state-machine.c +++ b/src/mono/mono/utils/mono-threads-state-machine.c @@ -105,6 +105,7 @@ unwrap_thread_state (MonoThreadInfo* info, static void check_thread_state (MonoThreadInfo* info) { +#ifdef ENABLE_CHECKED_BUILD_THREAD int raw_state, cur_state, suspend_count; gboolean no_safepoints; UNWRAP_THREAD_STATE (raw_state, cur_state, suspend_count, no_safepoints, info); @@ -133,6 +134,7 @@ check_thread_state (MonoThreadInfo* info) default: g_error ("Invalid state %d", cur_state); } +#endif } static void From 32e911e0926aef848d1fa5b797e8d21a58d89eae Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 14 Sep 2021 09:54:33 +0200 Subject: [PATCH 4/4] Change the #ifdef to ENABLE_CHECKED_BUILD which is enabled in all debug builds --- src/mono/mono/utils/mono-threads-coop.c | 2 +- src/mono/mono/utils/mono-threads-state-machine.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/utils/mono-threads-coop.c b/src/mono/mono/utils/mono-threads-coop.c index 752eb5c082791..970a7099e9ecf 100644 --- a/src/mono/mono/utils/mono-threads-coop.c +++ b/src/mono/mono/utils/mono-threads-coop.c @@ -95,7 +95,7 @@ coop_tls_pop (gpointer received_cookie) static void check_info (MonoThreadInfo *info, const gchar *action, const gchar *state, const char *func) { -#ifdef ENABLE_CHECKED_BUILD_GC +#ifdef ENABLE_CHECKED_BUILD g_assertf (info, "%s Cannot %s GC %s region if the thread is not attached", func, action, state); g_assertf (mono_thread_info_is_current (info), "%s [%p] Cannot %s GC %s region on a different thread", func, mono_thread_info_get_tid (info), action, state); g_assertf (mono_thread_info_is_live (info), "%s [%p] Cannot %s GC %s region if the thread is not live", func, mono_thread_info_get_tid (info), action, state); diff --git a/src/mono/mono/utils/mono-threads-state-machine.c b/src/mono/mono/utils/mono-threads-state-machine.c index ada6d8e21d02d..927d86d619f23 100644 --- a/src/mono/mono/utils/mono-threads-state-machine.c +++ b/src/mono/mono/utils/mono-threads-state-machine.c @@ -105,7 +105,7 @@ unwrap_thread_state (MonoThreadInfo* info, static void check_thread_state (MonoThreadInfo* info) { -#ifdef ENABLE_CHECKED_BUILD_THREAD +#ifdef ENABLE_CHECKED_BUILD int raw_state, cur_state, suspend_count; gboolean no_safepoints; UNWRAP_THREAD_STATE (raw_state, cur_state, suspend_count, no_safepoints, info);