From 6662a0f2fd05298af1f9b1b020fa526595f336f7 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Thu, 12 Dec 2019 19:22:18 -0800 Subject: [PATCH] Fix the gc layout algorithm to not double count byref (#814) --- .../src/tools/Common/JitInterface/CorInfoImpl.cs | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index 0e0d950..73ca9a3 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -1390,14 +1390,29 @@ namespace Internal.JitInterface return (uint)type.InstanceFieldAlignment.AsInt; } + private int MarkGcField(byte* gcPtrs, CorInfoGCType gcType) + { + // Ensure that if we have multiple fields with the same offset, + // that we don't double count the data in the gc layout. + if (*gcPtrs == (byte)CorInfoGCType.TYPE_GC_NONE) + { + *gcPtrs = (byte)gcType; + return 1; + } + else + { + Debug.Assert(*gcPtrs == (byte)gcType); + return 0; + } + } + private int GatherClassGCLayout(TypeDesc type, byte* gcPtrs) { int result = 0; if (type.IsByReferenceOfT || type.IsWellKnownType(WellKnownType.TypedReference)) { - *gcPtrs = (byte)CorInfoGCType.TYPE_GC_BYREF; - return 1; + return MarkGcField(gcPtrs, CorInfoGCType.TYPE_GC_BYREF); } foreach (var field in type.GetFields()) @@ -1438,20 +1453,9 @@ namespace Internal.JitInterface } else { - // Ensure that if we have multiple fields with the same offset, - // that we don't double count the data in the gc layout. - if (*fieldGcPtrs == (byte)CorInfoGCType.TYPE_GC_NONE) - { - *fieldGcPtrs = (byte)gcType; - result++; - } - else - { - Debug.Assert(*fieldGcPtrs == (byte)gcType); - } + result += MarkGcField(fieldGcPtrs, gcType); } } - return result; } -- 2.7.4