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/.
8 /* arena allocation for the frame tree and closely-related objects */
10 #ifndef nsPresArena_h___
11 #define nsPresArena_h___
13 #include "mozilla/ArenaAllocator.h"
14 #include "mozilla/ArenaObjectID.h"
15 #include "mozilla/Assertions.h"
16 #include "mozilla/MemoryChecking.h" // Note: Do not remove this, needed for MOZ_HAVE_MEM_CHECKS below
17 #include "mozilla/MemoryReporting.h"
20 #include "nsHashKeys.h"
22 #include "nsTHashtable.h"
26 template <size_t ArenaSize
, typename ObjectId
, size_t ObjectIdCount
>
29 nsPresArena() = default;
33 * Pool allocation with recycler lists indexed by object-type ID (see above).
34 * Every aID must always be used with the same object size, aSize.
36 void* Allocate(ObjectId aCode
, size_t aSize
);
37 void Free(ObjectId aCode
, void* aPtr
);
39 enum class ArenaKind
{ PresShell
, DisplayList
};
41 * Increment nsWindowSizes with sizes of interesting objects allocated in this
42 * arena, and put the general unclassified size in the relevant field
43 * depending on the arena size.
45 void AddSizeOfExcludingThis(nsWindowSizes
&, ArenaKind
) const;
47 void Check() { mPool
.Check(); }
52 nsTArray
<void*> mEntries
;
54 size_t mEntriesEverAllocated
;
56 FreeList() : mEntrySize(0), mEntriesEverAllocated(0) {}
58 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const {
59 return mEntries
.ShallowSizeOfExcludingThis(aMallocSizeOf
);
63 FreeList mFreeLists
[ObjectIdCount
];
64 mozilla::ArenaAllocator
<ArenaSize
, 8> mPool
;