[sgen] Moved `stopped_ip` and `stopped_domain` to Mono-specific code.
authorMark Probst <mark.probst@gmail.com>
Tue, 30 Dec 2014 18:42:51 +0000 (10:42 -0800)
committerMark Probst <mark.probst@gmail.com>
Wed, 29 Apr 2015 17:57:54 +0000 (10:57 -0700)
mono/metadata/sgen-client-mono.h
mono/metadata/sgen-client.h
mono/metadata/sgen-gc.c
mono/metadata/sgen-gc.h
mono/metadata/sgen-mono.c
mono/metadata/sgen-os-mach.c
mono/metadata/sgen-os-posix.c
mono/metadata/sgen-stw.c

index 8582244fa019065e468d766d86f824188f03c68d..fc8108f6d5651d2d12073c13d22329279b236558 100644 (file)
@@ -99,6 +99,9 @@ sgen_client_par_object_get_size (GCVTable *vtable, GCObject* o)
 typedef struct _SgenClientThreadInfo SgenClientThreadInfo;
 struct _SgenClientThreadInfo {
        MonoThreadInfo info;
+
+       gpointer stopped_ip;    /* only valid if the thread is stopped */
+       MonoDomain *stopped_domain; /* dsto */
 };
 
 #else
index ee73eff08e96635fb0346d6acf7f3df73885d553..5126af94e48c3ece3b1ac05e330b49fd4375903d 100644 (file)
@@ -99,6 +99,8 @@ const char* sgen_client_vtable_get_name (GCVTable *vtable);
 
 void sgen_client_pre_collection_checks (void);
 
+void sgen_client_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback);
+
 int sgen_client_stop_world (int generation);
 int sgen_client_restart_world (int generation, GGTimingInfo *timing);
 
index 14f954ceab600597671e573cef09fcadfff51275..b0482af445fc84cad11680546e3e0f1355ec752d 100644 (file)
@@ -2820,7 +2820,7 @@ scan_thread_data (void *start_nursery, void *end_nursery, gboolean precise, Scan
 }
 
 void*
-sgen_thread_register (SgenThreadInfo* info, void *addr)
+sgen_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback)
 {
        size_t stsize = 0;
        guint8 *staddr = NULL;
@@ -2839,9 +2839,8 @@ sgen_thread_register (SgenThreadInfo* info, void *addr)
        info->signal = 0;
 #endif
        info->skip = 0;
+       sgen_client_thread_register (info, stack_bottom_fallback);
        info->stack_start = NULL;
-       info->stopped_ip = NULL;
-       info->stopped_domain = NULL;
 #ifdef USE_MONO_CTX
        memset (&info->ctx, 0, sizeof (MonoContext));
 #else
@@ -2860,7 +2859,7 @@ sgen_thread_register (SgenThreadInfo* info, void *addr)
 #endif
                info->stack_end = staddr + stsize;
        } else {
-               gsize stack_bottom = (gsize)addr;
+               gsize stack_bottom = (gsize)stack_bottom_fallback;
                stack_bottom += 4095;
                stack_bottom &= ~4095;
                info->stack_end = (char*)stack_bottom;
index dfdf05675beabd808d0615e6a2c4a5509216291a..96f3a1edb319c46208808294e1bcf7bb5e7a40e5 100644 (file)
@@ -418,9 +418,6 @@ struct _SgenThreadInfo {
        unsigned int stop_count; /* to catch duplicate signals. */
 #endif
 
-       gpointer stopped_ip;    /* only valid if the thread is stopped */
-       MonoDomain *stopped_domain; /* dsto */
-
        /*FIXME pretty please finish killing ARCH_NUM_REGS */
 #ifdef USE_MONO_CTX
        MonoContext ctx;                /* ditto */
index eaf64033bd0db5784fe6cfddeb8be61586b0446a..b49b2df1dfaf55268e4eac7ba6307ab6648293ca 100644 (file)
@@ -653,7 +653,7 @@ mono_gc_set_current_thread_appdomain (MonoDomain *domain)
        /* Could be called from sgen_thread_unregister () with a NULL info */
        if (domain) {
                g_assert (info);
-               info->stopped_domain = domain;
+               info->client_info.stopped_domain = domain;
        }
 }
 
@@ -1961,6 +1961,13 @@ mono_gc_walk_heap (int flags, MonoGCReferences callback, void *data)
  * Threads
  */
 
+void
+sgen_client_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback)
+{
+       info->client_info.stopped_ip = NULL;
+       info->client_info.stopped_domain = NULL;
+}
+
 static gboolean
 is_critical_method (MonoMethod *method)
 {
index db68e94f79954d5696157fac41a460494c2e94e1..c4111ce68d15e11a2d21df8d0bac0f05090bad8e 100644 (file)
@@ -71,8 +71,8 @@ sgen_suspend_thread (SgenThreadInfo *info)
        mono_mach_arch_thread_state_to_mcontext (state, mctx);
        ctx.uc_mcontext = mctx;
 
-       info->stopped_domain = mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
-       info->stopped_ip = (gpointer) mono_mach_arch_get_ip (state);
+       info->client_info.stopped_domain = mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
+       info->client_info.stopped_ip = (gpointer) mono_mach_arch_get_ip (state);
        info->stack_start = NULL;
        stack_start = (char*) mono_mach_arch_get_sp (state) - REDZONE_SIZE;
        /* If stack_start is not within the limits, then don't set it in info and we will be restarted. */
@@ -92,9 +92,8 @@ sgen_suspend_thread (SgenThreadInfo *info)
        if (mono_gc_get_gc_callbacks ()->thread_suspend_func)
                mono_gc_get_gc_callbacks ()->thread_suspend_func (info->runtime_data, &ctx, NULL);
 
-       SGEN_LOG (2, "thread %p stopped at %p stack_start=%p", (void*)(gsize)info->client_info.info.native_handle, info->stopped_ip, info->stack_start);
-
-       binary_protocol_thread_suspend ((gpointer)mono_thread_info_get_tid (info), info->stopped_ip);
+       SGEN_LOG (2, "thread %p stopped at %p stack_start=%p", (void*)(gsize)info->client_info.info.native_handle, info->client_info.stopped_ip, info->stack_start);
+       binary_protocol_thread_suspend ((gpointer)mono_thread_info_get_tid (info), info->client_info.stopped_ip);
 
        return TRUE;
 }
index aa76b3923b6e995fc5a40d299410f285f779b297..a80339a0389f7071a4263d4739b163dca52f1ae6 100644 (file)
@@ -59,7 +59,7 @@ suspend_thread (SgenThreadInfo *info, void *context)
        MonoContext ctx;
        gpointer stack_start;
 
-       info->stopped_domain = mono_domain_get ();
+       info->client_info.stopped_domain = mono_domain_get ();
        info->signal = 0;
        stop_count = sgen_global_stop_count;
        /* duplicate signal */
@@ -69,10 +69,10 @@ suspend_thread (SgenThreadInfo *info, void *context)
 #ifdef USE_MONO_CTX
        if (context) {
                mono_sigctx_to_monoctx (context, &ctx);
-               info->stopped_ip = MONO_CONTEXT_GET_IP (&ctx);
+               info->client_info.stopped_ip = MONO_CONTEXT_GET_IP (&ctx);
                stack_start = (((guint8 *) MONO_CONTEXT_GET_SP (&ctx)) - REDZONE_SIZE);
        } else {
-               info->stopped_ip = NULL;
+               info->client_info.stopped_ip = NULL;
                stack_start = NULL;
        }
 #else
index 51575b724a22e10f6d7e8e9425b27706630f4a9f..905ae53038c84a634fe21f3c7e7eec38afe6e414 100644 (file)
@@ -123,7 +123,7 @@ restart_threads_until_none_in_managed_allocator (void)
                        if (info->skip || info->gc_disabled || info->suspend_done)
                                continue;
                        if (mono_thread_info_is_live (info) && (!info->stack_start || info->in_critical_region || info->client_info.info.inside_critical_region ||
-                                       is_ip_in_managed_allocator (info->stopped_domain, info->stopped_ip))) {
+                                       is_ip_in_managed_allocator (info->client_info.stopped_domain, info->client_info.stopped_ip))) {
                                binary_protocol_thread_restart ((gpointer)mono_thread_info_get_tid (info));
                                SGEN_LOG (3, "thread %p resumed.", (void*) (size_t) info->client_info.info.native_handle);
                                result = sgen_resume_thread (info);
@@ -138,8 +138,8 @@ restart_threads_until_none_in_managed_allocator (void)
                                   we're not restarting so
                                   that we can easily identify
                                   the others */
-                               info->stopped_ip = NULL;
-                               info->stopped_domain = NULL;
+                               info->client_info.stopped_ip = NULL;
+                               info->client_info.stopped_domain = NULL;
                                info->suspend_done = TRUE;
                        }
                } END_FOREACH_THREAD_SAFE
@@ -161,7 +161,7 @@ restart_threads_until_none_in_managed_allocator (void)
                /* stop them again */
                FOREACH_THREAD (info) {
                        gboolean result;
-                       if (info->skip || info->stopped_ip == NULL)
+                       if (info->skip || info->client_info.stopped_ip == NULL)
                                continue;
                        result = sgen_suspend_thread (info);
 
@@ -370,8 +370,8 @@ 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->stopped_domain = mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
-       info->stopped_ip = (gpointer) MONO_CONTEXT_GET_IP (&mono_thread_info_get_suspend_state (info)->ctx);
+       info->client_info.stopped_domain = 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;
 
        /* altstack signal handler, sgen can't handle them, mono-threads should have handled this. */