@@ -2906,7 +2906,7 @@ TypeHandle ClassLoader::DoIncrementalLoad(TypeKey *pTypeKey, TypeHandle typeHnd,
2906
2906
2907
2907
if (typeHnd.GetLoadLevel () >= CLASS_LOAD_EXACTPARENTS)
2908
2908
{
2909
- Notify (typeHnd);
2909
+ NotifyLoad (typeHnd);
2910
2910
}
2911
2911
2912
2912
return typeHnd;
@@ -3109,7 +3109,7 @@ TypeHandle ClassLoader::PublishType(TypeKey *pTypeKey, TypeHandle typeHnd)
3109
3109
// Notify profiler and debugger that a type load has completed
3110
3110
// Also adjust perf counters
3111
3111
/* static*/
3112
- void ClassLoader::Notify (TypeHandle typeHnd)
3112
+ void ClassLoader::NotifyLoad (TypeHandle typeHnd)
3113
3113
{
3114
3114
CONTRACTL
3115
3115
{
@@ -3177,6 +3177,68 @@ void ClassLoader::Notify(TypeHandle typeHnd)
3177
3177
}
3178
3178
}
3179
3179
3180
+ // Notify profiler that a MethodTable is being unloaded
3181
+ /* static*/
3182
+ void ClassLoader::NotifyUnload (MethodTable* pMT, bool unloadStarted)
3183
+ {
3184
+ CONTRACTL
3185
+ {
3186
+ NOTHROW;
3187
+ GC_TRIGGERS;
3188
+ MODE_ANY;
3189
+ FORBID_FAULT;
3190
+ PRECONDITION (pMT != NULL );
3191
+ }
3192
+ CONTRACTL_END
3193
+
3194
+ #ifdef PROFILING_SUPPORTED
3195
+ // If profiling, then notify the class is getting unloaded.
3196
+ {
3197
+ BEGIN_PROFILER_CALLBACK (CORProfilerTrackClasses ());
3198
+ {
3199
+ if (pMT->ContainsGenericVariables () || pMT->IsArray ())
3200
+ {
3201
+ // Don't notify the profiler about types with unbound variables or arrays.
3202
+ // See ClassLoadStarted callback for more details.
3203
+ return ;
3204
+ }
3205
+
3206
+ // Calls to the profiler callback may throw, or otherwise fail, if
3207
+ // the profiler AVs/throws an unhandled exception/etc. We don't want
3208
+ // those failures to affect the runtime, so we'll ignore them.
3209
+ //
3210
+ // Note that the profiler callback may turn around and make calls into
3211
+ // the profiling runtime that may throw. This try/catch block doesn't
3212
+ // protect the profiler against such failures. To protect the profiler
3213
+ // against that, we will need try/catch blocks around all calls into the
3214
+ // profiling API.
3215
+ //
3216
+ // (Bug #26467)
3217
+ //
3218
+
3219
+ FAULT_NOT_FATAL ();
3220
+
3221
+ EX_TRY
3222
+ {
3223
+ GCX_PREEMP ();
3224
+
3225
+ if (unloadStarted)
3226
+ (&g_profControlBlock)->ClassUnloadStarted ((ClassID) pMT);
3227
+ else
3228
+ (&g_profControlBlock)->ClassUnloadFinished ((ClassID) pMT, S_OK);
3229
+ }
3230
+ EX_CATCH
3231
+ {
3232
+ // The exception here came from the profiler itself. We'll just
3233
+ // swallow the exception, since we don't want the profiler to bring
3234
+ // down the runtime.
3235
+ }
3236
+ EX_END_CATCH (RethrowTerminalExceptions);
3237
+ }
3238
+ END_PROFILER_CALLBACK ();
3239
+ }
3240
+ #endif // PROFILING_SUPPORTED
3241
+ }
3180
3242
3181
3243
// -----------------------------------------------------------------------------
3182
3244
// Common helper for LoadTypeHandleForTypeKey and LoadTypeHandleForTypeKeyNoLock.
0 commit comments