Skip to content

Commit 9c54d30

Browse files
Move NotifyUnload method
(cherry picked from commit 97ee0de)
1 parent 577eb44 commit 9c54d30

File tree

5 files changed

+75
-77
lines changed

5 files changed

+75
-77
lines changed

src/coreclr/vm/ceeload.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,9 +1957,9 @@ void Module::FreeClassTables()
19571957

19581958
if (pMT != NULL && pMT->IsRestored())
19591959
{
1960-
EEClass::NotifyUnload(pMT, true);
1961-
pMT->GetClass()->Destruct(pMT);
1962-
EEClass::NotifyUnload(pMT, false);
1960+
ClassLoader::NotifyUnload(pMT, true);
1961+
pMT->GetClass()->Destruct();
1962+
ClassLoader::NotifyUnload(pMT, false);
19631963
}
19641964
}
19651965

@@ -1980,15 +1980,15 @@ void Module::FreeClassTables()
19801980
continue;
19811981

19821982
MethodTable * pMT = th.AsMethodTable();
1983-
EEClass::NotifyUnload(pMT, true);
1983+
ClassLoader::NotifyUnload(pMT, true);
19841984

19851985
// We need to call destruct on instances of EEClass whose "canonical" dependent lives in this table
19861986
if (pMT->IsCanonicalMethodTable())
19871987
{
1988-
pMT->GetClass()->Destruct(pMT);
1988+
pMT->GetClass()->Destruct();
19891989
}
19901990

1991-
EEClass::NotifyUnload(pMT, false);
1991+
ClassLoader::NotifyUnload(pMT, false);
19921992
}
19931993
}
19941994
}

src/coreclr/vm/class.cpp

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ void *EEClass::operator new(
7373
}
7474

7575
//*******************************************************************************
76-
void EEClass::Destruct(MethodTable * pOwningMT)
76+
void EEClass::Destruct()
7777
{
7878
CONTRACTL
7979
{
8080
NOTHROW;
8181
GC_TRIGGERS;
8282
FORBID_FAULT;
83-
PRECONDITION(pOwningMT != NULL);
8483
}
8584
CONTRACTL_END
8685

@@ -137,68 +136,6 @@ void EEClass::Destruct(MethodTable * pOwningMT)
137136
#endif // FEATURE_COMINTEROP
138137
}
139138

140-
//*******************************************************************************
141-
void EEClass::NotifyUnload(MethodTable* pMT, bool unloadStarted)
142-
{
143-
CONTRACTL
144-
{
145-
NOTHROW;
146-
GC_TRIGGERS;
147-
MODE_ANY;
148-
FORBID_FAULT;
149-
PRECONDITION(pMT != NULL);
150-
}
151-
CONTRACTL_END
152-
153-
#ifdef PROFILING_SUPPORTED
154-
// If profiling, then notify the class is getting unloaded.
155-
{
156-
BEGIN_PROFILER_CALLBACK(CORProfilerTrackClasses());
157-
{
158-
if (pMT->ContainsGenericVariables() || pMT->IsArray())
159-
{
160-
// Don't notify the profiler about types with unbound variables or arrays.
161-
// See ClassLoadStarted callback for more details.
162-
return;
163-
}
164-
165-
// Calls to the profiler callback may throw, or otherwise fail, if
166-
// the profiler AVs/throws an unhandled exception/etc. We don't want
167-
// those failures to affect the runtime, so we'll ignore them.
168-
//
169-
// Note that the profiler callback may turn around and make calls into
170-
// the profiling runtime that may throw. This try/catch block doesn't
171-
// protect the profiler against such failures. To protect the profiler
172-
// against that, we will need try/catch blocks around all calls into the
173-
// profiling API.
174-
//
175-
// (Bug #26467)
176-
//
177-
178-
FAULT_NOT_FATAL();
179-
180-
EX_TRY
181-
{
182-
GCX_PREEMP();
183-
184-
if (unloadStarted)
185-
(&g_profControlBlock)->ClassUnloadStarted((ClassID) pMT);
186-
else
187-
(&g_profControlBlock)->ClassUnloadFinished((ClassID) pMT, S_OK);
188-
}
189-
EX_CATCH
190-
{
191-
// The exception here came from the profiler itself. We'll just
192-
// swallow the exception, since we don't want the profiler to bring
193-
// down the runtime.
194-
}
195-
EX_END_CATCH(RethrowTerminalExceptions);
196-
}
197-
END_PROFILER_CALLBACK();
198-
}
199-
#endif // PROFILING_SUPPORTED
200-
}
201-
202139
//*******************************************************************************
203140
/*static*/ EEClass *
204141
EEClass::CreateMinimalClass(LoaderHeap *pHeap, AllocMemTracker *pamTracker)

src/coreclr/vm/class.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,7 @@ class EEClass // DO NOT CREATE A NEW EEClass USING NEW!
773773

774774
#ifndef DACCESS_COMPILE
775775
void *operator new(size_t size, LoaderHeap* pHeap, AllocMemTracker *pamTracker);
776-
void Destruct(MethodTable * pMT);
777-
778-
// Notify profiler about class unload
779-
static void NotifyUnload(MethodTable* pMT, bool unloadStarted);
776+
void Destruct();
780777

781778
static EEClass * CreateMinimalClass(LoaderHeap *pHeap, AllocMemTracker *pamTracker);
782779
#endif // !DACCESS_COMPILE

src/coreclr/vm/clsload.cpp

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,7 +2906,7 @@ TypeHandle ClassLoader::DoIncrementalLoad(TypeKey *pTypeKey, TypeHandle typeHnd,
29062906

29072907
if (typeHnd.GetLoadLevel() >= CLASS_LOAD_EXACTPARENTS)
29082908
{
2909-
Notify(typeHnd);
2909+
NotifyLoad(typeHnd);
29102910
}
29112911

29122912
return typeHnd;
@@ -3109,7 +3109,7 @@ TypeHandle ClassLoader::PublishType(TypeKey *pTypeKey, TypeHandle typeHnd)
31093109
// Notify profiler and debugger that a type load has completed
31103110
// Also adjust perf counters
31113111
/*static*/
3112-
void ClassLoader::Notify(TypeHandle typeHnd)
3112+
void ClassLoader::NotifyLoad(TypeHandle typeHnd)
31133113
{
31143114
CONTRACTL
31153115
{
@@ -3177,6 +3177,68 @@ void ClassLoader::Notify(TypeHandle typeHnd)
31773177
}
31783178
}
31793179

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+
}
31803242

31813243
//-----------------------------------------------------------------------------
31823244
// Common helper for LoadTypeHandleForTypeKey and LoadTypeHandleForTypeKeyNoLock.

src/coreclr/vm/clsload.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,9 @@ class ClassLoader
951951

952952
// Notify profiler and debugger that a type load has completed
953953
// Also update perf counters
954-
static void Notify(TypeHandle typeHnd);
954+
static void NotifyLoad(TypeHandle typeHnd);
955+
// Notify profiler that a MethodTable is being unloaded
956+
static void NotifyUnload(MethodTable* pMT, bool unloadStarted);
955957

956958
// Phase CLASS_LOAD_EXACTPARENTS of class loading
957959
// Load exact parents and interfaces and dependent structures (generics dictionary, vtable fixes)

0 commit comments

Comments
 (0)