Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT] Fix MD array GC series #86877

Merged
merged 4 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,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)((i - last) * IntPtr.Size);
Copy link
Member Author

@VSadov VSadov May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseOffset is not a factor in computing the last "skip" in a GC series element. It should be just
the end of the element - offset of the last GC pointer.

For SZ arrays the baseOffset is 2, so adding baseOffset - 2 was harmless.
In MD array it results in incorrect "skip".

VSadov marked this conversation as resolved.
Show resolved Hide resolved
*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