Skip to content

Commit 7a31c17

Browse files
authored
[Profiler] Update GetFunctionInfo2 to have a decent default ClassID (#107753)
* [Profiler] Modify GetFunctionInfo2 to always have classId In scenarios where missing frame information would prevent exact ClassID and type arguments from always being resolved, a decent default value such as the method's method table will atleast give callers some information. * [Profiler] Default GetFunctionInfo2 ClassID * Note and simplify logic
1 parent c582320 commit 7a31c17

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

src/coreclr/inc/corprof.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,7 +3168,7 @@ interface ICorProfilerInfo2 : ICorProfilerInfo
31683168
* When a COR_PRF_FRAME_INFO from any other source is passed, or
31693169
* when 0 is passed as the frameInfo argument, exact ClassID and type
31703170
* arguments cannot always be determined. The value returned in pClassId
3171-
* may be NULL and some type args will come back as System.Object.
3171+
* may not be exact and some type args will come back as System.Object.
31723172
*
31733173
*/
31743174
HRESULT GetFunctionInfo2(

src/coreclr/vm/proftoeeinterfaceimpl.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5983,11 +5983,11 @@ HRESULT ProfToEEInterfaceImpl::GetFunctionInfo2(FunctionID funcId,
59835983
TypeHandle specificClass;
59845984
MethodDesc* pActualMethod;
59855985

5986-
ClassID classId = 0;
5986+
TypeHandle typeHandle(pMethDesc->GetMethodTable());
5987+
ClassID classId = TypeHandleToClassID(typeHandle);
59875988

59885989
if (pMethDesc->IsSharedByGenericInstantiations())
59895990
{
5990-
BOOL exactMatch;
59915991
OBJECTREF pThis = NULL;
59925992

59935993
if (pFrameInfo != NULL)
@@ -6010,37 +6010,24 @@ HRESULT ProfToEEInterfaceImpl::GetFunctionInfo2(FunctionID funcId,
60106010
}
60116011
}
60126012

6013-
exactMatch = Generics::GetExactInstantiationsOfMethodAndItsClassFromCallInformation(
6013+
Generics::GetExactInstantiationsOfMethodAndItsClassFromCallInformation(
60146014
pMethDesc,
60156015
pThis,
60166016
PTR_VOID((pFrameInfo != NULL) ? pFrameInfo->extraArg : NULL),
60176017
&specificClass,
60186018
&pActualMethod);
60196019

6020-
if (exactMatch)
6020+
// When GetExactInstantiationsOfMethodAndItsClassFromCallInformation cannot determine
6021+
// the exact class match, the value is correct if the class is not a generic class
6022+
// or is instantiated with value types. Even if those conditions aren't met, the
6023+
// default returned value of the method's method table may still be helpful to callers.
6024+
if (specificClass != NULL)
60216025
{
60226026
classId = TypeHandleToClassID(specificClass);
60236027
}
6024-
else if (!specificClass.HasInstantiation() || !specificClass.IsSharedByGenericInstantiations())
6025-
{
6026-
//
6027-
// In this case we could not get the type args for the method, but if the class
6028-
// is not a generic class or is instantiated with value types, this value is correct.
6029-
//
6030-
classId = TypeHandleToClassID(specificClass);
6031-
}
6032-
else
6033-
{
6034-
//
6035-
// We could not get any class information.
6036-
//
6037-
classId = 0;
6038-
}
60396028
}
60406029
else
60416030
{
6042-
TypeHandle typeHandle(pMethDesc->GetMethodTable());
6043-
classId = TypeHandleToClassID(typeHandle);
60446031
pActualMethod = pMethDesc;
60456032
}
60466033

0 commit comments

Comments
 (0)