Bug 1207753 - Add TS annotations for some mozjemalloc mutexes r=jesup

Add thread-safety annotations for a few of the mutexes in mozjemalloc.

Differential Revision: https://phabricator.services.mozilla.com/D157858
This commit is contained in:
Ray Kraesig 2022-09-22 15:00:44 +00:00
Родитель 52af826568
Коммит 75b7dee465
2 изменённых файлов: 29 добавлений и 20 удалений

Просмотреть файл

@ -1220,39 +1220,43 @@ static ArenaCollection gArenas;
static AddressRadixTree<(sizeof(void*) << 3) - LOG2(kChunkSize)> gChunkRTree;
// Protects chunk-related data structures.
static Mutex chunks_mtx MOZ_UNANNOTATED;
static Mutex chunks_mtx;
// Trees of chunks that were previously allocated (trees differ only in node
// ordering). These are used when allocating chunks, in an attempt to re-use
// address space. Depending on function, different tree orderings are needed,
// which is why there are two trees with the same contents.
static RedBlackTree<extent_node_t, ExtentTreeSzTrait> gChunksBySize;
static RedBlackTree<extent_node_t, ExtentTreeTrait> gChunksByAddress;
static RedBlackTree<extent_node_t, ExtentTreeSzTrait> gChunksBySize
MOZ_GUARDED_BY(chunks_mtx);
static RedBlackTree<extent_node_t, ExtentTreeTrait> gChunksByAddress
MOZ_GUARDED_BY(chunks_mtx);
// Protects huge allocation-related data structures.
static Mutex huge_mtx MOZ_UNANNOTATED;
static Mutex huge_mtx;
// Tree of chunks that are stand-alone huge allocations.
static RedBlackTree<extent_node_t, ExtentTreeTrait> huge;
static RedBlackTree<extent_node_t, ExtentTreeTrait> huge
MOZ_GUARDED_BY(huge_mtx);
// Huge allocation statistics.
static size_t huge_allocated;
static size_t huge_mapped;
static size_t huge_allocated MOZ_GUARDED_BY(huge_mtx);
static size_t huge_mapped MOZ_GUARDED_BY(huge_mtx);
// **************************
// base (internal allocation).
static Mutex base_mtx;
// Current pages that are being used for internal memory allocations. These
// pages are carved up in cacheline-size quanta, so that there is no chance of
// false cache line sharing.
static void* base_pages;
static void* base_next_addr;
static void* base_next_decommitted;
static void* base_past_addr; // Addr immediately past base_pages.
static Mutex base_mtx MOZ_UNANNOTATED;
static size_t base_mapped;
static size_t base_committed;
static void* base_pages MOZ_GUARDED_BY(base_mtx);
static void* base_next_addr MOZ_GUARDED_BY(base_mtx);
static void* base_next_decommitted MOZ_GUARDED_BY(base_mtx);
// Address immediately past base_pages.
static void* base_past_addr MOZ_GUARDED_BY(base_mtx);
static size_t base_mapped MOZ_GUARDED_BY(base_mtx);
static size_t base_committed MOZ_GUARDED_BY(base_mtx);
// ******
// Arenas.
@ -1536,7 +1540,7 @@ static inline void pages_decommit(void* aAddr, size_t aSize) {
return true;
}
static bool base_pages_alloc(size_t minsize) {
static bool base_pages_alloc(size_t minsize) MOZ_REQUIRES(base_mtx) {
size_t csize;
size_t pminsize;
@ -4217,19 +4221,25 @@ static bool malloc_init_hard() {
// Initialize chunks data.
chunks_mtx.Init();
MOZ_PUSH_IGNORE_THREAD_SAFETY
gChunksBySize.Init();
gChunksByAddress.Init();
MOZ_POP_THREAD_SAFETY
// Initialize huge allocation data.
huge_mtx.Init();
MOZ_PUSH_IGNORE_THREAD_SAFETY
huge.Init();
huge_allocated = 0;
huge_mapped = 0;
MOZ_POP_THREAD_SAFETY
// Initialize base allocation data structures.
base_mtx.Init();
MOZ_PUSH_IGNORE_THREAD_SAFETY
base_mapped = 0;
base_committed = 0;
base_mtx.Init();
MOZ_POP_THREAD_SAFETY
// Initialize arenas collection here.
if (!gArenas.Init()) {

Просмотреть файл

@ -786,7 +786,8 @@ class GMut {
MOZ_CRASH("unreachable");
}
void EnsureValidAndInUse(GMutLock, void* aPtr, uintptr_t aIndex) {
void EnsureValidAndInUse(GMutLock, void* aPtr, uintptr_t aIndex)
MOZ_REQUIRES(sMutex) {
const AllocPageInfo& page = mAllocPages[aIndex];
// The pointer must point to the start of the allocation.
@ -800,9 +801,7 @@ class GMut {
// first, because that self-same PHC machinery needs to re-lock it, and
// the crash causes non-local control flow so sMutex won't be unlocked
// the normal way in the caller.
MOZ_PUSH_IGNORE_THREAD_SAFETY
sMutex.Unlock();
MOZ_POP_THREAD_SAFETY
*static_cast<uint8_t*>(aPtr) = 0;
MOZ_CRASH("unreachable");
}