File: nsPresArena.h

package info (click to toggle)
wine-gecko-2.21 2.21%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 646,272 kB
  • ctags: 630,086
  • sloc: cpp: 2,895,786; ansic: 1,502,970; python: 156,675; asm: 115,373; java: 111,421; sh: 63,309; xml: 62,872; makefile: 58,685; perl: 19,182; objc: 3,461; yacc: 2,051; lex: 979; pascal: 929; exp: 449; php: 244; lisp: 228; awk: 211; sed: 26; csh: 21; ada: 16; ruby: 3
file content (84 lines) | stat: -rw-r--r-- 2,891 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=2 sw=2 et tw=78:
 * 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/.
 */

#ifndef nsPresArena_h___
#define nsPresArena_h___

#include "nscore.h"
#include "nsQueryFrame.h"

#include "mozilla/StandardInteger.h"

struct nsArenaMemoryStats;

// 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
#define PRESARENA_MUST_FREE_DURING_DESTROY true
#else
#define PRESARENA_MUST_FREE_DURING_DESTROY false
#endif

class nsPresArena {
public:
  nsPresArena();
  ~nsPresArena();

  // Pool allocation with recycler lists indexed by object size, aSize.
  NS_HIDDEN_(void*) AllocateBySize(size_t aSize);
  NS_HIDDEN_(void)  FreeBySize(size_t aSize, void* aPtr);

  // 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);

  enum ObjectID {
    nsLineBox_id = nsQueryFrame::NON_FRAME_MARKER,
    nsRuleNode_id,
    nsStyleContext_id,

    // 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);

  /**
   * 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);

  /**
   * 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.
   */
  static uintptr_t GetPoisonValue();

private:
  struct State;
  State* mState;
};

#endif