Skip to content

ClassUnloadStarted callback of ICorProfilerCallback is not called for generic class instances in different LoaderAllocator #114068

@alexey-zakharov

Description

@alexey-zakharov

Description

ClassUnloadStarted and ClassUnloadFinished profiler api callbacks are not called for generic instances which are allocated under a different than defining module loader allocator. That:

The if (pMT->IsCanonicalMethodTable()) check in ‎Module::FreeClassTables method prevents the callback from being called.

Reproduction Steps

The following project demonstrates the issue
ClassUnloadRepro.zip

Expected behavior

Console output is

ClassUnloadStarted: TestLibrary.DummyType, TestLibrary.dll
ClassUnloadStarted: List<TestLibrary.DummyType>
ClassLoadFinished calls: 907
ClassUnloadStarted calls: 2

Actual behavior

Console output is

ClassUnloadStarted: TestLibrary.DummyType, TestLibrary.dll
ClassLoadFinished calls: 907
ClassUnloadStarted calls: 1

Regression?

No response

Known Workarounds

N/A

Configuration

.NET 8, 9, 10
Windows x64

Other information

Unity-Technologies#286 solves the issue but may introduce sideeffects on delegate code dereferencing - perhaps it would be better to split profiler callbacks from the other logic in EEClass::Destruct method

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions