-/* toolbox/memory.h - macros for memory management
+/* src/mm/memory.h - macros for memory management
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
- M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
- P. Tomsich, J. Wenninger
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
-
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Reinhard Grafl
-
- $Id: memory.h 1637 2004-12-01 10:33:25Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
#ifndef _MEMORY_H
#define _MEMORY_H
-#include "arch.h"
-#include "types.h"
+#include "config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <string.h>
+
+#include "vm/types.h"
+
+#include "mm/codememory.h"
+#include "mm/dumpmemory.h"
+
+
+/* constants for ENABLE_MEMCHECK **********************************************/
+
+#if defined(ENABLE_MEMCHECK)
+#define MEMORY_CANARY_SIZE 16
+#define MEMORY_CANARY_FIRST_BYTE 0xca
+#define MEMORY_CLEAR_BYTE 0xa5
+#endif /* defined(ENABLE_MEMCHECK) */
+
+
+/* internal includes **********************************************************/
+
+#include "mm/gc-common.h"
/*
mem_realloc ... change size of a memory block (position may change)
mem_usage ..... amount of allocated memory
-
- 2. explicit allocating, automatic deallocating
-
- dump_alloc .... allocate a memory block in the dump area
- dump_realloc .. change size of a memory block (position may change)
- dump_size ..... marks the current top of dump
- dump_release .. free all memory requested after the mark
-
-
There are some useful macros:
NEW (type) ....... allocate memory for an element of type `type`
MREALLOC (ptr,type,num1,num2) .. enlarge the array to size num2
-These macros do the same except they operate on the dump area:
-
- DNEW, DMNEW, DMREALLOC (there is no DFREE)
-
-
-------------------------------------------------------------------------------
Some more macros:
- ALIGN (pos, size) ... make pos divisible by size. always returns an
- address >= pos.
+ MEMORY_ALIGN (pos, size) ... make pos divisible by size. always returns an
+ address >= pos.
OFFSET (s,el) ....... returns the offset of 'el' in structure 's' in bytes.
*/
-
-#define DUMPBLOCKSIZE 2 << 13 /* 2 * 8192 bytes */
-#define ALIGNSIZE 8
+#define MEMORY_ALIGN(pos,size) ((((pos) + (size) - 1) / (size)) * (size))
+#define PADDING(pos,size) (MEMORY_ALIGN((pos),(size)) - (pos))
+#define OFFSET(s,el) ((int32_t) ((ptrint) &(((s*) 0)->el)))
-/* dumpblock *******************************************************************
-
- TODO
-
-*******************************************************************************/
+#define NEW(type) ((type *) mem_alloc(sizeof(type)))
+#define FREE(ptr,type) mem_free((ptr), sizeof(type))
-typedef struct dumpblock dumpblock;
+#define MNEW(type,num) ((type *) mem_alloc(sizeof(type) * (num)))
+#define MFREE(ptr,type,num) mem_free((ptr), sizeof(type) * (num))
-struct dumpblock {
- dumpblock *prev;
- u1 *dumpmem;
- s4 size;
-};
+#define MREALLOC(ptr,type,num1,num2) mem_realloc((ptr), sizeof(type) * (num1), \
+ sizeof(type) * (num2))
-/* dumpinfo ********************************************************************
+#define MCOPY(dest,src,type,num) memcpy((dest), (src), sizeof(type) * (num))
+#define MSET(ptr,byte,type,num) memset((ptr), (byte), sizeof(type) * (num))
+#define MZERO(ptr,type,num) MSET(ptr,0,type,num)
+#define MMOVE(dest,src,type,num) memmove((dest), (src), sizeof(type) * (num))
- DOCUMENT ME!
-*******************************************************************************/
+/* GC macros (boehm only) *****************************************************/
-typedef struct dumpinfo dumpinfo;
+#if defined(ENABLE_GC_BOEHM)
-struct dumpinfo {
- dumpblock *currentdumpblock;
- s4 allocateddumpsize;
- s4 useddumpsize;
-};
+/* Uncollectable memory which can contain references */
+#define GCNEW_UNCOLLECTABLE(type,num) ((type *) heap_alloc_uncollectable(sizeof(type) * (num)))
-/* Uncollectable memory which can contain references */
+#define GCNEW(type) heap_alloc(sizeof(type), true, NULL, true)
+#define GCMNEW(type,num) heap_alloc(sizeof(type) * (num), true, NULL, true)
-#define GCNEW(type,num) ((type *) heap_alloc_uncollectable(sizeof(type) * (num)))
#define GCFREE(ptr) heap_free((ptr))
-#define ALIGN(pos,size) ((((pos) + (size) - 1) / (size)) * (size))
-#define PADDING(pos,size) (ALIGN((pos),(size)) - (pos))
-#define OFFSET(s,el) ((int) ((size_t) & (((s*) 0)->el)))
-
+#endif
-#define NEW(type) ((type *) mem_alloc(sizeof(type)))
-#define FREE(ptr,type) mem_free((ptr), sizeof(type))
-#define MNEW(type,num) ((type *) mem_alloc(sizeof(type) * (num)))
-#define MFREE(ptr,type,num) mem_free((ptr), sizeof(type) * (num))
-#define MREALLOC(ptr,type,num1,num2) mem_realloc((ptr), sizeof(type) * (num1), \
- sizeof(type) * (num2))
+/* function prototypes ********************************************************/
-#define DNEW(type) ((type *) dump_alloc(sizeof(type)))
-#define DMNEW(type,num) ((type *) dump_alloc(sizeof(type) * (num)))
-#define DMREALLOC(ptr,type,num1,num2) dump_realloc((ptr), sizeof(type) * (num1), \
- sizeof(type) * (num2))
+bool memory_init(void);
-#define MCOPY(dest,src,type,num) memcpy((dest), (src), sizeof(type) * (num))
-#define MSET(ptr,byte,type,num) memset((ptr), (byte), sizeof(type) * (num))
+void memory_mprotect(void *addr, size_t len, int prot);
-#if defined(USE_CODEMMAP)
-#define CNEW(type,num) ((type *) mem_mmap(sizeof(type) * (num)))
-#define CFREE(ptr,num) /* nothing */
-#else
-#define CNEW(type,num) ((type *) mem_alloc(sizeof(type) * (num)))
-#define CFREE(ptr,num) mem_free((ptr), (num))
-#endif
+void *memory_checked_alloc(size_t size);
+void *memory_cnew(int32_t size);
+void memory_cfree(void *p, int32_t size);
-/* function prototypes ********************************************************/
+void *mem_alloc(int32_t size);
+void mem_free(void *m, int32_t size);
+void *mem_realloc(void *src, int32_t len1, int32_t len2);
-void *mem_mmap(s4 size);
-void *mem_alloc(s4 size);
-void mem_free(void *m, s4 size);
-void *mem_realloc(void *src, s4 len1, s4 len2);
+#if defined(ENABLE_THREADS)
+bool memory_start_thread(void);
+#endif
-void *dump_alloc(s4 size);
-void *dump_realloc(void *src, s4 len1, s4 len2);
-s4 dump_size();
-void dump_release(s4 size);
+#ifdef __cplusplus
+}
+#endif
#endif /* _MEMORY_H */
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/