From 5a834ff4af145ffb3a986101c7724f80eb4edadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Matos?= Date: Mon, 12 Oct 2015 14:38:48 +0100 Subject: Revert "Reworked coop GC stack handling in platforms with restricted access to register contexts." --- eglib/src/gbytearray.c | 7 ---- eglib/src/glib.h | 1 - mono/metadata/sgen-mono.c | 9 ----- mono/utils/mono-stack-unwinding.h | 2 -- mono/utils/mono-threads-api.h | 8 ++--- mono/utils/mono-threads-coop.c | 72 ++++++++------------------------------- mono/utils/mono-threads-coop.h | 29 +++++++--------- mono/utils/mono-threads.c | 5 --- mono/utils/mono-threads.h | 4 --- 9 files changed, 31 insertions(+), 106 deletions(-) diff --git a/eglib/src/gbytearray.c b/eglib/src/gbytearray.c index f8231b4834f..8702a4957a8 100644 --- a/eglib/src/gbytearray.c +++ b/eglib/src/gbytearray.c @@ -49,10 +49,3 @@ g_byte_array_append (GByteArray *array, { return (GByteArray *)g_array_append_vals ((GArray *)array, data, len); } - -void -g_byte_array_set_size (GByteArray *array, gint length) -{ - g_array_set_size ((GArray *)array, length); -} - diff --git a/eglib/src/glib.h b/eglib/src/glib.h index f5473bd2a5c..4b2c6d659d4 100644 --- a/eglib/src/glib.h +++ b/eglib/src/glib.h @@ -486,7 +486,6 @@ struct _GByteArray { GByteArray *g_byte_array_new (void); GByteArray* g_byte_array_append (GByteArray *array, const guint8 *data, guint len); guint8* g_byte_array_free (GByteArray *array, gboolean free_segment); -void g_byte_array_set_size (GByteArray *array, gint length); /* * Array diff --git a/mono/metadata/sgen-mono.c b/mono/metadata/sgen-mono.c index 11ab789d422..bb06f7eec02 100644 --- a/mono/metadata/sgen-mono.c +++ b/mono/metadata/sgen-mono.c @@ -2376,15 +2376,6 @@ sgen_client_scan_thread_data (void *start_nursery, void *end_nursery, gboolean p sgen_conservatively_pin_objects_from ((void**)&info->client_info.regs, (void**)&info->client_info.regs + ARCH_NUM_REGS, start_nursery, end_nursery, PIN_TYPE_STACK); #endif - { - // This is used on Coop GC for platforms where we cannot get the data for individual registers. - // We force a spill of all registers into the stack and pass a chunk of data into sgen. - MonoThreadUnwindState *state = mono_thread_info_get_suspend_state (info); - if (state && state->gc_stackdata) { - sgen_conservatively_pin_objects_from (state->gc_stackdata, (void**)((char*)state->gc_stackdata + state->gc_stackdata_size), - start_nursery, end_nursery, PIN_TYPE_STACK); - } - } } } END_FOREACH_THREAD } diff --git a/mono/utils/mono-stack-unwinding.h b/mono/utils/mono-stack-unwinding.h index 35f7bd01411..cfeb19d31b9 100644 --- a/mono/utils/mono-stack-unwinding.h +++ b/mono/utils/mono-stack-unwinding.h @@ -94,8 +94,6 @@ typedef struct { MonoContext ctx; gpointer unwind_data [3]; /*right now: domain, lmf and jit_tls*/ gboolean valid; - void *gc_stackdata; - int gc_stackdata_size; } MonoThreadUnwindState; diff --git a/mono/utils/mono-threads-api.h b/mono/utils/mono-threads-api.h index 47e3454c3d9..f94fd66e35b 100644 --- a/mono/utils/mono-threads-api.h +++ b/mono/utils/mono-threads-api.h @@ -20,8 +20,8 @@ This API is experimental. It will eventually be required to properly use the res */ /* Don't use those directly, use the MONO_(BEGIN|END)_EFRAME */ -MONO_API void* mono_threads_enter_gc_unsafe_region (void* stackdata); -MONO_API void mono_threads_exit_gc_unsafe_region (void *region_cookie, void* stackdata); +MONO_API void* mono_threads_enter_gc_unsafe_region (void); +MONO_API void mono_threads_exit_gc_unsafe_region (void *region_cookie); /* Use those macros to limit regions of code that interact with managed memory or use the embedding API. @@ -31,8 +31,8 @@ For further explanation of what can and can't be done in GC unsafe mode: http://www.mono-project.com/docs/advanced/runtime/docs/coop-suspend/#gc-unsafe-mode */ -#define MONO_BEGIN_EFRAME { void *__dummy; void *__region_cookie = mono_threads_enter_gc_unsafe_region (__dummy); -#define MONO_END_EFRAME mono_threads_exit_gc_unsafe_region (__region_cookie, __dummy); } +#define MONO_BEGIN_EFRAME { void *__region_cookie = mono_threads_enter_gc_unsafe_region (); +#define MONO_END_EFRAME mono_threads_exit_gc_unsafe_region (__region_cookie); } MONO_END_DECLS diff --git a/mono/utils/mono-threads-coop.c b/mono/utils/mono-threads-coop.c index e7e6db381d8..c1a8cad7473 100644 --- a/mono/utils/mono-threads-coop.c +++ b/mono/utils/mono-threads-coop.c @@ -14,7 +14,6 @@ #define _DARWIN_C_SOURCE #endif -#include #include #include #include @@ -30,13 +29,6 @@ #include #endif -#ifdef _MSC_VER -// TODO: Find MSVC replacement for __builtin_unwind_init -#define SAVE_REGS_ON_STACK g_assert_not_reached (); -#else -#define SAVE_REGS_ON_STACK __builtin_unwind_init (); -#endif - #ifdef USE_COOP_BACKEND volatile size_t mono_polling_required; @@ -75,36 +67,8 @@ mono_threads_state_poll (void) } } -static void * -return_stack_ptr () -{ - int i; - return &i; -} - -static void -copy_stack_data (MonoThreadInfo *info, void* stackdata_begin) -{ - MonoThreadUnwindState *state; - int stackdata_size; - void* stackdata_end = return_stack_ptr (); - - SAVE_REGS_ON_STACK; - - state = &info->thread_saved_state [SELF_SUSPEND_STATE_INDEX]; - - stackdata_size = (char*)stackdata_begin - (char*)stackdata_end; - g_assert (stackdata_size > 0); - - g_byte_array_set_size (info->stackdata, stackdata_size); - state->gc_stackdata = info->stackdata->data; - memcpy (state->gc_stackdata, stackdata_end, stackdata_size); - - state->gc_stackdata_size = stackdata_size; -} - void* -mono_threads_prepare_blocking (void* stackdata) +mono_threads_prepare_blocking (void) { MonoThreadInfo *info; ++coop_do_blocking_count; @@ -116,8 +80,6 @@ mono_threads_prepare_blocking (void* stackdata) return NULL; } - copy_stack_data (info, stackdata); - retry: ++coop_save_count; mono_threads_get_runtime_callbacks ()->thread_state_init (&info->thread_saved_state [SELF_SUSPEND_STATE_INDEX]); @@ -134,7 +96,7 @@ retry: } void -mono_threads_finish_blocking (void *cookie, void* stackdata) +mono_threads_finish_blocking (void *cookie) { static gboolean warned_about_bad_transition; MonoThreadInfo *info = cookie; @@ -166,7 +128,7 @@ mono_threads_finish_blocking (void *cookie, void* stackdata) void* -mono_threads_reset_blocking_start (void* stackdata) +mono_threads_reset_blocking_start (void) { MonoThreadInfo *info = mono_thread_info_current_unchecked (); ++coop_reset_blocking_count; @@ -175,8 +137,6 @@ mono_threads_reset_blocking_start (void* stackdata) if (!info || !mono_thread_info_is_live (info)) return NULL; - copy_stack_data (info, stackdata); - switch (mono_threads_transition_abort_blocking (info)) { case AbortBlockingIgnore: info->thread_saved_state [SELF_SUSPEND_STATE_INDEX].valid = FALSE; @@ -196,7 +156,7 @@ mono_threads_reset_blocking_start (void* stackdata) } void -mono_threads_reset_blocking_end (void *cookie, void* stackdata) +mono_threads_reset_blocking_end (void *cookie) { MonoThreadInfo *info = cookie; @@ -204,11 +164,11 @@ mono_threads_reset_blocking_end (void *cookie, void* stackdata) return; g_assert (info == mono_thread_info_current_unchecked ()); - mono_threads_prepare_blocking (stackdata); + mono_threads_prepare_blocking (); } void* -mono_threads_try_prepare_blocking (void* stackdata) +mono_threads_try_prepare_blocking (void) { MonoThreadInfo *info; ++coop_try_blocking_count; @@ -220,8 +180,6 @@ mono_threads_try_prepare_blocking (void* stackdata) return NULL; } - copy_stack_data (info, stackdata); - retry: ++coop_save_count; mono_threads_get_runtime_callbacks ()->thread_state_init (&info->thread_saved_state [SELF_SUSPEND_STATE_INDEX]); @@ -238,9 +196,9 @@ retry: } void -mono_threads_finish_try_blocking (void* cookie, void* stackdata) +mono_threads_finish_try_blocking (void* cookie) { - mono_threads_finish_blocking (cookie, stackdata); + mono_threads_finish_blocking (cookie); } gboolean @@ -252,7 +210,7 @@ mono_threads_core_begin_async_resume (MonoThreadInfo *info) gboolean mono_threads_core_begin_async_suspend (MonoThreadInfo *info, gboolean interrupt_kernel) -{ +{ mono_threads_add_to_pending_operation_set (info); /* There's nothing else to do after we async request the thread to suspend */ return TRUE; @@ -313,27 +271,27 @@ mono_threads_core_end_global_suspend (void) } void* -mono_threads_enter_gc_unsafe_region (void* stackdata) +mono_threads_enter_gc_unsafe_region (void) { - return mono_threads_reset_blocking_start (stackdata); + return mono_threads_reset_blocking_start (); } void -mono_threads_exit_gc_unsafe_region (void *regions_cookie, void* stackdata) +mono_threads_exit_gc_unsafe_region (void *regions_cookie) { - mono_threads_reset_blocking_end (regions_cookie, stackdata); + mono_threads_reset_blocking_end (regions_cookie); } #else void* -mono_threads_enter_gc_unsafe_region (void* stackdata) +mono_threads_enter_gc_unsafe_region (void) { return NULL; } void -mono_threads_exit_gc_unsafe_region (void *regions_cookie, void* stackdata) +mono_threads_exit_gc_unsafe_region (void *regions_cookie) { } diff --git a/mono/utils/mono-threads-coop.h b/mono/utils/mono-threads-coop.h index d103f42a5bd..88ae40aee87 100644 --- a/mono/utils/mono-threads-coop.h +++ b/mono/utils/mono-threads-coop.h @@ -22,44 +22,39 @@ #define MONO_PREPARE_BLOCKING \ { \ - void *__dummy; \ - void *__blocking_cookie = mono_threads_prepare_blocking (&__dummy); + void *__blocking_cookie = mono_threads_prepare_blocking (); #define MONO_FINISH_BLOCKING \ - mono_threads_finish_blocking (__blocking_cookie, &__dummy); \ + mono_threads_finish_blocking (__blocking_cookie); \ } #define MONO_PREPARE_RESET_BLOCKING \ { \ - void *__dummy; \ - void *__reset_cookie = mono_threads_reset_blocking_start (&__dummy); + void *__reset_cookie = mono_threads_reset_blocking_start (); #define MONO_FINISH_RESET_BLOCKING \ - mono_threads_reset_blocking_end (__reset_cookie, &__dummy); \ + mono_threads_reset_blocking_end (__reset_cookie); \ } #define MONO_TRY_BLOCKING \ { \ - void *__dummy; \ - void *__try_block_cookie = mono_threads_try_prepare_blocking (&__dummy); + void *__try_block_cookie = mono_threads_try_prepare_blocking (); #define MONO_FINISH_TRY_BLOCKING \ - mono_threads_finish_try_blocking (__try_block_cookie, &__dummy); \ + mono_threads_finish_try_blocking (__try_block_cookie); \ } /* Internal API */ void mono_threads_state_poll (void); -void mono_threads_state_poll_stack_data (void* stackdata); +void* mono_threads_prepare_blocking (void); +void mono_threads_finish_blocking (void* cookie); -void* mono_threads_prepare_blocking (void* stackdata); -void mono_threads_finish_blocking (void* cookie, void* stackdata); +void* mono_threads_reset_blocking_start (void); +void mono_threads_reset_blocking_end (void* cookie); -void* mono_threads_reset_blocking_start (void* stackdata); -void mono_threads_reset_blocking_end (void* cookie, void* stackdata); - -void* mono_threads_try_prepare_blocking (void* stackdata); -void mono_threads_finish_try_blocking (void* cookie, void* stackdata); +void* mono_threads_try_prepare_blocking (void); +void mono_threads_finish_try_blocking (void* cookie); /* JIT specific interface */ extern volatile size_t mono_polling_required; diff --git a/mono/utils/mono-threads.c b/mono/utils/mono-threads.c index b9526aa5fba..b1d5da9b917 100644 --- a/mono/utils/mono-threads.c +++ b/mono/utils/mono-threads.c @@ -15,7 +15,6 @@ #define _DARWIN_C_SOURCE #endif -#include #include #include #include @@ -327,8 +326,6 @@ register_thread (MonoThreadInfo *info, gpointer baseptr) info->stack_start_limit = staddr; info->stack_end = staddr + stsize; - info->stackdata = g_byte_array_new (); - mono_threads_platform_register (info); /* @@ -390,8 +387,6 @@ unregister_thread (void *arg) mono_thread_info_suspend_unlock (); - g_byte_array_free (info->stackdata, /*free_segment=*/TRUE); - /*now it's safe to free the thread info.*/ mono_thread_hazardous_free_or_queue (info, free_thread_info, TRUE, FALSE); mono_thread_small_id_free (small_id); diff --git a/mono/utils/mono-threads.h b/mono/utils/mono-threads.h index e0b979c0952..d153ca83c4e 100644 --- a/mono/utils/mono-threads.h +++ b/mono/utils/mono-threads.h @@ -10,7 +10,6 @@ #ifndef __MONO_THREADS_H__ #define __MONO_THREADS_H__ -#include #include #include #include @@ -225,9 +224,6 @@ typedef struct { int signal; #endif - /* This memory pool is used by coop GC to save stack data roots between GC unsafe regions */ - GByteArray *stackdata; - /*In theory, only the posix backend needs this, but having it on mach/win32 simplifies things a lot.*/ MonoThreadUnwindState thread_saved_state [2]; //0 is self suspend, 1 is async suspend. -- cgit v1.2.3