* m4/assertion.m4: Fixed copyright header.
[cacao.git] / src / mm / dumpmemory.h
1 /* src/mm/dumpmemory.h - dump memory management
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _DUMPMEMORY_H
27 #define _DUMPMEMORY_H
28
29 /* forward typedefs ***********************************************************/
30
31 typedef struct dumpblock_t dumpblock_t;
32 typedef struct dumpinfo_t  dumpinfo_t;
33
34 #include "config.h"
35
36 #include <stdint.h>
37 #include <string.h>
38
39
40 /* ATTENTION: We need to define dumpblock_t and dumpinfo_t before
41    internal includes, as we need dumpinfo_t as nested structure in
42    threadobject. */
43
44 /* dumpblock ******************************************************************/
45
46 #define DUMPBLOCKSIZE    2 << 13    /* 2 * 8192 bytes */
47 #define ALIGNSIZE        8
48
49 struct dumpblock_t {
50         dumpblock_t *prev;
51         void        *dumpmem;
52         int32_t      size;
53 };
54
55
56 /* dump_allocation *************************************************************
57
58    This struct is used to record dump memory allocations for ENABLE_MEMCHECK.
59
60 *******************************************************************************/
61
62 #if defined(ENABLE_MEMCHECK)
63 typedef struct dump_allocation_t dump_allocation_t;
64
65 struct dump_allocation_t {
66         dump_allocation_t *next;
67         void              *mem;
68         int32_t            useddumpsize;
69         int32_t            size;
70 };
71 #endif
72
73
74 /* dumpinfo *******************************************************************/
75
76 struct dumpinfo_t {
77         dumpblock_t       *currentdumpblock;        /* the current top-most block */
78         int32_t            allocateddumpsize;     /* allocated bytes in this area */
79         int32_t            useddumpsize;          /* used bytes in this dump area */
80 #if defined(ENABLE_MEMCHECK)
81         dump_allocation_t *allocations;       /* list of allocations in this area */
82 #endif
83 };
84
85
86 /* convenience macros *********************************************************/
87
88 #define DNEW(type)            ((type *) dump_alloc(sizeof(type)))
89 #define DMNEW(type,num)       ((type *) dump_alloc(sizeof(type) * (num)))
90 #define DMREALLOC(ptr,type,num1,num2) dump_realloc((ptr), sizeof(type) * (num1), \
91                                                           sizeof(type) * (num2))
92
93 /* function prototypes ********************************************************/
94
95 void    *dump_alloc(int32_t size);
96 void    *dump_realloc(void *src, int32_t len1, int32_t len2);
97 int32_t  dump_size(void);
98 void     dump_release(int32_t size);
99
100 #endif /* _DUMPMEMORY_H */
101
102
103 /*
104  * These are local overrides for various environment variables in Emacs.
105  * Please do not remove this and leave it at the end of the file, where
106  * Emacs will automagically detect them.
107  * ---------------------------------------------------------------------
108  * Local variables:
109  * mode: c
110  * indent-tabs-mode: t
111  * c-basic-offset: 4
112  * tab-width: 4
113  * End:
114  * vim:noexpandtab:sw=4:ts=4:
115  */