You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests/ObjectStackAllocationTests.cmd fails on the crossgen outerloop lanes. It looks like an object is being heap allocated that isn't expected to be, but that might be normal and expected for crossgen?
Return code: 1
Raw output file: C:\h\w\A5E609B0\w\AB7508F1\uploads\ObjectStackAllocation\ObjectStackAllocationTests\output.txt
Raw output:
BEGIN EXECUTION
ObjectStackAllocationTests.dll
1 file(s) copied.
7:03:05.78
Response file: C:\h\w\A5E609B0\w\AB7508F1\e\JIT\opt\ObjectStackAllocation\ObjectStackAllocationTests\\composite-r2r.dll.rsp
C:\h\w\A5E609B0\w\AB7508F1\e\JIT\opt\ObjectStackAllocation\ObjectStackAllocationTests\IL-CG2\*.dll
-o:C:\h\w\A5E609B0\w\AB7508F1\e\JIT\opt\ObjectStackAllocation\ObjectStackAllocationTests\\composite-r2r.dll
--targetarch:x64
--targetos:windows
--verify-type-and-field-layout
--method-layout:random
-r:C:\h\w\A5E609B0\p\System.*.dll
-r:C:\h\w\A5E609B0\p\Microsoft.*.dll
-r:C:\h\w\A5E609B0\p\xunit.*.dll
-r:C:\h\w\A5E609B0\p\mscorlib.dll
-r:C:\h\w\A5E609B0\p\netstandard.dll
"Running CrossGen2: "C:\h\w\A5E609B0\p\crossgen2\crossgen2.exe" @"C:\h\w\A5E609B0\w\AB7508F1\e\JIT\opt\ObjectStackAllocation\ObjectStackAllocationTests\\composite-r2r.dll.rsp" --composite --composite"
Emitting R2R PE file: C:\h\w\A5E609B0\w\AB7508F1\e\JIT\opt\ObjectStackAllocation\ObjectStackAllocationTests\\composite-r2r.dll
Emitting R2R PE file: C:\h\w\A5E609B0\w\AB7508F1\e\JIT\opt\ObjectStackAllocation\ObjectStackAllocationTests\ObjectStackAllocationTests.dll
"Running R2RDump: "dotnet" "C:\h\w\A5E609B0\p\r2rdump\r2rdump.dll" --header --sc --in C:\h\w\A5E609B0\w\AB7508F1\e\JIT\opt\ObjectStackAllocation\ObjectStackAllocationTests\\composite-r2r.dll --out C:\h\w\A5E609B0\w\AB7508F1\e\JIT\opt\ObjectStackAllocation\ObjectStackAllocationTests\\composite-r2r.dll.r2rdump --val"
7:03:06.34
"C:\h\w\A5E609B0\p\corerun.exe" -p "System.Reflection.Metadata.MetadataUpdater.IsSupported=false" -p "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true" ObjectStackAllocationTests.dll
System.InvalidOperationException: Unexpected allocation: 48 bytes
at ObjectStackAllocation.Tests.EnsureZeroAllocated(Int64 before)
at ObjectStackAllocation.Tests.ZeroAllocTest()
at ObjectStackAllocation.Tests.TestEntryPoint()
at __GeneratedMainWrapper.Main()
Expected: 100
Actual: 101
END EXECUTION - FAILED
FAILED
With a recent build things get a bit further, but the test still has failures (run with JitDisasmSummary=1 so we can see which parts of the test end up getting jitted):
Object allocation doesn't support CORINFO_HELP_READYTORUN_NEWARR_1. It's not hard to add support but it looks like quite often when the JIT asks the host to embed the type handle for the on stack array type the embedding fails with versioning issues. I don't think there is any way currently for the JIT to ask if a type can be embedded so that leaves us with two undesirable options:
try embedding blindly and so risk losing the whole method in R2R if the embedding request fails. This is what happens for AllocateArrayT<int> test above. In normal operation these methods will then compile at Tier0 and the jitted version will allocate too (though this specific test case will pass in CI because we disable tiered compilation). So we've wasted some R2R compile time and not gained any benefit at runtime.
don't try any array allocation and so possibly bake in allocation for some arrays that could be stack allocated. But maybe embedding always fails in these cases and so these "lost" stack allocations are illusory.
R2R can't inline as aggressively as Tier0, so tests where escape analysis depends on inlining may fail. This impacts the various SpanCapture... failing tests above. Here we should just mark the test methods as AggressiveOptimization.
If there was some kind of "can the JIT embed this type" interface call, then the JIT could try and maximize the amount of stack allocation but not at the expense of reducing the set of methods that can be R2Rd.
Activity
AndyAyersMS commentedon Jun 13, 2025
With a recent build things get a bit further, but the test still has failures (run with JitDisasmSummary=1 so we can see which parts of the test end up getting jitted):
There are a couple of issues:
CORINFO_HELP_READYTORUN_NEWARR_1. It's not hard to add support but it looks like quite often when the JIT asks the host to embed the type handle for the on stack array type the embedding fails with versioning issues. I don't think there is any way currently for the JIT to ask if a type can be embedded so that leaves us with two undesirable options:AllocateArrayT<int>test above. In normal operation these methods will then compile at Tier0 and the jitted version will allocate too (though this specific test case will pass in CI because we disable tiered compilation). So we've wasted some R2R compile time and not gained any benefit at runtime.SpanCapture...failing tests above. Here we should just mark the test methods asAggressiveOptimization.If there was some kind of "can the JIT embed this type" interface call, then the JIT could try and maximize the amount of stack allocation but not at the expense of reducing the set of methods that can be R2Rd.
@davidwrighton @jkotas thoughts on the above?
AndyAyersMS commentedon Jun 13, 2025
In the case above we're trying to embed the handle for
int[]which seems like it ought not to be versionable?JIT: enable stack allocation of more arrays in R2R
AndyAyersMS commentedon Jul 15, 2025
This requires #116651 which seems unlikely to make it into .NET 10.
AndyAyersMS commentedon Jul 17, 2025
Moving this to 11.0.
dotnet-policy-service commentedon Jul 3, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
AndyAyersMS commentedon Jul 15, 2026
Moving this out of 11.0
[wasm] Fix JIT helper calls modeled with the wrong return arity (#131383