2009-08-18 07:21:06 +04: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 15:12:37 +04: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-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___
|
|
|
|
|
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"
|
2009-09-16 02:00:04 +04:00
|
|
|
#include "nsQueryFrame.h"
|
2013-04-16 00:00:06 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "plarena.h"
|
2012-04-12 04:17:44 +04:00
|
|
|
|
2012-06-13 18:43:38 +04:00
|
|
|
struct nsArenaMemoryStats;
|
2012-06-06 21:29:16 +04:00
|
|
|
|
2009-08-18 07:21:06 +04:00
|
|
|
class nsPresArena {
|
|
|
|
public:
|
|
|
|
nsPresArena();
|
|
|
|
~nsPresArena();
|
|
|
|
|
2012-05-04 04:14:02 +04:00
|
|
|
enum ObjectID {
|
2012-05-04 04:14:02 +04:00
|
|
|
nsLineBox_id = nsQueryFrame::NON_FRAME_MARKER,
|
2012-06-06 21:35:40 +04:00
|
|
|
nsRuleNode_id,
|
|
|
|
nsStyleContext_id,
|
2014-07-19 08:22:20 +04:00
|
|
|
nsInheritedStyleData_id,
|
|
|
|
nsResetStyleData_id,
|
2015-06-23 04:48:18 +03:00
|
|
|
nsConditionalResetStyleData_id,
|
|
|
|
nsConditionalResetStyleDataEntry_id,
|
2013-04-01 19:26:02 +04:00
|
|
|
nsFrameList_id,
|
2012-05-04 04:14:02 +04:00
|
|
|
|
2014-10-17 00:10:00 +04:00
|
|
|
CustomCounterStyle_id,
|
|
|
|
DependentBuiltinCounterStyle_id,
|
|
|
|
|
2014-07-16 09:27:13 +04: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-16 00:00:06 +04: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-04 04:14:02 +04:00
|
|
|
NON_OBJECT_MARKER = 0x40000000
|
|
|
|
};
|
|
|
|
|
2013-04-16 00:00:06 +04:00
|
|
|
/**
|
|
|
|
* Pool allocation with recycler lists indexed by object size, aSize.
|
|
|
|
*/
|
2014-06-02 16:08:21 +04:00
|
|
|
void* AllocateBySize(size_t aSize)
|
2013-04-16 00:00:06 +04:00
|
|
|
{
|
|
|
|
return Allocate(uint32_t(aSize) | uint32_t(NON_OBJECT_MARKER), aSize);
|
|
|
|
}
|
2014-06-02 16:08:21 +04:00
|
|
|
void FreeBySize(size_t aSize, void* aPtr)
|
2013-04-16 00:00:06 +04:00
|
|
|
{
|
|
|
|
Free(uint32_t(aSize) | uint32_t(NON_OBJECT_MARKER), aPtr);
|
|
|
|
}
|
|
|
|
|
2013-04-16 00:00:06 +04: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 16:08:21 +04:00
|
|
|
void* AllocateByFrameID(nsQueryFrame::FrameIID aID, size_t aSize)
|
2013-04-16 00:00:06 +04:00
|
|
|
{
|
|
|
|
return Allocate(aID, aSize);
|
|
|
|
}
|
2014-06-02 16:08:21 +04:00
|
|
|
void FreeByFrameID(nsQueryFrame::FrameIID aID, void* aPtr)
|
2013-04-16 00:00:06 +04:00
|
|
|
{
|
|
|
|
Free(aID, aPtr);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-06-02 16:08:21 +04:00
|
|
|
void* AllocateByObjectID(ObjectID aID, size_t aSize)
|
2013-04-16 00:00:06 +04:00
|
|
|
{
|
|
|
|
return Allocate(aID, aSize);
|
|
|
|
}
|
2014-06-02 16:08:21 +04:00
|
|
|
void FreeByObjectID(ObjectID aID, void* aPtr)
|
2013-04-16 00:00:06 +04:00
|
|
|
{
|
|
|
|
Free(aID, aPtr);
|
|
|
|
}
|
2012-05-04 04:14:02 +04:00
|
|
|
|
2012-06-06 21:29:16 +04:00
|
|
|
/**
|
2013-10-01 03:20:23 +04: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 21:29:16 +04:00
|
|
|
*/
|
2013-10-01 03:20:23 +04:00
|
|
|
void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
nsArenaMemoryStats* aArenaStats);
|
2010-06-01 06:19:35 +04:00
|
|
|
|
2009-08-18 07:21:06 +04:00
|
|
|
private:
|
2014-06-02 16:08:21 +04:00
|
|
|
void* Allocate(uint32_t aCode, size_t aSize);
|
|
|
|
void Free(uint32_t aCode, void* aPtr);
|
2013-04-16 00:00:06 +04: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-08 03:48:38 +04:00
|
|
|
explicit FreeList(KeyTypePointer aKey)
|
2013-04-16 00:00:06 +04: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-06 00:27:41 +04:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{ return mEntries.SizeOfExcludingThis(aMallocSizeOf); }
|
|
|
|
|
2013-04-16 00:00:06 +04:00
|
|
|
enum { ALLOW_MEMMOVE = false };
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTHashtable<FreeList> mFreeLists;
|
|
|
|
PLArenaPool mPool;
|
2009-08-18 07:21:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|