From b306c03b3de293ad6cb0d0ed08ef87df9c7cc4e5 Mon Sep 17 00:00:00 2001 From: Rattenkrieg Date: Mon, 30 Nov 2020 00:06:22 +0300 Subject: [PATCH 1/2] conditionally assign (exact)contextHandle --- src/coreclr/src/jit/importer.cpp | 35 ++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index fb9e10c6a98093..00bf9d82c8e792 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -21195,12 +21195,43 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // the base in most other ways. *method = derivedMethod; *methodFlags = derivedMethodAttribs; - *contextHandle = MAKE_METHODCONTEXT(derivedMethod); + + if (((SIZE_T)(*contextHandle) & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD) + { + *contextHandle = MAKE_METHODCONTEXT(derivedMethod); + } + else + { + assert(((SIZE_T)(*contextHandle) & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_CLASS); + if (isExact) + { + *contextHandle = MAKE_CLASSCONTEXT(objClass); + } + else + { + *contextHandle = MAKE_CLASSCONTEXT(derivedClass); + } + } // Update context handle. if ((exactContextHandle != nullptr) && (*exactContextHandle != nullptr)) { - *exactContextHandle = MAKE_METHODCONTEXT(derivedMethod); + if (((SIZE_T)(*exactContextHandle) & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD) + { + *exactContextHandle = MAKE_METHODCONTEXT(derivedMethod); + } + else + { + assert(((SIZE_T)(*exactContextHandle) & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_CLASS); + if (isExact) + { + *exactContextHandle = MAKE_CLASSCONTEXT(objClass); + } + else + { + *exactContextHandle = MAKE_CLASSCONTEXT(derivedClass); + } + } } #ifdef FEATURE_READYTORUN_COMPILER From a471905a40bfd72ffef962b2a02d39df7bdb7ecb Mon Sep 17 00:00:00 2001 From: Rattenkrieg Date: Mon, 30 Nov 2020 23:44:00 +0300 Subject: [PATCH 2/2] assign updated context when exactContextHandle pointing to nullptr --- src/coreclr/src/jit/importer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 00bf9d82c8e792..055918d16c619b 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -21193,8 +21193,8 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // https://github.com/dotnet/runtime/issues/38477 // but hopefully the derived method conforms to // the base in most other ways. - *method = derivedMethod; - *methodFlags = derivedMethodAttribs; + *method = derivedMethod; + *methodFlags = derivedMethodAttribs; if (((SIZE_T)(*contextHandle) & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD) { @@ -21214,7 +21214,7 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, } // Update context handle. - if ((exactContextHandle != nullptr) && (*exactContextHandle != nullptr)) + if ((exactContextHandle != nullptr)) { if (((SIZE_T)(*exactContextHandle) & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD) {