Merge pull request #2274 from esdrubal/udpclientreceive
[mono.git] / mono / metadata / sgen-stw.c
index a0f1af5e0fc3867ab932e6fc1930ca21d0cf34eb..651dbb59de190cef0863ee60ba3ca6f95bad872b 100644 (file)
 #include "config.h"
 #ifdef HAVE_SGEN_GC
 
-#include "metadata/sgen-gc.h"
-#include "metadata/sgen-protocol.h"
-#include "metadata/sgen-memory-governor.h"
-#include "metadata/sgen-thread-pool.h"
+#include "sgen/sgen-gc.h"
+#include "sgen/sgen-protocol.h"
+#include "sgen/sgen-memory-governor.h"
+#include "sgen/sgen-thread-pool.h"
 #include "metadata/profiler-private.h"
-#include "metadata/sgen-client.h"
-#include "metadata/sgen-bridge-internal.h"
-#include "metadata/gc-internal.h"
+#include "sgen/sgen-client.h"
+#include "metadata/sgen-bridge-internals.h"
+#include "metadata/gc-internals.h"
 
 #define TV_DECLARE SGEN_TV_DECLARE
 #define TV_GETTIME SGEN_TV_GETTIME
 #define TV_ELAPSED SGEN_TV_ELAPSED
 
-static int sgen_unified_suspend_restart_world (void);
-static int sgen_unified_suspend_stop_world (void);
+static void sgen_unified_suspend_restart_world (void);
+static void sgen_unified_suspend_stop_world (void);
 
 unsigned int sgen_global_stop_count = 0;
 
@@ -80,7 +80,7 @@ update_current_thread_stack (void *start)
        ARCH_STORE_REGS (reg_ptr);
        memcpy (&info->client_info.regs, reg_ptr, sizeof (info->client_info.regs));
        if (mono_gc_get_gc_callbacks ()->thread_suspend_func)
-               mono_gc_get_gc_callbacks ()->thread_suspend_func (info->runtime_data, NULL, NULL);
+               mono_gc_get_gc_callbacks ()->thread_suspend_func (info->client_info.runtime_data, NULL, NULL);
 #endif
 }
 
@@ -103,7 +103,7 @@ is_ip_in_managed_allocator (MonoDomain *domain, gpointer ip)
         * missing methods (#13951). To work around this, we disable the AOT fallback. For this to work, the JIT needs
         * to register the jit info for all GC critical methods after they are JITted/loaded.
         */
-       ji = mono_jit_info_table_find_internal (domain, ip, FALSE, FALSE);
+       ji = mono_jit_info_table_find_internal (domain, (char *)ip, FALSE, FALSE);
        if (!ji)
                return FALSE;
 
@@ -206,11 +206,10 @@ static guint64 time_stop_world;
 static guint64 time_restart_world;
 
 /* LOCKING: assumes the GC lock is held */
-int
+void
 sgen_client_stop_world (int generation)
 {
        TV_DECLARE (end_handshake);
-       int count, dead;
 
        /* notify the profiler of the leftovers */
        /* FIXME this is the wrong spot at we can STW for non collection reasons. */
@@ -222,23 +221,23 @@ sgen_client_stop_world (int generation)
        /* We start to scan after locks are taking, this ensures we won't be interrupted. */
        sgen_process_togglerefs ();
 
-       update_current_thread_stack (&count);
+       update_current_thread_stack (&generation);
 
        sgen_global_stop_count++;
        SGEN_LOG (3, "stopping world n %d from %p %p", sgen_global_stop_count, mono_thread_info_current (), (gpointer)mono_native_thread_id_get ());
        TV_GETTIME (stop_world_time);
 
        if (mono_thread_info_unified_management_enabled ()) {
-               count = sgen_unified_suspend_stop_world ();
+               sgen_unified_suspend_stop_world ();
        } else {
+               int count, dead;
                count = sgen_thread_handshake (TRUE);
                dead = restart_threads_until_none_in_managed_allocator ();
                if (count < dead)
                        g_error ("More threads have died (%d) that been initialy suspended %d", dead, count);
-               count -= dead;
        }
 
-       SGEN_LOG (3, "world stopped %d thread(s)", count);
+       SGEN_LOG (3, "world stopped");
 
        TV_GETTIME (end_handshake);
        time_stop_world += TV_ELAPSED (stop_world_time, end_handshake);
@@ -246,15 +245,12 @@ sgen_client_stop_world (int generation)
        sgen_memgov_collection_start (generation);
        if (sgen_need_bridge_processing ())
                sgen_bridge_reset_data ();
-
-       return count;
 }
 
 /* LOCKING: assumes the GC lock is held */
-int
+void
 sgen_client_restart_world (int generation, GGTimingInfo *timing)
 {
-       int count;
        SgenThreadInfo *info;
        TV_DECLARE (end_sw);
        TV_DECLARE (start_handshake);
@@ -278,17 +274,16 @@ sgen_client_restart_world (int generation, GGTimingInfo *timing)
        TV_GETTIME (start_handshake);
 
        if (mono_thread_info_unified_management_enabled ())
-               count = sgen_unified_suspend_restart_world ();
+               sgen_unified_suspend_restart_world ();
        else
-               count = sgen_thread_handshake (FALSE);
-
+               sgen_thread_handshake (FALSE);
 
        TV_GETTIME (end_sw);
        time_restart_world += TV_ELAPSED (start_handshake, end_sw);
        usec = TV_ELAPSED (stop_world_time, end_sw);
        max_pause_usec = MAX (usec, max_pause_usec);
 
-       SGEN_LOG (2, "restarted %d thread(s) (pause time: %d usec, max: %d)", count, (int)usec, (int)max_pause_usec);
+       SGEN_LOG (2, "restarted (pause time: %d usec, max: %d)", (int)usec, (int)max_pause_usec);
 
        /*
         * We must release the thread info suspend lock after doing
@@ -309,8 +304,6 @@ sgen_client_restart_world (int generation, GGTimingInfo *timing)
                timing [0].stw_time = usec;
                timing [0].bridge_time = bridge_usec;
        }
-
-       return count;
 }
 
 void
@@ -374,7 +367,7 @@ update_sgen_info (SgenThreadInfo *info)
        char *stack_start;
 
        /* Once we remove the old suspend code, we should move sgen to directly access the state in MonoThread */
-       info->client_info.stopped_domain = mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
+       info->client_info.stopped_domain = (MonoDomain *)mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
        info->client_info.stopped_ip = (gpointer) MONO_CONTEXT_GET_IP (&mono_thread_info_get_suspend_state (info)->ctx);
        stack_start = (char*)MONO_CONTEXT_GET_SP (&mono_thread_info_get_suspend_state (info)->ctx) - REDZONE_SIZE;
 
@@ -390,12 +383,11 @@ update_sgen_info (SgenThreadInfo *info)
 #endif
 }
 
-static int
+static void
 sgen_unified_suspend_stop_world (void)
 {
        int restart_counter;
        SgenThreadInfo *info;
-       int count = 0;
        int sleep_duration = -1;
 
        mono_threads_begin_global_suspend ();
@@ -407,10 +399,8 @@ sgen_unified_suspend_stop_world (void)
                if (sgen_is_thread_in_current_stw (info)) {
                        info->client_info.skip = !mono_thread_info_begin_suspend (info, FALSE);
                        THREADS_STW_DEBUG ("[GC-STW-BEGIN-SUSPEND] SUSPEND thread %p skip %d\n", mono_thread_info_get_tid (info), info->client_info.skip);
-                       if (!info->client_info.skip)
-                               ++count;
                } else {
-                       THREADS_STW_DEBUG ("[GC-STW-BEGIN-SUSPEND] IGNORE thread %p skip %d\n", mono_thread_info_get_tid (info), info->skip);
+                       THREADS_STW_DEBUG ("[GC-STW-BEGIN-SUSPEND] IGNORE thread %p skip %d\n", mono_thread_info_get_tid (info), info->client_info.skip);
                }
        } END_FOREACH_THREAD_SAFE
 
@@ -431,7 +421,7 @@ sgen_unified_suspend_stop_world (void)
                        - We haven't accepted the previous suspend as good.
                        - We haven't gave up on it for this STW (it's either bad or asked not to)
                        */
-                       if (!mono_threads_core_check_suspend_result (info)) {
+                       if (!mono_thread_info_check_suspend_result (info)) {
                                THREADS_STW_DEBUG ("[GC-STW-RESTART] SKIP thread %p failed to finish to suspend\n", mono_thread_info_get_tid (info));
                                info->client_info.skip = TRUE;
                        } else if (mono_thread_info_in_critical_location (info)) {
@@ -487,22 +477,18 @@ sgen_unified_suspend_stop_world (void)
                        g_assert (!info->client_info.suspend_done || info == mono_thread_info_current ());
                }
        } END_FOREACH_THREAD_SAFE
-
-       return count;
 }
 
-static int
+static void
 sgen_unified_suspend_restart_world (void)
 {
        SgenThreadInfo *info;
-       int count = 0;
 
        THREADS_STW_DEBUG ("[GC-STW-END] *** BEGIN RESUME ***\n");
        FOREACH_THREAD_SAFE (info) {
                if (sgen_is_thread_in_current_stw (info)) {
                        g_assert (mono_thread_info_begin_resume (info));
                        THREADS_STW_DEBUG ("[GC-STW-RESUME-WORLD] RESUME thread %p\n", mono_thread_info_get_tid (info));
-                       ++count;
                } else {
                        THREADS_STW_DEBUG ("[GC-STW-RESUME-WORLD] IGNORE thread %p\n", mono_thread_info_get_tid (info));
                }
@@ -510,6 +496,5 @@ sgen_unified_suspend_restart_world (void)
 
        mono_threads_wait_pending_operations ();
        mono_threads_end_global_suspend ();
-       return count;
 }
 #endif