dotnet / runtime

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

question about understand interp generate transform code #109072

Open srxqds opened 1 month ago

srxqds commented 1 month ago

mono interp transfer il code to opcode in generate function: https://github.com/dotnet/runtime/blob/1e5bae2e56180897c95ac3f9adaa5609d14d20b3/src/mono/mono/mini/interp/transform.c#L9424

theTransformData allocate stack at below: https://github.com/dotnet/runtime/blob/1e5bae2e56180897c95ac3f9adaa5609d14d20b3/src/mono/mono/mini/interp/transform.c#L9501-L9508

and will store the custom data in data_items: https://github.com/dotnet/runtime/blob/1e5bae2e56180897c95ac3f9adaa5609d14d20b3/src/mono/mono/mini/interp/transform.c#L9476

at end of the function generate, I found the opcode or data_items will copy to InterpMethod in below code:

https://github.com/dotnet/runtime/blob/1e5bae2e56180897c95ac3f9adaa5609d14d20b3/src/mono/mono/mini/interp/transform.c#L9584-L9614

and copy InterpInst(allocated in interp_add_ins) at generate_compacted_code:

https://github.com/dotnet/runtime/blob/1e5bae2e56180897c95ac3f9adaa5609d14d20b3/src/mono/mono/mini/interp/transform.c#L9286-L9289

but I could not found the td->stack been copy before being freed at :

https://github.com/dotnet/runtime/blob/1e5bae2e56180897c95ac3f9adaa5609d14d20b3/src/mono/mono/mini/interp/transform.c#L9675-L9688

why not these data not restore to InterpMethod or maybe other place restore it?

could you help me? @BrzVlad

BrzVlad commented 1 month ago

td->stack and InterpInst* is information that is used only during compilation time. The list of InterpInst is iterated as the last step of compilation and in generate_compacted_code this list is compacted into an array of guint16 that represents the final generated code.