Merge pull request #3240 from alexanderkyte/aot_compiler_leaks
[mono.git] / mono / mini / method-to-ir.c
index ef28c27dedde0f938a8146a5998072fec0e8e55f..7f3c4f7e9c803d6ce2bbdae62bd5cee68638ed75 100644 (file)
@@ -9748,6 +9748,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
@@ -9967,20 +9981,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.
                         */
@@ -11333,6 +11333,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;