-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[threading] embedded mono hangs #16907
Conversation
When embedded mono is executing a C++ code, it didn't start to execute a C# code, we don't need to suspend the thread to run GC. Fixes mono#16192 Fixes mono#14725
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Needs some comments. Also a better commit message explaining the embedding scenario that we want to protect.
- Could you try also to mark
mono_jit_init
andmono_jit_init_version
asMONO_RT_EXTERNAL_ONLY
injit.h
- I think they're unused in the runtime - they're only for embedders. - I would just get rid of the cookie in
MONO_ENTER_GC_SAFE_UNBALANCED
and deleteMONO_EXIT_GC_SAFE_UNBALANCED
.
mono/mini/driver.c
Outdated
@@ -2754,7 +2754,9 @@ mono_main (int argc, char* argv[]) | |||
MonoDomain * | |||
mono_jit_init (const char *file) | |||
{ | |||
return mini_init (file, NULL); | |||
MonoDomain *ret = mini_init (file, NULL); | |||
MONO_ENTER_GC_SAFE_UNBALANCED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a comment here to explain why we want to leave this thread in GC Safe mode.
mono/mini/driver.c
Outdated
@@ -2780,7 +2782,9 @@ mono_jit_init (const char *file) | |||
MonoDomain * | |||
mono_jit_init_version (const char *domain_name, const char *runtime_version) | |||
{ | |||
return mini_init (domain_name, runtime_version); | |||
MonoDomain *ret = mini_init (domain_name, runtime_version); | |||
MONO_ENTER_GC_SAFE_UNBALANCED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a comment here.
mono/utils/mono-threads-api.h
Outdated
MONO_STACKDATA (__gc_safe_unbalanced_dummy); \ | ||
gpointer __gc_safe_unbalanced_cookie = mono_threads_enter_gc_safe_region_unbalanced_internal (&__gc_safe_unbalanced_dummy) | ||
|
||
#define MONO_EXIT_GC_SAFE_UNBALANCED \ | ||
mono_threads_exit_gc_safe_region_unbalanced_internal (__gc_safe_unbalanced_cookie, &__gc_safe_unbalanced_dummy); \ | ||
} while (0) | ||
mono_threads_exit_gc_safe_region_unbalanced_internal (__gc_safe_unbalanced_cookie, &__gc_safe_unbalanced_dummy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like this macro has almost no value: it won't compile unless you pair it with MONO_ENTER_GC_SAFE_UNBALANCED
(because it needs the cookie). But if you use it like that, it's balanced!
|
@monojenkins build failed |
@monojenkins build failed |
1 similar comment
@monojenkins build failed |
* [threading] embedded mono hangs When embedded mono is executing a C++ code, it didn't start to execute a C# code, we don't need to suspend the thread to run GC. Fixes mono/mono#16192 Fixes mono/mono#14725 * Changing what was discussed with Aleksey during our 1on1 * Changing what was suggested by Aleksey * Separating mono_init_version that is being used on tests from the embedded ones Commit migrated from mono/mono@5b108b5
…te transition. Starting with mono/mono#16907 , the Mono runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. The monotouch code did not expect that, and calls mono_gc_init_finalizer_thread() which also tries to enter GC-safe mode. Should fix mono/mono#19372
…te transition. (#8242) Starting with mono/mono#16907 , the Mono runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. The monotouch code did not expect that, and calls mono_gc_init_finalizer_thread() which also tries to enter GC-safe mode. Should fix mono/mono#19372
…te transition. Starting with mono/mono#16907 , the Mono runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. The monotouch code did not expect that, and calls mono_gc_init_finalizer_thread() which also tries to enter GC-safe mode. Should fix mono/mono#19372
…te transition. Starting with mono/mono#16907 , the Mono runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. The monotouch code did not expect that, and calls mono_gc_init_finalizer_thread() which also tries to enter GC-safe mode. Should fix mono/mono#19372
…te transition. Starting with mono/mono#16907 , the Mono runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. The monotouch code did not expect that, and calls mono_gc_init_finalizer_thread() which also tries to enter GC-safe mode. Should fix mono/mono#19372
…te transition. (#8245) Starting with mono/mono#16907 , the Mono runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. The monotouch code did not expect that, and calls mono_gc_init_finalizer_thread() which also tries to enter GC-safe mode. Should fix mono/mono#19372 Co-authored-by: Alexis Christoforides <alexis@thenull.net>
…te transition. (#8248) Starting with mono/mono#16907 , the Mono runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. The monotouch code did not expect that, and calls mono_gc_init_finalizer_thread() which also tries to enter GC-safe mode. Should fix mono/mono#19372 Co-authored-by: Alexis Christoforides <alexis@thenull.net>
Starting with #16907 , the runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. mono_gc_init_finalizer_thread() expects the GC to not already be in safe mode.
Starting with mono/mono#16907 , the runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. mono_gc_init_finalizer_thread() expects the GC to not already be in safe mode.
Starting with mono/mono#16907 , the runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. mono_gc_init_finalizer_thread() expects the GC to not already be in safe mode.
Starting with #16907 , the runtime ends in GC-Safe state (mode) after mono_jit_init_version() is called. mono_gc_init_finalizer_thread() expects the GC to not already be in safe mode.
When embedded mono is executing a C++ code, it didn't start to execute a C# code, we don't need to suspend the thread to run GC.
So my idea is set the flag MONO_THREAD_INFO_FLAGS_NO_GC when initializes mono embedded and only remove the flag MONO_THREAD_INFO_FLAGS_NO_GC when a mono_runtime_invoke_array or a mono_runtime_invoke is called.
Fixes #16192
Fixes #14725