Don't assume objects don't escape in pure helpers.
authorEugene Rozenfeld <erozen@microsoft.com>
Fri, 23 Nov 2018 22:55:02 +0000 (14:55 -0800)
committerEugene Rozenfeld <erozen@microsoft.com>
Sat, 24 Nov 2018 06:33:32 +0000 (22:33 -0800)
commita0bfc3087a3774e05172d656c423851425035c8b
tree744123326290a4fcc5247426437845efd0291675
parent0cd617e2636bb2c9b5b6f92ea28fd4a5dfd6a874
Don't assume objects don't escape in pure helpers.

We can't assume objects don't escape in helpers marked as pure for the following reasons:

1. The helpers may call user code that may make objects escape, e.g.,
https://github.com/dotnet/coreclr/blob/dotnet/coreclr@c94d8e68222d931d4bb1c4eb9a52b4b056e85f12/src/vm/jithelpers.cpp#L2371

2. The helpers usually protect gc pointers with GCPROTECT_BEGIN() so the pointers are reported as normal pointers to the gc.
Pointers to stack-allocated objects need to be reported as interior so they have to be protected with
GCPROTECT_BEGININTERIOR().

3. The helpers may cause these asserts in ValidateInner on stack-allocated objects:
https://github.com/dotnet/coreclr/blob/dotnet/coreclr@c94d8e68222d931d4bb1c4eb9a52b4b056e85f12/src/vm/object.cpp#L723
https://github.com/dotnet/coreclr/blob/dotnet/coreclr@c94d8e68222d931d4bb1c4eb9a52b4b056e85f12/src/vm/object.cpp#L730

Commit migrated from https://github.com/dotnet/coreclr/commit/65f88672f888e893a44f21b59ecfd87f4d17e499
src/coreclr/src/jit/objectalloc.cpp
src/coreclr/tests/src/JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests.cs