nsPresArena.h (1959B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 */ 7 8 /* arena allocation for the frame tree and closely-related objects */ 9 10 #ifndef nsPresArena_h___ 11 #define nsPresArena_h___ 12 13 #include "mozilla/ArenaAllocator.h" 14 #include "mozilla/ArenaObjectID.h" 15 #include "mozilla/MemoryChecking.h" // Note: Do not remove this, needed for MOZ_HAVE_MEM_CHECKS below 16 #include "mozilla/MemoryReporting.h" 17 #include "nsHashKeys.h" 18 #include "nsTArray.h" 19 #include "nsTHashtable.h" 20 #include "nscore.h" 21 22 class nsWindowSizes; 23 24 template <size_t ArenaSize, typename ObjectId, size_t ObjectIdCount> 25 class nsPresArena { 26 public: 27 nsPresArena() = default; 28 ~nsPresArena(); 29 30 /** 31 * Pool allocation with recycler lists indexed by object-type ID (see above). 32 * Every aID must always be used with the same object size, aSize. 33 */ 34 void* Allocate(ObjectId aCode, size_t aSize); 35 void Free(ObjectId aCode, void* aPtr); 36 37 enum class ArenaKind { PresShell, DisplayList }; 38 /** 39 * Increment nsWindowSizes with sizes of interesting objects allocated in this 40 * arena, and put the general unclassified size in the relevant field 41 * depending on the arena size. 42 */ 43 void AddSizeOfExcludingThis(nsWindowSizes&, ArenaKind) const; 44 45 void Check() { mPool.Check(); } 46 47 private: 48 class FreeList { 49 public: 50 nsTArray<void*> mEntries; 51 size_t mEntrySize; 52 size_t mEntriesEverAllocated; 53 54 FreeList() : mEntrySize(0), mEntriesEverAllocated(0) {} 55 56 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { 57 return mEntries.ShallowSizeOfExcludingThis(aMallocSizeOf); 58 } 59 }; 60 61 FreeList mFreeLists[ObjectIdCount]; 62 mozilla::ArenaAllocator<ArenaSize, 8> mPool; 63 }; 64 65 #endif