[Wasm] Write barriers#128225
Conversation
|
Tagging subscribers to this area: @agocke |
There was a problem hiding this comment.
Pull request overview
Initial scaffolding to make the WASM portable write barriers (RhpAssignRef, RhpCheckedAssignRef, RhpByRefAssignRef) use a "raw" calling convention that matches what RyuJIT expects for write barriers, rather than the trampolined WASM FCALL convention that threads callersStackPointer / portableEntryPointContext through. The actual barrier implementations still assert and will be filled in later.
Changes:
- Add new
FCDECL2_RAW/FCIMPL2_RAWmacros that bypass the WASM stack-pointer/entrypoint-context plumbing and define the function with the plain(a1, a2)signature; provide non-WASM fallbacks that alias toFCDECL2/FCIMPL2. - Switch the three
Rhp*AssignRefdeclarations injitinterface.hand definitions inWriteBarriers.cppto the new_RAWvariants. - Trivial whitespace cleanup in
jitinterface.h.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/coreclr/vm/fcall.h |
Adds WASM-specific FCDECL2_RAW / FCIMPL2_RAW macros and non-WASM fallbacks aliasing to the standard FCDECL2 / FCIMPL2. |
src/coreclr/vm/jitinterface.h |
Switches Rhp{Checked,ByRef,}AssignRef declarations to FCDECL2_RAW; trims trailing whitespace. |
src/coreclr/runtime/portable/WriteBarriers.cpp |
Updates the three portable write-barrier stubs to use FCDECL2_RAW / FCIMPL2_RAW. |
a35761f to
6604569
Compare
| #include <fcall.h> | ||
| #include "../gchelpers.inl" | ||
| #include "gcheaputilities.h" | ||
|
|
There was a problem hiding this comment.
This can use comment about why we have inline wasm implementation and not just regular C/C++ implementation.
| @@ -0,0 +1,113 @@ | |||
| // Licensed to the .NET Foundation under one or more agreements. | |||
| // The .NET Foundation licenses this file to you under the MIT license. | |||
There was a problem hiding this comment.
Can we move this file to src/coreclr/runtime/wasm ? We will want to use this implementation for naot. src/coreclr/runtime/wasm is the directory where files shared between regular coreclr and naot live.
| EXTERN_C FCDECL2_RAW(VOID, RhpAssignRef, Object **dst, Object *ref); | ||
| ASM_HELPER_2(VOID, RhpAssignRef, Object **dst, Object *ref) | ||
| __attribute__((alias("JIT_WriteBarrier"))); | ||
|
|
||
| EXTERN_C FCDECL2_RAW(VOID, RhpCheckedAssignRef, Object **dst, Object *ref); | ||
| ASM_HELPER_2(VOID, RhpCheckedAssignRef, Object **dst, Object *ref) | ||
| __attribute__((alias("JIT_CheckedWriteBarrier"))); | ||
|
|
There was a problem hiding this comment.
| EXTERN_C FCDECL2_RAW(VOID, RhpAssignRef, Object **dst, Object *ref); | |
| ASM_HELPER_2(VOID, RhpAssignRef, Object **dst, Object *ref) | |
| __attribute__((alias("JIT_WriteBarrier"))); | |
| EXTERN_C FCDECL2_RAW(VOID, RhpCheckedAssignRef, Object **dst, Object *ref); | |
| ASM_HELPER_2(VOID, RhpCheckedAssignRef, Object **dst, Object *ref) | |
| __attribute__((alias("JIT_CheckedWriteBarrier"))); |
Do we need these aliases?
It seems that things should work fine if the functions implementing this are called RhpAssignRef and RhpCheckedAssignRef, and JIT_WriteBarrier does not need to exist. Or is JIT_WriteBarrier referenced from somewhere in wasm builds?
There was a problem hiding this comment.
There are comments that refer to JIT_WriteBarrier but the thing that the comment is attached to is actually RhpAssignRef, e.g.
runtime/src/coreclr/runtime/arm64/WriteBarriers.asm
Lines 218 to 231 in ed8987f
JIT_WriteBarrier should only be used with the dynamically runtime generated write barriers.
| EXTERN_C FCDECL2_RAW(VOID, RhpByRefAssignRef, Object **dst, Object **ref); | ||
| ASM_HELPER_2(VOID, RhpByRefAssignRef, Object **dst, Object **ref) | ||
| { | ||
| GC_ASM("unreachable" | ||
| ); | ||
| } |
There was a problem hiding this comment.
| EXTERN_C FCDECL2_RAW(VOID, RhpByRefAssignRef, Object **dst, Object **ref); | |
| ASM_HELPER_2(VOID, RhpByRefAssignRef, Object **dst, Object **ref) | |
| { | |
| GC_ASM("unreachable" | |
| ); | |
| } |
We can define this helper as not implemented for wasm in src\coreclr\inc\jithelpers.h (notice that this file has similar arch-specific ifdefs for number of other helpers):
#ifdef TARGET_WASM
JITHELPER(CORINFO_HELP_ASSIGN_BYREF, NULL,METHOD__NIL)
#else
DYNAMICJITHELPER(CORINFO_HELP_ASSIGN_BYREF, RhpByRefAssignRef, METHOD__NIL)
#endif
| #include "../gchelpers.inl" | ||
| #include "gcheaputilities.h" | ||
|
|
||
| #define ASM_HELPER_2(rettype, funcname, a1, a2) \ |
There was a problem hiding this comment.
| #define ASM_HELPER_2(rettype, funcname, a1, a2) \ | |
| #ifdef FEATURE_MULTITHREADING | |
| #error The assembly implemementaiton of write barriers assumes single threaded wasm | |
| #endif | |
| #define ASM_HELPER_2(rettype, funcname, a1, a2) \ |
Sufficient for the R2R'd version of this to run without crashing:
Currently the write barrier in
ConcatTwoStringsfails due to the calling convention being wrong and then once the calling convention is fixed, it fails because we didn't implement the write barriers yet.This PR:
FCDECL2_RAW/FCIMPL2_RAWmacrosRhpByRefAssignRef's signature being incorrect (missing*)wasm/writebarriers.cppfile