2017-10-27 17:33:53 +00:00
|
|
|
/* -*- 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
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/.
|
2009-08-18 03:21:06 +00:00
|
|
|
*/
|
|
|
|
|
2013-04-15 20:00:06 +00:00
|
|
|
/* arena allocation for the frame tree and closely-related objects */
|
|
|
|
|
2009-08-18 03:21:06 +00:00
|
|
|
#ifndef nsPresArena_h___
|
|
|
|
#define nsPresArena_h___
|
|
|
|
|
2017-03-31 21:06:33 +00:00
|
|
|
#include "mozilla/ArenaAllocator.h"
|
2015-09-17 02:08:19 +00:00
|
|
|
#include "mozilla/ArenaObjectID.h"
|
2017-10-18 03:08:48 +00:00
|
|
|
#include "mozilla/Assertions.h"
|
2013-08-20 21:48:00 +00:00
|
|
|
#include "mozilla/MemoryChecking.h" // Note: Do not remove this, needed for MOZ_HAVE_MEM_CHECKS below
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-07-30 14:25:31 +00:00
|
|
|
#include <stdint.h>
|
2009-08-18 03:21:06 +00:00
|
|
|
#include "nscore.h"
|
2015-09-17 02:08:19 +00:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2013-04-15 20:00:06 +00:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTHashtable.h"
|
2012-04-12 00:17:44 +00:00
|
|
|
|
2017-08-10 04:14:09 +00:00
|
|
|
class nsWindowSizes;
|
2012-06-06 17:29:16 +00:00
|
|
|
|
2019-07-02 02:46:09 +00:00
|
|
|
template <size_t ArenaSize, typename ObjectId, size_t ObjectIdCount>
|
2009-08-18 03:21:06 +00:00
|
|
|
class nsPresArena {
|
|
|
|
public:
|
2018-12-12 19:09:14 +00:00
|
|
|
nsPresArena() = default;
|
2009-08-18 03:21:06 +00:00
|
|
|
~nsPresArena();
|
|
|
|
|
2013-04-15 20:00:06 +00:00
|
|
|
/**
|
|
|
|
* Pool allocation with recycler lists indexed by object-type ID (see above).
|
|
|
|
* Every aID must always be used with the same object size, aSize.
|
|
|
|
*/
|
2019-07-02 02:46:09 +00:00
|
|
|
void* Allocate(ObjectId aCode, size_t aSize);
|
|
|
|
void Free(ObjectId aCode, void* aPtr);
|
2017-10-18 03:08:48 +00:00
|
|
|
|
2019-07-02 02:46:09 +00:00
|
|
|
enum class ArenaKind { PresShell, DisplayList };
|
2012-06-06 17:29:16 +00:00
|
|
|
/**
|
2017-08-10 04:14:09 +00:00
|
|
|
* Increment nsWindowSizes with sizes of interesting objects allocated in this
|
2019-07-02 02:46:09 +00:00
|
|
|
* arena, and put the general unclassified size in the relevant field
|
|
|
|
* depending on the arena size.
|
2012-06-06 17:29:16 +00:00
|
|
|
*/
|
2019-07-02 02:46:09 +00:00
|
|
|
void AddSizeOfExcludingThis(nsWindowSizes&, ArenaKind) const;
|
2010-06-01 02:19:35 +00:00
|
|
|
|
2017-11-16 03:09:28 +00:00
|
|
|
void Check() { mPool.Check(); }
|
2017-10-18 03:08:48 +00:00
|
|
|
|
2009-08-18 03:21:06 +00:00
|
|
|
private:
|
2017-05-24 13:41:41 +00:00
|
|
|
class FreeList {
|
2013-04-15 20:00:06 +00:00
|
|
|
public:
|
|
|
|
nsTArray<void*> mEntries;
|
|
|
|
size_t mEntrySize;
|
|
|
|
size_t mEntriesEverAllocated;
|
|
|
|
|
2017-05-24 13:41:41 +00:00
|
|
|
FreeList() : mEntrySize(0), mEntriesEverAllocated(0) {}
|
2013-04-15 20:00:06 +00:00
|
|
|
|
2014-08-05 20:27:41 +00:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
2015-07-29 06:24:24 +00:00
|
|
|
return mEntries.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
2013-04-15 20:00:06 +00:00
|
|
|
};
|
|
|
|
|
2019-07-02 02:46:09 +00:00
|
|
|
FreeList mFreeLists[ObjectIdCount];
|
2018-12-12 19:09:14 +00:00
|
|
|
mozilla::ArenaAllocator<ArenaSize, 8> mPool;
|
2009-08-18 03:21:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|