[aot] Small AOT changes. Save some constants into the AOT image instead of duplicatin...
authorZoltan Varga <vargaz@gmail.com>
Tue, 29 Oct 2013 16:23:33 +0000 (17:23 +0100)
committerZoltan Varga <vargaz@gmail.com>
Tue, 29 Oct 2013 16:23:33 +0000 (17:23 +0100)
mono/mini/aot-compiler.c
mono/mini/aot-runtime.c
mono/mini/mini.h

index 849ed2de49c314907a3fa4e2ba98e8a4e3d42a59..6aef6f11f2ce3f8d361091e7bf4f58cff853de7a 100755 (executable)
@@ -188,10 +188,12 @@ typedef struct MonoAotCompile {
        guint32 final_got_size;
        /* Number of GOT entries reserved for trampolines */
        guint32 num_trampoline_got_entries;
+       guint32 tramp_page_size;
 
        guint32 num_trampolines [MONO_AOT_TRAMP_NUM];
        guint32 trampoline_got_offset_base [MONO_AOT_TRAMP_NUM];
        guint32 trampoline_size [MONO_AOT_TRAMP_NUM];
+       guint32 tramp_page_code_offsets [MONO_AOT_TRAMP_NUM];
 
        MonoAotOptions aot_opts;
        guint32 nmethods;
@@ -686,7 +688,7 @@ arch_init (MonoAotCompile *acfg)
  * calling code.
  */
 static void
-arch_emit_direct_call (MonoAotCompile *acfg, const char *target, gboolean external, int *call_size)
+arch_emit_direct_call (MonoAotCompile *acfg, const char *target, gboolean external, MonoJumpInfo *ji, int *call_size)
 {
 #if defined(TARGET_X86) || defined(TARGET_AMD64)
        /* Need to make sure this is exactly 5 bytes long */
@@ -1034,6 +1036,8 @@ arch_emit_specific_trampoline_pages (MonoAotCompile *acfg)
        if (!acfg->aot_opts.use_trampolines_page)
                return;
 
+       acfg->tramp_page_size = mono_pagesize ();
+
        sprintf (symbol, "%sspecific_trampolines_page", acfg->user_symbol_prefix);
        emit_alignment (acfg, mono_pagesize ());
        emit_global (acfg, symbol, TRUE);
@@ -4646,7 +4650,7 @@ emit_and_reloc_code (MonoAotCompile *acfg, MonoMethod *method, guint8 *code, gui
                                if (direct_call) {
                                        int call_size;
 
-                                       arch_emit_direct_call (acfg, direct_call_target, external_call, &call_size);
+                                       arch_emit_direct_call (acfg, direct_call_target, external_call, patch_info, &call_size);
                                        i += call_size - 1;
                                } else {
                                        int code_size;
@@ -5734,6 +5738,8 @@ emit_trampoline_full (MonoAotCompile *acfg, int got_offset, MonoTrampInfo *info,
        MonoJumpInfo *ji;
        GSList *unwind_ops;
 
+       g_assert (info);
+
        name = info->name;
        code = info->code;
        code_size = info->code_size;
@@ -6048,6 +6054,7 @@ emit_trampolines (MonoAotCompile *acfg)
                        }
 
                        emit_label (acfg, end_symbol);
+                       emit_int32 (acfg, 0);
                }
 
                arch_emit_specific_trampoline_pages (acfg);
@@ -7200,6 +7207,7 @@ emit_code (MonoAotCompile *acfg)
        }
        sprintf (symbol, "unbox_trampolines_end");
        emit_label (acfg, symbol);
+       emit_int32 (acfg, 0);
 }
 
 static void
@@ -8122,6 +8130,9 @@ emit_file_info (MonoAotCompile *acfg)
        emit_int32 (acfg, __alignof__ (gint64));
 #endif
        emit_int32 (acfg, MONO_TRAMPOLINE_NUM);
+       emit_int32 (acfg, acfg->tramp_page_size);
+       for (i = 0; i < MONO_AOT_TRAMP_NUM; ++i)
+               emit_int32 (acfg, acfg->tramp_page_code_offsets [i]);
 
        if (acfg->aot_opts.static_link) {
                char *p;
@@ -8624,7 +8635,7 @@ mono_compile_assembly (MonoAssembly *ass, guint32 opts, const char *aot_options)
        acfg->aot_opts.nrgctx_fetch_trampolines = 128;
        acfg->aot_opts.ngsharedvt_arg_trampolines = 128;
        acfg->aot_opts.llvm_path = g_strdup ("");
-#if MONOTOUCH
+#ifdef MONOTOUCH
        acfg->aot_opts.use_trampolines_page = TRUE;
 #endif
 
index bff826bf63b7459ffb9223d4a83fd19811caa36b..0eddbe6a8be3902766cc7c18a3fedf0aefbd5ab2 100644 (file)
@@ -104,9 +104,7 @@ typedef struct MonoAotModule {
        guint8 *plt_end;
        guint8 *blob;
        gint32 *code_offsets;
-#ifdef MONOTOUCH
        gpointer *method_addresses;
-#endif
        /* This contains <offset, index> pairs sorted by offset */
        /* This is needed because LLVM emitted methods can be in any order */
        gint32 *sorted_code_offsets;
@@ -1730,9 +1728,7 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
        }
 
        amodule->code_offsets = info->code_offsets;
-#ifdef MONOTOUCH
        amodule->method_addresses = info->method_addresses;
-#endif
        amodule->code = info->methods;
 #ifdef TARGET_ARM
        /* Mask out thumb interop bit */
@@ -1766,7 +1762,7 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
                amodule->code_offsets = g_malloc0 (amodule->info.nmethods * sizeof (gint32));
                for (i = 0; i < amodule->info.nmethods; ++i) {
                        /* method_addresses () contains a table of branches, since the ios linker can update those correctly */
-                       void *addr = get_arm_bl_target ((guint32*)(amodule->method_addresses + i));
+                       void *addr = get_arm_bl_target ((guint32*)amodule->method_addresses + i);
 
                        if (addr == amodule->method_addresses)
                                amodule->code_offsets [i] = 0xffffffff;
@@ -4279,14 +4275,16 @@ get_new_trampoline_from_page (int tramp_type)
        vm_address_t addr, taddr;
        kern_return_t ret;
        vm_prot_t prot, max_prot;
-       int psize;
+       int psize, specific_trampoline_size;
        unsigned char *code;
 
+       specific_trampoline_size = 2 * sizeof (gpointer);
+
        mono_aot_page_lock ();
        page = trampoline_pages [tramp_type];
        if (page && page->trampolines < page->trampolines_end) {
                code = page->trampolines;
-               page->trampolines += 8;
+               page->trampolines += specific_trampoline_size;
                mono_aot_page_unlock ();
                return code;
        }
@@ -4299,6 +4297,8 @@ get_new_trampoline_from_page (int tramp_type)
        amodule = image->aot_module;
        g_assert (amodule);
 
+       g_assert (amodule->info.tramp_page_size == psize);
+
        if (tramp_type == MONO_AOT_TRAMP_SPECIFIC)
                tpage = load_function (amodule, "specific_trampolines_page");
        else if (tramp_type == MONO_AOT_TRAMP_STATIC_RGCTX)
@@ -4342,7 +4342,7 @@ get_new_trampoline_from_page (int tramp_type)
                /* some other thread already allocated, so use that to avoid wasting memory */
                if (page && page->trampolines < page->trampolines_end) {
                        code = page->trampolines;
-                       page->trampolines += 8;
+                       page->trampolines += specific_trampoline_size;
                        mono_aot_page_unlock ();
                        vm_deallocate (mach_task_self (), addr, psize);
                        vm_deallocate (mach_task_self (), taddr, psize);
@@ -4454,7 +4454,7 @@ get_numerous_trampoline (MonoAotTrampoline tramp_type, int n_got_slots, MonoAotM
        *out_amodule = amodule;
 
 #ifdef MONOTOUCH
-#define        MONOTOUCH_TRAMPOLINES_ERROR ". See http://docs.xamarin.com/ios/troubleshooting for instruction on how to fix this condition"
+#define        MONOTOUCH_TRAMPOLINES_ERROR ". See http://docs.xamarin.com/ios/troubleshooting for instructions on how to fix this condition."
 #else
 #define        MONOTOUCH_TRAMPOLINES_ERROR ""
 #endif
index 8d363f0371d83809a7c2ad910f5cb089869c1dc9..7fe35b4d24230f3e6edaa1d5b77fdc78936e557b 100644 (file)
 #endif
 
 /* Version number of the AOT file format */
-#define MONO_AOT_FILE_VERSION 95
+#define MONO_AOT_FILE_VERSION 96
 
 //TODO: This is x86/amd64 specific.
 #define mono_simd_shuffle_mask(a,b,c,d) ((a) | ((b) << 2) | ((c) << 4) | ((d) << 6))