2009-08-17 20:21:06 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: set ts=2 sw=2 et tw=78:
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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-17 20:21:06 -07:00
|
|
|
*/
|
|
|
|
|
2013-04-15 13:00:06 -07:00
|
|
|
/* arena allocation for the frame tree and closely-related objects */
|
|
|
|
|
2009-08-17 20:21:06 -07:00
|
|
|
#ifndef nsPresArena_h___
|
|
|
|
#define nsPresArena_h___
|
|
|
|
|
2013-08-20 14:48:00 -07:00
|
|
|
#include "mozilla/MemoryChecking.h" // Note: Do not remove this, needed for MOZ_HAVE_MEM_CHECKS below
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-07-30 07:25:31 -07:00
|
|
|
#include <stdint.h>
|
2009-08-17 20:21:06 -07:00
|
|
|
#include "nscore.h"
|
2009-09-15 15:00:04 -07:00
|
|
|
#include "nsQueryFrame.h"
|
2013-04-15 13:00:06 -07:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "plarena.h"
|
2012-04-11 17:17:44 -07:00
|
|
|
|
2012-06-13 07:43:38 -07:00
|
|
|
struct nsArenaMemoryStats;
|
2012-06-06 10:29:16 -07:00
|
|
|
|
2009-08-17 20:21:06 -07:00
|
|
|
class nsPresArena {
|
|
|
|
public:
|
|
|
|
nsPresArena();
|
|
|
|
~nsPresArena();
|
|
|
|
|
2012-05-03 17:14:02 -07:00
|
|
|
enum ObjectID {
|
2012-05-03 17:14:02 -07:00
|
|
|
nsLineBox_id = nsQueryFrame::NON_FRAME_MARKER,
|
2012-06-06 10:35:40 -07:00
|
|
|
nsRuleNode_id,
|
|
|
|
nsStyleContext_id,
|
2014-07-18 21:22:20 -07:00
|
|
|
nsInheritedStyleData_id,
|
|
|
|
nsResetStyleData_id,
|
2013-04-01 08:26:02 -07:00
|
|
|
nsFrameList_id,
|
2012-05-03 17:14:02 -07:00
|
|
|
|
2014-10-16 13:10:00 -07:00
|
|
|
CustomCounterStyle_id,
|
|
|
|
DependentBuiltinCounterStyle_id,
|
|
|
|
|
2014-07-15 22:27:13 -07:00
|
|
|
First_nsStyleStruct_id,
|
|
|
|
DummyBeforeStyleStructs_id = First_nsStyleStruct_id - 1,
|
|
|
|
|
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_) \
|
|
|
|
nsStyle##name_##_id,
|
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
|
|
|
|
DummyAfterStyleStructs_id,
|
|
|
|
Last_nsStyleStruct_id = DummyAfterStyleStructs_id - 1,
|
|
|
|
|
2013-04-15 13:00:06 -07:00
|
|
|
/**
|
|
|
|
* The PresArena implementation uses this bit to distinguish objects
|
|
|
|
* allocated by size from objects allocated by type ID (that is, frames
|
|
|
|
* using AllocateByFrameID and other objects using AllocateByObjectID).
|
|
|
|
* It should not collide with any Object ID (above) or frame ID (in
|
|
|
|
* nsQueryFrame.h). It is not 0x80000000 to avoid the question of
|
|
|
|
* whether enumeration constants are signed.
|
|
|
|
*/
|
2012-05-03 17:14:02 -07:00
|
|
|
NON_OBJECT_MARKER = 0x40000000
|
|
|
|
};
|
|
|
|
|
2013-04-15 13:00:06 -07:00
|
|
|
/**
|
|
|
|
* Pool allocation with recycler lists indexed by object size, aSize.
|
|
|
|
*/
|
2014-06-02 05:08:21 -07:00
|
|
|
void* AllocateBySize(size_t aSize)
|
2013-04-15 13:00:06 -07:00
|
|
|
{
|
|
|
|
return Allocate(uint32_t(aSize) | uint32_t(NON_OBJECT_MARKER), aSize);
|
|
|
|
}
|
2014-06-02 05:08:21 -07:00
|
|
|
void FreeBySize(size_t aSize, void* aPtr)
|
2013-04-15 13:00:06 -07:00
|
|
|
{
|
|
|
|
Free(uint32_t(aSize) | uint32_t(NON_OBJECT_MARKER), aPtr);
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:00:06 -07:00
|
|
|
/**
|
|
|
|
* Pool allocation with recycler lists indexed by frame-type ID.
|
|
|
|
* Every aID must always be used with the same object size, aSize.
|
|
|
|
*/
|
2014-06-02 05:08:21 -07:00
|
|
|
void* AllocateByFrameID(nsQueryFrame::FrameIID aID, size_t aSize)
|
2013-04-15 13:00:06 -07:00
|
|
|
{
|
|
|
|
return Allocate(aID, aSize);
|
|
|
|
}
|
2014-06-02 05:08:21 -07:00
|
|
|
void FreeByFrameID(nsQueryFrame::FrameIID aID, void* aPtr)
|
2013-04-15 13:00:06 -07:00
|
|
|
{
|
|
|
|
Free(aID, aPtr);
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:00:06 -07: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.
|
|
|
|
*/
|
2014-06-02 05:08:21 -07:00
|
|
|
void* AllocateByObjectID(ObjectID aID, size_t aSize)
|
2013-04-15 13:00:06 -07:00
|
|
|
{
|
|
|
|
return Allocate(aID, aSize);
|
|
|
|
}
|
2014-06-02 05:08:21 -07:00
|
|
|
void FreeByObjectID(ObjectID aID, void* aPtr)
|
2013-04-15 13:00:06 -07:00
|
|
|
{
|
|
|
|
Free(aID, aPtr);
|
|
|
|
}
|
2012-05-03 17:14:02 -07:00
|
|
|
|
2012-06-06 10:29:16 -07:00
|
|
|
/**
|
2013-09-30 16:20:23 -07:00
|
|
|
* Increment aArenaStats with sizes of interesting objects allocated in this
|
|
|
|
* arena and its mOther field with the size of everything else.
|
2012-06-06 10:29:16 -07:00
|
|
|
*/
|
2013-09-30 16:20:23 -07:00
|
|
|
void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
nsArenaMemoryStats* aArenaStats);
|
2010-05-31 19:19:35 -07:00
|
|
|
|
2009-08-17 20:21:06 -07:00
|
|
|
private:
|
2014-06-02 05:08:21 -07:00
|
|
|
void* Allocate(uint32_t aCode, size_t aSize);
|
|
|
|
void Free(uint32_t aCode, void* aPtr);
|
2013-04-15 13:00:06 -07:00
|
|
|
|
|
|
|
// All keys to this hash table fit in 32 bits (see below) so we do not
|
|
|
|
// bother actually hashing them.
|
|
|
|
class FreeList : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef uint32_t KeyType;
|
|
|
|
nsTArray<void *> mEntries;
|
|
|
|
size_t mEntrySize;
|
|
|
|
size_t mEntriesEverAllocated;
|
|
|
|
|
|
|
|
typedef const void* KeyTypePointer;
|
|
|
|
KeyTypePointer mKey;
|
|
|
|
|
2014-08-07 16:48:38 -07:00
|
|
|
explicit FreeList(KeyTypePointer aKey)
|
2013-04-15 13:00:06 -07:00
|
|
|
: mEntrySize(0), mEntriesEverAllocated(0), mKey(aKey) {}
|
|
|
|
// Default copy constructor and destructor are ok.
|
|
|
|
|
|
|
|
bool KeyEquals(KeyTypePointer const aKey) const
|
|
|
|
{ return mKey == aKey; }
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey)
|
|
|
|
{ return NS_INT32_TO_PTR(aKey); }
|
|
|
|
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
|
|
|
{ return NS_PTR_TO_INT32(aKey); }
|
|
|
|
|
2014-08-05 13:27:41 -07:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{ return mEntries.SizeOfExcludingThis(aMallocSizeOf); }
|
|
|
|
|
2013-04-15 13:00:06 -07:00
|
|
|
enum { ALLOW_MEMMOVE = false };
|
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(MOZ_HAVE_MEM_CHECKS)
|
|
|
|
static PLDHashOperator UnpoisonFreeList(FreeList* aEntry, void*);
|
|
|
|
#endif
|
|
|
|
static PLDHashOperator FreeListEnumerator(FreeList* aEntry, void* aData);
|
|
|
|
|
|
|
|
nsTHashtable<FreeList> mFreeLists;
|
|
|
|
PLArenaPool mPool;
|
2009-08-17 20:21:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|