Skip to content

Commit dddc273

Browse files
authored
[mono][interp] Allow passing vtypes with a single scalar field to native code using the faster code path. (#79686)
This affects types like ObjectHandleOnStack which are passed to icalls.
1 parent e49d7ec commit dddc273

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

src/mono/mono/mini/interp/transform.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,43 @@ interp_transform_internal_calls (MonoMethod *method, MonoMethod *target_method,
25932593
return target_method;
25942594
}
25952595

2596+
static gboolean
2597+
interp_type_as_ptr (MonoType *tp);
2598+
2599+
/* Return whenever TYPE represents a vtype with only one scalar member */
2600+
static gboolean
2601+
is_scalar_vtype (MonoType *type)
2602+
{
2603+
MonoClass *klass;
2604+
MonoClassField *field;
2605+
gpointer iter;
2606+
2607+
if (!MONO_TYPE_ISSTRUCT (type))
2608+
return FALSE;
2609+
klass = mono_class_from_mono_type_internal (type);
2610+
mono_class_init_internal (klass);
2611+
2612+
int size = mono_class_value_size (klass, NULL);
2613+
if (size == 0 || size > SIZEOF_VOID_P)
2614+
return FALSE;
2615+
2616+
iter = NULL;
2617+
int nfields = 0;
2618+
field = NULL;
2619+
while ((field = mono_class_get_fields_internal (klass, &iter))) {
2620+
if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
2621+
continue;
2622+
nfields ++;
2623+
if (nfields > 1)
2624+
return FALSE;
2625+
MonoType *t = mini_get_underlying_type (field->type);
2626+
if (!interp_type_as_ptr (t))
2627+
return FALSE;
2628+
}
2629+
2630+
return TRUE;
2631+
}
2632+
25962633
static gboolean
25972634
interp_type_as_ptr (MonoType *tp)
25982635
{
@@ -2603,7 +2640,7 @@ interp_type_as_ptr (MonoType *tp)
26032640
if ((tp)->type == MONO_TYPE_I4)
26042641
return TRUE;
26052642
#if SIZEOF_VOID_P == 8
2606-
if ((tp)->type == MONO_TYPE_I8)
2643+
if ((tp)->type == MONO_TYPE_I8 || (tp)->type == MONO_TYPE_U8)
26072644
return TRUE;
26082645
#endif
26092646
if ((tp)->type == MONO_TYPE_BOOLEAN)
@@ -2612,6 +2649,8 @@ interp_type_as_ptr (MonoType *tp)
26122649
return TRUE;
26132650
if ((tp)->type == MONO_TYPE_VALUETYPE && m_class_is_enumtype (tp->data.klass))
26142651
return TRUE;
2652+
if (is_scalar_vtype (tp))
2653+
return TRUE;
26152654
return FALSE;
26162655
}
26172656

0 commit comments

Comments
 (0)