Skip to content

Commit

Permalink
[mono] Generate gsharedvt versions of the callvirt delegate invoke wr…
Browse files Browse the repository at this point in the history
…appers.

Also change the IL of the wrapper so it works with gsharedvt.
  • Loading branch information
vargaz committed Sep 23, 2023
1 parent 14c0fee commit 9782f0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/mono/mono/metadata/marshal-lightweight.c
Original file line number Diff line number Diff line change
Expand Up @@ -2094,13 +2094,13 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature
if (!closed_over_null) {
for (i = 1; i <= sig->param_count; ++i) {
mono_mb_emit_ldarg (mb, i);
if (i == 1 && (MONO_TYPE_ISSTRUCT (sig->params [0]) || MONO_TYPE_IS_PRIMITIVE (sig->params [0])))
mono_mb_emit_op (mb, CEE_BOX, mono_class_from_mono_type_internal (sig->params [0]));
if (i == 1) {
MonoType *t = sig->params [0];
if (!m_type_is_byref (t))
mono_mb_emit_op (mb, CEE_BOX, mono_class_from_mono_type_internal (t));
}
}
if (MONO_TYPE_ISSTRUCT (sig->params [0]) || MONO_TYPE_IS_PRIMITIVE (sig->params [0]))
mono_mb_emit_ldarg_addr (mb, 1);
else
mono_mb_emit_ldarg (mb, 1);
mono_mb_emit_ldarg_addr (mb, 1);
mono_mb_emit_ldarg (mb, 0);
mono_mb_emit_icall (mb, mono_get_addr_compiled_method);
mono_mb_emit_op (mb, CEE_CALLI, target_method_sig);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5573,7 +5573,7 @@ mono_get_addr_compiled_method (gpointer arg, MonoDelegate *del)
if (m_type_is_byref (invoke_sig->params [0])) {
arg_class = mono_class_from_mono_type_internal (invoke_sig->params [0]);
} else {
MonoObject *object = (MonoObject*)arg;
MonoObject *object = *(MonoObject**)arg;
arg_class = object->vtable->klass;
}

Expand Down
27 changes: 21 additions & 6 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5019,24 +5019,39 @@ add_full_aot_wrappers (MonoAotCompile *acfg)
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])) {
/* ref */
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 */

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 (acfg->jit_opts & MONO_OPT_GSHAREDVT) {
/* gsharedvt */
create_gsharedvt_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 */

m = mono_marshal_get_delegate_invoke_internal (inst, TRUE, FALSE, NULL);

gshared = mini_get_shared_method_full (m, SHARE_MODE_GSHAREDVT, error);
mono_error_assert_ok (error);

add_extra_method (acfg, gshared);
}
}
}

if (!mono_class_is_gtd (klass)) {

m = mono_marshal_get_delegate_invoke (method, NULL);

add_method (acfg, m);
Expand Down

0 comments on commit 9782f0f

Please sign in to comment.