From: Michal Strehovský Date: Mon, 27 Feb 2017 23:21:57 +0000 (-0800) Subject: Don't generate a runtime lookup for static base if not needed (dotnet/coreclr#9833) X-Git-Tag: submit/tizen/20210909.063632~11030^2~7931 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8db6217f5c9f4bc467005dcbb45e84935aedccfc;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Don't generate a runtime lookup for static base if not needed (dotnet/coreclr#9833) `fgInitThisClass` makes sure that the type initializer for the type that owns the method being compiled has run. On CoreCLR, the fallthrough code somehow ends up not doing a runtime lookup if the owning type is not canonical. We need to avoid it on CoreRT as well. Commit migrated from https://github.com/dotnet/coreclr/commit/4fb2f0ff574502894ab7657fe89e9f9f99eafe1a --- diff --git a/src/coreclr/src/jit/morph.cpp b/src/coreclr/src/jit/morph.cpp index 0035b9d..cac0ee8 100644 --- a/src/coreclr/src/jit/morph.cpp +++ b/src/coreclr/src/jit/morph.cpp @@ -16292,6 +16292,15 @@ GenTreePtr Compiler::fgInitThisClass() CORINFO_RESOLVED_TOKEN resolvedToken; memset(&resolvedToken, 0, sizeof(resolvedToken)); + // We are in a shared method body, but maybe we don't need a runtime lookup after all. + // This covers the case of a generic method on a non-generic type. + if (!(info.compClassAttr & CORINFO_FLG_SHAREDINST)) + { + resolvedToken.hClass = info.compClassHnd; + return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_STATIC_BASE, TYP_BYREF); + } + + // We need a runtime lookup. GenTreePtr ctxTree = getRuntimeContextTree(kind.runtimeLookupKind); // CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE with a zeroed out resolvedToken means "get the static