Merge pull request #3247 from lateralusX/jlorenss/win-x64-lmf-exception
authorJohan Lorensson <lateralusx.github@gmail.com>
Fri, 8 Jul 2016 06:24:04 +0000 (08:24 +0200)
committerGitHub <noreply@github.com>
Fri, 8 Jul 2016 06:24:04 +0000 (08:24 +0200)
Fix crash in mono mini exceptions.exe regression test on win x64.

19 files changed:
mcs/class/System.ServiceModel/System.ServiceModel/DuplexClientRuntimeChannel.cs
mcs/class/corlib/System.Runtime.Remoting.Contexts/SynchronizationAttribute.cs
mcs/class/corlib/Test/System.Runtime.Remoting.Contexts/SynchronizationAttributeTest.cs
mcs/class/corlib/Test/System.Runtime.Remoting/SynchronizationAttributeTest.cs
mono/metadata/cil-coff.h
mono/metadata/loader.c
mono/metadata/marshal.c
mono/metadata/metadata-verify.c
mono/mini/aot-compiler.c
mono/mini/aot-runtime.c
mono/mini/generics.cs
mono/mini/jit-icalls.c
mono/mini/method-to-ir.c
mono/mini/mini-generic-sharing.c
mono/mini/mini-llvm-cpp.cpp
mono/mini/mini-llvm-cpp.h
mono/mini/mini-llvm.c
mono/mini/mini-runtime.c
mono/mini/mini-trampolines.c

index 4fa56e12a78a964bba565818d308429d40ba09e6..db6647c76f5188f5277d129baca9bb48dc5f225e 100644 (file)
@@ -192,10 +192,6 @@ namespace System.ServiceModel.MonoInternal
                        } catch (Exception ex) {
                                // FIXME: log it.
                                Console.WriteLine (ex);
-                       } finally {
-                               // unless it is closed by session/call manager, move it back to the loop to receive the next message.
-                               if (loop && input.State != CommunicationState.Closed)
-                                       ProcessRequestOrInput (input);
                        }
                }
 
index 7ef860da45f1725dd95121b1d8a8473e9bdc6cc7..49628abb3446aa8cfedf988fde671a7fbea85738 100644 (file)
@@ -46,8 +46,6 @@ namespace System.Runtime.Remoting.Contexts
                bool _bReEntrant;
                int _flavor;
 
-               [NonSerialized]
-               bool _locked;
                [NonSerialized]
                int _lockCount;
                
@@ -90,32 +88,26 @@ namespace System.Runtime.Remoting.Contexts
                {
                        get 
                        { 
-                               return _locked
+                               return _lockCount > 0
                        }
                        
                        set 
                        {
                                if (value)
                                {
-                                       _mutex.WaitOne ();
+                                       AcquireLock ();
                                        lock (this)
                                        {
-                                               _lockCount++;
                                                if (_lockCount > 1)
                                                        ReleaseLock (); // Thread already had the lock
-                                                       
-                                               _ownerThread = Thread.CurrentThread;
                                        }
                                }
                                else
                                {
                                        lock (this)
                                        {
-                                               while (_lockCount > 0 && _ownerThread == Thread.CurrentThread)
-                                               {
-                                                       _lockCount--;
-                                                       _mutex.ReleaseMutex ();
-                                                       _ownerThread = null;
+                                               while (_lockCount > 0 && _ownerThread == Thread.CurrentThread) {
+                                                       ReleaseLock ();
                                                }
                                        }
                                }
@@ -140,7 +132,9 @@ namespace System.Runtime.Remoting.Contexts
                                if (_lockCount > 0 && _ownerThread == Thread.CurrentThread) {
                                        _lockCount--;
                                        _mutex.ReleaseMutex ();
-                                       _ownerThread = null;
+                                       if (_lockCount == 0) {
+                                               _ownerThread = null;
+                                       }
                                }
                        }
                }
index ba69ed0503ba2cef85676b6de18327fdc590a987..a217969aefd8fffb6424d2e93ee3bf40a7f73464 100644 (file)
@@ -71,6 +71,23 @@ namespace MonoTests.System.Runtime.Remoting.Contexts {
                        Assert.IsFalse (sa.Locked, "Locked");
                }
 
+               [Test]
+           public void SetLocked()
+               {
+                       SynchronizationAttribute sa = new SynchronizationAttribute(SynchronizationAttribute.REQUIRES_NEW);
+                       sa.Locked = true;
+                       Assert.IsTrue(sa.Locked, "Locked");
+                       sa.Locked = false;
+                       Assert.IsFalse(sa.Locked, "Locked");
+
+                       sa.Locked = true;
+                       Assert.IsTrue(sa.Locked, "Locked");
+                       sa.Locked = true;
+                       Assert.IsTrue(sa.Locked, "Locked");
+                       sa.Locked = false;
+                       Assert.IsFalse(sa.Locked, "Locked");
+               }
+
                [Test]
                public void SerializationRoundtrip ()
                {
index 7596f3fd8bd53e905af9346ae6d622ec6ce9f57d..4005d1ad6c56783437c7dc1339473b5cc4e2e445 100644 (file)
@@ -220,6 +220,7 @@ namespace MonoTests.System.Runtime.Remoting
                public void TestLocked1 ()
                {
                        sincob.Lock (false);
+
                        Thread tr = new Thread (new ThreadStart (FirstSyncThread));
                        tr.Start ();
                        Thread.Sleep (200);
@@ -331,6 +332,21 @@ namespace MonoTests.System.Runtime.Remoting
                        Assert.IsTrue (!otResult, "Concurrency detected in CallbackThread");
                }
 
+               [Test]
+               public void TestSynchronizationReleasedOnMultipleAcquire ()
+               {
+
+                       otResult = notreentrant.TestCallback ();
+                   
+                       Thread tr = new Thread (new ThreadStart (CallbackThread));
+                       tr.Start();
+                       
+                       bool terminated = tr.Join(2000);
+                       Assert.IsTrue(terminated, "Thread didn't get lock of context bound object.");
+                       
+                       Assert.IsTrue (!otResult, "Concurrency detected in CallbackThread");
+               }
+
                void CallbackThread ()
                {
                        otResult = notreentrant.TestCallback ();
index 26b4782ca5a101ac942172f0dbd61fb5a857493c..8581a042f2c310bafe764a2992b0897816939f08 100644 (file)
@@ -295,8 +295,8 @@ typedef struct {
 #define CLI_FLAGS_ILONLY         0x01
 #define CLI_FLAGS_32BITREQUIRED  0x02
 #define CLI_FLAGS_STRONGNAMESIGNED 0x8
-#define CLI_FLAGS_PREFERRED32BIT  0x10
 #define CLI_FLAGS_TRACKDEBUGDATA 0x00010000
+#define CLI_FLAGS_PREFERRED32BIT 0x00020000
        guint32        ch_flags;
 
        guint32        ch_entry_point;
index 2922234965a5035b83acf0ce6b3f0f7b51d22f18..4f36ba3c82c11fd5f55a5e8e10866928fdf0a9a5 100644 (file)
@@ -994,6 +994,7 @@ mono_dllmap_lookup_list (MonoDllMap *dll_map, const char *dll, const char* func,
                         */
                }
                if (dll_map->func && strcmp (dll_map->func, func) == 0) {
+                       *rdll = dll_map->target;
                        *rfunc = dll_map->target_func;
                        break;
                }
@@ -1021,7 +1022,7 @@ mono_dllmap_lookup (MonoImage *assembly, const char *dll, const char* func, cons
  * @dll: The name of the external library, as it would be found in the DllImport declaration.  If prefixed with 'i:' the matching of the library name is done without case sensitivity
  * @func: if not null, the mapping will only applied to the named function (the value of EntryPoint)
  * @tdll: The name of the library to map the specified @dll if it matches.
- * @tfunc: if func is not NULL, the name of the function that replaces the invocation
+ * @tfunc: The name of the function that replaces the invocation.  If NULL, it is replaced with a copy of @func.
  *
  * LOCKING: Acquires the loader lock.
  *
@@ -1056,7 +1057,7 @@ mono_dllmap_insert (MonoImage *assembly, const char *dll, const char *func, cons
                entry->dll = dll? g_strdup (dll): NULL;
                entry->target = tdll? g_strdup (tdll): NULL;
                entry->func = func? g_strdup (func): NULL;
-               entry->target_func = tfunc? g_strdup (tfunc): NULL;
+               entry->target_func = tfunc? g_strdup (tfunc): (func? g_strdup (func): NULL);
 
                global_loader_data_lock ();
                entry->next = global_dll_map;
@@ -1067,7 +1068,7 @@ mono_dllmap_insert (MonoImage *assembly, const char *dll, const char *func, cons
                entry->dll = dll? mono_image_strdup (assembly, dll): NULL;
                entry->target = tdll? mono_image_strdup (assembly, tdll): NULL;
                entry->func = func? mono_image_strdup (assembly, func): NULL;
-               entry->target_func = tfunc? mono_image_strdup (assembly, tfunc): NULL;
+               entry->target_func = tfunc? mono_image_strdup (assembly, tfunc): (func? mono_image_strdup (assembly, func): NULL);
 
                mono_image_lock (assembly);
                entry->next = assembly->dll_map;
index 6dbf07f79414184cba5de202f48ecdc4484bd312..3edf257bee53630bcae260331657d73c757d2a3a 100644 (file)
@@ -4220,7 +4220,6 @@ mono_marshal_get_runtime_invoke (MonoMethod *method, gboolean virtual_)
  * ARGS should contain the this argument too.
  * This wrapper serves the same purpose as the runtime-invoke wrappers, but there
  * is only one copy of it, which is useful in full-aot.
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod*
 mono_marshal_get_runtime_invoke_dynamic (void)
@@ -4447,7 +4446,6 @@ mono_mb_emit_auto_layout_exception (MonoMethodBuilder *mb, MonoClass *klass)
 /*
  * generates IL code for the icall wrapper (the generated method
  * calls the unmanaged code in func)
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod *
 mono_marshal_get_icall_wrapper (MonoMethodSignature *sig, const char *name, gconstpointer func, gboolean check_exceptions)
@@ -7594,7 +7592,6 @@ mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, MonoM
  *
  * generates IL code for the pinvoke wrapper (the generated method
  * calls the unmanaged code in piinfo->addr)
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod *
 mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions, gboolean aot)
@@ -8653,7 +8650,6 @@ generate_check_cache (int obj_arg_position, int class_arg_position, int cache_ar
 
 /*
  * This does the equivalent of mono_object_castclass_with_cache.
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod *
 mono_marshal_get_castclass_with_cache (void)
@@ -8739,7 +8735,6 @@ mono_marshal_isinst_with_cache (MonoObject *obj, MonoClass *klass, uintptr_t *ca
 
 /*
  * This does the equivalent of mono_object_isinst_with_cache.
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod *
 mono_marshal_get_isinst_with_cache (void)
@@ -8916,7 +8911,6 @@ mono_marshal_get_isinst (MonoClass *klass)
  * an instance of the given type, icluding the case where the object is a proxy.
  * The generated function has the following signature:
  * MonoObject* __castclass_wrapper_ (MonoObject *obj)
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod *
 mono_marshal_get_castclass (MonoClass *klass)
@@ -8999,7 +8993,6 @@ mono_marshal_get_castclass (MonoClass *klass)
  * @klass:
  *
  * generates IL code for StructureToPtr (object structure, IntPtr ptr, bool fDeleteOld)
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod *
 mono_marshal_get_struct_to_ptr (MonoClass *klass)
@@ -9073,7 +9066,6 @@ mono_marshal_get_struct_to_ptr (MonoClass *klass)
  * @klass:
  *
  * generates IL code for PtrToStructure (IntPtr src, object structure)
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod *
 mono_marshal_get_ptr_to_struct (MonoClass *klass)
@@ -9152,7 +9144,6 @@ mono_marshal_get_ptr_to_struct (MonoClass *klass)
  * This is used to avoid infinite recursion since it is hard to determine where to
  * replace a method with its synchronized wrapper, and where not.
  * The runtime should execute METHOD instead of the wrapper.
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod *
 mono_marshal_get_synchronized_inner_wrapper (MonoMethod *method)
@@ -9520,8 +9511,6 @@ record_slot_vstore (MonoObject *array, size_t index, MonoObject *value)
 #endif
 
 /*
- * The wrapper info for the wrapper is a WrapperInfo structure.
- *
  * TODO:
  *     - Separate simple interfaces from variant interfaces or mbr types. This way we can avoid the icall for them.
  *     - Emit a (new) mono bytecode that produces OP_COND_EXC_NE_UN to raise ArrayTypeMismatch
@@ -9930,9 +9919,6 @@ mono_marshal_get_virtual_stelemref_wrappers (int *nwrappers)
        return res;
 }
 
-/*
- * The wrapper info for the wrapper is a WrapperInfo structure.
- */
 MonoMethod*
 mono_marshal_get_stelemref (void)
 {
@@ -10083,8 +10069,6 @@ mono_marshal_get_stelemref (void)
  * mono_marshal_get_gsharedvt_in_wrapper:
  *
  *   This wrapper handles calls from normal code to gsharedvt code.
- *
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod*
 mono_marshal_get_gsharedvt_in_wrapper (void)
@@ -10119,8 +10103,6 @@ mono_marshal_get_gsharedvt_in_wrapper (void)
  * mono_marshal_get_gsharedvt_out_wrapper:
  *
  *   This wrapper handles calls from gsharedvt code to normal code.
- *
- * The wrapper info for the wrapper is a WrapperInfo structure.
  */
 MonoMethod*
 mono_marshal_get_gsharedvt_out_wrapper (void)
index 287c68fbfb79d3413a3767ca63c0a9a0e3e66b35..2c5612c2a1d6a4f30c2da778f08d6998505904ff 100644 (file)
@@ -730,7 +730,7 @@ verify_cli_header (VerifyContext *ctx)
        if (!read32 (ptr + 8) || !read32 (ptr + 12))
                ADD_ERROR (ctx, g_strdup_printf ("Missing medatata section in the CLI header"));
 
-       if ((read32 (ptr + 16) & ~0x0001000B) != 0)
+       if ((read32 (ptr + 16) & ~0x0003000B) != 0)
                ADD_ERROR (ctx, g_strdup_printf ("Invalid CLI header flags"));
 
        ptr += 24;
index 1023abcd24b7e671292956637232d53f4d7426b5..7c3fa351ccef1d807ab5e4d2c43863f7d1bb8aea 100644 (file)
@@ -902,7 +902,10 @@ arch_init (MonoAotCompile *acfg)
        if (acfg->aot_opts.mtriple && strstr (acfg->aot_opts.mtriple, "darwin")) {
                g_string_append (acfg->llc_args, "-mattr=+v6");
        } else {
-#ifdef ARM_FPU_VFP
+#if defined(ARM_FPU_VFP_HARD)
+               g_string_append (acfg->llc_args, " -mattr=+vfp2,-neon,+d16 -float-abi=hard");
+               g_string_append (acfg->as_args, " -mfpu=vfp3");
+#elif defined(ARM_FPU_VFP)
                g_string_append (acfg->llc_args, " -mattr=+vfp2,-neon,+d16");
                g_string_append (acfg->as_args, " -mfpu=vfp3");
 #else
index 5aa2ca6d88adbd0f277161acc20065472074ea20..d4eb786235ed89a7de1860e7c2be46fce9e9ecab 100644 (file)
@@ -1782,17 +1782,6 @@ check_usable (MonoAssembly *assembly, MonoAotFileInfo *info, guint8 *blob, char
                msg = g_strdup_printf ("not compiled with --aot=llvmonly");
                usable = FALSE;
        }
-#ifdef TARGET_ARM
-       /* mono_arch_find_imt_method () requires this */
-       if ((info->flags & MONO_AOT_FILE_FLAG_WITH_LLVM) && !mono_use_llvm) {
-               msg = g_strdup_printf ("compiled against LLVM");
-               usable = FALSE;
-       }
-       if (!(info->flags & MONO_AOT_FILE_FLAG_WITH_LLVM) && mono_use_llvm) {
-               msg = g_strdup_printf ("not compiled against LLVM");
-               usable = FALSE;
-       }
-#endif
        if (mini_get_debug_options ()->mdb_optimizations && !(info->flags & MONO_AOT_FILE_FLAG_DEBUG) && !full_aot) {
                msg = g_strdup_printf ("not compiled for debugging");
                usable = FALSE;
index 1284cb292ae733f3f58dc8b78c5a07d72d31e488..80638b5048e6edf80854c7509ee3b7d18292cd5c 100644 (file)
@@ -898,6 +898,7 @@ class Tests
        }
 
        [Category ("!FULLAOT")]
+       [Category ("!BITCODE")]
        public static int test_0_regress_668095_synchronized_gshared () {
                return DoSomething (new DefaultRetriever ());
        }
index 8651aa25ec497c574a6d492e6ae6e9b324be8e14..d7c6d9a232fe63bbbf3731b6bd6567f2caf676eb 100644 (file)
@@ -1630,6 +1630,9 @@ resolve_vcall (MonoVTable *vt, int slot, MonoMethod *imt_method, gpointer *out_a
                        need_unbox_tramp = TRUE;
        }
 
+       if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
+               m = mono_marshal_get_synchronized_wrapper (m);
+
        // FIXME: This can throw exceptions
        addr = compiled_method = mono_compile_method_checked (m, error);
        mono_error_assert_ok (error);
@@ -1751,9 +1754,11 @@ mono_resolve_generic_virtual_iface_call (MonoVTable *vt, int imt_slot, MonoMetho
        if (vt->klass->valuetype)
                need_unbox_tramp = TRUE;
 
-       // FIXME: This can throw exceptions
+       if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
+               m = mono_marshal_get_synchronized_wrapper (m);
+
        addr = compiled_method = mono_compile_method_checked (m, &error);
-       mono_error_assert_ok (&error);
+       mono_error_raise_exception (&error);
        g_assert (addr);
 
        addr = mini_add_method_wrappers_llvmonly (m, addr, FALSE, need_unbox_tramp, &arg);
@@ -1816,12 +1821,16 @@ mono_llvmonly_init_delegate (MonoDelegate *del)
         * but we don't have a a structure which could own its memory.
         */
        if (G_UNLIKELY (!ftndesc)) {
-               gpointer addr = mono_compile_method_checked (del->method, &error);
+               MonoMethod *m = del->method;
+               if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
+                       m = mono_marshal_get_synchronized_wrapper (m);
+
+               gpointer addr = mono_compile_method_checked (m, &error);
                if (mono_error_set_pending_exception (&error))
                        return;
 
-               if (del->method->klass->valuetype && mono_method_signature (del->method)->hasthis)
-                   addr = mono_aot_get_unbox_trampoline (del->method);
+               if (m->klass->valuetype && mono_method_signature (m)->hasthis)
+                   addr = mono_aot_get_unbox_trampoline (m);
 
                gpointer arg = mini_get_delegate_arg (del->method, addr);
 
@@ -1842,6 +1851,9 @@ mono_llvmonly_init_delegate_virtual (MonoDelegate *del, MonoObject *target, Mono
 
        method = mono_object_get_virtual_method (target, method);
 
+       if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
+               method = mono_marshal_get_synchronized_wrapper (method);
+
        del->method = method;
        del->method_ptr = mono_compile_method_checked (method, &error);
        if (mono_error_set_pending_exception (&error))
index 78273ea20ded7003986b6263cec58c7ca4ab481d..d0232dd540fe9da0b8d36379f37b14fad2b433be 100644 (file)
@@ -9745,6 +9745,20 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
 
                        inline_costs += 10 * num_calls++;
 
+                       /*
+                        * Synchronized wrappers.
+                        * Its hard to determine where to replace a method with its synchronized
+                        * wrapper without causing an infinite recursion. The current solution is
+                        * to add the synchronized wrapper in the trampolines, and to
+                        * change the called method to a dummy wrapper, and resolve that wrapper
+                        * to the real method in mono_jit_compile_method ().
+                        */
+                       if (cfg->method->wrapper_type == MONO_WRAPPER_SYNCHRONIZED) {
+                               MonoMethod *orig = mono_marshal_method_from_wrapper (cfg->method);
+                               if (cmethod == orig || (cmethod->is_inflated && mono_method_get_declaring_generic_method (cmethod) == orig))
+                                       cmethod = mono_marshal_get_synchronized_inner_wrapper (cmethod);
+                       }
+
                        /*
                         * Making generic calls out of gsharedvt methods.
                         * This needs to be used for all generic calls, not just ones with a gsharedvt signature, to avoid
@@ -9964,20 +9978,6 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                                }
                        }
 
-                       /* 
-                        * Synchronized wrappers.
-                        * Its hard to determine where to replace a method with its synchronized
-                        * wrapper without causing an infinite recursion. The current solution is
-                        * to add the synchronized wrapper in the trampolines, and to
-                        * change the called method to a dummy wrapper, and resolve that wrapper
-                        * to the real method in mono_jit_compile_method ().
-                        */
-                       if (cfg->method->wrapper_type == MONO_WRAPPER_SYNCHRONIZED) {
-                               MonoMethod *orig = mono_marshal_method_from_wrapper (cfg->method);
-                               if (cmethod == orig || (cmethod->is_inflated && mono_method_get_declaring_generic_method (cmethod) == orig))
-                                       cmethod = mono_marshal_get_synchronized_inner_wrapper (cmethod);
-                       }
-
                        /*
                         * Virtual calls in llvm-only mode.
                         */
@@ -11330,6 +11330,11 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
 
                                        MONO_EMIT_NULL_CHECK (cfg, sp [0]->dreg);
 
+                                       if (ins_flag & MONO_INST_VOLATILE) {
+                                               /* Volatile stores have release semantics, see 12.6.7 in Ecma 335 */
+                                               emit_memory_barrier (cfg, MONO_MEMORY_BARRIER_REL);
+                                       }
+
                                        if (mini_is_gsharedvt_klass (klass)) {
                                                MonoInst *offset_ins;
 
index e1e2eb19b430c0040972a551caad3acf31f757a0..aca368c9dba9e1ad8ef382fa8e7532a93981ffe5 100644 (file)
@@ -607,6 +607,7 @@ inflate_info (MonoRuntimeGenericContextInfoTemplate *oti, MonoGenericContext *co
                MonoMethod *inflated_method;
                MonoType *inflated_type = mono_class_inflate_generic_type_checked (&method->klass->byval_arg, context, &error);
                mono_error_assert_ok (&error); /* FIXME don't swallow the error */
+               WrapperInfo *winfo = NULL;
 
                MonoClass *inflated_class = mono_class_from_mono_type (inflated_type);
                MonoJumpInfoGSharedVtCall *res;
@@ -620,7 +621,13 @@ inflate_info (MonoRuntimeGenericContextInfoTemplate *oti, MonoGenericContext *co
 
                mono_class_init (inflated_class);
 
-               g_assert (!method->wrapper_type);
+               if (method->wrapper_type) {
+                       winfo = mono_marshal_get_wrapper_info (method);
+
+                       g_assert (winfo);
+                       g_assert (winfo->subtype == WRAPPER_SUBTYPE_SYNCHRONIZED_INNER);
+                       method = winfo->d.synchronized_inner.method;
+               }
 
                if (inflated_class->byval_arg.type == MONO_TYPE_ARRAY ||
                                inflated_class->byval_arg.type == MONO_TYPE_SZARRAY) {
@@ -633,6 +640,12 @@ inflate_info (MonoRuntimeGenericContextInfoTemplate *oti, MonoGenericContext *co
                }
                mono_class_init (inflated_method->klass);
                g_assert (inflated_method->klass == inflated_class);
+
+               if (winfo) {
+                       g_assert (winfo->subtype == WRAPPER_SUBTYPE_SYNCHRONIZED_INNER);
+                       inflated_method = mono_marshal_get_synchronized_inner_wrapper (inflated_method);
+               }
+
                res->method = inflated_method;
 
                return res;
@@ -1758,6 +1771,9 @@ instantiate_info (MonoDomain *domain, MonoRuntimeGenericContextInfoTemplate *oti
 
                g_assert (method->is_inflated);
 
+               if (mono_llvm_only && (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED))
+                       method = mono_marshal_get_synchronized_wrapper (method);
+
                if (!virtual_) {
                        addr = mono_compile_method_checked (method, error);
                        return_val_if_nok (error, NULL);
index e3219686ae2cf5beb7eb8ea5adb7fc9987e51d86..425eea95ed81854b1d84e0637c7a0929dc3dbbc7 100644 (file)
@@ -54,10 +54,20 @@ mono_llvm_build_alloca (LLVMBuilderRef builder, LLVMTypeRef Ty,
 
 LLVMValueRef 
 mono_llvm_build_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
-                                         const char *Name, gboolean is_volatile, BarrierKind barrier)
+                                         const char *Name, gboolean is_volatile)
 {
        LoadInst *ins = unwrap(builder)->CreateLoad(unwrap(PointerVal), is_volatile, Name);
 
+       return wrap(ins);
+}
+
+LLVMValueRef
+mono_llvm_build_atomic_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
+                                                        const char *Name, gboolean is_volatile, int alignment, BarrierKind barrier)
+{
+       LoadInst *ins = unwrap(builder)->CreateLoad(unwrap(PointerVal), is_volatile, Name);
+
+       ins->setAlignment (alignment);
        switch (barrier) {
        case LLVM_BARRIER_NONE:
                break;
index 06858713f4eaa99ab63cacd0d6449007fb203876..064c587ce54d5773cf59881f420947ea1d302d81 100644 (file)
@@ -44,9 +44,13 @@ mono_llvm_build_alloca (LLVMBuilderRef builder, LLVMTypeRef Ty,
 
 LLVMValueRef 
 mono_llvm_build_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
-                                         const char *Name, gboolean is_volatile, BarrierKind barrier);
+                                         const char *Name, gboolean is_volatile);
 
 LLVMValueRef 
+mono_llvm_build_atomic_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
+                                                        const char *Name, gboolean is_volatile, int alignment, BarrierKind barrier);
+
+LLVMValueRef
 mono_llvm_build_aligned_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
                                                          const char *Name, gboolean is_volatile, int alignment);
 
index 55bdb27e7912ca542b6b022cab3c259ffcda7b6c..e2f963bff0461fef64bb49cb4b48b6efddff8916 100644 (file)
@@ -1958,15 +1958,18 @@ emit_load_general (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder
                 * LLVM will generate invalid code when encountering a load from a
                 * NULL address.
                 */
-                res = mono_llvm_build_load (*builder_ref, addr, name, is_faulting, barrier);
+               if (barrier != LLVM_BARRIER_NONE)
+                       res = mono_llvm_build_atomic_load (*builder_ref, addr, name, is_faulting, size, barrier);
+               else
+                       res = mono_llvm_build_load (*builder_ref, addr, name, is_faulting);
 
-                /* Mark it with a custom metadata */
-                /*
-                if (is_faulting)
-                        set_metadata_flag (res, "mono.faulting.load");
-                */
+               /* Mark it with a custom metadata */
+               /*
+                 if (is_faulting)
+                 set_metadata_flag (res, "mono.faulting.load");
+               */
 
-                return res;
+               return res;
        }
 }
 
@@ -3364,7 +3367,7 @@ process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref,
                if (!ctx->imt_rgctx_loc)
                        ctx->imt_rgctx_loc = build_alloca_llvm_type (ctx, ctx->module->ptr_type, sizeof (gpointer));
                LLVMBuildStore (builder, convert (ctx, ctx->values [call->rgctx_arg_reg], ctx->module->ptr_type), ctx->imt_rgctx_loc);
-               args [cinfo->rgctx_arg_pindex] = mono_llvm_build_load (builder, ctx->imt_rgctx_loc, "", TRUE, LLVM_BARRIER_NONE);
+               args [cinfo->rgctx_arg_pindex] = mono_llvm_build_load (builder, ctx->imt_rgctx_loc, "", TRUE);
 #else
                args [cinfo->rgctx_arg_pindex] = convert (ctx, values [call->rgctx_arg_reg], ctx->module->ptr_type);
 #endif
@@ -3377,7 +3380,7 @@ process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref,
                if (!ctx->imt_rgctx_loc)
                        ctx->imt_rgctx_loc = build_alloca_llvm_type (ctx, ctx->module->ptr_type, sizeof (gpointer));
                LLVMBuildStore (builder, convert (ctx, ctx->values [call->imt_arg_reg], ctx->module->ptr_type), ctx->imt_rgctx_loc);
-               args [cinfo->imt_arg_pindex] = mono_llvm_build_load (builder, ctx->imt_rgctx_loc, "", TRUE, LLVM_BARRIER_NONE);
+               args [cinfo->imt_arg_pindex] = mono_llvm_build_load (builder, ctx->imt_rgctx_loc, "", TRUE);
 #else
                args [cinfo->imt_arg_pindex] = convert (ctx, values [call->imt_arg_reg], ctx->module->ptr_type);
 #endif
@@ -5449,8 +5452,7 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
                case OP_ATOMIC_LOAD_U8:
                case OP_ATOMIC_LOAD_R4:
                case OP_ATOMIC_LOAD_R8: {
-                       //#if LLVM_API_VERSION > 100
-#if 0
+#if LLVM_API_VERSION > 100
                        int size;
                        gboolean sext, zext;
                        LLVMTypeRef t;
@@ -5501,10 +5503,12 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
                        BarrierKind barrier = (BarrierKind) ins->backend.memory_barrier_kind;
                        LLVMValueRef index, addr, value, base;
 
+#if LLVM_API_VERSION < 100
                        if (!cfg->llvm_only) {
                                set_failure (ctx, "atomic mono.store intrinsic");
                                break;
                        }
+#endif
 
                        if (!values [ins->inst_destbasereg]) {
                            set_failure (ctx, "inst_destbasereg");
@@ -5597,7 +5601,7 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
                         *   mono_threads_state_poll ();
                         * FIXME: Use a preserveall wrapper
                         */
-                       val = mono_llvm_build_load (builder, convert (ctx, lhs, LLVMPointerType (IntPtrType (), 0)), "", TRUE, LLVM_BARRIER_NONE);
+                       val = mono_llvm_build_load (builder, convert (ctx, lhs, LLVMPointerType (IntPtrType (), 0)), "", TRUE);
                        cmp = LLVMBuildICmp (builder, LLVMIntEQ, val, LLVMConstNull (LLVMTypeOf (val)), "");
                        poll_bb = gen_bb (ctx, "POLL_BB");
                        cont_bb = gen_bb (ctx, "CONT_BB");
@@ -8676,6 +8680,9 @@ mono_llvm_emit_aot_module (const char *filename, const char *cu_name)
                while (g_hash_table_iter_next (&iter, (void**)&method, (void**)&callers)) {
                        LLVMValueRef lmethod;
 
+                       if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
+                               continue;
+
                        lmethod = (LLVMValueRef)g_hash_table_lookup (module->method_to_lmethod, method);
                        if (lmethod) {
                                for (l = callers; l; l = l->next) {
index 1bef455a1ee74fbc73b6cd8ee286a4e7aa0c92d0..83420c5224454b776c59d42a65d582694ffa7fcb 100644 (file)
@@ -1810,6 +1810,10 @@ mono_jit_compile_method_with_opt (MonoMethod *method, guint32 opt, MonoError *er
 
        mono_error_init (error);
 
+       if (mono_llvm_only)
+               /* Should be handled by the caller */
+               g_assert (!(method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED));
+
        /*
         * ICALL wrappers are handled specially, since there is only one copy of them
         * shared by all appdomains.
index da6f70e82b331cd8bf57073534697ee4ea43444a..fbc9674fb52702f0c2a3cc0100b36a9d93f35393 100644 (file)
@@ -1509,6 +1509,9 @@ mono_create_jit_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *e
        mono_error_init (error);
 
        if (mono_aot_only) {
+               if (mono_llvm_only && method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
+                       method = mono_marshal_get_synchronized_wrapper (method);
+
                /* Avoid creating trampolines if possible */
                gpointer code = mono_jit_find_compiled_method (domain, method);