Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[runtime] Reworked coop GC stack handling in platforms with restricte…
…d access to register contexts.
- Loading branch information
Showing
9 changed files
with
103 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,13 @@ | |
#include <mono/utils/mach-support.h> | ||
#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; | ||
|
@@ -67,8 +74,36 @@ mono_threads_state_poll (void) | |
} | ||
} | ||
|
||
static void * | ||
return_stack_ptr () | ||
{ | ||
int i; | ||
return &i; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tritao
Author
Contributor
|
||
} | ||
|
||
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) | ||
mono_threads_prepare_blocking (void* stackdata) | ||
{ | ||
MonoThreadInfo *info; | ||
++coop_do_blocking_count; | ||
|
@@ -80,6 +115,8 @@ mono_threads_prepare_blocking (void) | |
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]); | ||
|
@@ -96,7 +133,7 @@ mono_threads_prepare_blocking (void) | |
} | ||
|
||
void | ||
mono_threads_finish_blocking (void *cookie) | ||
mono_threads_finish_blocking (void *cookie, void* stackdata) | ||
{ | ||
static gboolean warned_about_bad_transition; | ||
MonoThreadInfo *info = cookie; | ||
|
@@ -128,7 +165,7 @@ mono_threads_finish_blocking (void *cookie) | |
|
||
|
||
void* | ||
mono_threads_reset_blocking_start (void) | ||
mono_threads_reset_blocking_start (void* stackdata) | ||
{ | ||
MonoThreadInfo *info = mono_thread_info_current_unchecked (); | ||
++coop_reset_blocking_count; | ||
|
@@ -137,6 +174,8 @@ mono_threads_reset_blocking_start (void) | |
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; | ||
|
@@ -156,19 +195,19 @@ mono_threads_reset_blocking_start (void) | |
} | ||
|
||
void | ||
mono_threads_reset_blocking_end (void *cookie) | ||
mono_threads_reset_blocking_end (void *cookie, void* stackdata) | ||
{ | ||
MonoThreadInfo *info = cookie; | ||
|
||
if (!info) | ||
return; | ||
|
||
g_assert (info == mono_thread_info_current_unchecked ()); | ||
mono_threads_prepare_blocking (); | ||
mono_threads_prepare_blocking (stackdata); | ||
} | ||
|
||
void* | ||
mono_threads_try_prepare_blocking (void) | ||
mono_threads_try_prepare_blocking (void* stackdata) | ||
{ | ||
MonoThreadInfo *info; | ||
++coop_try_blocking_count; | ||
|
@@ -180,6 +219,8 @@ mono_threads_try_prepare_blocking (void) | |
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]); | ||
|
@@ -196,9 +237,9 @@ mono_threads_try_prepare_blocking (void) | |
} | ||
|
||
void | ||
mono_threads_finish_try_blocking (void* cookie) | ||
mono_threads_finish_try_blocking (void* cookie, void* stackdata) | ||
{ | ||
mono_threads_finish_blocking (cookie); | ||
mono_threads_finish_blocking (cookie, stackdata); | ||
} | ||
|
||
gboolean | ||
|
@@ -210,7 +251,7 @@ mono_threads_core_begin_async_resume (MonoThreadInfo *info) | |
|
||
gboolean | ||
mono_threads_core_begin_async_suspend (MonoThreadInfo *info, gboolean interrupt_kernel) | ||
{ | ||
{ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
mono_threads_add_to_pending_operation_set (info); | ||
/* There's nothing else to do after we async request the thread to suspend */ | ||
return TRUE; | ||
|
@@ -271,27 +312,27 @@ mono_threads_core_end_global_suspend (void) | |
} | ||
|
||
void* | ||
mono_threads_enter_gc_unsafe_region (void) | ||
mono_threads_enter_gc_unsafe_region (void* stackdata) | ||
{ | ||
return mono_threads_reset_blocking_start (); | ||
return mono_threads_reset_blocking_start (stackdata); | ||
} | ||
|
||
void | ||
mono_threads_exit_gc_unsafe_region (void *regions_cookie) | ||
mono_threads_exit_gc_unsafe_region (void *regions_cookie, void* stackdata) | ||
{ | ||
mono_threads_reset_blocking_end (regions_cookie); | ||
mono_threads_reset_blocking_end (regions_cookie, stackdata); | ||
} | ||
|
||
#else | ||
|
||
void* | ||
mono_threads_enter_gc_unsafe_region (void) | ||
mono_threads_enter_gc_unsafe_region (void* stackdata) | ||
{ | ||
return NULL; | ||
} | ||
|
||
void | ||
mono_threads_exit_gc_unsafe_region (void *regions_cookie) | ||
mono_threads_exit_gc_unsafe_region (void *regions_cookie, void* stackdata) | ||
{ | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
why not use __builtin_frame_address on compilers that support it (gcc and llvm), as we have a warning every time this function is compiled?