Bug 1395509 - Allow multiple associations for some memory uses r=sfink

Some kinds of memory use (e.g. reg exp byte code) require multiple memory associations for a single cell. This patch adds machinery to let that happen for specific uses.

Differential Revision: https://phabricator.services.mozilla.com/D34723
This commit is contained in:
Jon Coppeard 2019-06-12 16:19:52 +01:00
parent e5408fbd5b
commit e7e5bc5f08
2 changed files with 29 additions and 4 deletions

View File

@ -779,6 +779,8 @@ class MemoryTracker {
HashMap<ZoneAllocPolicy*, size_t, DefaultHasher<ZoneAllocPolicy*>,
SystemAllocPolicy>;
bool allowMultipleAssociations(MemoryUse use) const;
size_t getAndRemoveEntry(const Key& key, LockGuard<Mutex>& lock);
Mutex mutex;

View File

@ -698,6 +698,12 @@ void MemoryTracker::checkEmptyOnDestroy() {
MOZ_ASSERT(ok);
}
inline bool MemoryTracker::allowMultipleAssociations(MemoryUse use) const {
// For most uses only one association is possible for each GC thing. Allow a
// one-to-many relationship only where necessary.
return false;
}
void MemoryTracker::trackMemory(Cell* cell, size_t nbytes, MemoryUse use) {
MOZ_ASSERT(cell->isTenured());
@ -707,8 +713,12 @@ void MemoryTracker::trackMemory(Cell* cell, size_t nbytes, MemoryUse use) {
AutoEnterOOMUnsafeRegion oomUnsafe;
auto ptr = map.lookupForAdd(key);
if (ptr) {
MOZ_CRASH_UNSAFE_PRINTF("Association already present: %p 0x%zx %s", cell,
nbytes, MemoryUseName(use));
if (!allowMultipleAssociations(use)) {
MOZ_CRASH_UNSAFE_PRINTF("Association already present: %p 0x%zx %s", cell,
nbytes, MemoryUseName(use));
}
ptr->value() += nbytes;
return;
}
if (!map.add(ptr, key, nbytes)) {
@ -727,13 +737,26 @@ void MemoryTracker::untrackMemory(Cell* cell, size_t nbytes, MemoryUse use) {
MOZ_CRASH_UNSAFE_PRINTF("Association not found: %p 0x%zx %s", cell, nbytes,
MemoryUseName(use));
}
if (ptr->value() != nbytes) {
if (!allowMultipleAssociations(use) && ptr->value() != nbytes) {
MOZ_CRASH_UNSAFE_PRINTF(
"Association for %p %s has different size: "
"expected 0x%zx but got 0x%zx",
cell, MemoryUseName(use), ptr->value(), nbytes);
}
map.remove(ptr);
if (ptr->value() < nbytes) {
MOZ_CRASH_UNSAFE_PRINTF(
"Association for %p %s size is too small: "
"expected at least 0x%zx but got 0x%zx",
cell, MemoryUseName(use), nbytes, ptr->value());
}
ptr->value() -= nbytes;
if (ptr->value() == 0) {
map.remove(ptr);
}
}
void MemoryTracker::swapMemory(Cell* a, Cell* b, MemoryUse use) {