-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
[Core] Improve CowData
and Memory
metadata alignment.
#87814
Conversation
1c3ed24
to
ffc07df
Compare
Tested on:
On 32-bit Linux, I'm getting a few failed Another unrelated note: 32-bit MinGW GCC crash when building with debug symbols on Windows (cross-building is fine), probably symbols are not too big (might be worth adding a note to the compiling page). |
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.
The changes here make a lot of sense to me
core/os/memory.cpp
Outdated
// Alignment: ↓ max_align_t ↓ uint64_t ↓ max_align_t | ||
// ┌─────────────────┬──┬────────────────┬──┬───────────... | ||
// │ uint64_t │░░│ uint64_t │░░│ T[] | ||
// │ alloc size │░░│ element count │░░│ data | ||
// └─────────────────┴──┴────────────────┴──┴───────────... | ||
// Offset: ↑ _size_offset ↑ _elem_offset ↑ _data_offset | ||
|
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.
Good idea!
core/templates/cowdata.h
Outdated
@@ -46,7 +46,7 @@ class CharString; | |||
template <class T, class V> | |||
class VMap; | |||
|
|||
SAFE_NUMERIC_TYPE_PUN_GUARANTEES(uint64_t) | |||
static_assert(std::is_trivially_destructible<std::atomic<uint64_t>>::value); |
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.
If this because of the SafeNumeric<uint64_t>
around, I'd suggest including this in the set of type-pun guarantees macro in safe_refcount.h
.
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.
It is part of SAFE_NUMERIC_TYPE_PUN_GUARANTEES
:
#define SAFE_NUMERIC_TYPE_PUN_GUARANTEES(m_type) \
static_assert(sizeof(SafeNumeric<m_type>) == sizeof(m_type)); \
static_assert(alignof(SafeNumeric<m_type>) == alignof(m_type)); \
static_assert(std::is_trivially_destructible<std::atomic<m_type>>::value);
We take case or sizes and alignment manually (since alignof
part is not true on 32-bit platforms), and I have copy-pasted the remaining check here (but I'm not sure if there's any point for checking it for uint64_t
at all).
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.
Ah, makes sense.
Needs rebase after #87871. |
4c086be
to
b5a96b0
Compare
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.
Re-confirming
Thanks! |
Would be good to get a Godot-cpp equivalent fix too |
Will do it soon. |
Fixes #87442
This should not change real memory structure on any platform. But instead of hard-coded values, it is using actual sizes and alignments to allocate and access metadata.