Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Don't assume objects don't escape in pure helpers. #21177

Merged
merged 1 commit into from Nov 24, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/jit/objectalloc.cpp
Expand Up @@ -579,14 +579,12 @@ bool ObjectAllocator::CanLclVarEscapeViaParentStack(ArrayStack<GenTree*>* parent

if (asCall->gtCallType == CT_HELPER)
{
const CorInfoHelpFunc helperNum = comp->eeGetHelperNum(asCall->gtCallMethHnd);
// TODO-ObjectStackAllocation: Special-case helpers here that

Choose a reason for hiding this comment

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

@erozenfeld - is there a tracking issue for this TODO?

Copy link
Member Author

Choose a reason for hiding this comment

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

@CarolEidt It's one of the items in todo list in https://github.com/dotnet/coreclr/issues/20253#issue-366568135 :

  • special case calls to helpers where arguments don't escape (this will require ensuring that the helpers report gc arguments as interior to gc)

// 1. Don't make objects escape.
// 2. Protect objects as interior (GCPROTECT_BEGININTERIOR() instead of GCPROTECT_BEGIN()).
// 3. Don't check that the object is in the heap in ValidateInner.

if (Compiler::s_helperCallProperties.IsPure(helperNum))
{
// Pure helpers don't modify the heap.
// TODO-ObjectStackAllocation: We may be able to special-case more helpers here.
canLclVarEscapeViaParentStack = false;
}
canLclVarEscapeViaParentStack = true;
}
break;
}
Expand Down
Expand Up @@ -101,10 +101,6 @@ public static int Main()

CallTestAndVerifyAllocation(AllocateSimpleClassesAndNECompareThem, 1, expectedAllocationKind);

CallTestAndVerifyAllocation(AllocateSimpleClassAndCheckType, 1, expectedAllocationKind);

CallTestAndVerifyAllocation(AllocateSimpleClassAndCast, 7, expectedAllocationKind);

CallTestAndVerifyAllocation(AllocateSimpleClassAndGetField, 7, expectedAllocationKind);

CallTestAndVerifyAllocation(AllocateClassWithNestedStructAndGetField, 5, expectedAllocationKind);
Expand All @@ -116,6 +112,12 @@ public static int Main()
expectedAllocationKind = AllocationKind.Heap;
}

// This test calls CORINFO_HELP_ISINSTANCEOFCLASS
CallTestAndVerifyAllocation(AllocateSimpleClassAndCheckType, 1, expectedAllocationKind);

// This test calls CORINFO_HELP_CHKCASTCLASS_SPECIAL
CallTestAndVerifyAllocation(AllocateSimpleClassAndCast, 7, expectedAllocationKind);

// Stack allocation of classes with GC fields is currently disabled
CallTestAndVerifyAllocation(AllocateSimpleClassWithGCFieldAndAddFields, 12, expectedAllocationKind);

Expand Down