Mon Jan 19 17:44:50 CET 2004 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / mini / aot.c
index 8f1a00801d20225ce297e4adef06df0b4792b8d1..a24419d440eff910468080f669dca3d5c3212713 100644 (file)
@@ -170,9 +170,11 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
                        if (!info->image_table [i]) {
                                if (mono_aot_verbose > 0)
                                        printf ("AOT module %s is out of date.\n", aot_name);
-                               g_free (info->methods);
+                               mono_g_hash_table_destroy (info->methods);
                                g_free (info->image_table);
+#ifndef HAVE_BOEHM_GC
                                g_free (info);
+#endif
                                g_free (aot_name);
                                g_module_close (assembly->aot_module);
                                assembly->aot_module = NULL;
@@ -248,6 +250,9 @@ mono_aot_get_method_inner (MonoDomain *domain, MonoMethod *method)
        if (!method->token)
                return NULL;
 
+       if (mono_profiler_get_events () & MONO_PROFILE_ENTER_LEAVE)
+               return NULL;
+
        if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
                (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
                (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
@@ -283,11 +288,11 @@ mono_aot_get_method_inner (MonoDomain *domain, MonoMethod *method)
                        memcpy (code, minfo->info->code_start, minfo->info->code_size);
 
                        if (mono_aot_verbose > 1)
-                               printf ("REUSE METHOD: %s %p - %p.\n", mono_method_full_name (method, TRUE), code, (char*)code + code_len);
+                               printf ("REUSE METHOD: %s %p - %p.\n", mono_method_full_name (method, TRUE), code, (char*)code + minfo->info->code_size);
 
                        /* Do this outside the lock to avoid deadlocks */
                        LeaveCriticalSection (&aot_mutex);
-                       mono_arch_patch_code (method, domain, code, minfo->patch_info);
+                       mono_arch_patch_code (method, domain, code, minfo->patch_info, TRUE);
                        EnterCriticalSection (&aot_mutex);
 
                        /* Relocate jinfo */
@@ -410,7 +415,7 @@ mono_aot_get_method_inner (MonoDomain *domain, MonoMethod *method)
                gpointer *table;
                int pages;
                int i, err;
-               guint32 last_offset;
+               guint32 last_offset, buf_len;
 
                if (aot_module->opts & MONO_OPT_SHARED)
                        mp = mono_mempool_new ();
@@ -521,7 +526,8 @@ mono_aot_get_method_inner (MonoDomain *domain, MonoMethod *method)
                        case MONO_PATCH_INFO_LDSTR:
                        case MONO_PATCH_INFO_LDTOKEN:
                        case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
-                               ji->data.target = *data;
+                               image = aot_module->image_table [(int)data [0]];
+                               ji->data.token = mono_jump_info_token_new (mp, image, (int)data [1]);
                                break;
                        case MONO_PATCH_INFO_EXC_NAME:
                                ji->data.klass = decode_class_info (aot_module, data);
@@ -542,6 +548,11 @@ mono_aot_get_method_inner (MonoDomain *domain, MonoMethod *method)
                        patch_info = ji;
                }
 
+               info = (gpointer)((guint8*)info + 4);
+               buf_len = *(guint32*)info;
+               info = (gpointer)((guint8*)info + 4);
+               mono_debug_add_aot_method (domain, method, code, (guint8*)info, buf_len);
+
                if (use_loaded_code) {
                /* disable write protection */
 #ifndef PLATFORM_WIN32
@@ -559,7 +570,7 @@ mono_aot_get_method_inner (MonoDomain *domain, MonoMethod *method)
 
                /* Do this outside the lock to avoid deadlocks */
                LeaveCriticalSection (&aot_mutex);
-               mono_arch_patch_code (method, domain, code, patch_info);
+               mono_arch_patch_code (method, domain, code, patch_info, TRUE);
                EnterCriticalSection (&aot_mutex);
 
                if (aot_module->opts & MONO_OPT_SHARED)
@@ -906,7 +917,8 @@ emit_method (MonoAotCompile *acfg, MonoCompile *cfg)
                case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
                        fprintf (tmpfp, "\t.align 8\n");
                        fprintf (tmpfp, "%s_p_%d:\n", mname, j);
-                       fprintf (tmpfp, "\t.long 0x%08x\n", patch_info->data.token);
+                       fprintf (tmpfp, "\t.long 0x%08x\n", get_image_index (acfg, patch_info->data.token->image));
+                       fprintf (tmpfp, "\t.long 0x%08x\n", patch_info->data.token->token);
                        j++;
                        break;
                default:
@@ -1030,6 +1042,21 @@ emit_method (MonoAotCompile *acfg, MonoCompile *cfg)
        /* NULL terminated array */
        fprintf (tmpfp, "\t.long 0\n");
 
+       {
+               guint8 *buf;
+               guint32 buf_len;
+
+               mono_debug_serialize_debug_info (cfg, &buf, &buf_len);
+
+               fprintf (tmpfp, "\t.long %d\n", buf_len);
+
+               for (i = 0; i < buf_len; ++i)
+                       fprintf (tmpfp, ".byte %d\n", (unsigned int) buf [i]);
+
+               if (buf_len > 0)
+                       g_free (buf);
+       }
+
        /* fixme: save the rest of the required infos */
 
        g_free (mname);
@@ -1050,7 +1077,7 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts)
        MonoAotCompile *acfg;
        gboolean *emitted;
 
-       printf ("Mono AOT compiler - compiling assembly %s\n", image->name);
+       printf ("Mono Ahead of Time compiler - compiling assembly %s\n", image->name);
 
        i = g_file_open_tmp ("mono_aot_XXXXXX", &tmpfname, NULL);
        tmpfp = fdopen (i, "w+");
@@ -1103,7 +1130,7 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts)
                //printf ("START:           %s\n", mono_method_full_name (method, TRUE));
                //mono_compile_method (method);
 
-               cfg = mini_method_compile (method, opts, mono_root_domain, 0);
+               cfg = mini_method_compile (method, opts, mono_root_domain, FALSE, 0);
                g_assert (cfg);
 
                if (cfg->disable_aot) {
@@ -1234,11 +1261,11 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts)
        system (com);
        g_free (com);*/
 
-       printf ("Compiled %d out of %d methods (%d%%)\n", ccount, mcount, (ccount*100)/mcount);
-       printf ("%d methods contain absolute addresses (%d%%)\n", abscount, (abscount*100)/mcount);
-       printf ("%d methods contain wrapper references (%d%%)\n", wrappercount, (wrappercount*100)/mcount);
-       printf ("%d methods contain lmf pointers (%d%%)\n", lmfcount, (lmfcount*100)/mcount);
-       printf ("%d methods have other problems (%d%%)\n", ocount, (ocount*100)/mcount);
+       printf ("Compiled %d out of %d methods (%d%%)\n", ccount, mcount, mcount ? (ccount*100)/mcount : 100);
+       printf ("%d methods contain absolute addresses (%d%%)\n", abscount, mcount ? (abscount*100)/mcount : 100);
+       printf ("%d methods contain wrapper references (%d%%)\n", wrappercount, mcount ? (wrappercount*100)/mcount : 100);
+       printf ("%d methods contain lmf pointers (%d%%)\n", lmfcount, mcount ? (lmfcount*100)/mcount : 100);
+       printf ("%d methods have other problems (%d%%)\n", ocount, mcount ? (ocount*100)/mcount : 100);
        unlink (tmpfname);
 
        return 0;