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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsPresArena_h___
|
|
|
|
#define nsPresArena_h___
|
|
|
|
|
|
|
|
#include "nscore.h"
|
2009-09-15 15:00:04 -07:00
|
|
|
#include "nsQueryFrame.h"
|
|
|
|
|
2012-04-11 17:17:44 -07:00
|
|
|
#include "mozilla/StandardInteger.h"
|
|
|
|
|
2012-06-06 10:29:16 -07:00
|
|
|
class nsArenaMemoryStats;
|
|
|
|
|
2009-09-15 15:00:04 -07:00
|
|
|
// Uncomment this to disable arenas, instead forwarding to
|
|
|
|
// malloc for every allocation.
|
|
|
|
//#define DEBUG_TRACEMALLOC_PRESARENA 1
|
|
|
|
|
|
|
|
// The debugging version of nsPresArena does not free all the memory it
|
|
|
|
// allocated when the arena itself is destroyed.
|
|
|
|
#ifdef DEBUG_TRACEMALLOC_PRESARENA
|
2011-10-17 07:59:28 -07:00
|
|
|
#define PRESARENA_MUST_FREE_DURING_DESTROY true
|
2009-09-15 15:00:04 -07:00
|
|
|
#else
|
2011-10-17 07:59:28 -07:00
|
|
|
#define PRESARENA_MUST_FREE_DURING_DESTROY false
|
2009-09-15 15:00:04 -07:00
|
|
|
#endif
|
2009-08-17 20:21:06 -07:00
|
|
|
|
|
|
|
class nsPresArena {
|
|
|
|
public:
|
|
|
|
nsPresArena();
|
|
|
|
~nsPresArena();
|
|
|
|
|
2012-05-03 17:14:02 -07:00
|
|
|
// Pool allocation with recycler lists indexed by object size, aSize.
|
2009-09-15 15:00:04 -07:00
|
|
|
NS_HIDDEN_(void*) AllocateBySize(size_t aSize);
|
|
|
|
NS_HIDDEN_(void) FreeBySize(size_t aSize, void* aPtr);
|
|
|
|
|
2012-05-03 17:14:02 -07:00
|
|
|
// Pool allocation with recycler lists indexed by frame-type ID.
|
|
|
|
// Every aID must always be used with the same object size, aSize.
|
|
|
|
NS_HIDDEN_(void*) AllocateByFrameID(nsQueryFrame::FrameIID aID, size_t aSize);
|
|
|
|
NS_HIDDEN_(void) FreeByFrameID(nsQueryFrame::FrameIID aID, void* aPtr);
|
2009-08-17 20:21:06 -07:00
|
|
|
|
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,
|
2012-05-03 17:14:02 -07:00
|
|
|
|
2012-05-03 17:14:02 -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.
|
|
|
|
NON_OBJECT_MARKER = 0x40000000
|
|
|
|
};
|
|
|
|
|
|
|
|
// Pool allocation with recycler lists indexed by object-type ID (see above).
|
|
|
|
// Every aID must always be used with the same object size, aSize.
|
|
|
|
NS_HIDDEN_(void*) AllocateByObjectID(ObjectID aID, size_t aSize);
|
|
|
|
NS_HIDDEN_(void) FreeByObjectID(ObjectID aID, void* aPtr);
|
|
|
|
|
2012-06-06 10:29:16 -07:00
|
|
|
/**
|
|
|
|
* Fill aArenaStats with sizes of interesting objects allocated in
|
|
|
|
* this arena and its mOther field with the size of everything else.
|
|
|
|
*/
|
|
|
|
void SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
nsArenaMemoryStats* aArenaStats);
|
2010-05-31 19:19:35 -07:00
|
|
|
|
2011-03-17 20:14:31 -07:00
|
|
|
/**
|
|
|
|
* Get the poison value that can be used to fill a memory space with
|
|
|
|
* an address that leads to a safe crash when dereferenced.
|
|
|
|
*
|
|
|
|
* The caller is responsible for ensuring that a pres shell has been
|
|
|
|
* initialized before calling this.
|
|
|
|
*/
|
2012-04-11 17:17:44 -07:00
|
|
|
static uintptr_t GetPoisonValue();
|
2011-03-17 20:14:31 -07:00
|
|
|
|
2009-08-17 20:21:06 -07:00
|
|
|
private:
|
|
|
|
struct State;
|
|
|
|
State* mState;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|