Allow jit to examine type of initonly static ref typed fields (dotnet/coreclr#20886)
authorAndy Ayers <andya@microsoft.com>
Mon, 12 Nov 2018 18:58:03 +0000 (10:58 -0800)
committerGitHub <noreply@github.com>
Mon, 12 Nov 2018 18:58:03 +0000 (10:58 -0800)
commit4d62f0c762f98aec5b652fac5e03a6b13ba078c8
tree84373c902f382aed59c9a5b4a2614f94eddebab2
parent300b46595a54fde995740691982b4409c37393e1
Allow jit to examine type of initonly static ref typed fields (dotnet/coreclr#20886)

The jit incorporates the value of integer and float typed initonly static
fields into its codegen, if the class initializer has already run.

The jit can't incorporate the values of ref typed initonly static fields,
but the types of those values can't change, and the jit can use this knowledge
to enable type based optimizations like devirtualization.

In particular for static fields initialized by complex class factory logic the
jit can now see the end result of that logic instead of having to try and deduce
the type of object that will initialize or did initialize the field.

Examples of this factory pattern in include `EqualityComparer<T>.Default` and
`Comparer<T>.Default`. The former is already optimized in some cases by via
special-purpose modelling in the framework, jit, and runtime (see dotnet/coreclr#14125) but
the latter is not. With this change calls through `Comparer<T>.Default` may now
also devirtualize (though won't yet inline as the devirtualization happens
late).

Also update the reflection code to throw an exception instead of changing the value
of a fully initialized static readonly field.

Closes dotnet/coreclr#4108.

Commit migrated from https://github.com/dotnet/coreclr/commit/c2abe892b227740c4b8baa51f5433dfc1101a52f
24 files changed:
src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h
src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h
src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp
src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h
src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp
src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp
src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp
src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp
src/coreclr/src/dlls/mscorrc/mscorrc.rc
src/coreclr/src/dlls/mscorrc/resource.h
src/coreclr/src/inc/corinfo.h
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/gentree.cpp
src/coreclr/src/jit/jitconfigvalues.h
src/coreclr/src/vm/jitinterface.cpp
src/coreclr/src/vm/jitinterface.h
src/coreclr/src/vm/reflectioninvocation.cpp
src/coreclr/src/zap/zapinfo.cpp
src/coreclr/src/zap/zapinfo.h
src/coreclr/tests/CoreFX/CoreFX.issues.json
src/coreclr/tests/src/JIT/opt/Devirtualization/readonlystatic.cs [new file with mode: 0644]
src/coreclr/tests/src/JIT/opt/Devirtualization/readonlystatic.csproj [new file with mode: 0644]
src/coreclr/tests/src/reflection/SetValue/TrySetReadonlyStaticField.cs [new file with mode: 0644]
src/coreclr/tests/src/reflection/SetValue/TrySetReadonlyStaticField.csproj [new file with mode: 0644]