[Mono-dev] Jump trampoline threading problem with synchronized methods

Martin Däumler mdae at cs.tu-chemnitz.de
Thu Jun 9 03:41:25 EDT 2011

On 08.06.11 11:13 pm, Rodrigo Kumpera wrote:
> On Wed, Jun 8, 2011 at 10:49 AM, Martin Däumler <mdae at cs.tu-chemnitz.de
> <mailto:mdae at cs.tu-chemnitz.de>> wrote:
>     On 30.05.11 4:50 pm, Rodrigo Kumpera wrote:
>      > The fix is to actually disable jmp to synchronized methods and use a
>      > regular call.
>     Hello,
>     what is about the "LDFTN" IL-opcode? Mono's JIT-compiler emits
>     an internal jit call to "mono_ldftn()" that uses jump trampolines.
>     So I assume that the optimization also might bypass a wrapper
>     of the method going to be loaded.


I appended a test case. In the test case, two threads are started.
The threads execute the methods "jumpStart1()" and "jumpStart2()",
respectively. Those methods load a pointer to the synchronized
method "syncMethod()" via "ldftn". That method is called via
"calli" and it increments a static class variable ten times. So,
the expected output is "10" and "20", because the method
"syncMethod()" is synchronized. However, sometimes the output
is "10" and "10". I tested with Mono 2.6.1 on x86 Linux and
Mono 2.10.2 on Mac OS X. On .NET, it seems to work because
in all test runs the output was "10" and "20".

If I disable the jump trampoline optimization in
"mono_create_jump_trampoline()", "mono_jit_compile_method_inner()"
and "mono_post_process_patches()" it seems to work correctly.

With kind regards,
Martin Däumler
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: thread-ldftn.il
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110609/f3680d09/attachment-0001.pl 

More information about the Mono-devel-list mailing list