From 5faed55cf399ea1d338cfa55515ff6e87c8d0f98 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 5 May 2023 11:20:46 -0400 Subject: [PATCH 1/4] Try to init less for G[][] --- src/mono/mono/metadata/class-init.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/metadata/class-init.c b/src/mono/mono/metadata/class-init.c index dc6e35862ea29..74113a4c73d5c 100644 --- a/src/mono/mono/metadata/class-init.c +++ b/src/mono/mono/metadata/class-init.c @@ -1183,8 +1183,9 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound mono_class_setup_supertypes (klass); - if (mono_class_is_ginst (eclass)) - mono_class_init_internal (eclass); + //if (mono_class_is_ginst (eclass)) + // mono_class_init_internal (eclass); + // NOTE: this is also probably too aggressive if eclass is not a valuetype if (!eclass->size_inited) mono_class_setup_fields (eclass); mono_class_set_type_load_failure_causedby_class (klass, eclass, "Could not load array element type"); From 212fdcd904a5430538dc535510274e59c5cb0193 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 19 May 2023 16:50:41 -0400 Subject: [PATCH 2/4] Add regression test --- .../GitHub_85821/GitHub_85821.csproj | 9 +++++ .../regressions/GitHub_85821/repro.cs | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/tests/Loader/classloader/regressions/GitHub_85821/GitHub_85821.csproj create mode 100644 src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs diff --git a/src/tests/Loader/classloader/regressions/GitHub_85821/GitHub_85821.csproj b/src/tests/Loader/classloader/regressions/GitHub_85821/GitHub_85821.csproj new file mode 100644 index 0000000000000..32355f272f908 --- /dev/null +++ b/src/tests/Loader/classloader/regressions/GitHub_85821/GitHub_85821.csproj @@ -0,0 +1,9 @@ + + + true + Exe + + + + + diff --git a/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs b/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs new file mode 100644 index 0000000000000..281a6a2b6fc0e --- /dev/null +++ b/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs @@ -0,0 +1,34 @@ +using System; + +/* Regression test for https://github.com/dotnet/runtime/issues/85821 + * ensure that self-referencing generic instances are initialized correctly and don't TLE + */ + +public class Program +{ + public static int Main() + { + var test = typeof(Node); + var fit = test.GetField("Children").FieldType; + if (fit == null) + return 101; + + var test2 = typeof(Node2); + var fit2 = test2.GetField("Children").FieldType; + if (fit2 == null) + return 102; + + return 100; + } +} + +public class Node +{ + public Node[] Children; +} + + +public class Node2 +{ + public Node2[][] Children; +} From 52ff6eaf6b7f534376f02b51a629a3874efda143 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 19 May 2023 16:59:15 -0400 Subject: [PATCH 3/4] remove commented code; update note comment --- src/mono/mono/metadata/class-init.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/metadata/class-init.c b/src/mono/mono/metadata/class-init.c index 74113a4c73d5c..dca64cab11ce0 100644 --- a/src/mono/mono/metadata/class-init.c +++ b/src/mono/mono/metadata/class-init.c @@ -1183,9 +1183,10 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound mono_class_setup_supertypes (klass); - //if (mono_class_is_ginst (eclass)) - // mono_class_init_internal (eclass); - // NOTE: this is also probably too aggressive if eclass is not a valuetype + // NOTE: this is probably too aggressive if eclass is not a valuetype. It looks like we + // only need the size info in order to set MonoClass:has_references for this array type - + // and for that we only need to setup the fields of the element type if it's not a reference + // type. if (!eclass->size_inited) mono_class_setup_fields (eclass); mono_class_set_type_load_failure_causedby_class (klass, eclass, "Could not load array element type"); From 2364842f3b5615ebe1f6b79f9a5f2d9f259c5203 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 19 May 2023 17:04:38 -0400 Subject: [PATCH 4/4] add valuetype testcases, too --- .../regressions/GitHub_85821/repro.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs b/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs index 281a6a2b6fc0e..7c6d52f7932eb 100644 --- a/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs +++ b/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs @@ -12,12 +12,22 @@ public static int Main() var fit = test.GetField("Children").FieldType; if (fit == null) return 101; - + var test2 = typeof(Node2); var fit2 = test2.GetField("Children").FieldType; if (fit2 == null) return 102; + var test3 = typeof(NodeVT); + var fit3 = test3.GetField("Children").FieldType; + if (fit3 == null) + return 103; + + var test4 = typeof(NodeVT2); + var fit4 = test4.GetField("Children").FieldType; + if (fit4 == null) + return 104; + return 100; } } @@ -27,8 +37,17 @@ public class Node public Node[] Children; } - public class Node2 { public Node2[][] Children; } + +public struct NodeVT +{ + public NodeVT[] Children; +} + +public struct NodeVT2 +{ + public NodeVT2[][] Children; +}