A deadlock occures when compiling a code with recursive calls:
public static void x(int x) {
    if (x == 0)
        x(1);
}

The solution is not to try to lock the mutex if the invoke target
points to the same compilation_unit as the currently compiling one.

Signed-off-by: Tomek Grabiec <[email protected]>
---
 arch/x86/insn-selector_32.brg |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg
index 0413593..fe37565 100644
--- a/arch/x86/insn-selector_32.brg
+++ b/arch/x86/insn-selector_32.brg
@@ -440,15 +440,21 @@ reg:      EXPR_INVOKE(arg) 1
        method  = expr->target_method;
        cu      = method->compilation_unit;
 
-       pthread_mutex_lock(&cu->mutex);
-       is_compiled = cu->is_compiled;
-
-       if (is_compiled)
-               target = method_native_ptr(method);
-       else
+       if (cu == s->b_parent) {
+               /* This is a recursive invoke */
+               is_compiled = false;
                target = method_trampoline_ptr(method);
+       } else {
+               pthread_mutex_lock(&cu->mutex);
+               is_compiled = cu->is_compiled;
 
-       pthread_mutex_unlock(&cu->mutex);
+               if (is_compiled)
+                       target = method_native_ptr(method);
+               else
+                       target = method_trampoline_ptr(method);
+
+               pthread_mutex_unlock(&cu->mutex);
+       }
 
        var = get_fixed_var(s->b_parent, REG_EAX);
        state->reg1 = var;
-- 
1.6.0.6


------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to