Skip to content

Mono Method Body Replacement #44806

Closed
Closed

Description

@lambdageek

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) value debug. 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

Tasks

Priority 0

Priority 1

Future (.net7 +)

Moved to #57365

Bugs

Activity

  1. removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 17, 2020
  2. self-assigned this
    on Nov 17, 2020
  3. added this to the 6.0.0 milestone on Nov 17, 2020
  4. srxqds commented on Nov 17, 2020

    @srxqds
    Contributor

    why not support for jit?

  5. srxqds commented on Dec 5, 2020

    @srxqds
    Contributor

    hope you can support it in jit mode

  6. lambdageek commented on Dec 5, 2020

    @lambdageek
    MemberAuthor

    @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 (MonoClass etc); and in the compilation stage and the execution engine. The advantage of doing interpreter first is that it has a relatively isolated compilation (inter/transform.c) and there is a single place where the code to be executed is looked up. So we can make a small change that we are pretty sure won't lead to a ton of bugs.

    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.

  7. 4 remaining items

  8. added a commit that references this issue on Mar 3, 2021
  9. srxqds commented on Jun 22, 2021

    @srxqds
    Contributor

    hi, when can you begin to support add static fields and methods to existing classes work?

  10. lambdageek commented on Aug 13, 2021

    @lambdageek
    MemberAuthor

    Pushed the future work to a separate tracking issue. This one is done. #57365

  11. ghost locked as resolved and limited conversation to collaborators on Sep 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-EnC-monoHot Reload for WebAssembly, iOS/Android, etchard-problemtrackingThis issue is tracking the completion of other related issues.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions