Skip to content
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

Merged
merged 19 commits into from
Nov 18, 2022
Merged

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Jul 23, 2022

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

@dotnet-issue-labeler
Copy link

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.

@ghost
Copy link

ghost commented Jul 23, 2022

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

#68928

Author: BrzVlad
Assignees: BrzVlad
Labels:

area-System.Reflection

Milestone: -


if (!obj) {
MonoObjectHandle obj_h = mono_object_new_handle (m->klass, error);
goto_if_nok (error, return_null);
Copy link
Contributor

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.

@srxqds
Copy link
Contributor

srxqds commented Aug 4, 2022

hi, this will merge to rc1?

@marek-safar
Copy link
Contributor

Could you look into fixing this for DynamicMethod as well?

@BrzVlad
Copy link
Member Author

BrzVlad commented Sep 29, 2022

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.

@BrzVlad BrzVlad marked this pull request as ready for review September 29, 2022 15:14
// 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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
@BrzVlad
Copy link
Member Author

BrzVlad commented Nov 17, 2022

can we merge this ?

@BrzVlad BrzVlad merged commit aa012f4 into dotnet:main Nov 18, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mono work necessary to support IL-based invoke Update runtime Invoke exception handling
7 participants