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

Martin Däumler mdae at cs.tu-chemnitz.de
Tue May 31 07:43:25 EDT 2011


On 30.05.11 16:50, Rodrigo Kumpera wrote:
> The fix is to actually disable jmp to synchronized methods and use a
> regular call.
>
>
> On Mon, May 30, 2011 at 11:46 AM, Martin Däumler <mdae at cs.tu-chemnitz.de
> <mailto:mdae at cs.tu-chemnitz.de>> wrote:
>
>     Hello,
>
>     maybe there might be a problem with a optimization in the jump
>     trampoline code. In the IL code example appended, the main method
>     creates two threads that start with a method that jumps to a
>     synchronized method. The final value of the variable "count"
>     should be 20, but it isn't always so. If you change the jump
>     instruction to call instruction, the code works as expected. I
>     tested with Mono 2.6.1, 2.6.7 and 2.10.2 on an x86 machine
>     running Linux.
>
>     In "mono_postprocess_patches()", the handle to the method is stored
>     in the hash table "jump_target_hash". When the synchronized method
>     ("tolleMethode()") is jumped to the first time, the magic trampoline
>     creates a wrapper and returns the address of the wrapper. The first
>     jump instruction is patched with that address. A later lookup in the
>     "jump_target_hash" ("mono_jit_compile_method_inner()", in the scope
>     of the JIT-compilation of the wrapper) doesn't return pending jump
>     patches because the method handle of "tolleMethod()" is stored,
>     instead of the wrapper's handle. So, the second jump instruction
>     is not patched (if it is JIT-compiled so far).
>
>     Even worse: When the wrapper is executed, the method "tolleMethode()"
>     is JIT-compiled. Then, in "mono_jit_compile_method_inner()", there
>     is a hash hit and the second jump instruction is patched with
>     the method's address instead of her wrapper's one. So, I suggest to
>     check for a synchronized method in "mono_postprocess_patches()",
>     to create a wrapper if needed and to change the patch's target
>     method to the wrapper. There might be other problems I don't see?

Hello,

this "fix" would work but I believe this problem targets all methods
that need a wrapper, doesn't it?


With kind regards,
Martin Däumler


More information about the Mono-devel-list mailing list