-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[mono][aot] Enabling AOT wrappers for virtual delegates #85643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
33604b1
e0d201d
6b6dae9
c98a748
0dbe14f
030c8af
01231ce
dc5ae4b
1b80a47
534c69f
f791de0
d0442b2
1405f3f
3144e6e
175dae9
3658fbc
350bf94
9f4788c
26bf6bf
3e4c73d
d44a7ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -3922,12 +3922,15 @@ encode_method_ref (MonoAotCompile *acfg, MonoMethod *method, guint8 *buf, guint8 | |||
encode_klass_ref (acfg, method->klass, p, &p); | ||||
} else { | ||||
MonoMethodSignature *sig = mono_method_signature_internal (method); | ||||
WrapperInfo *wrapper_info = mono_marshal_get_wrapper_info (method); | ||||
|
||||
encode_value (0, p, &p); | ||||
if (method->wrapper_type == MONO_WRAPPER_DELEGATE_INVOKE) | ||||
encode_value (wrapper_info ? wrapper_info->subtype : 0, p, &p); | ||||
encode_signature (acfg, sig, p, &p); | ||||
encode_value (info ? info->subtype : 0, p, &p); | ||||
|
||||
if (info && info->subtype == WRAPPER_SUBTYPE_DELEGATE_INVOKE_VIRTUAL) | ||||
encode_klass_ref (acfg, info->d.delegate_invoke.method->klass, p, &p); | ||||
else | ||||
encode_signature (acfg, sig, p, &p); | ||||
} | ||||
break; | ||||
} | ||||
|
@@ -4546,6 +4549,41 @@ can_marshal_struct (MonoClass *klass) | |||
return can_marshal; | ||||
} | ||||
|
||||
/* Create a ref shared instantiation */ | ||||
static void | ||||
create_ref_shared_inst (MonoAotCompile *acfg, MonoMethod *method, MonoGenericContext *ctx) | ||||
{ | ||||
MonoGenericContext shared_context; | ||||
MonoType **args; | ||||
MonoGenericInst *inst; | ||||
MonoGenericContainer *container; | ||||
|
||||
memset (ctx, 0, sizeof (MonoGenericContext)); | ||||
|
||||
if (mono_class_is_gtd (method->klass)) { | ||||
shared_context = mono_class_get_generic_container (method->klass)->context; | ||||
inst = shared_context.class_inst; | ||||
|
||||
args = g_new0 (MonoType*, inst->type_argc); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the memory being deallocated correctly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it is not. I would suggest deallocating it after runtime/src/mono/mono/metadata/metadata.c Line 3399 in 175dae9
^ @vargaz There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can be freed, but the aot compiler is already leaking memory in a number of places, so its not that important. |
||||
for (guint i = 0; i < inst->type_argc; ++i) | ||||
args [i] = mono_get_object_type (); | ||||
ctx->class_inst = mono_metadata_get_generic_inst (inst->type_argc, args); | ||||
g_free (args); | ||||
} | ||||
if (method->is_generic) { | ||||
container = mono_method_get_generic_container (method); | ||||
g_assert (!container->is_anonymous && container->is_method); | ||||
shared_context = container->context; | ||||
inst = shared_context.method_inst; | ||||
|
||||
args = g_new0 (MonoType*, inst->type_argc); | ||||
for (int i = 0; i < container->type_argc; ++i) | ||||
args [i] = mono_get_object_type (); | ||||
ctx->method_inst = mono_metadata_get_generic_inst (inst->type_argc, args); | ||||
g_free (args); | ||||
} | ||||
} | ||||
|
||||
static void | ||||
create_gsharedvt_inst (MonoAotCompile *acfg, MonoMethod *method, MonoGenericContext *ctx) | ||||
{ | ||||
|
@@ -4962,13 +5000,39 @@ add_full_aot_wrappers (MonoAotCompile *acfg) | |||
if (!m_class_is_delegate (klass) || klass == mono_defaults.delegate_class || klass == mono_defaults.multicastdelegate_class) | ||||
continue; | ||||
|
||||
method = mono_get_delegate_invoke_internal (klass); | ||||
if (mono_class_is_gtd (klass)) { | ||||
MonoGenericContext ctx; | ||||
MonoMethod *inst, *gshared; | ||||
|
||||
create_ref_shared_inst (acfg, method, &ctx); | ||||
|
||||
inst = mono_class_inflate_generic_method_checked (method, &ctx, error); | ||||
g_assert (is_ok (error)); /* FIXME don't swallow the error */ | ||||
|
||||
sig = mono_method_signature_internal (method); | ||||
if (sig->param_count && !m_class_is_byreflike (mono_class_from_mono_type_internal (sig->params [0])) && !m_type_is_byref (sig->params [0])) { | ||||
m = mono_marshal_get_delegate_invoke_internal (inst, TRUE, FALSE, NULL); | ||||
|
||||
gshared = mini_get_shared_method_full (m, SHARE_MODE_NONE, error); | ||||
mono_error_assert_ok (error); | ||||
|
||||
add_extra_method (acfg, gshared); | ||||
} | ||||
} | ||||
|
||||
if (!mono_class_is_gtd (klass)) { | ||||
method = mono_get_delegate_invoke_internal (klass); | ||||
|
||||
m = mono_marshal_get_delegate_invoke (method, NULL); | ||||
|
||||
add_method (acfg, m); | ||||
|
||||
sig = mono_method_signature_internal (method); | ||||
if (sig->param_count && !m_class_is_byreflike (mono_class_from_mono_type_internal (sig->params [0])) && !m_type_is_byref (sig->params [0])) { | ||||
m = mono_marshal_get_delegate_invoke_internal (method, TRUE, FALSE, NULL); | ||||
add_method (acfg, m); | ||||
} | ||||
|
||||
method = try_get_method_nofail (klass, "BeginInvoke", -1, 0); | ||||
if (method) | ||||
add_method (acfg, mono_marshal_get_delegate_begin_invoke (method)); | ||||
|
Uh oh!
There was an error while loading. Please reload this page.