From 3bc311ff173b1ab16f60c300fe5e4a9ed5bb63b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 26 Oct 2016 14:41:26 -0700 Subject: [PATCH 1/2] Support for ready to run generic initThisClass --- src/jit/morph.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/jit/morph.cpp b/src/jit/morph.cpp index b55c24a55b5c..47cb51517a7d 100644 --- a/src/jit/morph.cpp +++ b/src/jit/morph.cpp @@ -16201,6 +16201,20 @@ GenTreePtr Compiler::fgInitThisClass() // context parameter is this that we don't need the eager reporting logic.) lvaGenericsContextUsed = true; +#ifdef FEATURE_READYTORUN_COMPILER + // Only CoreRT understands CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE. Don't do this on CoreCLR. + if (opts.IsReadyToRun() && eeGetEEInfo()->targetAbi == CORINFO_CORERT_ABI) + { + CORINFO_RESOLVED_TOKEN resolvedToken; + ZeroMemory(&resolvedToken, sizeof(resolvedToken)); + resolvedToken.hClass = info.compClassHnd; + + GenTreePtr ctxTree = getRuntimeContextTree(kind.runtimeLookupKind); + return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, TYP_BYREF, + gtNewArgList(ctxTree), &kind); + } +#endif + switch (kind.runtimeLookupKind) { case CORINFO_LOOKUP_THISOBJ: From 9fd8441d04744897ade3107af8258b16f48d9d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 26 Oct 2016 21:01:22 -0700 Subject: [PATCH 2/2] Fixes * lvaGenericsContextUsed is set by getRuntimeContextTree, no need to set it twice. * Add comment * Don't set hClass --- src/jit/morph.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/jit/morph.cpp b/src/jit/morph.cpp index 47cb51517a7d..73e5b2f7e10e 100644 --- a/src/jit/morph.cpp +++ b/src/jit/morph.cpp @@ -16196,25 +16196,28 @@ GenTreePtr Compiler::fgInitThisClass() } else { - // Collectible types requires that for shared generic code, if we use the generic context paramter - // that we report it. (This is a conservative approach, we could detect some cases particularly when the - // context parameter is this that we don't need the eager reporting logic.) - lvaGenericsContextUsed = true; - #ifdef FEATURE_READYTORUN_COMPILER // Only CoreRT understands CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE. Don't do this on CoreCLR. if (opts.IsReadyToRun() && eeGetEEInfo()->targetAbi == CORINFO_CORERT_ABI) { CORINFO_RESOLVED_TOKEN resolvedToken; ZeroMemory(&resolvedToken, sizeof(resolvedToken)); - resolvedToken.hClass = info.compClassHnd; GenTreePtr ctxTree = getRuntimeContextTree(kind.runtimeLookupKind); + + // CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE with a zeroed out resolvedToken means "get the static + // base of the class that owns the method being compiled". If we're in this method, it means we're not + // inlining and there's no ambiguity. return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, TYP_BYREF, gtNewArgList(ctxTree), &kind); } #endif + // Collectible types requires that for shared generic code, if we use the generic context paramter + // that we report it. (This is a conservative approach, we could detect some cases particularly when the + // context parameter is this that we don't need the eager reporting logic.) + lvaGenericsContextUsed = true; + switch (kind.runtimeLookupKind) { case CORINFO_LOOKUP_THISOBJ: