/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* arena allocation for the frame tree and closely-related objects */
// We only hand out aligned sizes
aSize = mPool.AlignedSize(aSize);
FreeList* list = &mFreeLists[size_t(aCode)];
nsTArray<void*>::index_type len = list->mEntries.Length(); if (list->mEntrySize == 0) {
MOZ_ASSERT(len == 0, "list with entries but no recorded size");
list->mEntrySize = aSize;
} else {
MOZ_ASSERT(list->mEntrySize == aSize, "different sizes for same object type code");
}
void* result; if (len > 0) { // Remove from the end of the mEntries array to avoid memmoving entries, // and use SetLengthAndRetainStorage to avoid a lot of malloc/free // from ShrinkCapacity on smaller sizes. 500 pointers means the malloc size // for the array is 4096 bytes or more on a 64-bit system. The next smaller // size is 2048 (with jemalloc), which we consider not worth compacting.
result = list->mEntries.Elements()[len - 1]; if (list->mEntries.Capacity() > 500) {
list->mEntries.RemoveElementAtUnsafe(len - 1);
} else {
list->mEntries.SetLengthAndRetainStorage(len - 1);
} #ifdefined(DEBUG)
{
MOZ_MAKE_MEM_DEFINED(result, list->mEntrySize); char* p = reinterpret_cast<char*>(result); char* limit = p + list->mEntrySize; for (; p < limit; p += sizeof(uintptr_t)) {
uintptr_t val = *reinterpret_cast<uintptr_t*>(p); if (val != mozPoisonValue()) {
MOZ_ReportAssertionFailure(
nsPrintfCString("PresArena: poison overwritten; " "wanted %.16" PRIx64 " " "found %.16" PRIx64 " " "errors in bits %.16" PRIx64 " ",
uint64_t(mozPoisonValue()), uint64_t(val),
uint64_t(mozPoisonValue() ^ val))
.get(),
__FILE__, __LINE__);
MOZ_CRASH();
}
}
} #endif
MOZ_MAKE_MEM_UNDEFINED(result, list->mEntrySize); return result;
}
// Allocate a new chunk from the arena
list->mEntriesEverAllocated++; return mPool.Allocate(aSize);
}
// Try to recycle this entry.
FreeList* list = &mFreeLists[size_t(aCode)];
MOZ_ASSERT(list->mEntrySize > 0, "object of this type was never allocated");
template <size_t ArenaSize, typename ObjectId, size_t ObjectIdCount> void nsPresArena<ArenaSize, ObjectId, ObjectIdCount>::AddSizeOfExcludingThis(
nsWindowSizes& aSizes, ArenaKind aKind) const { // We do a complicated dance here because we want to measure the // space taken up by the different kinds of objects in the arena, // but we don't have pointers to those objects. And even if we did, // we wouldn't be able to use mMallocSizeOf on them, since they were // allocated out of malloc'd chunks of memory. So we compute the // size of the arena as known by malloc and we add up the sizes of // all the objects that we care about. Subtracting these two // quantities gives us a catch-all "other" number, which includes // slop in the arena itself as well as the size of objects that // we've not measured explicitly.
// Note that we're not measuring the size of the entries on the free // list here. The free list knows how many objects we've allocated // ever (which includes any objects that may be on the FreeList's // |mEntries| at this point) and we're using that to determine the // total size of objects allocated with a given ID.
size_t totalSize = entry->mEntrySize * entry->mEntriesEverAllocated;
auto& field = aKind == ArenaKind::PresShell
? aSizes.mLayoutPresShellSize
: aSizes.mLayoutRetainedDisplayListSize;
field += mallocSize - totalSizeInFreeLists;
}
// Explicitly instantiate templates for the used nsPresArena allocator sizes. // This is needed because nsPresArena definition is split across multiple files. templateclass nsPresArena<8192, ArenaObjectID, eArenaObjectID_COUNT>; templateclass nsPresArena<32768, DisplayListArenaObjectId,
size_t(DisplayListArenaObjectId::COUNT)>;
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.