Skip to content

Commit

Permalink
[NativeAOT] Fix MD array GC series (#86877)
Browse files Browse the repository at this point in the history
* Fix MD array GC series

* add a test

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
VSadov and jkotas authored May 30, 2023
1 parent da01301 commit 0a3fb4c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ private static unsafe int CreateArrayGCDesc(LowLevelList<bool> bitfield, int ran
{
if (numSeries > 0)
{
*ptr-- = (short)((bitfield.Count - last + baseOffset - 2) * IntPtr.Size);
*ptr-- = (short)((bitfield.Count - last) * IntPtr.Size);
*ptr-- = numPtrs;

*(void**)gcdesc = (void*)-numSeries;
Expand Down
48 changes: 48 additions & 0 deletions src/tests/nativeaot/SmokeTests/DynamicGenerics/B282745.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,54 @@ public static void testMDArrayWithPointerLikeValuesOfKnownStructType()
GenericType<object>.test();
}

struct SomeGenStruct1<T>
{
public T o;
public int i;
public long l;
public long l1;
}

public class GenericType1<T>
{
public static void test()
{
int[] lengths = { 42, 2, 3 };
SomeGenStruct1<T>[,,] array = (SomeGenStruct1<T>[,,])Array.CreateInstance(typeof(SomeGenStruct1<T>), lengths);

for (int i = 0; i < 42; i++)
{
array[i,0,0].o = default(T);
array[i,0,0].i = GetIntPtrOnHeapAsInt();
array[i,0,0].l = GetIntPtrOnHeapAsInt();

array[i,1,2].o = default(T);
array[i,1,2].i = GetIntPtrOnHeapAsInt();
array[i,1,2].l = GetIntPtrOnHeapAsLong();

array[i,1,1].o = default(T);
array[i,1,1].i = GetIntPtrOnHeapAsInt();
array[i,1,1].l = GetIntPtrOnHeapAsLong();
}

GC.Collect();

GC.KeepAlive(array);

RuntimeTypeHandle arrayTypeHandle = array.GetType().TypeHandle;
#if INTERNAL_CONTRACTS
Assert.IsTrue(RuntimeAugments.IsDynamicType(arrayTypeHandle));
#endif
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
[TestMethod]
public static void testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType()
{
GenericType1<object>.test();
}

[MethodImpl(MethodImplOptions.NoInlining)]
[TestMethod]
public static void testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static int Main(string[] args)
new CoreFXTestLibrary.Internal.TestInfo("B282745.testIntMDArrayWithPointerLikeValues", () => global::B282745.testIntMDArrayWithPointerLikeValues(), null),
new CoreFXTestLibrary.Internal.TestInfo("B282745.testLongMDArrayWithPointerLikeValues", () => global::B282745.testLongMDArrayWithPointerLikeValues(), null),
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfKnownStructType", () => global::B282745.testMDArrayWithPointerLikeValuesOfKnownStructType(), null),
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType", () => global::B282745.testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType(), null),
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType", () => global::B282745.testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType(), null),
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfUnknownStructPrimitiveType", () => global::B282745.testMDArrayWithPointerLikeValuesOfUnknownStructPrimitiveType(), null),
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWith3Dimensions", () => global::B282745.testMDArrayWith3Dimensions(), null),
Expand Down

0 comments on commit 0a3fb4c

Please sign in to comment.