From 29a2383333fdd4d49101d37ea61571747454aae9 Mon Sep 17 00:00:00 2001 From: lateralusX Date: Mon, 3 Jun 2019 11:43:16 +0200 Subject: [PATCH] Increase main thread stack size on Windows. On Windows default thread stack size has been 1MB for a long time (both 32/64-bit). When starting to use interpreter some of the tests include deep recursions that will hit stackoverflow on Windows (ackermann.exe as one example). This commit adjust the default reserved stack size to 8MB for debug builds and 1.5MB (same as coreclr), for main thread only. All other threads will still default to 1MB stack size (both debug/release). --- mono/utils/mono-threads-windows.c | 12 +++++++++--- msvc/mono.vcxproj | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mono/utils/mono-threads-windows.c b/mono/utils/mono-threads-windows.c index 70b15dd3729..af86c3b909e 100644 --- a/mono/utils/mono-threads-windows.c +++ b/mono/utils/mono-threads-windows.c @@ -350,13 +350,19 @@ mono_threads_suspend_get_abort_signal (void) #if defined (HOST_WIN32) +#define MONO_WIN32_DEFAULT_NATIVE_STACK_SIZE (1024 * 1024) + gboolean mono_thread_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_data, gsize* const stack_size, MonoNativeThreadId *tid) { HANDLE result; DWORD thread_id; + gsize set_stack_size = MONO_WIN32_DEFAULT_NATIVE_STACK_SIZE; + + if (stack_size && *stack_size) + set_stack_size = *stack_size; - result = CreateThread (NULL, stack_size ? *stack_size : 0, (LPTHREAD_START_ROUTINE) thread_fn, thread_data, 0, &thread_id); + result = CreateThread (NULL, set_stack_size, (LPTHREAD_START_ROUTINE) thread_fn, thread_data, 0, &thread_id); if (!result) return FALSE; @@ -370,7 +376,7 @@ mono_thread_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_d if (stack_size) { // TOOD: Use VirtualQuery to get correct value // http://stackoverflow.com/questions/2480095/thread-stack-size-on-windows-visual-c - *stack_size = 2 * 1024 * 1024; + *stack_size = set_stack_size; } return TRUE; @@ -392,7 +398,7 @@ mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2) gboolean mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg) { - return CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)func, arg, 0, tid) != NULL; + return CreateThread (NULL, MONO_WIN32_DEFAULT_NATIVE_STACK_SIZE, (LPTHREAD_START_ROUTINE)func, arg, 0, tid) != NULL; } gboolean diff --git a/msvc/mono.vcxproj b/msvc/mono.vcxproj index 4602e6c91f5..28d7a720215 100644 --- a/msvc/mono.vcxproj +++ b/msvc/mono.vcxproj @@ -107,6 +107,7 @@ Console + 0x800000 false @@ -141,6 +142,7 @@ xcopy "$(SolutionDir)setup-vs-msvcbuild-env.bat" "$(OutDir)" /q /y >nul 2> Console + 0x800000 xcopy "$(SolutionDir)mono-sgen-msvc.sh" "$(OutDir)" /q /y >nul 2>&1 @@ -168,6 +170,7 @@ xcopy "$(SolutionDir)setup-vs-msvcbuild-env.bat" "$(OutDir)" /q /y >nul 2> Console + 0x180000 xcopy "$(SolutionDir)mono-sgen-msvc.sh" "$(OutDir)" /q /y >nul 2>&1 @@ -196,6 +199,7 @@ xcopy "$(SolutionDir)setup-vs-msvcbuild-env.bat" "$(OutDir)" /q /y >nul 2> $(MONO_LIBMONO_LIB);%(AdditionalDependencies) Console + 0x180000 xcopy "$(SolutionDir)mono-sgen-msvc.sh" "$(OutDir)" /q /y >nul 2>&1 -- 2.11.4.GIT