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 "nsDataHashtable.h"
21 #include "nsHashKeys.h"
23 #include "nsTHashtable.h"
27 template <size_t ArenaSize
, typename ObjectId
, size_t ObjectIdCount
>
30 nsPresArena() = default;
34 * Pool allocation with recycler lists indexed by object-type ID (see above).
35 * Every aID must always be used with the same object size, aSize.
37 void* Allocate(ObjectId aCode
, size_t aSize
);
38 void Free(ObjectId aCode
, void* aPtr
);
40 enum class ArenaKind
{ PresShell
, DisplayList
};
42 * Increment nsWindowSizes with sizes of interesting objects allocated in this
43 * arena, and put the general unclassified size in the relevant field
44 * depending on the arena size.
46 void AddSizeOfExcludingThis(nsWindowSizes
&, ArenaKind
) const;
48 void Check() { mPool
.Check(); }
53 nsTArray
<void*> mEntries
;
55 size_t mEntriesEverAllocated
;
57 FreeList() : mEntrySize(0), mEntriesEverAllocated(0) {}
59 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const {
60 return mEntries
.ShallowSizeOfExcludingThis(aMallocSizeOf
);
64 FreeList mFreeLists
[ObjectIdCount
];
65 mozilla::ArenaAllocator
<ArenaSize
, 8> mPool
;