Reach the weak table's unlocked words through std::atomic - #406
Open
DTW-Thalion wants to merge 1 commit into
Open
Reach the weak table's unlocked words through std::atomic#406DTW-Thalion wants to merge 1 commit into
DTW-Thalion wants to merge 1 commit into
Conversation
The isa word of a weak-reference control block and the slot of a weak variable are both reached without a lock, and neither can be declared as an atomic object: the isa word has to stay layout compatible with an object so the block can be handed out as an id, and the slot belongs to the caller. Both now go through an atomic pointer, as the reference count word does, rather than through the atomic builtins. The value type is void* because an Objective-C object pointer is not a permitted atomic value type. The orderings are unchanged and arc.mm compiles to the same instructions.
Member
|
The C++ spec is actually a bit more complex here than it needs to be and there's work ongoing to simplify it. All being well, C++29 will require that all non-atomic loads and stores of primitive types behave as if they were relaxed-consistency atomic. This is, it turns out, what all compilers do anyway. GCC accidentally forced |
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.
arc.mm reached two words through the atomic builtins while the reference count
word went through std::atomic. Both are on the weak-table paths: the isa word of
a control block, read without a lock by asWeakRef, and the slot of a weak
variable, written and read under whichever stripe lock owns the block it points
at.
Neither can be declared as an atomic object. The isa word has to stay layout
compatible with an object so a control block can be handed out as an id, and the
slot belongs to the caller and arrives as id* from objc_storeWeak. Both now go
through an atomic pointer instead, which is how the reference count word has
been reached since #399.
The value type is void* rather than id because an Objective-C object pointer is
not a permitted atomic value type. That is what the casts to void** in the
previous code were for.
The orderings are unchanged: relaxed on the isa publish and read, acquire and
release on the slot. arc.mm compiles to the same instructions as before, byte
for byte in the disassembly, and the 198 tests pass.