Bug 1863920 - Align mark bits to cache line size r=sfink

Differential Revision: https://phabricator.services.mozilla.com/D193187
This commit is contained in:
Jon Coppeard
2023-11-10 10:14:01 +00:00
parent e621f5f210
commit ed6c2733b6
4 changed files with 17 additions and 11 deletions

View File

@@ -29,6 +29,10 @@ class NurseryDecommitTask;
JS_PUBLIC_API bool CurrentThreadCanAccessZone(JS::Zone* zone);
// To prevent false sharing, some data structures are aligned to a typical cache
// line size.
static constexpr size_t TypicalCacheLineSize = 64;
namespace gc {
class Arena;
@@ -183,7 +187,7 @@ enum class ColorBit : uint32_t { BlackBit = 0, GrayOrBlackBit = 1 };
enum class MarkColor : uint8_t { Gray = 1, Black = 2 };
// Mark bitmap for a tenured heap chunk.
struct MarkBitmap {
struct alignas(TypicalCacheLineSize) MarkBitmap {
static constexpr size_t WordCount = ArenaBitmapWords * ArenasPerChunk;
MarkBitmapWord bitmap[WordCount];

View File

@@ -610,7 +610,10 @@ void ChunkPool::verifyChunks() const {
}
}
void TenuredChunk::verify() const {
void TenuredChunk::verify() {
MOZ_ASSERT(
(uintptr_t(markBits.arenaBits(&arenas[0])) % TypicalCacheLineSize) == 0);
MOZ_ASSERT(info.numArenasFree <= ArenasPerChunk);
MOZ_ASSERT(info.numArenasFreeCommitted <= info.numArenasFree);

View File

@@ -21,10 +21,6 @@ class AutoLockGC;
class AutoLockGCBgAlloc;
class Nursery;
// To prevent false sharing, some data structures are aligned to a typical cache
// line size.
static constexpr size_t TypicalCacheLineSize = 64;
namespace gc {
class Arena;
@@ -710,9 +706,9 @@ class TenuredChunk : public TenuredChunkBase {
Arena* fetchNextFreeArena(GCRuntime* gc);
#ifdef DEBUG
void verify() const;
void verify();
#else
void verify() const {}
void verify() {}
#endif
private:

View File

@@ -507,12 +507,15 @@ void js::gc::MarkingValidator::nonIncrementalMark(AutoGCSession& session) {
AutoLockGC lock(gc);
for (auto chunk = gc->allNonEmptyChunks(lock); !chunk.done();
chunk.next()) {
MarkBitmap* bitmap = &chunk->markBits;
auto entry = MakeUnique<MarkBitmap>();
if (!entry) {
// Bug 1842582: Allocate mark bit buffer in two stages to avoid alignment
// restriction which we currently can't support.
void* buffer = js_malloc(sizeof(MarkBitmap));
if (!buffer) {
return;
}
UniquePtr<MarkBitmap> entry(new (buffer) MarkBitmap);
MarkBitmap* bitmap = &chunk->markBits;
memcpy((void*)entry->bitmap, (void*)bitmap->bitmap,
sizeof(bitmap->bitmap));