Add full-aot support for Volatile.Read<T>/Write<T> ().
authorZoltan Varga <vargaz@gmail.com>
Thu, 7 Mar 2013 18:59:41 +0000 (19:59 +0100)
committerZoltan Varga <vargaz@gmail.com>
Fri, 8 Mar 2013 01:33:28 +0000 (02:33 +0100)
mono/mini/aot-compiler.c
mono/mini/aot-runtime.c
mono/mini/generics.cs

index d5d2fdb77ac2e552f1a73ff0d8ca591175c6d965..482c1540c1d815c014620ae7920f8813c7f725d8 100644 (file)
@@ -4089,6 +4089,24 @@ add_generic_instances (MonoAotCompile *acfg)
                                }
                        }
                }
+
+               /* Same for Volatile.Read/Write<T> */
+               {
+                       MonoGenericContext ctx;
+                       MonoType *args [16];
+                       MonoMethod *m;
+                       MonoClass *volatile_klass = mono_class_from_name (mono_defaults.corlib, "System.Threading", "Volatile");
+                       gpointer iter = NULL;
+
+                       while ((m = mono_class_get_methods (volatile_klass, &iter))) {
+                               if ((!strcmp (m->name, "Read") || !strcmp (m->name, "Write")) && m->is_generic) {
+                                       memset (&ctx, 0, sizeof (ctx));
+                                       args [0] = &mono_defaults.object_class->byval_arg;
+                                       ctx.method_inst = mono_metadata_get_generic_inst (1, args);
+                                       add_extra_method (acfg, mono_marshal_get_native_wrapper (mono_class_inflate_generic_method (m, &ctx), TRUE, TRUE));
+                               }
+                       }
+               }
        }
 }
 
index 91c7c1dcbb1068cf78c5ce8362473c548a905043..1d8f33dab956974c2fe9c90075e87e55700c092c 100644 (file)
@@ -3484,7 +3484,11 @@ mono_aot_get_method (MonoDomain *domain, MonoMethod *method)
                }
 
                /* Same for CompareExchange<T> and Exchange<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") || !strcmp (method->name, "Exchange")) && MONO_TYPE_IS_REFERENCE (mono_method_signature (method)->params [1])) {
+               /* Same for Volatile.Read<T>/Write<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") || !strcmp (method->name, "Exchange")) && MONO_TYPE_IS_REFERENCE (mono_method_signature (method)->params [1])) ||
+                        (!strcmp (method->klass->name_space, "System.Threading") && !strcmp (method->klass->name, "Volatile") && (!strcmp (method->name, "Read") && MONO_TYPE_IS_REFERENCE (mono_method_signature (method)->ret))) ||
+                        (!strcmp (method->klass->name_space, "System.Threading") && !strcmp (method->klass->name, "Volatile") && (!strcmp (method->name, "Write") && MONO_TYPE_IS_REFERENCE (mono_method_signature (method)->params [1]))))) {
                        MonoMethod *m;
                        MonoGenericContext ctx;
                        MonoType *args [16];
index 5c74f76f9ea14bad25ab01439af57b2f751d3afa..b36764385103ed01522b607827f5def0bacf4fdc 100644 (file)
@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.CompilerServices;
+using System.Threading;
 
 class Tests {
 
@@ -1013,4 +1014,10 @@ class Tests {
                        return 3;
                return 0;
        }
+
+       public static int test_0_volatile_read_write () {
+               string foo = "ABC";
+               Volatile.Write (ref foo, "DEF");
+               return Volatile.Read (ref foo) == "DEF" ? 0 : 1;
+       }
 }