dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.14k stars 4.71k forks source link

JIT-EE: Annotate APIs as Invariant/Non-invariant #90886

Open EgorBo opened 1 year ago

EgorBo commented 1 year ago

Context: https://github.com/dotnet/runtime/issues/90711#issuecomment-1684085272 (the whole thread)

Some EE apis aren't invariant by design (invariant as in - always return the same value for the same arguments) and JIT has to be careful with them (for the rest, we can make SPMI assert in case if they turn out to be non-invariant). The task is to mark them with some special marker-macro or comment in ThunkInput.txt and generate asserts for SPMI (in case if we make methodcontext.cpp at least partially auto-generated for trivial cases) and, also, revise all uses for potential problems. From a quick look these APIs are not invariant:

last two should be still invariant as of today, but they might start using the same trick as getHelperFtn (return direct address in case if destination function already reached the final tier).

ghost commented 1 year ago

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch See info in area-owners.md if you want to be subscribed.

Issue Details
Context: https://github.com/dotnet/runtime/issues/90711#issuecomment-1684085272 (the whole thread) Some EE apis aren't invariant by design (invariant as in - always return the same value for the same arguments) and JIT has to be careful with them (for the rest, we can make SPMI assert in case if the turn out to be non-invariant). The task is to mark them with some special marker-macro or comment in ThunkInput.txt and generate asserts for SPMI (in case if we make `methodcontext.cpp` at least partially auto-generated for trivial cases) and, also, revise all uses for potential problems. From a quick look these APIs are not invariant: - `uint32_t getMethodAttribs(CORINFO_METHOD_HANDLE ftn);` - `CorInfoInline canInline(CORINFO_METHOD_HANDLE callerHnd, CORINFO_METHOD_HANDLE calleeHnd);` - `uint32_t getClassAttribs(CORINFO_CLASS_HANDLE cls)` - `bool getIsClassInitedFlagAddress(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, int* offset)` - `CorInfoInitClassResult initClass(CORINFO_FIELD_HANDLE field, CORINFO_METHOD_HANDLE method, CORINFO_CONTEXT_HANDLE context)` - `bool getStaticFieldContent(CORINFO_FIELD_HANDLE field, uint8_t *buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects);` - `CORINFO_CLASS_HANDLE getStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, BoolStar pIsSpeculative);` - `void* getHelperFtn (CorInfoHelpFunc ftnNum, void **ppIndirection);` - `void getFunctionEntryPoint(CORINFO_METHOD_HANDLE ftn, CORINFO_CONST_LOOKUP* pResult, CORINFO_ACCESS_FLAGS accessFlags);` - `void getFunctionFixedEntryPoint(CORINFO_METHOD_HANDLE ftn, bool isUnsafeFunctionPointer, CORINFO_CONST_LOOKUP * pResult);` last two should be still invariant as of today, but they might start using the same trick as `getHelperFtn` (return direct address in case if destination function already reached the final tier).
Author: EgorBo
Assignees: -
Labels: `area-CodeGen-coreclr`, `needs-area-label`
Milestone: -