-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Web.JS] call mono_wasm_gc_lock in MonoHeapLock #46909
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
Conversation
Mutating UI components from worker thread is interesting scenario which we should address I think. Otherwise LGTM |
The goal is to provide an API that can be called from JS to block a background GC from moving objects that may be accessed unsafely from JS. Blazor does this during rendering - it traverses a set of rendering objects from JS in order to apply changes to the DOM. Important notes for consumers of this API: 1. While the runtime GC lock is locked, calling any C# function or doing anything that may trigger managed allocation will block the runtime. 2. In a threaded build, only the main browser thread is allowed to call the `mono_wasm_gc_lock` function 3. The runtime lock is not recursive 4. Background threads initially continue running, so the managed object graph may change even while the GC lock is held (although objects may not move). Background threads could mutate valuetype fields of reachable objects, even while the GC lock is held. However background threads will block as soon as they try to do any allocation. 5. The main browser thread may assume that managed heap objects will not move while the lock is held. The corresponding aspnetcore API is dotnet/aspnetcore#46909 * add wasm entrypoints to lock the GC from JS * move gc lock api to INTERNAL object * enter GC Unsafe before manipulating the locks This is an exported API, so we're normally in GC Safe mode on entry
Runtime change has been merged. This PR doesn't depend on the runtime bits (and in fact, won't do anything different until threading is enabled) - if it's paired with a runtime that doesn't have the API, it behaves as before. This is ready for review now. |
That's a good point - thanks for raising it. I don't think this can lead to any problems based on how rendering is implemented currently, but we are going to have to make sure we don't later add any logic to |
As long as Blazor WebAssembly implements support for a renderer sync context (equivalent to the one for Blazor Server / WebView), then this should be covered automatically. Components would have to dispatch to the sync context to update their render output, but the sync context would be locked while an existing renderbatch is in process of being applied to the DOM. |
blazorwasm and the runtime must be in lockstep. There's no supported scenario where the API might be missing
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Take the runtime's GC lock when creating a heap lock.
Important Notes
mono_wasm_gc_lock
functionCorresponding runtime change dotnet/runtime#82646