Skip to content

[wasm][R2R] Objects outlive the expected GC under ReadyToRun, breaking finalization/resurrection tests (Samples/gc, arrres_il_r) #134994

Description

@lewing

Description

Under browser-wasm CoreCLR ReadyToRun (test code compiled with crossgen2), two GC finalization tests fail. In both, an object that should be unreachable at a GC.Collect() survives it and is finalized only at a later collection.

GC/Scenarios/Samples/gc (GC-scenarios1, out of process). The Introduction demo's objects are not finalized by the GC.Collect() + WaitForPendingFinalizers() that follows them. They are finalized one collection later, inside the Resurrection demo. The resurrection object is likewise not finalized at its collection, so ResObjHolder is still null:

Demo start: Object Resurrection.
   Obj(Resurrection): BaseObj Constructor
   Obj(Resurrection): ResurrectObj Constructor
   Forcing a garbage collection
   Waiting for Finalizers to complete
      Obj(Introduction): DerivedObj Finalize
      Obj(Introduction): BaseObj Finalize
      ...
   Finalizers are complete
System.NullReferenceException: Object reference not set to an instance of an object.
   at Application.ResurrectionDemo()
   at Application.TestEntryPoint()

JIT/Methodical/Arrays/misc/arrres_il_r (Methodical_r1, out of process). The test throws when the finalizer has not run and resurrected the object after a collection:

Unhandled exception. System.Exception: Exception of type 'System.Exception' was thrown.
   at GCTest_arrres_il.Test.Main()
Aborted(native code called abort())

arrres_il_r already notes that it depends on fully optimized code reporting precise lifetimes (JitOptimizationSensitive). It also fails in crossgen composite lanes (#109311).

Both tests pass in the browser-wasm interpreter leg, so this is specific to test code compiled with ReadyToRun on wasm. A likely cause is that wasm R2R reports a stack slot as live for longer than the object's actual lifetime. Compare #134803, where wasm reports stack roots as pinned.

Configuration

Note

This issue was drafted with GitHub Copilot assistance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmWebAssembly architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIos-browserBrowser variant of arch-wasm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions