[sgen] Move DTrace support to Mono-specific code.
[mono.git] / mono / metadata / sgen-stw.c
index b994e0bdf489bfe41fa7fa5a2a030ee1cf5564af..fd8c08581b7ee4bcc22ccb4d59502c5f152b73eb 100644 (file)
 #include "metadata/sgen-gc.h"
 #include "metadata/sgen-protocol.h"
 #include "metadata/sgen-memory-governor.h"
+#include "metadata/sgen-thread-pool.h"
 #include "metadata/profiler-private.h"
 #include "utils/mono-time.h"
-#include "utils/dtrace.h"
 #include "utils/mono-counters.h"
 #include "utils/mono-threads.h"
 
+static gboolean world_is_stopped = FALSE;
+
 #define TV_DECLARE SGEN_TV_DECLARE
 #define TV_GETTIME SGEN_TV_GETTIME
 #define TV_ELAPSED SGEN_TV_ELAPSED
@@ -101,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);
+       ji = mono_jit_info_table_find_internal (domain, ip, FALSE, FALSE);
        if (!ji)
                return FALSE;
 
@@ -215,9 +217,11 @@ sgen_stop_world (int generation)
 {
        TV_DECLARE (end_handshake);
        int count, dead;
+       long long major_total = -1, major_marked = -1, los_total = -1, los_marked = -1;
+
+       SGEN_ASSERT (0, !world_is_stopped, "Why are we stopping a stopped world?");
 
        mono_profiler_gc_event (MONO_GC_EVENT_PRE_STOP_WORLD, generation);
-       MONO_GC_WORLD_STOP_BEGIN ();
        binary_protocol_world_stopping (sgen_timestamp ());
        acquire_gc_locks ();
 
@@ -240,15 +244,13 @@ sgen_stop_world (int generation)
                count -= dead;
        }
 
+       world_is_stopped = TRUE;
+
        SGEN_LOG (3, "world stopped %d thread(s)", count);
        mono_profiler_gc_event (MONO_GC_EVENT_POST_STOP_WORLD, generation);
-       MONO_GC_WORLD_STOP_END ();
-       if (binary_protocol_is_enabled ()) {
-               long long major_total = -1, major_marked = -1, los_total = -1, los_marked = -1;
-               if (binary_protocol_is_heavy_enabled ())
-                       count_cards (&major_total, &major_marked, &los_total, &los_marked);
-               binary_protocol_world_stopped (sgen_timestamp (), major_total, major_marked, los_total, los_marked);
-       }
+       if (binary_protocol_is_heavy_enabled ())
+               count_cards (&major_total, &major_marked, &los_total, &los_marked);
+       binary_protocol_world_stopped (sgen_timestamp (), major_total, major_marked, los_total, los_marked);
 
        TV_GETTIME (end_handshake);
        time_stop_world += TV_ELAPSED (stop_world_time, end_handshake);
@@ -271,6 +273,8 @@ sgen_restart_world (int generation, GGTimingInfo *timing)
        TV_DECLARE (end_bridge);
        unsigned long usec, bridge_usec;
 
+       SGEN_ASSERT (0, world_is_stopped, "Why are we restarting a running world?");
+
        if (binary_protocol_is_enabled ()) {
                long long major_total = -1, major_marked = -1, los_total = -1, los_marked = -1;
                if (binary_protocol_is_heavy_enabled ())
@@ -283,7 +287,7 @@ sgen_restart_world (int generation, GGTimingInfo *timing)
        if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_GC_MOVES))
                sgen_gc_event_moves ();
        mono_profiler_gc_event (MONO_GC_EVENT_PRE_START_WORLD, generation);
-       MONO_GC_WORLD_RESTART_BEGIN (generation);
+
        FOREACH_THREAD (info) {
                info->stack_start = NULL;
 #ifdef USE_MONO_CTX
@@ -305,9 +309,11 @@ sgen_restart_world (int generation, GGTimingInfo *timing)
        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);
+
+       world_is_stopped = FALSE;
+
        SGEN_LOG (2, "restarted %d thread(s) (pause time: %d usec, max: %d)", count, (int)usec, (int)max_pause_usec);
        mono_profiler_gc_event (MONO_GC_EVENT_POST_START_WORLD, generation);
-       MONO_GC_WORLD_RESTART_END (generation);
        binary_protocol_world_restarted (generation, sgen_timestamp ());
 
        /*
@@ -340,6 +346,12 @@ sgen_restart_world (int generation, GGTimingInfo *timing)
        return count;
 }
 
+gboolean
+sgen_is_world_stopped (void)
+{
+       return world_is_stopped;
+}
+
 void
 sgen_init_stw (void)
 {
@@ -380,7 +392,7 @@ sgen_is_thread_in_current_stw (SgenThreadInfo *info)
        We can't suspend the workers that will do all the heavy lifting.
        FIXME Use some state bit in SgenThreadInfo for this.
        */
-       if (sgen_is_worker_thread (mono_thread_info_get_tid (info))) {
+       if (sgen_thread_pool_is_thread_pool_thread (mono_thread_info_get_tid (info))) {
                return FALSE;
        }