[gc] Remove mono_gc_set_stack_end (#3845)
authorLudovic Henry <ludovic@xamarin.com>
Fri, 28 Oct 2016 12:49:23 +0000 (08:49 -0400)
committerGitHub <noreply@github.com>
Fri, 28 Oct 2016 12:49:23 +0000 (08:49 -0400)
* [sgen] Add stress test

This hope to suspend a thread while it is in the process of attaching or detaching.

* [sgen] Fix unified suspend

This would cause a crash with unified suspend: if a thread would be suspended at mono-threads.c:1168, the stack_start would be greater than the stack_end, triggering the g_error at sgen-stw.c:351. The stack_end would initially be initialized in `sgen_client_thread_register`, but it would be overriden in start_wrapper at threads.c:893.

mono/metadata/threads.c
mono/tests/Makefile.am
mono/tests/sgen-new-threads-collect.cs [new file with mode: 0644]

index 2ae43aab0ae3be675b979e4cb5756fc1d6ed169a..32fd488fb868a78fd0c11adb60b375e38bee9c45 100644 (file)
@@ -890,9 +890,6 @@ static gsize WINAPI start_wrapper(void *data)
 {
        volatile gsize dummy;
 
-       /* Avoid scanning the frames above this frame during a GC */
-       mono_gc_set_stack_end ((void*)&dummy);
-
        return start_wrapper_internal ((StartInfo*) data, (gsize*) &dummy);
 }
 
index 511e581b66e8de2ea699639b8c4e1102b9835645..6439b02c37ce85d54c3ba9061751796f58271a4b 100644 (file)
@@ -1112,7 +1112,7 @@ debug-casts:
        @$(MCS) -r:TestDriver.dll $(srcdir)/debug-casts.cs
        @$(RUNTIME) --debug=casts debug-casts.exe
 
-EXTRA_DIST += sgen-bridge.cs sgen-descriptors.cs sgen-gshared-vtype.cs sgen-bridge-major-fragmentation.cs sgen-domain-unload.cs sgen-weakref-stress.cs sgen-cementing-stress.cs sgen-case-23400.cs     finalizer-wait.cs critical-finalizers.cs sgen-domain-unload-2.cs sgen-suspend.cs sgen-new-threads-dont-join-stw.cs sgen-new-threads-dont-join-stw-2.cs sgen-bridge-xref.cs bug-17590.cs sgen-toggleref.cs sgen-bridge-gchandle.cs
+EXTRA_DIST += sgen-bridge.cs sgen-descriptors.cs sgen-gshared-vtype.cs sgen-bridge-major-fragmentation.cs sgen-domain-unload.cs sgen-weakref-stress.cs sgen-cementing-stress.cs sgen-case-23400.cs     finalizer-wait.cs critical-finalizers.cs sgen-domain-unload-2.cs sgen-suspend.cs sgen-new-threads-dont-join-stw.cs sgen-new-threads-dont-join-stw-2.cs sgen-new-threads-collect.cs sgen-bridge-xref.cs bug-17590.cs sgen-toggleref.cs sgen-bridge-gchandle.cs
 
 
 sgen-tests:
@@ -1137,6 +1137,7 @@ SGEN_REGULAR_TESTS_UNIVERSAL =    \
        sgen-case-23400.exe     \
        sgen-new-threads-dont-join-stw.exe      \
        sgen-new-threads-dont-join-stw-2.exe    \
+       sgen-new-threads-collect.exe    \
        gc-graystack-stress.exe \
        bug-17590.exe
 
diff --git a/mono/tests/sgen-new-threads-collect.cs b/mono/tests/sgen-new-threads-collect.cs
new file mode 100644 (file)
index 0000000..5deee6b
--- /dev/null
@@ -0,0 +1,51 @@
+
+using System;
+using System.Collections.Concurrent;
+using System.Threading;
+
+class Driver
+{
+       public static void Main ()
+       {
+               BlockingCollection<Thread> threads = new BlockingCollection<Thread> (new ConcurrentQueue<Thread> (), 128);
+
+               bool finished = false;
+
+               Thread gcThread = new Thread (() => {
+                       while (!finished) {
+                               GC.Collect ();
+                               Thread.Yield ();
+                       }
+               });
+
+               Thread joinThread = new Thread (() => {
+                       for (int i = 0; ; ++i) {
+                               Thread t = threads.Take ();
+                               if (t == null)
+                                       break;
+                               t.Join ();
+                               if ((i + 1) % (50) == 0)
+                                       Console.Write (".");
+                               if ((i + 1) % (50 * 50) == 0)
+                                       Console.WriteLine ();
+                       }
+               });
+
+               gcThread.Start ();
+               joinThread.Start ();
+
+               for (int i = 0; i < 10 * 1000; ++i) {
+                       Thread t = new Thread (() => { Thread.Yield (); });
+                       t.Start ();
+
+                       threads.Add (t);
+               }
+
+               threads.Add (null);
+
+               joinThread.Join ();
+
+               finished = true;
+               gcThread.Join ();
+       }
+}
\ No newline at end of file