Skip to content

Commit 27a328a

Browse files
kgmichaelgsharp
authored andcommitted
[mono] Miscellaneous startup optimizations (dotnet#101263)
* Optimize out an unnecessary memset under g_slist_prepend * Don't inline constructors of Exception or its descendants into interpreter method bodies
1 parent f00fc0c commit 27a328a

5 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/mono/mono/eglib/gslist.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ g_slist_append (GSList *list, gpointer data)
5252
GSList*
5353
g_slist_prepend (GSList *list, gpointer data)
5454
{
55-
GSList *head = g_slist_alloc ();
55+
// We don't need to zero the allocation using g_slist_alloc since we fully initialize the node
56+
GSList *head = g_new (GSList, 1);
5657
head->data = data;
5758
head->next = list;
5859

src/mono/mono/metadata/class-getters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ MONO_CLASS_GETTER(m_class_is_interfaces_inited, gboolean, , MonoClass, interface
4848
MONO_CLASS_GETTER(m_class_is_simd_type, gboolean, , MonoClass, simd_type)
4949
MONO_CLASS_GETTER(m_class_is_has_finalize_inited, gboolean, , MonoClass, has_finalize_inited)
5050
MONO_CLASS_GETTER(m_class_is_fields_inited, gboolean, , MonoClass, fields_inited)
51+
MONO_CLASS_GETTER(m_class_is_exception_class, gboolean, , MonoClass, is_exception_class)
5152
MONO_CLASS_GETTER(m_class_has_failure, gboolean, , MonoClass, has_failure)
5253
MONO_CLASS_GETTER(m_class_has_deferred_failure, gboolean, , MonoClass, has_deferred_failure)
5354
MONO_CLASS_GETTER(m_class_has_weak_fields, gboolean, , MonoClass, has_weak_fields)

src/mono/mono/metadata/class-init.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,17 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token, MonoError
735735
}
736736
}
737737

738+
// compute is_exception_class, used by interp to avoid inlining exception handling code
739+
if (
740+
klass->parent && !m_class_is_valuetype (klass) &&
741+
!m_class_is_interface (klass)
742+
) {
743+
if (m_class_is_exception_class (klass->parent))
744+
klass->is_exception_class = 1;
745+
else if (!strcmp (klass->name, "Exception") && !strcmp(klass->name_space, "System"))
746+
klass->is_exception_class = 1;
747+
}
748+
738749
mono_loader_unlock ();
739750

740751
MONO_PROFILER_RAISE (class_loaded, (klass));
@@ -926,6 +937,7 @@ mono_class_create_generic_inst (MonoGenericClass *gclass)
926937
klass->this_arg.byref__ = TRUE;
927938
klass->is_inlinearray = gklass->is_inlinearray;
928939
klass->inlinearray_value = gklass->inlinearray_value;
940+
klass->is_exception_class = gklass->is_exception_class;
929941
klass->enumtype = gklass->enumtype;
930942
klass->valuetype = gklass->valuetype;
931943

src/mono/mono/metadata/class-private-definition.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ struct _MonoClass {
6868
guint no_special_static_fields : 1; /* has no thread/context static fields */
6969

7070
guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
71-
72-
/* next byte*/
7371
guint interfaces_inited : 1; /* interfaces is initialized */
72+
/* next byte*/
7473
guint simd_type : 1; /* class is a simd intrinsic type */
7574
guint has_finalize_inited : 1; /* has_finalize is initialized */
7675
guint fields_inited : 1; /* setup_fields () has finished */
@@ -79,6 +78,8 @@ struct _MonoClass {
7978
guint has_dim_conflicts : 1; /* Class has conflicting default interface methods */
8079
guint any_field_has_auto_layout : 1; /* a field in this type's layout uses auto-layout */
8180
guint has_deferred_failure : 1;
81+
/* next byte*/
82+
guint is_exception_class : 1; /* is System.Exception or derived from it */
8283

8384
MonoClass *parent;
8485
MonoClass *nested_in;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,9 @@ interp_method_check_inlining (TransformData *td, MonoMethod *method, MonoMethodS
29072907
if (g_list_find (td->dont_inline, method))
29082908
return FALSE;
29092909

2910+
if (m_class_is_exception_class (method->klass) && !strcmp (method->name, ".ctor"))
2911+
return FALSE;
2912+
29102913
return TRUE;
29112914
}
29122915

0 commit comments

Comments
 (0)