Is the jit supposed to hoist init type checks this hard? #122605
Replies: 2 comments 2 replies
-
|
In practice, a type is often considered touched when a method referencing the type get touched. The timing of static constructor is non-deterministic. It's not suggested to depend on its side effect. |
Beta Was this translation helpful? Give feedback.
-
|
Is class
There is also this comment in the JIT explaining that when a type is marked You can see in the source JIT source several places where the presence of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider static types A with a method
void OhGodWhyand B with another methodvoid DoWorkand a static constructor (.cctor) .(Note that this isn't a minimal repro as I couldn't isolate the behaviour.)
In Release, depending on the shape of the code, the generated asm for
OhGodWhywill have the first instruction a type initialisation check for type B followed by a conditional jump to said initialisation and a jump back to the first written line of code. This makes the type B.cctoralways run even if we never touch B, by returning early.Is this intended behaviour? And if so then what's causing it? 👀
I would love to learn more about how the JIT reasons, thank you for your time! 🙂
Beta Was this translation helpful? Give feedback.
All reactions