From 8db6217f5c9f4bc467005dcbb45e84935aedccfc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Strehovsk=C3=BD?= Date: Mon, 27 Feb 2017 15:21:57 -0800 Subject: [PATCH] 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 --- src/coreclr/src/jit/morph.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 2.7.4