Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper context in initClass for GDV #87847

Merged
merged 31 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
81df161
Slightly faster atomic increment
EgorBo Jun 13, 2023
145f1b2
Merge branch 'main' of github.com:dotnet/runtime
EgorBo Jun 19, 2023
9c6343f
Merge branch 'main' of github.com:dotnet/runtime
EgorBo Jun 20, 2023
c8e0dd0
use proper context in GDV
EgorBo Jun 20, 2023
bee352f
test
EgorBo Jun 21, 2023
fa14183
test2
EgorBo Jun 22, 2023
c35c337
Test fix
EgorBo Jun 24, 2023
6716059
Update jitinterface.cpp
EgorBo Jun 25, 2023
8babb27
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jun 25, 2023
7ef4563
test 3
EgorBo Jun 25, 2023
05d2660
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jun 30, 2023
632efc9
Test
EgorBo Jun 30, 2023
5347598
Update importercalls.cpp
EgorBo Jun 30, 2023
6ee9280
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jun 30, 2023
39478fa
fix regressions
EgorBo Jun 30, 2023
848d4ff
Update importercalls.cpp
EgorBo Jun 30, 2023
671e7a6
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jul 2, 2023
fdc390a
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jul 2, 2023
19b8e25
revert
EgorBo Jul 3, 2023
7ee1d65
Merge branch 'fix-ravendb-issue' of github.com:EgorBo/runtime-1 into …
EgorBo Jul 13, 2023
3d68462
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jul 13, 2023
0d4fddb
test fix
EgorBo Jul 15, 2023
83462ac
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jul 15, 2023
c49687b
temp fix for r2r
EgorBo Jul 16, 2023
be7b14d
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jul 16, 2023
361d9dd
Revert r2r workaround
EgorBo Jul 17, 2023
8ff5b0a
Tweak behavior of resolveVirtualMethod in the managed compilers to ha…
davidwrighton Jul 18, 2023
bb7009d
Be a bit more permissive around unboxing stubs in checking virtual ov…
davidwrighton Jul 18, 2023
254a843
Fix Unix build break
davidwrighton Jul 19, 2023
fbee1a6
This is a cleaner fix
davidwrighton Jul 21, 2023
a7ee0bf
Merge branch 'main' of github.com:dotnet/runtime into fix-ravendb-issue
EgorBo Jul 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7152,12 +7152,13 @@ class Compiler

bool isCompatibleMethodGDV(GenTreeCall* call, CORINFO_METHOD_HANDLE gdvTarget);

void addGuardedDevirtualizationCandidate(GenTreeCall* call,
CORINFO_METHOD_HANDLE methodHandle,
CORINFO_CLASS_HANDLE classHandle,
unsigned methodAttr,
unsigned classAttr,
unsigned likelihood);
void addGuardedDevirtualizationCandidate(GenTreeCall* call,
CORINFO_METHOD_HANDLE methodHandle,
CORINFO_CLASS_HANDLE classHandle,
CORINFO_CONTEXT_HANDLE contextHandle,
unsigned methodAttr,
unsigned classAttr,
unsigned likelihood);

int getGDVMaxTypeChecks()
{
Expand Down
36 changes: 23 additions & 13 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5931,8 +5931,8 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,
likelyHood += 100 - likelyHood * numExactClasses;
}

addGuardedDevirtualizationCandidate(call, exactMethod, exactCls, exactMethodAttrs, clsAttrs,
likelyHood);
addGuardedDevirtualizationCandidate(call, exactMethod, exactCls, dvInfo.exactContext, exactMethodAttrs,
clsAttrs, likelyHood);
}

if (call->GetInlineCandidatesCount() == numExactClasses)
Expand All @@ -5959,6 +5959,8 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,
CORINFO_METHOD_HANDLE likelyMethod = likelyMethodes[candidateId];
unsigned likelihood = likelihoods[candidateId];

CORINFO_CONTEXT_HANDLE likelyContext = NULL;

uint32_t likelyClassAttribs = 0;
if (likelyClass != NO_CLASS_HANDLE)
{
Expand Down Expand Up @@ -5993,8 +5995,8 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,
// Continue checking other candidates, maybe some of them will succeed.
break;
}

likelyMethod = dvInfo.devirtualizedMethod;
likelyContext = dvInfo.exactContext;
likelyMethod = dvInfo.devirtualizedMethod;
}

uint32_t likelyMethodAttribs = info.compCompHnd->getMethodAttribs(likelyMethod);
Expand Down Expand Up @@ -6062,8 +6064,8 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,

// Add this as a potential candidate.
//
addGuardedDevirtualizationCandidate(call, likelyMethod, likelyClass, likelyMethodAttribs, likelyClassAttribs,
likelihood);
addGuardedDevirtualizationCandidate(call, likelyMethod, likelyClass, likelyContext, likelyMethodAttribs,
likelyClassAttribs, likelihood);
}
}

Expand All @@ -6088,12 +6090,13 @@ void Compiler::considerGuardedDevirtualization(GenTreeCall* call,
// classAttr - attributes of the class
// likelihood - odds that this class is the class seen at runtime
//
void Compiler::addGuardedDevirtualizationCandidate(GenTreeCall* call,
CORINFO_METHOD_HANDLE methodHandle,
CORINFO_CLASS_HANDLE classHandle,
unsigned methodAttr,
unsigned classAttr,
unsigned likelihood)
void Compiler::addGuardedDevirtualizationCandidate(GenTreeCall* call,
CORINFO_METHOD_HANDLE methodHandle,
CORINFO_CLASS_HANDLE classHandle,
CORINFO_CONTEXT_HANDLE contextHandle,
unsigned methodAttr,
unsigned classAttr,
unsigned likelihood)
{
// This transformation only makes sense for delegate and virtual calls
assert(call->IsDelegateInvoke() || call->IsVirtual());
Expand Down Expand Up @@ -6166,6 +6169,7 @@ void Compiler::addGuardedDevirtualizationCandidate(GenTreeCall* call,
pInfo->guardedClassHandle = classHandle;
pInfo->likelihood = likelihood;
pInfo->requiresInstMethodTableArg = false;
pInfo->exactContextHnd = contextHandle;

// If the guarded class is a value class, look for an unboxed entry point.
//
Expand Down Expand Up @@ -7754,10 +7758,16 @@ void Compiler::impCheckCanInline(GenTreeCall* call,
return;
}

CORINFO_CONTEXT_HANDLE exactContext = pParam->exactContextHnd;
if (pParam->call->IsGuardedDevirtualizationCandidate())
{
exactContext = pParam->call->GetGDVCandidateInfo(pParam->candidateIndex)->exactContextHnd;
}

// Speculatively check if initClass() can be done.
// If it can be done, we will try to inline the method.
CorInfoInitClassResult const initClassResult =
compCompHnd->initClass(nullptr /* field */, ftn /* method */, pParam->exactContextHnd /* context */);
compCompHnd->initClass(nullptr /* field */, ftn /* method */, exactContext /* context */);

if (initClassResult & CORINFO_INITCLASS_DONT_INLINE)
{
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,12 +1015,6 @@ CorInfoInitClassResult MethodContext::repInitClass(CORINFO_FIELD_HANDLE field,
key.method = CastHandle(method);
key.context = CastHandle(context);

if ((InitClass == nullptr) || (InitClass->GetIndex(key) == -1))
{
// We could try additional inlines with stress modes, just reject them.
return CORINFO_INITCLASS_DONT_INLINE;
}

DWORD value = InitClass->Get(key);
DEBUG_REP(dmpInitClass(key, value));
CorInfoInitClassResult result = (CorInfoInitClassResult)value;
Expand Down
26 changes: 13 additions & 13 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8425,22 +8425,22 @@ bool CEEInfo::resolveVirtualMethodHelper(CORINFO_DEVIRTUALIZATION_INFO * info)
return false;
}

if (pBaseMT->IsInterface())
{

#ifdef FEATURE_COMINTEROP
// Don't try and devirtualize com interface calls.
if (pObjMT->IsComObjectType())
{
info->detail = CORINFO_DEVIRTUALIZATION_FAILED_COM;
return false;
}
// Don't try and devirtualize com interface calls.
if (pBaseMT->IsInterface() && pObjMT->IsComObjectType())
{
info->detail = CORINFO_DEVIRTUALIZATION_FAILED_COM;
return false;
}
#endif // FEATURE_COMINTEROP

if (info->context != nullptr)
{
pBaseMT = GetTypeFromContext(info->context).GetMethodTable();
}
if (info->context != nullptr)
{
pBaseMT = GetTypeFromContext(info->context).GetMethodTable();
}

if (pBaseMT->IsInterface())
{

// Interface call devirtualization.
//
Expand Down