Allow jit to examine type of initonly static ref typed fields (#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)
commitc2abe892b227740c4b8baa51f5433dfc1101a52f
tree994c07557800a0db391bfad7b0df8c9097b783bf
parenta49296e266ae9aa0bee760f2fcf51d3497ba818d
Allow jit to examine type of initonly static ref typed fields (#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 #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 #4108.
24 files changed:
src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h
src/ToolBox/superpmi/superpmi-shared/lwmlist.h
src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp
src/ToolBox/superpmi/superpmi-shared/methodcontext.h
src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp
src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp
src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp
src/ToolBox/superpmi/superpmi/icorjitinfo.cpp
src/dlls/mscorrc/mscorrc.rc
src/dlls/mscorrc/resource.h
src/inc/corinfo.h
src/jit/compiler.h
src/jit/gentree.cpp
src/jit/jitconfigvalues.h
src/vm/jitinterface.cpp
src/vm/jitinterface.h
src/vm/reflectioninvocation.cpp
src/zap/zapinfo.cpp
src/zap/zapinfo.h
tests/CoreFX/CoreFX.issues.json
tests/src/JIT/opt/Devirtualization/readonlystatic.cs [new file with mode: 0644]
tests/src/JIT/opt/Devirtualization/readonlystatic.csproj [new file with mode: 0644]
tests/src/reflection/SetValue/TrySetReadonlyStaticField.cs [new file with mode: 0644]
tests/src/reflection/SetValue/TrySetReadonlyStaticField.csproj [new file with mode: 0644]