* ResourceReaderTest.cs: Add a little logic for finding
[mono.git] / mono / jit / trampoline.c
index 4d364992c3a7f2128ad0b327a9e6882689dd4819..5bbfd7fb3d3d690d3c5998e2c3cfc2ad95365d36 100644 (file)
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/tabledefs.h>
 #include <mono/arch/x86/x86-codegen.h>
+#include <mono/metadata/mono-debug-debugger.h>
 
 #include "jit.h"
 #include "codegen.h"
 
+/*
+ * Address of the x86 trampoline code.  This is used by the debugger to check
+ * whether a method is a trampoline.
+ */
+guint8 *mono_generic_trampoline_code = NULL;
+
 /*
  * get_unbox_trampoline:
  * @m: method pointer
@@ -97,8 +104,8 @@ x86_magic_trampoline (int eax, int ecx, int edx, int esi, int edi,
                        *((guint32*)(code + 2)) = (guint)addr - ((guint)code + 1) - 5; 
                        return addr;
                } else {
-                       printf ("%x %x %x %x %x %x \n", code [0], code [1], code [2], code [3],
-                               code [4], code [5]);
+                       printf ("Invalid trampoline sequence: %x %x %x %x %x %x %x\n", code [0], code [1], code [2], code [3],
+                               code [4], code [5], code [6]);
                        g_assert_not_reached ();
                }
        }
@@ -149,10 +156,7 @@ x86_magic_trampoline (int eax, int ecx, int edx, int esi, int edi,
 gpointer
 arch_create_jit_trampoline (MonoMethod *method)
 {
-       MonoDomain *domain = mono_domain_get ();
        guint8 *code, *buf;
-       static guint8 *vc = NULL;
-       GHashTable *jit_code_hash;
 
        /* previously created trampoline code */
        if (method->info)
@@ -169,24 +173,24 @@ arch_create_jit_trampoline (MonoMethod *method)
            (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)) {
                MonoMethod *nm;
                
-               nm = mono_marshal_get_native_wrapper (method);
-               method->info = mono_compile_method (nm);
-               return method->info;
-       }
+               if (!method->addr && (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
+                       mono_lookup_pinvoke_call (method);
 
-       /* check if we already have JITed code */
-       if (mono_jit_share_code)
-               jit_code_hash = mono_root_domain->jit_code_hash;
-       else
-               jit_code_hash = domain->jit_code_hash;
-
-       if ((code = g_hash_table_lookup (jit_code_hash, method))) {
-               mono_jit_stats.methods_lookups++;
-               return code;
+#ifdef MONO_USE_EXC_TABLES
+               if (mono_method_blittable (method)) {
+                       method->info = method->addr;
+               } else {
+#endif
+                       nm = mono_marshal_get_native_wrapper (method);
+                       method->info = mono_compile_method (nm);
+#ifdef MONO_USE_EXC_TABLES
+               }
+#endif
+               return method->info;
        }
 
-       if (!vc) {
-               vc = buf = g_malloc (256);
+       if (!mono_generic_trampoline_code) {
+               mono_generic_trampoline_code = buf = g_malloc (256);
                /* save caller save regs because we need to do a call */ 
                x86_push_reg (buf, X86_EDX);
                x86_push_reg (buf, X86_EAX);
@@ -253,12 +257,12 @@ arch_create_jit_trampoline (MonoMethod *method)
                /* call the compiled method */
                x86_jump_reg (buf, X86_EAX);
 
-               g_assert ((buf - vc) <= 256);
+               g_assert ((buf - mono_generic_trampoline_code) <= 256);
        }
 
        code = buf = g_malloc (16);
        x86_push_imm (buf, method);
-       x86_jump_code (buf, vc);
+       x86_jump_code (buf, mono_generic_trampoline_code);
        g_assert ((buf - code) <= 16);
 
        /* store trampoline address */