don't discard iframe children.
[kdelibs.git] / khtml / misc / arena.h
blob88e77bc2a5bf4393e8ca42cbe5629039e5afaed5
1 /*
2 * Copyright (C) 1998-2000 Netscape Communications Corporation.
4 * Other contributors:
5 * Nick Blievers <nickb@adacel.com.au>
6 * Jeff Hostetler <jeff@nerdone.com>
7 * Tom Rini <trini@kernel.crashing.org>
8 * Raffaele Sena <raff@netwinder.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * Alternatively, the contents of this file may be used under the terms
25 * of either the Mozilla Public License Version 1.1, found at
26 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
27 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
28 * (the "GPL"), in which case the provisions of the MPL or the GPL are
29 * applicable instead of those above. If you wish to allow use of your
30 * version of this file only under the terms of one of those two
31 * licenses (the MPL or the GPL) and not to allow others to use your
32 * version of this file under the LGPL, indicate your decision by
33 * deletingthe provisions above and replace them with the notice and
34 * other provisions required by the MPL or the GPL, as the case may be.
35 * If you do not delete the provisions above, a recipient may use your
36 * version of this file under any of the LGPL, the MPL or the GPL.
39 #ifndef ARENA_H
40 #define ARENA_H
42 #include <config-khtml.h>
44 // VG annotations for arenas disabled since still buggy
45 #if 0 && defined(HAVE_VALGRIND_MEMCHECK_H) && !defined(NDEBUG)
47 #include <valgrind/memcheck.h>
48 #define VALGRIND_SUPPORT
50 #else
52 #define VALGRIND_CREATE_MEMPOOL(base, redZone, zeroed)
53 #define VALGRIND_DESTROY_MEMPOOL(base)
54 #define VALGRIND_MEMPOOL_ALLOC(base, addr, size)
55 #define VALGRIND_MEMPOOL_FREE(base, addr)
57 #endif
60 #define ARENA_ALIGN_MASK 3
62 typedef unsigned long uword;
64 namespace khtml {
66 struct Arena {
67 Arena* next; // next arena
68 uword base; // aligned base address
69 uword limit; // end of arena (1+last byte)
70 uword avail; // points to next available byte in arena
73 struct ArenaPool {
74 Arena first; // first arena in pool list.
75 Arena* current; // current arena.
76 unsigned int arenasize;
77 unsigned int largealloc; // threshold for fractional allocation strategy
78 unsigned int cumul; // total bytes in pool.
79 uword mask; // Mask (power-of-2 - 1)
82 void InitArenaPool(ArenaPool *pool, const char *name,
83 unsigned int size, unsigned int align);
84 void FinishArenaPool(ArenaPool *pool);
85 void FreeArenaPool(ArenaPool *pool);
86 void* ArenaAllocate(ArenaPool *pool, unsigned int nb);
87 void ArenaFinish(void);
89 #define ARENA_ALIGN(pool, n) (((uword)(n) + ARENA_ALIGN_MASK) & ~ARENA_ALIGN_MASK)
90 #define INIT_ARENA_POOL(pool, name, size) \
91 InitArenaPool(pool, name, size, ARENA_ALIGN_MASK + 1)
93 #define ARENA_ALLOCATE(p, pool, nb) \
94 Arena *_a = (pool)->current; \
95 unsigned int _nb = ARENA_ALIGN(pool, nb); \
96 uword _p = _a->avail; \
97 uword _q = _p + _nb; \
98 if (_q > _a->limit) \
99 _p = (uword)ArenaAllocate(pool, _nb); \
100 else { \
101 VALGRIND_MEMPOOL_ALLOC(_a->base, _p, _nb); \
102 _a->avail = _q; \
104 p = (void *)_p;
107 #define ARENA_MARK(pool) ((void *) (pool)->current->avail)
108 #define UPTRDIFF(p,q) ((uword)(p) - (uword)(q))
110 #ifdef DEBUG
111 #define FREE_PATTERN 0xDA
112 #define CLEAR_UNUSED(a) (assert((a)->avail <= (a)->limit), \
113 memset((void*)(a)->avail, FREE_PATTERN, \
114 (a)->limit - (a)->avail))
115 #define CLEAR_ARENA(a) memset((void*)(a), FREE_PATTERN, \
116 (a)->limit - (uword)(a))
117 #else
118 #define CLEAR_UNUSED(a)
119 #define CLEAR_ARENA(a)
120 #endif
123 } // namespace
125 #endif