Skip to content

Crossgen outerloop regression: JIT/opt/ObjectStackAllocation/ObjectStackAllocationTests/ObjectStackAllocationTests.cmd #109314

Description

@kg

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

Activity

  1. self-assigned this
    on May 21, 2025
  2. added this to the 10.0.0 milestone on May 21, 2025
  3. AndyAyersMS commented on Jun 13, 2025

    @AndyAyersMS
    Member

    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):

    SUCCESS (AllocateSimpleClassAndAddFields)
    SUCCESS (AllocateSimpleClassesAndEQCompareThem)
    SUCCESS (AllocateSimpleClassesAndNECompareThem)
    SUCCESS (AllocateSimpleClassAndGetField)
    SUCCESS (AllocateClassWithNestedStructAndGetField)
    SUCCESS (AllocateClassWithNestedStructAndAddFields)
    SUCCESS (AllocateSimpleClassWithGCFieldAndAddFields)
    SUCCESS (AllocateSimpleClassAndAssignRefToAField)
    SUCCESS (TestMixOfReportingAndWriteBarriers)
    SUCCESS (AllocateSimpleClassAndCheckTypeNoHelper)
    SUCCESS (AllocateClassWithGcFieldAndInt)
    SUCCESS (BoxSimpleStructAndAddFields)
      41: JIT compiled ObjectStackAllocation.Tests:AllocateArrayWithNonGCElements():int [FullOpts, IL size=28, code size=289, hash=0x15561db7]
    SUCCESS (AllocateArrayWithNonGCElements)
      42: JIT compiled ObjectStackAllocation.Tests:AllocateArrayWithGCElements():int [FullOpts, IL size=39, code size=306, hash=0x0245b8f8]
    SUCCESS (AllocateArrayWithGCElements)
      43: JIT compiled ObjectStackAllocation.Tests:AllocateArrayT[int]():int [FullOpts, IL size=31, code size=286, hash=0xa46f0952]
    SUCCESS (AllocateArrayT)
    FAILURE (AllocateArrayT): unexpected allocation of 360 bytes
    FAILURE (SpanCaptureArray1): unexpected allocation of 424 bytes
    FAILURE (SpanCaptureArray2): unexpected allocation of 424 bytes
    FAILURE (SpanCaptureArrayT): unexpected allocation of 176 bytes
    FAILURE (SpanCaptureArrayT): unexpected allocation of 320 bytes
      44: JIT compiled ObjectStackAllocation.Tests:StructReferredObjects():int [FullOpts, IL size=84, code size=120, hash=0xfcf19673]
    SUCCESS (StructReferredObjects)
    SUCCESS (AllocateSimpleClassAndCheckTypeHelper)
    SUCCESS (AllocateSimpleClassAndCast)
    SUCCESS (AllocateArrayWithNonGCElementsEscape)
    SUCCESS (AllocateArrayWithGCElementsEscape)
    SUCCESS (SpanEscapeArrayArg)
    SUCCESS (SpanEscapeArrayArgCopy)
    SUCCESS (SpanEscapeArrayOutParam)
    SUCCESS (SpanEscapeArrayOutParam2)
    SUCCESS (SpanEscapeRef)
    SUCCESS (StructReferredObjectEscape1)
    SUCCESS (StructReferredObjectEscape2)
    SUCCESS (StructReferredObjectEscape3)
    SUCCESS (StructReferredObjectEscape4)
    SUCCESS (StructReferredObjectEscape5)
      45: JIT compiled ObjectStackAllocation.Tests:AllocateArrayWithNonGCElementsOutOfRangeLeft():int [FullOpts, IL size=18, code size=302, hash=0xa1cf0414]
      46: JIT compiled Internal.Runtime.CompilerHelpers.ThrowHelpers:ThrowIndexOutOfRangeException() [FullOpts, IL size=6, code size=41, hash=0xf634c5d9]
    SUCCESS (AllocateArrayWithNonGCElementsOutOfRangeLeft)
      47: JIT compiled ObjectStackAllocation.Tests:AllocateArrayWithNonGCElementsOutOfRangeRight():int [FullOpts, IL size=19, code size=305, hash=0xcc42f56f]
    SUCCESS (AllocateArrayWithNonGCElementsOutOfRangeRight)
    SUCCESS (AllocateNegativeLengthArrayWithNonGCElements)
    SUCCESS (AllocateLongLengthArrayWithNonGCElements)
    
    

    There are a couple of issues:

    • 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.

    @davidwrighton @jkotas thoughts on the above?

  4. AndyAyersMS commented on Jun 13, 2025

    @AndyAyersMS
    Member

    In the case above we're trying to embed the handle for int[] which seems like it ought not to be versionable?

  5. added a commit that references this issue on Jun 13, 2025
    8baf0bd
  6. AndyAyersMS commented on Jul 15, 2025

    @AndyAyersMS
    Member

    This requires #116651 which seems unlikely to make it into .NET 10.

  7. AndyAyersMS commented on Jul 17, 2025

    @AndyAyersMS
    Member

    Moving this to 11.0.

  8. modified the milestones: 10.0.0, 11.0.0 on Jul 17, 2025
  9. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    and removed on Jul 3, 2026
  10. dotnet-policy-service commented on Jul 3, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  11. AndyAyersMS commented on Jul 15, 2026

    @AndyAyersMS
    Member

    Moving this out of 11.0

  12. modified the milestones: 11.0.0, Future on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

  • Status
    No status

Relationships

None yet

Development

No branches or pull requests

Issue actions