-
Notifications
You must be signed in to change notification settings - Fork 505
Wasm: call RhpAssignRef for stfld and stelem #8171
Conversation
Yes: stind.ref, stobj. Also, make sure to handle value types. When the valuetype contains object references, the write barrier needs to be called for each of them. |
|
I think I'm going to need to add DataLayout to LLVMSharp for this so marking as draft for now. |
|
I have dotnet/LLVMSharp#141 which will allow this to progress I hope. |
|
I'm having some trouble creating a failing test for assigning structs which contain object references before I actually make the fix. I have I expect the |
| } | ||
|
|
||
| private void CastingStore(LLVMValueRef address, StackEntry value, TypeDesc targetType, string targetName = null) | ||
| private void CastingStore(LLVMValueRef address, StackEntry value, TypeDesc targetType, bool withBarrier, string targetName = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: withBarrier -> withGCBarrier to avoid confusion with memory barrier.
src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs
Outdated
Show resolved
Hide resolved
| } | ||
| if (!childStruct) | ||
| { | ||
| _builder.BuildStore(llvmValue, typedStoreLocation); // just copy all the fields again for simplicity, if all the fields where set using RhpAssignRef then a possible optimisation would be to skip this line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a potential for race conditions if the LLVM codegen is used for anything multithreaded. Maybe add a comment about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, think I understand - thread1 can RhpAssignRef a struct field (after thread2 has done the same), thread1 calls BuildStore and then thread2 can get switched back in and executes BuildStore. Thread 2's field which requires the GC write barrier is then lost. Will add a comment for now.
Co-authored-by: Jan Kotas <[email protected]>
clarify variable name add race condition TODO
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This PR changes the implementation of stfld and stelem when the target type
IsGCPointerand adds a test for objects rooted through a Gen 2 parent. Are there other opcodes whereRhpAssignRefshould be used?Thanks @Suchiman