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] Always zero-init if object contains pointers #100265

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/Runtime/GCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ static Object* GcAllocInternal(MethodTable* pEEType, uint32_t uFlags, uintptr_t
ASSERT(!pThread->IsDoNotTriggerGcSet());
ASSERT(pThread->IsCurrentThreadInCooperativeMode());

if (pEEType->ContainsPointers())
{
uFlags |= GC_ALLOC_CONTAINS_REF;
uFlags &= ~GC_ALLOC_ZEROING_OPTIONAL;
}

size_t cbSize = pEEType->GetBaseSize();

if (pEEType->HasComponentSize())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,8 @@ private unsafe static void AllocateArrayPinned_ManagedValueType_CanRoundtripThro
byte* pointer = (byte*)Unsafe.AsPointer(ref array[0]); // Unsafe.AsPointer is safe since array is pinned
var size = Unsafe.SizeOf<EmbeddedValueType<string>>();

GC.Collect();

for(int i = 0; i < length; ++i)
{
int idx = rng.Next(length);
Expand Down
Loading