Skip to content
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

Move MonoClass:inlinearray_value out of MonoClass #109363

Merged
merged 11 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -5254,7 +5254,7 @@ buffer_add_value_full (Buffer *buf, MonoType *t, void *addr, MonoDomain *domain,
}
if (CHECK_PROTOCOL_VERSION(2, 65)) {
if (m_class_is_inlinearray (klass) && nfields == 1)
buffer_add_int (buf, m_class_inlinearray_value (klass));
buffer_add_int (buf, mono_class_get_inlinearray_value (klass) );
else
buffer_add_int (buf, -1);
}
Expand Down Expand Up @@ -5292,7 +5292,7 @@ buffer_add_value_full (Buffer *buf, MonoType *t, void *addr, MonoDomain *domain,
if (CHECK_PROTOCOL_VERSION(2, 65)) {
if (m_class_is_inlinearray (klass) && nfields == 1) {
int element_size = mono_class_instance_size (mono_class_from_mono_type_internal (f->type)) - MONO_ABI_SIZEOF (MonoObject);
int array_size = m_class_inlinearray_value (klass);
int array_size = mono_class_get_inlinearray_value (klass);
for (int i = 1; i < array_size; i++)
buffer_add_value_full (buf, f->type, ((char*)mono_vtype_get_field_addr (addr, f)) + (i*element_size), domain, FALSE, parent_vtypes, len_fixed_array != 1 ? len_fixed_array : isFixedSizeArray(f));
}
Expand Down
16 changes: 16 additions & 0 deletions src/mono/mono/metadata/class-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef enum {
PROP_FIELD_DEF_VALUES_4BYTESWIZZLE = 12, /* MonoFieldDefaultValue* with default values swizzled at 4 byte boundaries*/
PROP_FIELD_DEF_VALUES_8BYTESWIZZLE = 13, /* MonoFieldDefaultValue* with default values swizzled at 8 byte boundaries*/
PROP_METADATA_UPDATE_INFO = 14, /* MonoClassMetadataUpdateInfo* */
PROP_INLINEARRAY_VALUE = 15, /* System.Runtime.CompilerServices.InlineArrayAttribute length value */
} InfrequentDataKind;

/* Accessors based on class kind*/
Expand Down Expand Up @@ -684,6 +685,21 @@ mono_class_has_metadata_update_info (MonoClass *klass)
}
}

gint32
mono_class_get_inlinearray_value (MonoClass *klass)
{
Uint32Property *prop = (Uint32Property*)mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_INLINEARRAY_VALUE);
return prop ? prop->value : 0;
}

void
mono_class_set_inlinearray_value (MonoClass *klass, gint32 value)
{
Uint32Property *prop = (Uint32Property*)mono_class_alloc (klass, sizeof (Uint32Property));
prop->head.tag = PROP_INLINEARRAY_VALUE;
prop->value = value;
mono_property_bag_add (m_class_get_infrequent_data (klass), prop);
}

#ifdef MONO_CLASS_DEF_PRIVATE
#define MONO_CLASS_GETTER(funcname, rettype, optref, argtype, fieldname) rettype funcname (argtype *klass) { return optref klass-> fieldname ; }
Expand Down
1 change: 0 additions & 1 deletion src/mono/mono/metadata/class-getters.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ MONO_CLASS_GETTER(m_class_was_typebuilder, gboolean, , MonoClass, wastypebuilder
MONO_CLASS_GETTER(m_class_is_array_special_interface, gboolean, , MonoClass, is_array_special_interface)
MONO_CLASS_GETTER(m_class_is_byreflike, gboolean, , MonoClass, is_byreflike)
MONO_CLASS_GETTER(m_class_is_inlinearray, gboolean, , MonoClass, is_inlinearray)
MONO_CLASS_GETTER(m_class_inlinearray_value, gint32, , MonoClass, inlinearray_value)
MONO_CLASS_GETTER(m_class_get_min_align, guint8, , MonoClass, min_align)
MONO_CLASS_GETTER(m_class_get_packing_size, guint, , MonoClass, packing_size)
MONO_CLASS_GETTER(m_class_is_ghcimpl, gboolean, , MonoClass, ghcimpl)
Expand Down
8 changes: 4 additions & 4 deletions src/mono/mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ mono_class_setup_fields (MonoClass *klass)
instance_size = MONO_ABI_SIZEOF (MonoObject);
}

if (m_class_is_inlinearray (klass) && m_class_inlinearray_value (klass) <= 0) {
if (m_class_is_inlinearray (klass) && mono_class_get_inlinearray_value (klass) <= 0) {
if (mono_get_runtime_callbacks ()->mono_class_set_deferred_type_load_failure_callback)
mono_get_runtime_callbacks ()->mono_class_set_deferred_type_load_failure_callback (klass, "Inline array length property must be positive.");
else
Expand Down Expand Up @@ -735,7 +735,7 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token, MonoError
attr = class_has_inlinearray_attribute (klass);
if (attr.has_attr) {
klass->is_inlinearray = 1;
klass->inlinearray_value = GPOINTER_TO_INT32 (attr.value);
mono_class_set_inlinearray_value(klass, GPOINTER_TO_INT32 (attr.value));
}
}

Expand Down Expand Up @@ -940,7 +940,7 @@ mono_class_create_generic_inst (MonoGenericClass *gclass)
klass->this_arg.data.generic_class = klass->_byval_arg.data.generic_class = gclass;
klass->this_arg.byref__ = TRUE;
klass->is_inlinearray = gklass->is_inlinearray;
klass->inlinearray_value = gklass->inlinearray_value;
mono_class_set_inlinearray_value(klass, mono_class_get_inlinearray_value(gklass));
klass->is_exception_class = gklass->is_exception_class;
klass->enumtype = gklass->enumtype;
klass->valuetype = gklass->valuetype;
Expand Down Expand Up @@ -2295,7 +2295,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_
const guint32 struct_max_size = 1024 * 1024;
guint32 initial_size = size;
// If size overflows, it returns 0
size *= m_class_inlinearray_value (klass);
size *= mono_class_get_inlinearray_value (klass);
inlined_fields++;
if(size == 0 || size > struct_max_size) {
if (mono_get_runtime_callbacks ()->mono_class_set_deferred_type_load_failure_callback) {
Expand Down
6 changes: 6 additions & 0 deletions src/mono/mono/metadata/class-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,12 @@ mono_class_get_declsec_flags (MonoClass *klass);
void
mono_class_set_declsec_flags (MonoClass *klass, guint32 value);

gint32
mono_class_get_inlinearray_value (MonoClass *klass);
lambdageek marked this conversation as resolved.
Show resolved Hide resolved

void
mono_class_set_inlinearray_value (MonoClass *klass, gint32 value);

void
mono_class_set_weak_bitmap (MonoClass *klass, int nbits, gsize *bits);

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/class-private-definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct _MonoClass {
guint16 *interface_offsets_packed;
guint8 *interface_bitmap;

gint32 inlinearray_value; /* System.Runtime.CompilerServices.InlineArrayAttribute length value */

guint name_hash;

MonoClass **interfaces;
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5983,7 +5983,7 @@ mono_marshal_load_type_info (MonoClass* klass)
// Limit the max size of array instance to 1MiB
const int struct_max_size = 1024 * 1024;
guint32 initial_size = size;
size *= m_class_inlinearray_value (klass);
size *= mono_class_get_inlinearray_value (klass);
if(size == 0 || size > struct_max_size) {
if (mono_get_runtime_callbacks ()->mono_class_set_deferred_type_load_failure_callback) {
if (mono_get_runtime_callbacks ()->mono_class_set_deferred_type_load_failure_callback (klass, "Inline array struct size out of bounds, abnormally large."))
Expand Down Expand Up @@ -6815,7 +6815,7 @@ static void record_inlinearray_struct_physical_lowering (guint8* lowered_bytes,
g_assert (field);

MonoType* fieldType = field->type;
for (int i = 0; i < m_class_inlinearray_value(klass); ++i) {
for (int i = 0; i < mono_class_get_inlinearray_value (klass); ++i) {
record_struct_field_physical_lowering(lowered_bytes, fieldType, offset + m_field_get_offset(field) + i * mono_type_size(fieldType, &align) - type_offset);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ compute_class_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int
guint32 field_instance_offset = field_offset;
// If struct has InlineArray attribute, iterate `length` times to set a bitmap
if (m_class_is_inlinearray (p))
field_iter = m_class_inlinearray_value (p);
field_iter = mono_class_get_inlinearray_value (p);

if (field_iter > 500)
g_warning ("Large number of iterations detected when creating a GC bitmap, might affect performance.");
Expand Down
Loading