[threads] Enable blocking transition with MONO_ENABLE_BLOCKING_TRANSITION env variabl...
[mono.git] / mono / mini / method-to-ir.c
index 0c37dc1533c5b699e6444e144b806f9f8a7dfaed..619b1e68aa41d5d950a2c877a9f4df482b3c6a4f 100644 (file)
@@ -11457,7 +11457,20 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                                CHECK_STACK (info->sig->param_count);
                                sp -= info->sig->param_count;
 
-                               ins = mono_emit_jit_icall (cfg, info->func, sp);
+                               if (cfg->compile_aot && !strcmp (info->name, "mono_threads_attach_coop")) {
+                                       MonoInst *addr;
+
+                                       /*
+                                        * This is called on unattached threads, so it cannot go through the trampoline
+                                        * infrastructure. Use an indirect call through a got slot initialized at load time
+                                        * instead.
+                                        */
+                                       EMIT_NEW_AOTCONST (cfg, addr, MONO_PATCH_INFO_JIT_ICALL_ADDR_NOCALL, (char*)info->name);
+                                       ins = mini_emit_calli (cfg, info->sig, sp, addr, NULL, NULL);
+                               } else {
+                                       ins = mono_emit_jit_icall (cfg, info->func, sp);
+                               }
+
                                if (!MONO_TYPE_IS_VOID (info->sig->ret))
                                        *sp++ = ins;
 
@@ -11473,18 +11486,21 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                                CHECK_STACK_OVF (1);
 
                                switch (ip [1]) {
-                                       case CEE_MONO_LDPTR_CARD_TABLE:
-                                               ins = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_GC_CARD_TABLE_ADDR, NULL);
-                                               break;
-                                       case CEE_MONO_LDPTR_NURSERY_START:
-                                               ins = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_GC_NURSERY_START, NULL);
-                                               break;
-                                       case CEE_MONO_LDPTR_NURSERY_BITS:
-                                               ins = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_GC_NURSERY_BITS, NULL);
-                                               break;
-                                       case CEE_MONO_LDPTR_INT_REQ_FLAG:
-                                               ins = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_INTERRUPTION_REQUEST_FLAG, NULL);
-                                               break;
+                               case CEE_MONO_LDPTR_CARD_TABLE:
+                                       ins = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_GC_CARD_TABLE_ADDR, NULL);
+                                       break;
+                               case CEE_MONO_LDPTR_NURSERY_START:
+                                       ins = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_GC_NURSERY_START, NULL);
+                                       break;
+                               case CEE_MONO_LDPTR_NURSERY_BITS:
+                                       ins = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_GC_NURSERY_BITS, NULL);
+                                       break;
+                               case CEE_MONO_LDPTR_INT_REQ_FLAG:
+                                       ins = mini_emit_runtime_constant (cfg, MONO_PATCH_INFO_INTERRUPTION_REQUEST_FLAG, NULL);
+                                       break;
+                               default:
+                                       g_assert_not_reached ();
+                                       break;
                                }
 
                                *sp++ = ins;
@@ -11749,7 +11765,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                                MonoInst *ad_ins, *jit_tls_ins;
                                MonoBasicBlock *next_bb = NULL, *call_bb = NULL;
 
-                               g_assert (!mono_threads_is_coop_enabled ());
+                               g_assert (!mono_threads_is_blocking_transition_enabled ());
 
                                cfg->orig_domain_var = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_LOCAL);