Author: zoltan
Date: 2008-02-21 07:55:47 -0500 (Thu, 21 Feb 2008)
New Revision: 96339
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/aot-compiler.c
trunk/mono/mono/mini/aot-runtime.c
trunk/mono/mono/mini/mini.c
trunk/mono/mono/mini/patch-info.h
Log:
2008-02-21 Zoltan Varga <[EMAIL PROTECTED]>
* aot-compiler.c (encode_patch): Handle ICALL_ADDR patch type.
* aot-runtime.c (decode_patch_info): Ditto.
* mini.c (mono_resolve_patch_target): Ditto.
* aot-compiler.c (compile_method): Add some experimental code for AOT
compiling
icall wrappers.
* patch-info.h (PATCH_INFO): Add 'ICALL_ADDR' patch type.
* mini.c (mono_method_to_ir): Convert a CEE_MONO_LDPTR opcode to an AOT
constant
if it references an icall address.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2008-02-21 12:54:27 UTC (rev 96338)
+++ trunk/mono/mono/mini/ChangeLog 2008-02-21 12:55:47 UTC (rev 96339)
@@ -1,3 +1,19 @@
+2008-02-21 Zoltan Varga <[EMAIL PROTECTED]>
+
+ * aot-compiler.c (encode_patch): Handle ICALL_ADDR patch type.
+
+ * aot-runtime.c (decode_patch_info): Ditto.
+
+ * mini.c (mono_resolve_patch_target): Ditto.
+
+ * aot-compiler.c (compile_method): Add some experimental code for AOT
compiling
+ icall wrappers.
+
+ * patch-info.h (PATCH_INFO): Add 'ICALL_ADDR' patch type.
+
+ * mini.c (mono_method_to_ir): Convert a CEE_MONO_LDPTR opcode to an AOT
constant
+ if it references an icall address.
+
2008-02-20 Zoltan Varga <[EMAIL PROTECTED]>
* cpu-s390x.md: Remove some more unused opcodes.
Modified: trunk/mono/mono/mini/aot-compiler.c
===================================================================
--- trunk/mono/mono/mini/aot-compiler.c 2008-02-21 12:54:27 UTC (rev 96338)
+++ trunk/mono/mono/mini/aot-compiler.c 2008-02-21 12:55:47 UTC (rev 96339)
@@ -115,6 +115,7 @@
GPtrArray *shared_patches;
GHashTable *image_hash;
GHashTable *method_to_cfg;
+ GHashTable *wrapper_to_method;
GHashTable *token_info_hash;
GPtrArray *image_table;
GList *method_order;
@@ -1837,6 +1838,20 @@
return get_got_offset (acfg, ji);
}
+static guint32
+get_method_index (MonoAotCompile *acfg, MonoMethod *method)
+{
+ int method_index = mono_metadata_token_index (method->token);
+
+ if (method_index == 0) {
+ MonoMethod *wrapped = g_hash_table_lookup
(acfg->wrapper_to_method, method);
+ g_assert (wrapped);
+ method_index = mono_metadata_token_index (wrapped->token);
+ }
+
+ return method_index;
+}
+
static void
emit_method_code (MonoAotCompile *acfg, MonoCompile *cfg)
{
@@ -1855,7 +1870,7 @@
code = cfg->native_code;
header = mono_method_get_header (method);
- method_index = mono_metadata_token_index (method->token);
+ method_index = get_method_index (acfg, method);
/* Make the labels local */
symbol = g_strdup_printf (".Lm_%x", method_index);
@@ -2018,6 +2033,7 @@
case MONO_PATCH_INFO_METHODCONST:
case MONO_PATCH_INFO_METHOD:
case MONO_PATCH_INFO_METHOD_JUMP:
+ case MONO_PATCH_INFO_ICALL_ADDR:
encode_method_ref (acfg, patch_info->data.method, p, &p);
break;
case MONO_PATCH_INFO_INTERNAL_METHOD: {
@@ -2091,7 +2107,7 @@
encode_field_info (acfg, patch_info->data.field, p, &p);
}
break;
- case MONO_PATCH_INFO_WRAPPER: {
+ case MONO_PATCH_INFO_WRAPPER:
encode_value (patch_info->data.method->wrapper_type, p, &p);
switch (patch_info->data.method->wrapper_type) {
@@ -2132,7 +2148,6 @@
g_assert_not_reached ();
}
break;
- }
default:
g_warning ("unable to handle jump info %d", patch_info->type);
g_assert_not_reached ();
@@ -2152,7 +2167,7 @@
GPtrArray *patches;
MonoJumpInfo *patch_info;
MonoMethodHeader *header;
- guint32 last_offset, method_idx;
+ guint32 last_offset, method_index;
guint8 *p, *buf;
guint32 first_got_offset;
@@ -2160,10 +2175,10 @@
code = cfg->native_code;
header = mono_method_get_header (method);
- method_idx = mono_metadata_token_index (method->token);
+ method_index = get_method_index (acfg, method);
/* Make the labels local */
- symbol = g_strdup_printf (".Lm_%x_p", method_idx);
+ symbol = g_strdup_printf (".Lm_%x_p", method_index);
/* Sort relocations */
patches = g_ptr_array_new ();
@@ -2171,7 +2186,7 @@
g_ptr_array_add (patches, patch_info);
g_ptr_array_sort (patches, compare_patches);
- first_got_offset = acfg->method_got_offsets [mono_metadata_token_index
(cfg->method->token)];
+ first_got_offset = acfg->method_got_offsets [method_index];
/**********************/
/* Encode method info */
@@ -2229,7 +2244,7 @@
}
if (n_patches)
- g_assert (acfg->has_got_slots [method_idx]);
+ g_assert (acfg->has_got_slots [method_index]);
encode_value (n_patches, p, &p);
@@ -2297,7 +2312,7 @@
emit_exception_debug_info (MonoAotCompile *acfg, MonoCompile *cfg)
{
MonoMethod *method;
- int k, buf_size;
+ int k, buf_size, method_index;
guint32 debug_info_size;
guint8 *code;
char *symbol;
@@ -2308,8 +2323,10 @@
code = cfg->native_code;
header = mono_method_get_header (method);
+ method_index = get_method_index (acfg, method);
+
/* Make the labels local */
- symbol = g_strdup_printf (".Le_%x_p", mono_metadata_token_index
(method->token));
+ symbol = g_strdup_printf (".Le_%x_p", method_index);
buf_size = header->num_clauses * 256 + 128;
p = buf = g_malloc (buf_size);
@@ -2689,23 +2706,27 @@
method_idx = mono_metadata_token_index (method->token);
/* fixme: maybe we can also precompile wrapper methods */
- if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
- (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
+ if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
(method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
(method->flags & METHOD_ATTRIBUTE_ABSTRACT)) {
//printf ("Skip (impossible): %s\n", mono_method_full_name
(method, TRUE));
return;
}
- acfg->stats.mcount++;
+ if (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)
+ return;
- /* fixme: we need to patch the IP for the LMF in that case */
- if (method->save_lmf) {
- //printf ("Skip (needs lmf): %s\n", mono_method_full_name
(method, TRUE));
- acfg->stats.lmfcount++;
- return;
+#if 0
+ if (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) {
+ /* Compile the wrapper instead */
+ MonoMethod *wrapper = mono_marshal_get_native_wrapper (method,
check_for_pending_exc);
+ g_hash_table_insert (acfg->wrapper_to_method, wrapper, method);
+ method = wrapper;
}
+#endif
+ acfg->stats.mcount++;
+
if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
/*
* FIXME: Enabling this causes virtual-sync.exe to fail, since
the trampoline
@@ -3458,6 +3479,7 @@
acfg->patch_to_shared_got_offset = g_hash_table_new
(mono_patch_info_hash, mono_patch_info_equal);
acfg->shared_patches = g_ptr_array_new ();
acfg->method_to_cfg = g_hash_table_new (NULL, NULL);
+ acfg->wrapper_to_method = g_hash_table_new (NULL, NULL);
acfg->token_info_hash = g_hash_table_new (NULL, NULL);
acfg->image_hash = g_hash_table_new (NULL, NULL);
acfg->image_table = g_ptr_array_new ();
Modified: trunk/mono/mono/mini/aot-runtime.c
===================================================================
--- trunk/mono/mono/mini/aot-runtime.c 2008-02-21 12:54:27 UTC (rev 96338)
+++ trunk/mono/mono/mini/aot-runtime.c 2008-02-21 12:55:47 UTC (rev 96339)
@@ -1153,7 +1153,8 @@
switch (ji->type) {
case MONO_PATCH_INFO_METHOD:
case MONO_PATCH_INFO_METHODCONST:
- case MONO_PATCH_INFO_METHOD_JUMP: {
+ case MONO_PATCH_INFO_METHOD_JUMP:
+ case MONO_PATCH_INFO_ICALL_ADDR: {
guint32 token;
image = decode_method_ref (aot_module, &token, p, &p);
Modified: trunk/mono/mono/mini/mini.c
===================================================================
--- trunk/mono/mono/mini/mini.c 2008-02-21 12:54:27 UTC (rev 96338)
+++ trunk/mono/mono/mini/mini.c 2008-02-21 12:55:47 UTC (rev 96339)
@@ -7921,11 +7921,26 @@
break;
}
- case CEE_MONO_LDPTR:
+ case CEE_MONO_LDPTR: {
+ gpointer ptr;
+
CHECK_STACK_OVF (1);
CHECK_OPSIZE (6);
token = read32 (ip + 2);
- NEW_PCONST (cfg, ins,
mono_method_get_wrapper_data (method, token));
+
+ ptr = mono_method_get_wrapper_data (method,
token);
+ if (cfg->compile_aot &&
cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+ MonoMethod *wrapped =
mono_marshal_method_from_wrapper (cfg->method);
+
+ if (wrapped && ptr != NULL &&
mono_lookup_internal_call (wrapped) == ptr) {
+ NEW_AOTCONST (cfg, ins,
MONO_PATCH_INFO_ICALL_ADDR, wrapped);
+ ins->cil_code = ip;
+ *sp++ = ins;
+ ip += 6;
+ break;
+ }
+ }
+ NEW_PCONST (cfg, ins, ptr);
ins->cil_code = ip;
*sp++ = ins;
ip += 6;
@@ -7933,6 +7948,7 @@
/* Can't embed random pointers into AOT code */
cfg->disable_aot = 1;
break;
+ }
case CEE_MONO_VTADDR:
CHECK_STACK (1);
--sp;
@@ -10041,6 +10057,9 @@
case MONO_PATCH_INFO_DECLSEC:
target = (mono_metadata_blob_heap
(patch_info->data.token->image, patch_info->data.token->token) + 2);
break;
+ case MONO_PATCH_INFO_ICALL_ADDR:
+ target = mono_lookup_internal_call (patch_info->data.method);
+ break;
case MONO_PATCH_INFO_BB_OVF:
case MONO_PATCH_INFO_EXC_OVF:
case MONO_PATCH_INFO_GOT_OFFSET:
Modified: trunk/mono/mono/mini/patch-info.h
===================================================================
--- trunk/mono/mono/mini/patch-info.h 2008-02-21 12:54:27 UTC (rev 96338)
+++ trunk/mono/mono/mini/patch-info.h 2008-02-21 12:55:47 UTC (rev 96339)
@@ -30,4 +30,5 @@
PATCH_INFO(DECLSEC, "declsec")
PATCH_INFO(RVA, "rva")
PATCH_INFO(DELEGATE_TRAMPOLINE, "delegate_trampoline")
+PATCH_INFO(ICALL_ADDR, "icall_addr")
PATCH_INFO(NONE, "none")
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches