Repository navigation
Send profiler ClassUnload callbacks for array types - #136862
Merged
Merged
Conversation
dotnet#120796 made ClassLoader::NotifyLoad report array method tables, but NotifyUnload still returns early for arrays. When a collectible module unloads, Module::FreeClassTables calls NotifyUnload for each array type in the module's table. So a profiler got ClassLoadStarted and ClassLoadFinished for T[], but never ClassUnloadStarted or ClassUnloadFinished. Drop the IsArray check, so NotifyUnload skips the same types as NotifyLoad. The classload profiler test could not see this, because the test profiler names every array "ArrayClass". The test now names arrays by their element type, so it counts TestClass[], which List<TestClass> allocates. It expects 8 loads and 8 unloads; without the runtime change it sees 8 loads and 7 unloads.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new array callbacks cause the profiler’s unload handler to fail on array class IDs, while the test’s collection before Unload() can miss this failure.
1 open issue
What changed in this PR
This PR restores matching profiler load and unload notifications for array types in CoreCLR, completing the array callback support introduced in #120796.
Changes:
- Allow array types through
ClassLoader::NotifyUnload, while still excluding types with unbound generic variables. - Update the
classloadprofiler test to recognize arrays by element type and expect eight load/unload pairs. - Correct a comment in module cleanup to describe the skipped
TypeDescentries.
| File | Description |
|---|---|
src/tests/profiler/native/classload/classload.h |
Declares the array-aware type-name helper. |
src/tests/profiler/native/classload/classload.cpp |
Counts array callbacks and updates expected totals. |
src/coreclr/vm/clsload.cpp |
Enables profiler unload callbacks for array types. |
src/coreclr/vm/ceeload.cpp |
Corrects the cleanup comment; no behavior change. |
Review effort: Balanced
With array types now reported to ClassUnloadStarted, the getappdomainstaticaddress test profiler calls GetClassIDInfo2 on them. That returns CORPROF_E_CLASSID_IS_ARRAY, and the profiler counts it as a failure. Skip array classes there, as ClassLoadFinished already does. The test did not catch this: it called GC.Collect before Unload and did not collect again afterward. Earlier runs show no module-unload callback. The test now holds a WeakReference to the context and runs up to ten collections after Unload, stopping once the context is gone.
Contributor
Author
|
Thank you for the review and merge! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related to #120799.
This PR makes
ClassLoader::NotifyUnloadreport array types, so profilers get the unload callbacks that match the array load callbacks added in #120796. It also updates two profiler tests:classloadnow counts arrays, andgetappdomainstaticaddressnow runs up to ten collections afterUnload()and skips arrays in its unload callback.The gap
#114107 added
ClassLoader::NotifyUnloadand theclassloadtest.NotifyUnloadskipped the same types thatNotifyLoadskipped then: method tables that contain generic variables, and arrays. #120796 then madeNotifyLoadreport array method tables, butNotifyUnloadstill returns early for arrays. When a collectible module unloads,Module::FreeClassTablescallsNotifyUnloadfor each array type in the module's table. So forT[], withTin a collectibleAssemblyLoadContext, a profiler getsClassLoadStartedandClassLoadFinishedbut neverClassUnloadStartedorClassUnloadFinished. TheClassIDit was given stops being valid without notice.Change
NotifyUnloadno longer checksIsArray(), so it skips the same types asNotifyLoad: method tables that contain generic variables.Test
The
classloadprofiler test could not see the gap. It counts only types whose name containsUnloadLibrary.TestClass, and the shared test profiler'sGetClassIDNamenames every array "ArrayClass". The test now names an array by its element type (throughIsArrayClass), so it countsTestClass[], whichList<TestClass>allocates. It now expects 8 loads and 8 unloads instead of 7 and 7.The fix also showed a gap in the
getappdomainstaticaddresstest. InClassUnloadStarted, its profiler callsGetClassIDInfo2. That call returnsCORPROF_E_CLASSID_IS_ARRAYfor the array types the runtime now reports. The profiler now skips arrays there, as itsClassLoadFinishedalready does. The test missed this: it calledGC.Collect()beforeUnload()and did not collect again afterward, and the earlier runs show no module-unload callback. The test now holds aWeakReferenceto the context and runs up to ten collections, stopping once the context is gone.Validation
I ran the validation with a Checked runtime and Release libraries at main
c772c4c. The table compares runs without the runtime fix, with it, and after reverting it again. For the last run, I rebuilt the runtime a second time and ranclassloadon its own.classloadwithout the fixI ran the updated
getappdomainstaticaddresstest four ways per platform. It passes without the runtime fix. With the runtime fix but without the profiler's array skip, it fails withCORPROF_E_CLASSID_IS_ARRAY. It passes with the runtime fix and the skip. It fails again when only the skip is removed.With the runtime fix and both updated tests, every test under
src/tests/profiler(Pri 1 build) passes: 31 on linux-x64 and osx-arm64, and 32 on windows-arm64, whereijwalso runs. The fourJitOptimizationSensitivetests (DynamicOptimization,eventpipe,multiple,rejit) ran withDOTNET_TieredCompilation=0. In the earlier full runs without the runtime fix, made before thegetappdomainstaticaddresschange, onlyclassloadfailed.Note
This PR was prepared with AI assistance (Anthropic Claude), under my direction. I reviewed the change and this description before posting.