From cd95c8f8e8aa1c13d4d8b48fbdb8bc7497b2dbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 31 Dec 2024 06:39:04 +0100 Subject: [PATCH 1/2] Fix reporting GC fields from base types Fixes #110836. When we extended managed CorInfoImpl to support object stack allocation in #104411, there was one more spot that assumed valuetypes only in `GatherClassGCLayout` that we missed. This resulted in not reporting any GC pointers in base types. --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index f29717b0d3a2c3..b9bdb5e55f7924 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -2287,6 +2287,10 @@ private int MarkGcField(byte* gcPtrs, CorInfoGCType gcType) private int GatherClassGCLayout(MetadataType type, byte* gcPtrs) { int result = 0; + + if (type.MetadataBaseType is { ContainsGCPointers: true } baseType) + result += GatherClassGCLayout(baseType, gcPtrs); + bool isInlineArray = type.IsInlineArray; foreach (var field in type.GetFields()) From cc096105efc08c625146f9e82a95c5aaea4563e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 31 Dec 2024 22:48:18 -0800 Subject: [PATCH 2/2] Update corinfo.h --- src/coreclr/inc/corinfo.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 068ee41bbb72a5..cab2f6c71d7447 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -2374,10 +2374,10 @@ class ICorStaticInfo bool fDoubleAlignHint = false ) = 0; - // This is only called for Value classes. It returns a boolean array - // in representing of 'cls' from a GC perspective. The class is - // assumed to be an array of machine words - // (of length // getClassSize(cls) / TARGET_POINTER_SIZE), + // Returns a boolean array representing 'cls' from a GC perspective. + // The class is assumed to be an array of machine words + // (of length getClassSize(cls) / TARGET_POINTER_SIZE for value classes + // and getHeapClassSize(cls) / TARGET_POINTER_SIZE for reference types), // 'gcPtrs' is a pointer to an array of uint8_ts of this length. // getClassGClayout fills in this array so that gcPtrs[i] is set // to one of the CorInfoGCType values which is the GC type of