Skip to content

Crossgen outerloop regression: WeakReference/IsAlive/IsAlive.cmd #109312

Closed

Description

@kg

WeakReference/IsAlive/IsAlive.cmd fails on the crossgen outerloop lanes:

Return code:      1
Raw output file:      C:\h\w\A5E609B0\w\A9D4091E\uploads\API\WeakReference\IsAlive\output.txt
Raw output:
BEGIN EXECUTION
IsAlive.dll
        1 file(s) copied.
 7:04:11.39
Response file: C:\h\w\A5E609B0\w\A9D4091E\e\GC\API\WeakReference\IsAlive\\composite-r2r.dll.rsp
C:\h\w\A5E609B0\w\A9D4091E\e\GC\API\WeakReference\IsAlive\IL-CG2\*.dll
-o:C:\h\w\A5E609B0\w\A9D4091E\e\GC\API\WeakReference\IsAlive\\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\A9D4091E\e\GC\API\WeakReference\IsAlive\\composite-r2r.dll.rsp"   --composite  --composite"
Emitting R2R PE file: C:\h\w\A5E609B0\w\A9D4091E\e\GC\API\WeakReference\IsAlive\\composite-r2r.dll
Emitting R2R PE file: C:\h\w\A5E609B0\w\A9D4091E\e\GC\API\WeakReference\IsAlive\IsAlive.dll
"Running R2RDump:  "dotnet" "C:\h\w\A5E609B0\p\r2rdump\r2rdump.dll" --header --sc --in C:\h\w\A5E609B0\w\A9D4091E\e\GC\API\WeakReference\IsAlive\\composite-r2r.dll --out C:\h\w\A5E609B0\w\A9D4091E\e\GC\API\WeakReference\IsAlive\\composite-r2r.dll.r2rdump --val"
 7:04:11.92
 "C:\h\w\A5E609B0\p\corerun.exe" -p "System.Reflection.Metadata.MetadataUpdater.IsSupported=false" -p "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true"  IsAlive.dll 
True
True
Test for WeakReference.IsAlive failed!
Xunit.Sdk.EqualException: Assert.Equal() Failure: Values differ
Expected: 100
Actual:   1
   at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in /_/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs:line 174
   at __GeneratedMainWrapper.Main()
Expected: 100
Actual: 101
END EXECUTION - FAILED
FAILED

Activity

  1. added
    untriaged
    on Oct 28, 2024
  2. kg commented on Jul 23, 2025

    @kg
    ContributorAuthor

    This may be a test quality issue, based on examining the test. I don't think it necessarily indicates a bug in crossgen. There is a suspicious codepath in the test that intentionally returns 100 which, if I understand the GC correctly, should never be reachable:

    if(ans1==false) { // GC.Collect() has already occurred..under GCStress
    Console.WriteLine("Test for WeakReference.IsAlive passed!");
    return 100;
    }

    The test failure described in the original post indicates that the array pointed to by the weak reference is still alive after a single invocation of GC.Collect. My best guess for why this would happen is a dangling managed reference to the array at the point of the collection, but I'm not actually certain that the GC is obligated to get rid of the array under these circumstances even if it's unreachable?

    When I run this test locally without crossgen involved at all, it fails:

    PS Z:\runtime> Z:\runtime\artifacts\tests\coreclr\windows.x64.Debug\GC\API\WeakReference\IsAlive\IsAlive.cmd
    BEGIN EXECUTION
     "Z:\runtime\artifacts\tests\coreclr\windows.x64.Debug\Tests\Core_Root\corerun.exe" -p "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true"  IsAlive.dll
    True
    True
    Test for WeakReference.IsAlive failed!
    Xunit.Sdk.EqualException: Assert.Equal() Failure: Values differ
    Expected: 100
    Actual:   1
       at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in /_/src/arcade/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs:line 174
       at __GeneratedMainWrapper.Main()
    Expected: 100
    Actual: 101
    
  3. Maoni0 commented on Jul 23, 2025

    @Maoni0
    Member

    if you induce a full blocking GC (which GC.Collect() does), GC is not in charge of determining what should be live at all. it just gets told by the rest of the runtime. so if the JIT tells the GC what that weakref points to is dead at the time of that GC, it's guaranteed that GC will null the target of the handle the weakref contains (which will cause IsAlive to return false); otherwise IsAlive will return true.

  4. removed
    untriaged
    on Jul 24, 2025
  5. locked and limited conversation to collaborators on Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions