Author: zoltan
Date: 2005-06-18 10:11:54 -0400 (Sat, 18 Jun 2005)
New Revision: 46187
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/aot.c
trunk/mono/mono/mini/mini.h
trunk/mono/mono/mini/tramp-x86.c
Log:
2005-06-18 Zoltan Varga <[EMAIL PROTECTED]>
* aot.c: Lower memory usage while loading AOT methods.
* tramp-x86.c: Avoid allocating+freeing MonoJitInfo structures.
* mini.h: Bump AOT file format version.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2005-06-18 13:15:18 UTC (rev 46186)
+++ trunk/mono/mono/mini/ChangeLog 2005-06-18 14:11:54 UTC (rev 46187)
@@ -1,3 +1,11 @@
+2005-06-18 Zoltan Varga <[EMAIL PROTECTED]>
+
+ * aot.c: Lower memory usage while loading AOT methods.
+
+ * tramp-x86.c: Avoid allocating+freeing MonoJitInfo structures.
+
+ * mini.h: Bump AOT file format version.
+
2005-06-17 Zoltan Varga <[EMAIL PROTECTED]>
* mini.c (mono_method_to_ir): Allow STACK_PTR as input to SWITCH.
Modified: trunk/mono/mono/mini/aot.c
===================================================================
--- trunk/mono/mono/mini/aot.c 2005-06-18 13:15:18 UTC (rev 46186)
+++ trunk/mono/mono/mini/aot.c 2005-06-18 14:11:54 UTC (rev 46187)
@@ -73,6 +73,7 @@
MonoImage **image_table;
gboolean out_of_date;
guint8 *code;
+ guint8 *code_end;
guint32 *code_offsets;
guint8 *method_infos;
guint32 *method_info_offsets;
@@ -528,6 +529,7 @@
/* Read method and method_info tables */
g_module_symbol (assembly->aot_module, "method_offsets",
(gpointer*)&info->code_offsets);
g_module_symbol (assembly->aot_module, "methods",
(gpointer*)&info->code);
+ g_module_symbol (assembly->aot_module, "methods_end",
(gpointer*)&info->code_end);
g_module_symbol (assembly->aot_module, "method_info_offsets",
(gpointer*)&info->method_info_offsets);
g_module_symbol (assembly->aot_module, "method_infos",
(gpointer*)&info->method_infos);
g_module_symbol (assembly->aot_module, "class_infos",
(gpointer*)&info->class_infos);
@@ -747,8 +749,7 @@
guint code_len, used_int_regs, used_strings;
MonoJitInfo *jinfo;
MonoMemPool *mp;
- GPtrArray *patches;
- int i, pindex, got_index;
+ int i, pindex, got_index, n_patches;
gboolean non_got_patches, keep_patches = TRUE;
gboolean has_clauses;
guint8 *p;
@@ -817,7 +818,10 @@
keep_patches = FALSE;
#endif
- if (*p) {
+ n_patches = decode_value (p, &p);
+
+ if (n_patches) {
+ MonoJumpInfo *patches;
MonoImage *image;
gpointer *table;
int i;
@@ -831,11 +835,11 @@
/* First load the type + offset table */
last_offset = 0;
- patches = g_ptr_array_new ();
-
- while (*p) {
- MonoJumpInfo *ji = mono_mempool_alloc0 (mp, sizeof
(MonoJumpInfo));
+ patches = mono_mempool_alloc (mp, sizeof (MonoJumpInfo) *
n_patches);
+ for (pindex = 0; pindex < n_patches; ++pindex) {
+ MonoJumpInfo *ji = &patches [pindex];
+
#if defined(MONO_ARCH_HAVE_PIC_AOT)
ji->type = *p;
p ++;
@@ -860,19 +864,14 @@
ji->next = patch_info;
patch_info = ji;
-
- g_ptr_array_add (patches, ji);
}
- /* Null terminated array */
- p ++;
+ got_slots = g_malloc (sizeof (guint32) * n_patches);
+ memset (got_slots, 0xff, sizeof (guint32) * n_patches);
- got_slots = g_malloc (sizeof (guint32) * patches->len);
- memset (got_slots, 0xff, sizeof (guint32) * patches->len);
-
/* Then load the other data */
- for (pindex = 0; pindex < patches->len; ++pindex) {
- MonoJumpInfo *ji = g_ptr_array_index (patches, pindex);
+ for (pindex = 0; pindex < n_patches; ++pindex) {
+ MonoJumpInfo *ji = &patches [pindex];
switch (ji->type) {
case MONO_PATCH_INFO_CLASS:
@@ -1051,8 +1050,8 @@
/* Do this outside the lock to avoid deadlocks */
LeaveCriticalSection (&aot_mutex);
non_got_patches = FALSE;
- for (pindex = 0; pindex < patches->len; ++pindex) {
- MonoJumpInfo *ji = g_ptr_array_index (patches, pindex);
+ for (pindex = 0; pindex < n_patches; ++pindex) {
+ MonoJumpInfo *ji = &patches [pindex];
if (is_got_patch (ji->type)) {
if (!aot_module->got [got_slots [pindex]])
@@ -1079,7 +1078,6 @@
EnterCriticalSection (&aot_mutex);
#endif
- g_ptr_array_free (patches, TRUE);
g_free (got_slots);
if (!keep_patches)
@@ -1103,8 +1101,6 @@
}
cleanup:
- g_ptr_array_free (patches, TRUE);
-
/* FIXME: The space in domain->mp is wasted */
if (aot_module->opts & MONO_OPT_SHARED)
/* No need to cache patches */
@@ -1558,7 +1554,7 @@
MonoMethod *method;
GList *l;
FILE *tmpfp;
- int i, j, k, pindex, buf_size;
+ int i, j, k, pindex, buf_size, n_patches;
guint32 debug_info_size;
guint8 *code;
char *mname, *mname_p;
@@ -1634,6 +1630,22 @@
encode_value (first_got_offset, p, &p);
#endif
+ n_patches = 0;
+ for (pindex = 0; pindex < patches->len; ++pindex) {
+ patch_info = g_ptr_array_index (patches, pindex);
+
+ if ((patch_info->type == MONO_PATCH_INFO_LABEL) ||
+ (patch_info->type == MONO_PATCH_INFO_BB) ||
+ (patch_info->type == MONO_PATCH_INFO_GOT_OFFSET) ||
+ (patch_info->type == MONO_PATCH_INFO_NONE))
+ /* Nothing to do */
+ continue;
+
+ n_patches ++;
+ }
+
+ encode_value (n_patches, p, &p);
+
/* First emit the type+position table */
last_offset = 0;
j = 0;
@@ -1676,13 +1688,6 @@
#endif
}
- /*
- * 0 is PATCH_INFO_BB, which can't be in the file.
- */
- /* NULL terminated array */
- *p = 0;
- p ++;
-
/* Then emit the other info */
for (pindex = 0; pindex < patches->len; ++pindex) {
patch_info = g_ptr_array_index (patches, pindex);
@@ -2110,6 +2115,12 @@
emit_method_code (acfg, cfgs [i]);
}
+ symbol = g_strdup_printf ("methods_end");
+ emit_section_change (tmpfp, ".text", 0);
+ emit_global (tmpfp, symbol, FALSE);
+ emit_alignment (tmpfp, 8);
+ emit_label (tmpfp, symbol);
+
/* Emit method info */
symbol = g_strdup_printf ("method_infos");
emit_section_change (tmpfp, ".text", 1);
@@ -2117,6 +2128,10 @@
emit_alignment (tmpfp, 8);
emit_label (tmpfp, symbol);
+ /* To reduce size of generate assembly */
+ symbol = g_strdup_printf ("mi");
+ emit_label (tmpfp, symbol);
+
for (i = 0; i < image->tables [MONO_TABLE_METHOD].rows; ++i) {
if (cfgs [i])
emit_method_info (acfg, cfgs [i]);
@@ -2267,7 +2282,7 @@
sep = ",";
if (cfgs [i]) {
symbol = g_strdup_printf (".Lm_%x_p", i + 1);
- fprintf (tmpfp, "%s%s - method_infos", sep, symbol);
+ fprintf (tmpfp, "%s%s - mi", sep, symbol);
}
else
fprintf (tmpfp, "%s0", sep);
Modified: trunk/mono/mono/mini/mini.h
===================================================================
--- trunk/mono/mono/mini/mini.h 2005-06-18 13:15:18 UTC (rev 46186)
+++ trunk/mono/mono/mini/mini.h 2005-06-18 14:11:54 UTC (rev 46187)
@@ -43,7 +43,7 @@
#endif
/* Version number of the AOT file format */
-#define MONO_AOT_FILE_VERSION "19"
+#define MONO_AOT_FILE_VERSION "20"
#if 1
#define mono_bitset_test_fast(set,n) (((guint32*)set)[2+(n)/32] & (1 << ((n) %
32)))
Modified: trunk/mono/mono/mini/tramp-x86.c
===================================================================
--- trunk/mono/mono/mini/tramp-x86.c 2005-06-18 13:15:18 UTC (rev 46186)
+++ trunk/mono/mono/mini/tramp-x86.c 2005-06-18 14:11:54 UTC (rev 46187)
@@ -349,11 +349,10 @@
#define TRAMPOLINE_SIZE 10
-static MonoJitInfo*
-create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type,
MonoDomain *domain)
+static gpointer
+create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type,
MonoDomain *domain, guint32 *code_len)
{
guint8 *code, *buf, *tramp;
- MonoJitInfo *ji;
tramp = mono_get_trampoline_code (tramp_type);
@@ -365,23 +364,30 @@
x86_jump_code (buf, tramp);
g_assert ((buf - code) <= TRAMPOLINE_SIZE);
- ji = g_new0 (MonoJitInfo, 1);
- ji->code_start = code;
- ji->code_size = buf - code;
+ mono_arch_flush_icache (code, buf - code);
- mono_arch_flush_icache (ji->code_start, ji->code_size);
-
mono_jit_stats.method_trampolines++;
- return ji;
+ if (code_len)
+ *code_len = buf - code;
+
+ return code;
}
MonoJitInfo*
mono_arch_create_jump_trampoline (MonoMethod *method)
{
- MonoJitInfo *ji = create_specific_trampoline (method,
MONO_TRAMPOLINE_JUMP, mono_domain_get ());
+ MonoJitInfo *ji;
+ gpointer code;
+ guint32 code_size;
+ code = create_specific_trampoline (method, MONO_TRAMPOLINE_JUMP,
mono_domain_get (), &code_size);
+
+ ji = g_new0 (MonoJitInfo, 1);
+ ji->code_start = code;
+ ji->code_size = code_size;
ji->method = method;
+
return ji;
}
@@ -399,22 +405,13 @@
gpointer
mono_arch_create_jit_trampoline (MonoMethod *method)
{
- MonoJitInfo *ji;
- gpointer code_start;
-
- ji = create_specific_trampoline (method, MONO_TRAMPOLINE_GENERIC,
mono_domain_get ());
- code_start = ji->code_start;
- g_free (ji);
-
- return code_start;
+ return create_specific_trampoline (method, MONO_TRAMPOLINE_GENERIC,
mono_domain_get (), NULL);
}
gpointer
mono_arch_create_jit_trampoline_from_token (MonoImage *image, guint32 token)
{
MonoDomain *domain = mono_domain_get ();
- MonoJitInfo *ji;
- gpointer code_start;
guint8 *buf, *start;
mono_domain_lock (domain);
@@ -425,11 +422,7 @@
buf += sizeof (gpointer);
*(guint32*)buf = token;
- ji = create_specific_trampoline (start, MONO_TRAMPOLINE_AOT, domain);
- code_start = ji->code_start;
- g_free (ji);
-
- return code_start;
+ return create_specific_trampoline (start, MONO_TRAMPOLINE_AOT, domain,
NULL);
}
/**
@@ -446,14 +439,7 @@
gpointer
mono_arch_create_class_init_trampoline (MonoVTable *vtable)
{
- MonoJitInfo *ji;
- gpointer code;
-
- ji = create_specific_trampoline (vtable, MONO_TRAMPOLINE_CLASS_INIT,
vtable->domain);
- code = ji->code_start;
- g_free (ji);
-
- return code;
+ return create_specific_trampoline (vtable, MONO_TRAMPOLINE_CLASS_INIT,
vtable->domain, NULL);
}
void
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches