Avoid cctor check if we provably executed it - #131526
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
This PR updates the AOT RyuJit JIT-EE interface to use initClass analysis (rather than a coarse “has lazy cctor” check) when reporting static field access requirements, enabling the JIT to elide redundant class-constructor checks when initialization is already provably satisfied (e.g., instance-method cases).
Changes:
- Refactors
initClassin the shared JitInterface to add aFieldDesc/MethodDescoverload and a handle-based wrapper. - Updates
ILCompiler.RyuJitgetFieldInfoto consultinitClassand (a) setCORINFO_FLG_FIELD_INITCLASSonly when needed and (b) choose relocatable static base access when init is not required.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Adds an overload to run initClass logic directly on FieldDesc/MethodDesc, with a wrapper for handle-based entrypoints. |
| src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | Uses initClass results in getFieldInfo to avoid unnecessary cctor triggering / helper usage for static field accesses. |
| if (_compilation.HasLazyStaticConstructor(field.OwningType)) | ||
| if (initResult != CorInfoInitClassResult.CORINFO_INITCLASS_NOT_REQUIRED) | ||
| { | ||
| fieldFlags |= CORINFO_FIELD_FLAGS.CORINFO_FLG_FIELD_INITCLASS; |
There was a problem hiding this comment.
CORINFO_FLG_FIELD_INITCLASS means "initClass has to be called before accessing the field". We should not need to optimize it by calling initClass proactively before the flag is set. The JIT is going to call initClass when CORINFO_FLG_FIELD_INITCLASS is set.
|
Worth noting that this can change behaviour for calling instance methods with null this, but ECMA explicitly permits skipping cctor then (still there could be code relying on it being executed). |
For this program and the S method:
Before:
After: