-
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 Method Body Replacement #44806
Comments
Tagging subscribers to this area: @CoffeeFlux Issue Details
|
why not support for jit? |
hope you can support it in jit mode |
@srxqds The reason we're initially focusing on the interpreter is both for practical implementation reasons and due to the use-case that we're targeting. The use-case is Blazor WebAssembly and Xamarin mobile developers who are iterating on their code. This functionality is intended to be an improvement to the developer experience, not something that we expect developers to ship in production to end-users. For this use-case, it made sense to focus on the interpreter - because that's all that is available for WebAssembly, and it can also be supported on mobile. The practical engineering reason is because this is going to involve a lot of changes at a foundational level in Mono. There are basically three places where we will need to make changes: in the low-level code that deals with .NET IL metadata; in the type system representation ( So we can focus on making changes to the metadata and the type system without also having to deal with the compilation and execution engine at the same time. Once the metadata and typesystem changes are stable, it might make sense to look at the JIT, but right now it would just be a distraction. |
ok, thank you for reply. |
First part of support for metadata updates. Contributes to dotnet/runtime#44806 The feature is off by default. To enable, build with `/p:MonoMetadataUpdate=true` (e.g. `./build.sh --os browser /p:MonoMetadataUpdate=true`). There are samples in `src/mono/netcore/sample/mbr` (see the README - the samples aren't completely standalone and need some external tooling to build) for console (only tested on Mac and Linux) and wasm. There's a demo at https://lambdageek.dev/dl0/
First part of support for metadata updates. Contributes to dotnet/runtime#44806 The feature is off by default. To enable, build with `/p:MonoMetadataUpdate=true` (e.g. `./build.sh --os browser /p:MonoMetadataUpdate=true`). There are samples in `src/mono/netcore/sample/mbr` (see the README - the samples aren't completely standalone and need some external tooling to build) for console (only tested on Mac and Linux) and wasm. There's a demo at https://lambdageek.dev/dl0/ * Initial metadata-update prototype Co-Authored-By: Bernhard Urban-Forster <lewurm@gmail.com> * Add metadata-update.{c,h} to CMakeLists.txt * Add icall to corelib * Add console and browser metadata update samples Both samples depend on the roslynildiff tool which should be specified with a RoslynILDiffFullPath property in the .csproj files for the projects. * Add README for mbr samples * [build] Add initial runtime support for MonoMetadataUpdate property In the runtime defines cmake ENABLE_METADATA_UPDATE option and sets a preprocessor flag. In System.Private.CoreLib, defines FEATURE_METADATA_UPDATE and uses it to throw a NotSupportedException from LoadMetadataUpdate * [runtime] ifdef out metadata updates if not enabled Also move execution engine initialization into the main update function and use a MonoError to signal failures (such as if interp inlining is not turned off) instead of asserting at startup. * [wasm] set log mask to metadata-update * [mbr] Add InjectUpdate fn to sample * [metadata-update] don't merge heaps * Don't make entrypoint public yet * Add LoadMetadataUpdate to linker descriptor * [wasm] add default Makefile variable value * fix mono/mono CI don't try to run enc tests yet since they depend on roslynildiff * remove mono/mono/tests/enc Will add as runtime tests in a future PR * [metadata-update] Add per-thread exposed generation A thread has to voluntarily roll up to the latest published generation in order to see updates. - Roll up to the latest published generation when attaching a thread - The updater thread sees the allocated unpublished generation * [mbr] Fixup console sample Use a single changing testfile * [metadata-update] delete unused method * [mbr] Use 2 threads in console sample * [metadata-update] Respect exposed generation in MethdDef RVA lookups * [interp] Expose latest metadata update before transforming methods * [mbr] Update samples after rebase Use the WasmApp.targets * [metadata-update] Don't fail after the first unsupported edit Log all the unsupported edits, then cancel the update * [metadata_update] Keep track of logical table sizes for deltas Keep track of inserted/modified rows for each table in each delta. This will help to use a simpler algorithm to locate effective table rows by keeping track of the logical number of rows in the appended tables * [metadata-update] Use a GList for MonoImage:delta_image We're going to need to walk backwards from the latest published delta * [metadata-update] add effective table lookup debug output * Address review feedback * [interp] Save top interp frame at MINT_SAFEPOINT to ThreadContext Give metadata updates a peek at the interp frames since the LMF so that it can copy the InterpMethods that are currently executing This only works with hybrid and full coop suspend. Preemptive suspend will need another mechanism. * [mbr] Extend console sample Add a busy thread to demonstrate that interp frames since the last managed frame are visible to the metadata update mechanism and the active method bodies are copied before being invalidated. * [interp] Check mono_polling_required at safepoint Co-authored-by: Bernhard Urban-Forster <lewurm@gmail.com> Co-authored-by: lambdageek <lambdageek@users.noreply.github.com>
[Mono.Debugger.Soft] add ModuleMirror.ApplyChanges [Mono.Debugging.Soft] add SoftDebuggerSession.ApplyChanges Related mono/mono Mono.Debugger.Soft PR: mono/mono#20889 Related dotnet/runtime PR: dotnet/runtime#49043 Contributes to dotnet/runtime#44806
hi, when can you begin to support add static fields and methods to existing classes work? |
Pushed the future work to a separate tracking issue. This one is done. #57365 |
Contributes to dotnet/xamarin#13 and dotnet/aspnetcore#5456
Overview
The goal of Mono method body replacement is to improve the inner dev loop experience for customers using Xamarin to create mobile apps and those using Blazor to create WebAssembly projects.
Method body replacement is a subset of a more general hot reload experience with a restricted subset of allowed edits. Non-supported ("rude") edits will generally be rejected by the tooling outside the runtime, however the runtime
itself should be transactional in that a change is either committed by the runtime in total or else it is rejected and the runtime state is unchanged.
The changes are delivered to the runtime using the EnC "dmeta" and "DIL" (and "DPDB") delta files. If the changes are accepted, then future invocations of methods affected by the delta will use the new method bodies. Currently executing versions of the methods will use the previous versions.
Multiple versions of changes can be applied in succession. Once a change is applied, it cannot be unapplied (but of course a new change can be used to undo the previous change). For collectible ALCs unloading the assembly will unload all its changes.
Method body replacement will only be supported with the Mono interpreter with inlining turned off. The
DOTNET_MODIFIABLE_ASSEMBLIES
environment variable must be set to the (case-insensitive) valuedebug
. The assemblies that are eligible for modifications must be compiled with the/debug
option.Method body replacement will not interfere with debugging.
Metadata deltas will be injected either using the debugger or using a managed API. If the debugger is not involved, the runtime will pause the executing user threads at critical points during the update.
End to end scenarios
dotnet-watch
)MAUIpostponed to .net7WebAssemblypostponed to .net7Tasks
Priority 0
DONE PR #45612 Put the metadata update work-in-progress under a compile-time feature flag and merge to dotnet/runtime master.
Fix potential race when one thread is doing a metadata update and another is transforming some method. May need some kind of rwlock. (Fixed as part of [Mono] Initial metadata update support #45612 - we now use an explicit call to expose the update to a thread (at entry to the interpreter transformer)
Support preemptive suspend, or elsePR [mono] Set thread suspend default in mono.proj; default to hybrid #46873 use hybrid suspend by default, and communicate to downstream projects that MBR requires hybrid/coop suspend (mostly affects XM and XI - single-threaded wasm is ok)Write up a list of edits that we expect to support and coordinate with Roslyn team to implement a delta generator that rejects unsupported edits. Summary ecma335 gist
Measure perf impact of metadata update infrastructure on the interpreter. (That is, if there are no updates coming, what is the overhead?) [mono] Enable MBR by default if interpreter is enabled #46842 (comment)
set compile time feature flag to on by default; put functionality under a runtime feature flag
Investigate workload dev/production packs - turn off MBR in productionWe're using the mono runtime components infrastructure for thisDebugger
If there is a breakpoint in an old version of a method we need to send back info identifying the method version, not just a token so that the debugger frontend can display a view of the old code. This may require debugger-libs and soft debugger protocol workWe invalidate old breakpoints and set them in the updated method body.Propose and implement required runtime APIs (Coordinate with Support Dev inner loop improvements in CoreCLR VM #45629 so that ideally Mono and CoreCLR implement the same API.)
DOTNET_MODIFIABLE_ASSEMBLIES=debug
is set. PR [mono][mbr] Implement DOTNET_MODIFIABLE_ASSEMBLIES support #49507Properly detect cases we don't support, backout metadata updates and raise a single well-defined managed exception that leaves the runtime in a functional state.No need to roll back, update failures are fatal and don't need to be rolled back.set up testing infrastructure and run CI
System.Runtime.Loader.Tests
testsuite [System.Runtime.Loader] Add hot reload test infrastructure #51144Enable testing on Android, iOSnet7src/mono/netcore/samples/mbr
) into functional testsManaged API to return hot reload supported edits internal runtime API to return hot reload capabilities #50111
Priority 1
Investigate MonoImage refcount mistake - fix the shutdown hack ((The shutdown code is dead on netcore).exe_image
)Support more edits
(P1) Add a notification mechanism for EnC and HotReload #49361 Managed events that fire when a delta is applied
Use MetadataUpdateHandlerAttribute to clear Mono's reflection cache Use MetadataUpdateHandlerAttribute to clear Mono's reflection cache #50978net7[mono] block debugger attach after managed
ApplyUpdate
is called #55228 PR: [mono] Disable unsupported apply update scenarios #55698Hot Reload Manager support may need Add support for host startup hooks to Mono #47462 - add support for host startup hooks to monoMAUI and Blazor WebAssembly will inject the hot reload manager using their own mechanisms.Feature flag API to enable IL trimming of hot reload support code Consider a hot reload feature switch for linking #51159
Block applying changes to assemblies that have AOT images loaded.There's no supported hybrid interp/AOT scenarios.Future (.net7 +)
Moved to #57365
Bugs
<Counter/>
components would render as another previously added component)BadImageFormatException
thrown from the caller of an updated method.The text was updated successfully, but these errors were encountered: