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