Skip to content

Intrinsic support for transient codegen. #115639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 22, 2025

Conversation

AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented May 16, 2025

The previous transient codegen paths only handled lifetime management when the method had no metadata back IL (that is, RVA == 0). The InstanceCalli scenario creates intrinsic methods which have metadata, but that metadata is copied and then modified falling into a middle ground that the existing logic didn't handle properly. The tricky scenario is when these new instrinsic types were inlined (lifetimes were being ignored). This change fixes that up but did require a bit of clean-up in the UnsafeJitFunction as it relates to the JIT and interpreter interaction.

Fixes #115429

The previous transient codegen paths only handled
lifetime management when the method had no
metadata back IL (that is, RVA == 0). The InstanceCalli
logic is marked as an intrinsic and has metadata,
but that metadata is copied and then modified falling
back to a middle ground that the existing logic didn't
handle properly. The tricky scenario is when these
new instrinsic types were inlined (lifetimes were
being ignored). This change fixes that up but did require
a bit of clean-up in the UnsafeJitFunction as it relates
to the JIT and interpreter interaction.
Copy link
Contributor

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

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds intrinsic support for transient codegen by consolidating method-info retrieval into a new worker function, renaming the helper context, and refactoring the JIT/interpreter code path to handle transient lifetimes and jump-stub overflow more cleanly.

  • Rename MethodInfoHelperContext to MethodInfoWorkerContext and unify handling in getMethodInfoWorker.
  • Refactor UnsafeJitFunctionWorker and UnsafeJitFunction to use MethodInfoWorkerContext and introduce JumpStubOverflowCheck.
  • Remove legacy debug buffers and simplify constructor signatures by removing default parameters.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/coreclr/vm/jitinterface.h Forward-declare MethodInfoWorkerContext, replace getTransientMethodInfo with getMethodInfoWorker, update ctor signatures
src/coreclr/vm/jitinterface.cpp Rename helper class, implement getMethodInfoWorker, remove old transient logic, add JumpStubOverflowCheck, refactor UnsafeJitFunction
Comments suppressed due to low confidence (4)

src/coreclr/vm/jitinterface.cpp:7497

  • The new getMethodInfoWorker path, including transient-method handling and inlining logic, isn't covered by existing tests. Add unit or integration tests to validate behavior for both metadata-backed and transient IL methods.
void CEEInfo::getMethodInfoWorker(

src/coreclr/vm/jitinterface.cpp:13446

  • [nitpick] The retry loop in UnsafeJitFunction uses while(true) with continue, which can obscure control flow. Consider a do { ... } while (overflowDetected) pattern or an explicit retry label to improve readability.
while (true)

src/coreclr/vm/jitinterface.cpp:13314

  • The static flag g_fAllowRel32 is mutated by Detected() without synchronization, leading to potential race conditions in multi-threaded JIT scenarios. Consider using thread-local storage or a lock to guard modifications.
BOOL JumpStubOverflowCheck::g_fAllowRel32 = TRUE;

src/coreclr/vm/jitinterface.h:520

  • Removing the default allowInlining = true parameter in these constructors changes their API and may break existing call sites. Verify all callers have been updated or restore the default to preserve backward compatibility.
CEECodeGenInfo(MethodDesc* fd, COR_ILMETHOD_DECODER* header, EECodeGenManager* jm, bool allowInlining)

@jkotas
Copy link
Member

jkotas commented May 16, 2025

The failure looks related

Beginning scenario: RunBasicScenario_UnsafeRead
ASSERT FAILED
	Expression: GetRVA() == 0
	Location:   line 21 in /Users/runner/work/1/s/src/coreclr/vm/asyncthunks.cpp
	Function:   TryGenerateAsyncThunk
	Process:    31332
App Exit Code: 22

@AaronRobinsonMSFT
Copy link
Member Author

@jkotas and @ericstj I added an overly aggressive assert that tripped on x86 with C++/CLI so that was the last failure. The assert would have needed to be removed for #115345 anyways. This should be ready for review now.

@AaronRobinsonMSFT
Copy link
Member Author

/azp list

Copy link

CI/CD Pipelines for this repository:

@AaronRobinsonMSFT
Copy link
Member Author

/azp run runtime-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rhuijben
Copy link
Contributor

Please fix the typo in the title of the PR before merging ;-)

@AaronRobinsonMSFT AaronRobinsonMSFT changed the title Instrinic support for transient codegen. Intrinsic support for transient codegen. May 19, 2025
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@AaronRobinsonMSFT
Copy link
Member Author

/ba-g Unrelated CoreCLR Android timeout.

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit fc85a87 into dotnet:main May 22, 2025
93 of 95 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the runtime_115429 branch May 22, 2025 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

R2R + Jit issue when inlining intrinsic methods
3 participants