Repository navigation
Make the generational write barrier's mark byte accesses atomic - #479
Open
dimensionscape wants to merge 1 commit into
Open
dimensionscape wants to merge 1 commit into
dimensionscape wants to merge 1 commit into
Conversation
Under HXCPP_GC_GENERATIONAL the write barrier reads an object's mark byte, and its slow path sets the remembered bit in it. Two threads storing into one old array at once did both with plain accesses, so one could set the bit while the other read the byte: ThreadSanitizer reported it in GenerationalArrayYoungLog, between YoungStore and the barrier inlined into the test's generated code. Either value read is handled, and both threads only set the same bit, but it was a data race all the same. So was the young log's count, ioLogged, which the code already says may lose updates between threads. hx::BarrierMarkByte reads the byte with a relaxed atomic load, a plain byte load where it compiles to one, and hx::BarrierRemember sets the bit with an atomic or. The barrier macros, YoungStore, the hash maps' barrier and the cppia JIT's pushWriteBarrier use them, and the count is read and written with relaxed atomics. Test: the TSan job, which reported the race in GenerationalArrayYoungLog; and the Generational regression tests, a cppia JIT test and gc stress, all built generational, on Windows x64.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The TSan check on #474 reported a data race in GenerationalArrayYoungLog, a test already on main: under
HXCPP_GC_GENERATIONAL, two threads storing into one old array read and set the array's mark byte with plain accesses, one inYoungStoresetting the remembered bit and the other in the write barrier inlined into the generated code. Either value read is handled and both only set the same bit, but it was a data race, and any PR's TSan run could hit it.The barrier reads the mark byte with a relaxed atomic load, which is the same plain byte load where it compiles to one, and sets the remembered bit with an atomic or, through
hx::BarrierMarkByteandhx::BarrierRememberin GC.h. The barrier macros,YoungStore, the hash maps' barrier and the cppia JIT'spushWriteBarrieruse them, and the young log's count is read and written with relaxed atomics.Run on Windows x64: the 12 Generational regression tests, a cppia JIT test and gc stress, all built generational, and a default build. The TSan job here is the check for the race itself.