[sgen] Split up concurrent sweep from worker logic
[mono.git] / mono / metadata / sgen-stw.c
index 22ff814df699bdcad3b99b174a2f25ee433e93ea..fc1de7c25f87aa9759f19d52f0741c0b911fd71f 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * sgen-stw.c: Stop the world functionality
+/**
+ * \file
+ * Stop the world functionality
  *
  * Author:
  *     Paolo Molaro (lupus@ximian.com)
@@ -19,7 +20,7 @@
 #include "sgen/sgen-gc.h"
 #include "sgen/sgen-protocol.h"
 #include "sgen/sgen-memory-governor.h"
-#include "sgen/sgen-thread-pool.h"
+#include "sgen/sgen-workers.h"
 #include "metadata/profiler-private.h"
 #include "sgen/sgen-client.h"
 #include "metadata/sgen-bridge-internals.h"
@@ -226,7 +227,8 @@ sgen_is_thread_in_current_stw (SgenThreadInfo *info, int *reason)
        We can't suspend the workers that will do all the heavy lifting.
        FIXME Use some state bit in SgenThreadInfo for this.
        */
-       if (sgen_thread_pool_is_thread_pool_thread (mono_thread_info_get_tid (info))) {
+       if (sgen_thread_pool_is_thread_pool_thread (major_collector.get_sweep_pool (), mono_thread_info_get_tid (info)) ||
+                       sgen_workers_is_worker_thread (mono_thread_info_get_tid (info))) {
                if (reason)
                        *reason = 4;
                return FALSE;
@@ -358,12 +360,14 @@ sgen_unified_suspend_stop_world (void)
                /* Once we remove the old suspend code, we should move sgen to directly access the state in MonoThread */
                info->client_info.stack_start = (gpointer) ((char*)MONO_CONTEXT_GET_SP (&info->client_info.ctx) - REDZONE_SIZE);
 
-               /* altstack signal handler, sgen can't handle them, mono-threads should have handled this. */
-               if (!info->client_info.stack_start
-                        || info->client_info.stack_start < info->client_info.stack_start_limit
+               if (info->client_info.stack_start < info->client_info.stack_start_limit
                         || info->client_info.stack_start >= info->client_info.stack_end) {
-                       g_error ("BAD STACK: stack_start = %p, stack_start_limit = %p, stack_end = %p",
-                               info->client_info.stack_start, info->client_info.stack_start_limit, info->client_info.stack_end);
+                       /*
+                        * Thread context is in unhandled state, most likely because it is
+                        * dying. We don't scan it.
+                        * FIXME We should probably rework and check the valid flag instead.
+                        */
+                       info->client_info.stack_start = NULL;
                }
 
                stopped_ip = (gpointer) (MONO_CONTEXT_GET_IP (&info->client_info.ctx));