[coop] Don't emit safepoints in the wrapper of the polling function.
authorRodrigo Kumpera <kumpera@gmail.com>
Sun, 9 Aug 2015 05:55:26 +0000 (01:55 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 10 Aug 2015 14:25:21 +0000 (10:25 -0400)
Otherwise during a collection the wrapper would call itself resulting
in a stack overflow.

mono/mini/mini.c

index 49caf63669df5b3a5a8946ae644c2be1b7892255..120ccefb8ca1f8b0bbb52d0fdb6c7de8dcf705d8 100644 (file)
@@ -3098,6 +3098,23 @@ static void
 mono_insert_safepoints (MonoCompile *cfg)
 {
        MonoBasicBlock *bb;
+       if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+               WrapperInfo *info = mono_marshal_get_wrapper_info (cfg->method);
+#if defined(__native_client__) || defined(__native_client_codegen__)
+               gpointer poll_func = &mono_nacl_gc;
+#elif defined(USE_COOP_GC)
+               gpointer poll_func = &mono_threads_state_poll;
+#else
+               gpointer poll_func = NULL;
+#endif
+
+               if (info->subtype == WRAPPER_SUBTYPE_ICALL_WRAPPER && info->d.icall.func == poll_func) {
+                       if (cfg->verbose_level > 1)
+                               printf ("SKIPPING SAFEPOINTS for the polling function icall\n");
+                       return;
+               }
+       }
+
 
        if (cfg->verbose_level > 1)
                printf ("INSERTING SAFEPOINTS\n");