[Mono] Initial metadata update support (#45612)
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Mon, 11 Jan 2021 18:13:10 +0000 (13:13 -0500)
committerGitHub <noreply@github.com>
Mon, 11 Jan 2021 18:13:10 +0000 (13:13 -0500)
commitb0a316f4dc5c22cee297f71860f76e2a8a240e14
treeb105eeeccf1c34f32e39cca4bab80f3555a4c0b6
parent4848f51c05b06db166c83b685f12b351cb7991ef
[Mono] Initial metadata update support (#45612)

* 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>
50 files changed:
src/mono/cmake/config.h.in
src/mono/cmake/options.cmake
src/mono/mono.proj
src/mono/mono/cil/tables.def
src/mono/mono/metadata/CMakeLists.txt
src/mono/mono/metadata/Makefile.am
src/mono/mono/metadata/class.c
src/mono/mono/metadata/domain.c
src/mono/mono/metadata/icall-decl.h
src/mono/mono/metadata/icall-def-netcore.h
src/mono/mono/metadata/icall.c
src/mono/mono/metadata/image.c
src/mono/mono/metadata/loader.c
src/mono/mono/metadata/metadata-internals.h
src/mono/mono/metadata/metadata-update.c [new file with mode: 0644]
src/mono/mono/metadata/metadata-update.h [new file with mode: 0644]
src/mono/mono/metadata/metadata.c
src/mono/mono/metadata/metadata.h
src/mono/mono/metadata/object-internals.h
src/mono/mono/metadata/threads.c
src/mono/mono/mini/ee.h
src/mono/mono/mini/interp-stubs.c
src/mono/mono/mini/interp/interp-internals.h
src/mono/mono/mini/interp/interp.c
src/mono/mono/mini/interp/transform.c
src/mono/mono/mini/mini-runtime.c
src/mono/mono/utils/mono-logger-internals.h
src/mono/mono/utils/mono-logger.c
src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj
src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml
src/mono/netcore/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.Mono.cs
src/mono/netcore/sample/mbr/DeltaHelper.targets [new file with mode: 0644]
src/mono/netcore/sample/mbr/DeltaHelper/DeltaHelper.cs [new file with mode: 0644]
src/mono/netcore/sample/mbr/DeltaHelper/DeltaHelper.csproj [new file with mode: 0644]
src/mono/netcore/sample/mbr/README.md [new file with mode: 0644]
src/mono/netcore/sample/mbr/browser/Makefile [new file with mode: 0644]
src/mono/netcore/sample/mbr/browser/Program.cs [new file with mode: 0644]
src/mono/netcore/sample/mbr/browser/Program_v1.cs [new file with mode: 0644]
src/mono/netcore/sample/mbr/browser/Program_v2.cs [new file with mode: 0644]
src/mono/netcore/sample/mbr/browser/WasmDelta.csproj [new file with mode: 0644]
src/mono/netcore/sample/mbr/browser/index.html [new file with mode: 0644]
src/mono/netcore/sample/mbr/browser/runtime.js [new file with mode: 0644]
src/mono/netcore/sample/mbr/console/ConsoleDelta.csproj [new file with mode: 0644]
src/mono/netcore/sample/mbr/console/Makefile [new file with mode: 0644]
src/mono/netcore/sample/mbr/console/Program.cs [new file with mode: 0644]
src/mono/netcore/sample/mbr/console/TestClass.cs [new file with mode: 0644]
src/mono/netcore/sample/mbr/console/TestClass_v1.cs [new file with mode: 0644]
src/mono/wasm/Makefile
src/mono/wasm/runtime/driver.c
src/mono/wasm/wasm.proj