Commit 5687506
authored
[Xamarin.Android.Build.Tasks] enable ForceInterpretedInvoke switch (#7972)
Fixes: dotnet/runtime#83893
Context: dotnet/runtime#72717
In .NET 8, `System.Reflection.{ConstructorInfo,MethodInfo}.Invoke()`
will use `System.Reflection.Emit` when called more than once.
This impacts startup in mobile applications, so it may not be a
desirable feature.
Unfortunately, this appears to happen quite easily in Android apps;
some examples (using a custom dotnet/runtime build for extra output):
* https://gist.github.com/ivanpovazan/2563ea9d2fea320e6425cfcc58da3ee5
* https://gist.github.com/ivanpovazan/d2546d4abad17900d4366cc29e1689b2
The primary situation in which this happens is that all Java-originated
`Java.Lang.Object` subclass constructor invocations always hit
`ConstructorInfo.Invoke()`; see `TypeManager.Activate()`.
To solve this problem, we can set:
<ItemGroup>
<RuntimeHostConfigurationOption
Include="Switch.System.Reflection.ForceInterpretedInvoke"
Value="$(_SystemReflectionForceInterpretedInvoke)"
Trim="true"
/>
</ItemGroup>
Setting the `Switch.System.Reflection.ForceInterpretedInvoke` switch
to True causes the `System.Reflection.Emit` codepath to be *skipped*.
We can set `$(_SystemReflectionForceInterpretedInvoke)` to test
out the setting in various apps.
I added a test to verify the "private" switch is actually set.
I also updated the `.aotprofile` to verify that all
`System.Reflection.Emit` code paths disappear from
`dotnet new android` applications.1 parent 6352fe0 commit 5687506
File tree
5 files changed
+53
-71
lines changed- src
- Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets
- profiled-aot
- tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/System
5 files changed
+53
-71
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
39 | 44 | | |
40 | 45 | | |
41 | 46 | | |
| |||
Binary file not shown.
0 commit comments