Skip to content

RuntimeHelpers.PrepareDelegate/PrepareMethod should JIT the given method #9437

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

Closed
tmds opened this issue Dec 14, 2017 · 9 comments
Closed

RuntimeHelpers.PrepareDelegate/PrepareMethod should JIT the given method #9437

tmds opened this issue Dec 14, 2017 · 9 comments
Labels
area-VM-coreclr help wanted [up-for-grabs] Good issue for external contributors

Comments

@tmds
Copy link
Member

tmds commented Dec 14, 2017

There is a comment here:

https://github.com/dotnet/coreclr/blob/b9affb49f79ed8319923c2f5b07b4aeeb04efe36/src/mscorlib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs#L147-L149

But I can't figure out if it is supported or not.

In case it isn't supported, is there another way to ensure certain methods in a call graph are jitted? Or to jit a method without calling it?

@jkotas
Copy link
Member

jkotas commented Dec 14, 2017

PrepareConstrainedRegions is no-op in .NET Core.

@jkotas
Copy link
Member

jkotas commented Dec 14, 2017

ensure certain methods in a call graph are jitted?

There is not such method today. I think it may be reasonable to fix RuntimeHelpers.PrepareDelegate / PrepareMethod to JIT the method given to it (just the single method - without the complicated limited call-graph walk done by full .NET Framework implementation).

@4creators
Copy link
Contributor

I think it may be reasonable to fix RuntimeHelpers.PrepareDelegate / PrepareMethod to JIT the method given to it (just the single method

This could be very useful for hardware intrinsics in R2R scenarios.

@jkotas
Copy link
Member

jkotas commented Dec 14, 2017

@4creators Could you please elaborate why you think it would be helpful?

@4creators
Copy link
Contributor

@jkotas maybe we can move discussion on how to use it in hardware intrinsics to #9408 as it will fit the scope of that issue

@mattwarren
Copy link
Contributor

I think it may be reasonable to fix RuntimeHelpers.PrepareDelegate / PrepareMethod to JIT the method given to it (just the single method - without the complicated limited call-graph walk done by full .NET Framework implementation).

Yes, this would be nice, based on this comment from @AndyAyersMS it currently has some limitations and the workaround is tricky.

Although I assume from your comment that you're not proposing to also JIT the entire call-graph, just a single method, is that correct?

Would PrepareMethod ever be extended to do this, i.e. ensure the entire call-graph of a method is also JITted, or is that not something you think the run-time should provide?

@jkotas
Copy link
Member

jkotas commented Dec 15, 2017

the entire call-graph, just a single method, is that correct?

The problem is with finding the entire call-graph is. Static non-virtual calls are easy, but the transitive closure can be very large. In full .NET Framework, this method also consults ReliabilityContract attributes to constraint the call graph to reasonable size.

Virtual calls, generics and every other runtime feature are hard. It would basically have to do same kind of global analysis as full AOT compilation does (slow and complex).

We prefer to describe behavior in terms of what guarantees are provided. Not in terms of how the guarantees are implemented. The guarantees that the PrepareMethod provides in .NET Framework are that the runtime will not introduce exceptions in the part of the callgraph that is annotated as reliable (ie the only exceptions thrown during execution of the code are the ones caused by the user code). These guarantees have been implemented by JITing a bunch of stuff upfront and pre-initializing all sorts of other stuff that can lead to runtime-thrown exceptions. That implementation was not the only way to implement the guarantees.

This feature was originally implemented for SQL CLR. It was super hard to test and use correctly.

it currently has some limitations

This applies to .NET Framework.

My though above was that we can improve .NET Core compatibility for cases where folks take advantage of PrepareMethod side-effects in .NET Framework.

@tmds
Copy link
Member Author

tmds commented Dec 18, 2017

@jkotas I'm fine with this issue being closed or re-purposed to track support for PrepareMethod.

@jkotas jkotas changed the title Q: Does .NET Core support PrepareConstrainedRegions? RuntimeHelpers.PrepareDelegate/PrepareMethod should JIT the given method Dec 18, 2017
jkotas referenced this issue in jkotas/coreclr Feb 14, 2018
CoreCLR implementation of this method triggers jiting of the given method only.
It does not walk a subset of callgraph to provide CER guarantees because of CERs
are not supported by CoreCLR.

Fixes #15522
jkotas referenced this issue in dotnet/coreclr Feb 15, 2018
…16382)

* Implement RuntimeHelpers.PrepareMethod/PrepareDelegate for CoreCLR

CoreCLR implementation of this method triggers jiting of the given method only.
It does not walk a subset of callgraph to provide CER guarantees because of CERs
are not supported by CoreCLR.

Fixes #15522
@tmds
Copy link
Member Author

tmds commented Feb 15, 2018

Thank you for implementing @jkotas!

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-coreclr help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

4 participants