Special case Interlocked.CompareExchange<T> in the aot runtime.
authorZoltan Varga <vargaz@gmail.com>
Tue, 16 Nov 2010 19:44:45 +0000 (20:44 +0100)
committerZoltan Varga <vargaz@gmail.com>
Tue, 16 Nov 2010 19:44:45 +0000 (20:44 +0100)
mono/mini/aot-runtime.c

index ca53b586623d47a4a47e2c107ea6ce2cb2f18b2b..4004e1e8dcd6aac20065c198598e9be827865ac3 100644 (file)
@@ -2846,6 +2846,35 @@ mono_aot_get_method (MonoDomain *domain, MonoMethod *method)
                                return code;
                }
 
+               /* Same for CompareExchange<T> */
+               if (method_index == 0xffffff && method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE && method->klass->image == mono_defaults.corlib && !strcmp (method->klass->name_space, "System.Threading") && !strcmp (method->klass->name, "Interlocked") && !strcmp (method->name, "CompareExchange")) {
+                       MonoMethod *m;
+                       MonoGenericContext ctx;
+                       MonoType *args [16];
+                       gpointer iter = NULL;
+
+                       while ((m = mono_class_get_methods (method->klass, &iter))) {
+                               if (mono_method_signature (m)->generic_param_count && !strcmp (m->name, "CompareExchange"))
+                                       break;
+                       }
+                       g_assert (m);
+
+                       memset (&ctx, 0, sizeof (ctx));
+                       args [0] = &mono_defaults.object_class->byval_arg;
+                       ctx.method_inst = mono_metadata_get_generic_inst (1, args);
+
+                       m = mono_marshal_get_native_wrapper (mono_class_inflate_generic_method (m, &ctx), TRUE, TRUE);
+
+                       /* 
+                        * Get the code for the <object> instantiation which should be emitted into
+                        * the mscorlib aot image by the AOT compiler.
+                        */
+                       code = mono_aot_get_method (domain, m);
+                       if (code)
+                               return code;
+                       printf ("HIT!\n");
+               }
+
                if (method_index == 0xffffff && method->is_inflated && mono_method_is_generic_sharable_impl_full (method, FALSE, TRUE)) {
                        /* Partial sharing */
                        method_index = find_extra_method (mini_get_shared_method (method), &amodule);