Commit 7d42864
authored
[Java.Interop.Tools.Cecil] DirectoryAssemblyResolver+MemoryMappedFile (#1103)
Context: dotnet/linker#1130
Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1783420
In dotnet/linker#1130, their version of `DirectoryAssemblyResolver`
was reworked to use [`MemoryMappedFile`][0] in the .NET 6 time frame.
Port these changes to Java.Interop, as we have MSBuild tasks in
xamarin/xamarin-android that use `DirectoryAssemblyResolver`.
Primarily, the [`<GenerateJavaStubs/>` MSBuild task][1] uses
`DirectoryAssemblyResolver` to iterate over types in assembly to emit
Java source code and generate `AndroidManifest.xml`.
Note: `MemoryMappedFile` can *only* be used when we are *not* opening
the assembly as `.ReadWrite`. Trying to use `MemoryMappedFile` for
read+write scenarios would result in an `InvalidOperationException`:
error XAGJS7009: System.InvalidOperationException: Operation is not valid due to the current state of the object.
error XAGJS7009: at Mono.Cecil.Cil.DefaultSymbolWriterProvider.GetSymbolWriter(ModuleDefinition module, String fileName)
error XAGJS7009: at Mono.Cecil.ModuleWriter.GetSymbolWriter(ModuleDefinition module, String fq_name, ISymbolWriterProvider symbol_writer_provider, WriterParameters parameters)
error XAGJS7009: at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
error XAGJS7009: at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
error XAGJS7009: at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
error XAGJS7009: at Mono.Cecil.AssemblyDefinition.Write(String fileName, WriterParameters parameters)
error XAGJS7009: at Xamarin.Android.Tasks.MarshalMethodsAssemblyRewriter.Rewrite(DirectoryAssemblyResolver resolver, List`1 targetAssemblyPaths, Boolean brokenExceptionTransitions)
error XAGJS7009: at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res, Boolean useMarshalMethods)
error XAGJS7009: at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
The results of these changes in a `dotnet new maui` project,
an initial clean build:
* Before MemoryMappedFile: GenerateJavaStubs = 1.318 s, 1 calls.
* After MemoryMappedFile: GenerateJavaStubs = 1.254 s, 1 calls.
Saving ~64ms or about ~5% in this example.
Note: The current version of the linker's resolver in .NET 8+ has
[moved to the dotnet/runtime repo][2].
[0]: https://learn.microsoft.com/dotnet/api/system.io.memorymappedfiles.memorymappedfile?view=net-8.0
[1]: https://github.com/xamarin/xamarin-android/blob/e694ba52a0cf5f45b213c8902bdbfb0ed348374a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs#L131
[2]: https://github.com/dotnet/runtime/blob/cd7d006030a7feace9076fa275fb5bffc1bf4a90/src/tools/illink/src/linker/Linker/AssemblyResolver.cs1 parent 3c2a066 commit 7d42864
File tree
1 file changed
+35
-2
lines changed- src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil
1 file changed
+35
-2
lines changedLines changed: 35 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
106 | 112 | | |
107 | 113 | | |
108 | 114 | | |
| |||
160 | 166 | | |
161 | 167 | | |
162 | 168 | | |
163 | | - | |
| 169 | + | |
164 | 170 | | |
165 | 171 | | |
166 | 172 | | |
167 | 173 | | |
168 | 174 | | |
169 | 175 | | |
170 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
171 | 204 | | |
172 | 205 | | |
173 | 206 | | |
| |||
0 commit comments