Skip to content

Commit bbe5c66

Browse files
authored
[mono] Generate gsharedvt versions of the callvirt delegate invoke wrappers. (#92472)
Also change the IL of the wrapper so it works with gsharedvt.
1 parent 5dfd805 commit bbe5c66

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

src/mono/mono/metadata/marshal-lightweight.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -2094,13 +2094,13 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature
20942094
if (!closed_over_null) {
20952095
for (i = 1; i <= sig->param_count; ++i) {
20962096
mono_mb_emit_ldarg (mb, i);
2097-
if (i == 1 && (MONO_TYPE_ISSTRUCT (sig->params [0]) || MONO_TYPE_IS_PRIMITIVE (sig->params [0])))
2098-
mono_mb_emit_op (mb, CEE_BOX, mono_class_from_mono_type_internal (sig->params [0]));
2097+
if (i == 1) {
2098+
MonoType *t = sig->params [0];
2099+
if (!m_type_is_byref (t))
2100+
mono_mb_emit_op (mb, CEE_BOX, mono_class_from_mono_type_internal (t));
2101+
}
20992102
}
2100-
if (MONO_TYPE_ISSTRUCT (sig->params [0]) || MONO_TYPE_IS_PRIMITIVE (sig->params [0]))
2101-
mono_mb_emit_ldarg_addr (mb, 1);
2102-
else
2103-
mono_mb_emit_ldarg (mb, 1);
2103+
mono_mb_emit_ldarg_addr (mb, 1);
21042104
mono_mb_emit_ldarg (mb, 0);
21052105
mono_mb_emit_icall (mb, mono_get_addr_compiled_method);
21062106
mono_mb_emit_op (mb, CEE_CALLI, target_method_sig);

src/mono/mono/metadata/marshal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5573,7 +5573,7 @@ mono_get_addr_compiled_method (gpointer arg, MonoDelegate *del)
55735573
if (m_type_is_byref (invoke_sig->params [0])) {
55745574
arg_class = mono_class_from_mono_type_internal (invoke_sig->params [0]);
55755575
} else {
5576-
MonoObject *object = (MonoObject*)arg;
5576+
MonoObject *object = *(MonoObject**)arg;
55775577
arg_class = object->vtable->klass;
55785578
}
55795579

src/mono/mono/mini/aot-compiler.c

+21-6
Original file line numberDiff line numberDiff line change
@@ -5019,24 +5019,39 @@ add_full_aot_wrappers (MonoAotCompile *acfg)
50195019
MonoGenericContext ctx;
50205020
MonoMethod *inst, *gshared;
50215021

5022-
create_ref_shared_inst (acfg, method, &ctx);
5023-
5024-
inst = mono_class_inflate_generic_method_checked (method, &ctx, error);
5025-
g_assert (is_ok (error)); /* FIXME don't swallow the error */
5026-
50275022
sig = mono_method_signature_internal (method);
50285023
if (sig->param_count && !m_class_is_byreflike (mono_class_from_mono_type_internal (sig->params [0])) && !m_type_is_byref (sig->params [0])) {
5024+
/* ref */
5025+
create_ref_shared_inst (acfg, method, &ctx);
5026+
5027+
inst = mono_class_inflate_generic_method_checked (method, &ctx, error);
5028+
g_assert (is_ok (error)); /* FIXME don't swallow the error */
5029+
50295030
m = mono_marshal_get_delegate_invoke_internal (inst, TRUE, FALSE, NULL);
50305031

50315032
gshared = mini_get_shared_method_full (m, SHARE_MODE_NONE, error);
50325033
mono_error_assert_ok (error);
50335034

50345035
add_extra_method (acfg, gshared);
5036+
5037+
if (acfg->jit_opts & MONO_OPT_GSHAREDVT) {
5038+
/* gsharedvt */
5039+
create_gsharedvt_inst (acfg, method, &ctx);
5040+
5041+
inst = mono_class_inflate_generic_method_checked (method, &ctx, error);
5042+
g_assert (is_ok (error)); /* FIXME don't swallow the error */
5043+
5044+
m = mono_marshal_get_delegate_invoke_internal (inst, TRUE, FALSE, NULL);
5045+
5046+
gshared = mini_get_shared_method_full (m, SHARE_MODE_GSHAREDVT, error);
5047+
mono_error_assert_ok (error);
5048+
5049+
add_extra_method (acfg, gshared);
5050+
}
50355051
}
50365052
}
50375053

50385054
if (!mono_class_is_gtd (klass)) {
5039-
50405055
m = mono_marshal_get_delegate_invoke (method, NULL);
50415056

50425057
add_method (acfg, m);

0 commit comments

Comments
 (0)