-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[mono] Unify invoke code with coreclr #72717
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-reflection |
src/mono/mono/metadata/icall.c
Outdated
|
||
if (!obj) { | ||
MonoObjectHandle obj_h = mono_object_new_handle (m->klass, error); | ||
goto_if_nok (error, return_null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to use the non _handle functions and MONO_HANDLE_PIN () in this function.
6c9caa3
to
dd5ab0e
Compare
hi, this will merge to rc1? |
dd5ab0e
to
2d374e5
Compare
d256579
to
63ede38
Compare
061bb7a
to
d0d180b
Compare
a76abee
to
c0268a5
Compare
Could you look into fixing this for DynamicMethod as well? |
Not sure what you mean by this. Most of the code for invoking a DynamicMethod is shared now. |
5300688
to
1ed045d
Compare
// Temporary placeholder until Mono adds support for supporting boxing true Nullables. | ||
internal static object? ReboxFromNullable(object? src) => src; | ||
[MethodImplAttribute(MethodImplOptions.InternalCall)] | ||
private static extern void ReboxFromNullable (object? src, ObjectHandleOnStack res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Methods in Nullable.Mono.cs
translate between normal boxed valuetypes and nullable structures, while these icalls translate between normal boxed valuetypes and boxed nullable structures.
This version doesn't receive a MonoArray of params as objects, rather a simple array of byrefs. There is also no need for special handling for nullables. The runtime invoke wrapper receives a boxed nullable, this conversion happens in managed code using ReboxFromNullable and ReboxToNullable. This change might have some side effects on other API making use of the runtime invoke wrapper!
Behavior was changed recently.
Aside from perf optimization, this allows the usage of LocalAppContextSwitches for invoke tests. Before this change, invoke machinery was initialized before the appcontext properties were set, failing to detect ForceInterpretedInvoke and ForceEmitInvoke properties. CoreCLR also hardcodes string type param.
This API already receives a boxed nullable now.
CoreCLR achieves this via NextCallReturnAddress. Add another intrinsic to be used for mono.
Remove special handling for nullables and throwing of NullByRefReturnException.
Which was still used only by mono_runtime_invoke_array
Nullable<T> only has 1 param constructor that creates a boxed vtype
With same behavior as before, except we have to handle conversions between nullable and boxedvt ourserlves, since it is no longer done by the runtime invoke wrapper.
… method overrides Seems to be possible via reflection, ex System.Reflection.Emit.Tests.MethodBuilderDefineMethodOverride.DefineMethodOverride_CalledTwiceWithSameBodies_Works
1ed045d
to
93ca85f
Compare
can we merge this ? |
Unification of invoke paths enables use of IL Emit Invoke also on mono.
InternalInvoke now receives arguments byref, enabling support for future APIs making use of this.
Fixes #68928
Fixes #67457