-
Notifications
You must be signed in to change notification settings - Fork 508
Support for IL interpreter in CoreRT #5011
Comments
The interpreter implementation is always tighly coupled with the underlying runtime implementation details. It cannot be easily ported from runtime to runtime. This would be more like a rewrite, maybe using some of the ideas from the other implementations. We would want to rewrite it in C# for CoreRT. Implementing it in C/C++ for CoreRT would be much harder than implementing it in C#. BTW: We have interpreter in CoreCLR as well: https://github.com/dotnet/coreclr/blob/master/src/vm/interpreter.cpp . It is not shipping in .NET Core because of .NET Core would not benefit from it. It has been used for new platform bringups, and various experiments. There are two distinct pieces:
|
@jkotas looking to take a first pass at this. However, I have a couple of questions:
|
CoreRT has capability to manufacture entrypoints. Look for
Code under src\System.Private.Jit was a prototype for JIT support in CoreRT. It was able to run a few methods, nothing extensive. It does not ship, and it is not used in the default CoreRT config and it has likely bit-rotten and does not work anymore. |
Thanks for the quick response. I have more stuff I'm curious about What happens when I ask because I'm trying my best to avoid using reflection and instead leverage the underlying runtime capabilities. Specifically how info like the value of static and instance fields are retrieved from a handle to a managed object ( |
I've written about this scenario, see the section on 'How does Reflection work?' (referring to the CoreCLR) |
Sweet! thanks Matt! Will take a look. |
Yup, that definitely answers my question, knew there had to be an FCALL somewhere |
I've looked into the equivalent flow for CoreRT (mostly just for my own interest) and unless I'm missing something it's all in C#, which is pretty cool (I know that's one of the goals of CoreRT, it's just interesting to see it in action)!
At this point there are no C# method bodies, but after a bit of digging, it seems that the |
You should write a blog post on this 😃 |
Here's also for my second question on getting field info from an object reference:
|
It looks like you're on the right track with the implementation details in System.Private.Reflection.Execution (no FCALLs in CoreRT). @MichalStrehovsky or @davidwrighton, do you have any details to fill in? |
Just out of interest, from reading this post there seems to be 2 possible approaches to allowing runtime code generation in CoreRT:
I was wondering what's the preferred approach? Or in an ideal world would you have both? (leaving aside the cost to implement, engineering time, other priorities, etc) Is 2) less preferable because it's no longer 'AOT compiled' or is that not really a concern? I assume that 1) is slower, but does that matter? |
Interpreter is good to have for places where (Ryu)JIT is not available, not allowed (e.g. Apple devices), or not desirable (e.g. environments locked down for security). It may be also used as part of tiered code generation strategy. |
Hi @jkotas, I've taken a thorough look through the code, especially the parts involved in building thunks for
Cheers |
I have found that we have this actually wrapped in more easy to use type:
Yes, it points to the memory block where arguments are stored in. I have found that we have this actually wrapped in more easy to use type:
|
Thanks for info, been a bit busy with work. Will take a first pass over the weekend |
Hi @jkotas, quick questions about the
|
Store it as a field in your type inherited from CallInterceptor.
It should be computed from the MethodDesc. I would just make something simple to make the prototype work. Eventually, it may need to handle IL coming from all sort of different places - something like
|
I'll like to run my thought process by you @jkotas, kindly correct me anywhere I might have it wrong:
|
@tonerdo Yes, you got it. I do not see anything wrong in your description. |
* add support for newarr opcode (#5011) * add support for ldlen opcode (#5011) * add support for stelem.* opcodes (#5011) * add support for ldelem.* opcodes (#5011) * use the right arguement type metadata (#5011) * handle when index values are native int (#5011) * use generic Unsafe class to read/write array elements (#5011) * add array bounds check (#5011) * add assignability checks for stelem.ref opcode (#5011) * add IntPtr to int conversion bounds check (#5011) * simplify IntPtr<->int bounds check expression (#5011)
* Add support for ldfld and stfld (#5011) * Make interpreter methods take an concrete *Desc types * Update load and store field methods to handle specific types (5011) * Add support for static fields belonging to dynamically loaded types * Add support for loading and storing fields in native metadata * Use byte arrays to represent statics bases * Add support for static constructors * Include module name in key identity check * Ensure static class constructor is run for native format types * Retrieve non gc statics from typeloader environment * Allocate memory for non gc statics (#5011) * Add support for dynamic static constructors in runtime (#5011) * Ensure static constructors of compiled in types are run (#5011) * Use RuntimeTypeHandle when type is in native binary (#5011) * Simplify static field load/store methods (#5011) * Add support for gc statics of dynamic types (#5011) * Fix static field get/set for pre-compiled in types * Add TryGetThreadStaticFieldDataDirect method * Remove StaticsRegion class * Use state.GcDataSize to calculate eetype base size * Improve support for gc statics * s/GetHasCode/GetHashCode * Improve code comments * Clean up thread static support code
We should consider porting Mono's .NET interpreter (http://www.mono-project.com/news/2017/11/13/mono-interpreter/) over to CoreRT, to support runtime IL generation and execution within native code
The text was updated successfully, but these errors were encountered: