From 1f7a9b353adc30b8317507bed5265e063ec20b5e Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Thu, 8 Jan 2015 13:01:39 -0800 Subject: [PATCH] [sgen] Move thread info to Mono client code. --- mono/metadata/sgen-client-mono.h | 2 ++ mono/metadata/sgen-gc.c | 36 +------------------------------- mono/metadata/sgen-gc.h | 8 ------- mono/metadata/sgen-mono.c | 36 ++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/mono/metadata/sgen-client-mono.h b/mono/metadata/sgen-client-mono.h index 7b9ccb7f1fc..2b04ceab650 100644 --- a/mono/metadata/sgen-client-mono.h +++ b/mono/metadata/sgen-client-mono.h @@ -570,9 +570,11 @@ gboolean sgen_resume_thread (SgenThreadInfo *info); void sgen_wait_for_suspend_ack (int count); #ifdef HAVE_KW_THREAD +extern __thread SgenThreadInfo *sgen_thread_info; #define TLAB_ACCESS_INIT #define IN_CRITICAL_REGION sgen_thread_info->client_info.in_critical_region #else +extern MonoNativeTlsKey thread_info_key; #define TLAB_ACCESS_INIT SgenThreadInfo *__thread_info__ = mono_native_tls_get_value (thread_info_key) #define IN_CRITICAL_REGION (__thread_info__->client_info.in_critical_region) #endif diff --git a/mono/metadata/sgen-gc.c b/mono/metadata/sgen-gc.c index bd53e2c2ef1..a2362238ca9 100644 --- a/mono/metadata/sgen-gc.c +++ b/mono/metadata/sgen-gc.c @@ -391,12 +391,6 @@ SgenHashTable roots_hash [ROOT_TYPE_NUM] = { }; static mword roots_size = 0; /* amount of memory in the root set */ -MonoNativeTlsKey thread_info_key; - -#ifdef HAVE_KW_THREAD -__thread SgenThreadInfo *sgen_thread_info; -#endif - /* The size of a TLAB */ /* The bigger the value, the less often we have to go to the slow path to allocate a new * one, but the more space is wasted by threads not allocating much memory. @@ -2694,11 +2688,6 @@ sgen_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback) { #ifndef HAVE_KW_THREAD info->tlab_start = info->tlab_next = info->tlab_temp_end = info->tlab_real_end = NULL; - - g_assert (!mono_native_tls_get_value (thread_info_key)); - mono_native_tls_set_value (thread_info_key, info); -#else - sgen_thread_info = info; #endif sgen_init_tlab_info (info); @@ -2715,12 +2704,6 @@ sgen_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback) void sgen_thread_unregister (SgenThreadInfo *p) { -#ifndef HAVE_KW_THREAD - mono_native_tls_set_value (thread_info_key, NULL); -#else - sgen_thread_info = NULL; -#endif - sgen_client_thread_unregister (p); } @@ -3054,23 +3037,6 @@ sgen_gc_init (void) sgen_client_init (); -#ifndef HAVE_KW_THREAD - mono_native_tls_alloc (&thread_info_key, NULL); -#if defined(__APPLE__) || defined (HOST_WIN32) - /* - * CEE_MONO_TLS requires the tls offset, not the key, so the code below only works on darwin, - * where the two are the same. - */ - mono_tls_key_set_offset (TLS_KEY_SGEN_THREAD_INFO, thread_info_key); -#endif -#else - { - int tls_offset = -1; - MONO_THREAD_VAR_OFFSET (sgen_thread_info, tls_offset); - mono_tls_key_set_offset (TLS_KEY_SGEN_THREAD_INFO, tls_offset); - } -#endif - /* * This needs to happen before any internal allocations because * it inits the small id which is required for hazard pointer @@ -3078,7 +3044,7 @@ sgen_gc_init (void) */ sgen_os_init (); - mono_thread_info_attach (&dummy); + mono_gc_register_thread (&dummy); if (!minor_collector_opt) { sgen_simple_nursery_init (&sgen_minor_collector); diff --git a/mono/metadata/sgen-gc.h b/mono/metadata/sgen-gc.h index a03e97aa786..1c16682b9c7 100644 --- a/mono/metadata/sgen-gc.h +++ b/mono/metadata/sgen-gc.h @@ -936,14 +936,6 @@ sgen_is_object_alive_for_current_gen (char *object) int sgen_gc_invoke_finalizers (void); -/* TLS Data */ - -extern MonoNativeTlsKey thread_info_key; - -#ifdef HAVE_KW_THREAD -extern __thread SgenThreadInfo *sgen_thread_info; -#endif - /* Other globals */ extern GCMemSection *nursery_section; diff --git a/mono/metadata/sgen-mono.c b/mono/metadata/sgen-mono.c index 8fce31f580c..d6a38d9c111 100644 --- a/mono/metadata/sgen-mono.c +++ b/mono/metadata/sgen-mono.c @@ -45,6 +45,12 @@ gboolean sgen_mono_xdomain_checks = FALSE; /* Functions supplied by the runtime to be called by the GC */ static MonoGCCallbacks gc_callbacks; +#ifdef HAVE_KW_THREAD +__thread SgenThreadInfo *sgen_thread_info; +#else +MonoNativeTlsKey thread_info_key; +#endif + #define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1)) #define OPDEF(a,b,c,d,e,f,g,h,i,j) \ @@ -2092,6 +2098,13 @@ sgen_client_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback) size_t stsize = 0; guint8 *staddr = NULL; +#ifndef HAVE_KW_THREAD + g_assert (!mono_native_tls_get_value (thread_info_key)); + mono_native_tls_set_value (thread_info_key, info); +#else + sgen_thread_info = info; +#endif + info->client_info.skip = 0; info->client_info.stopped_ip = NULL; info->client_info.stopped_domain = NULL; @@ -2131,6 +2144,12 @@ sgen_client_thread_unregister (SgenThreadInfo *p) { MonoNativeThreadId tid; +#ifndef HAVE_KW_THREAD + mono_native_tls_set_value (thread_info_key, NULL); +#else + sgen_thread_info = NULL; +#endif + tid = mono_thread_info_get_tid (p); if (p->client_info.info.runtime_thread) @@ -2666,6 +2685,23 @@ sgen_client_init (void) sgen_register_fixed_internal_mem_type (INTERNAL_MEM_EPHEMERON_LINK, sizeof (EphemeronLinkNode)); mono_sgen_init_stw (); + +#ifndef HAVE_KW_THREAD + mono_native_tls_alloc (&thread_info_key, NULL); +#if defined(__APPLE__) || defined (HOST_WIN32) + /* + * CEE_MONO_TLS requires the tls offset, not the key, so the code below only works on darwin, + * where the two are the same. + */ + mono_tls_key_set_offset (TLS_KEY_SGEN_THREAD_INFO, thread_info_key); +#endif +#else + { + int tls_offset = -1; + MONO_THREAD_VAR_OFFSET (sgen_thread_info, tls_offset); + mono_tls_key_set_offset (TLS_KEY_SGEN_THREAD_INFO, tls_offset); + } +#endif } gboolean -- 2.25.1