-/* 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 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
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 575 2003-11-09 17:26:53Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
#ifndef _MEMORY_H
#define _MEMORY_H
-#include "types.h"
+/* forward typedefs ***********************************************************/
+
+typedef struct dumpblock_t dumpblock_t;
+typedef struct dumpinfo_t dumpinfo_t;
+
+#include "config.h"
+
+#include <string.h>
+
+#include "vm/types.h"
+
+
+/* ATTENTION: We need to define dumpblock_t and dumpinfo_t before
+ internal includes, as we need dumpinfo_t as nested structure in
+ threadobject. */
+
+/* dumpblock ******************************************************************/
+
+#define DUMPBLOCKSIZE 2 << 13 /* 2 * 8192 bytes */
+#define ALIGNSIZE 8
+
+struct dumpblock_t {
+ dumpblock_t *prev;
+ u1 *dumpmem;
+ s4 size;
+};
+
+
+/* dump_allocation *************************************************************
+
+ This struct is used to record dump memory allocations for ENABLE_MEMCHECK.
+
+*******************************************************************************/
+
+#if defined(ENABLE_MEMCHECK)
+typedef struct dump_allocation_t dump_allocation_t;
+
+struct dump_allocation_t {
+ dump_allocation_t *next;
+ u1 *mem;
+ s4 useddumpsize;
+ s4 size;
+};
+#endif
+
+
+/* dumpinfo *******************************************************************/
+
+struct dumpinfo_t {
+ dumpblock_t *currentdumpblock; /* the current top-most block */
+ s4 allocateddumpsize; /* allocated bytes in this area */
+ s4 useddumpsize; /* used bytes in this dump area */
+#if defined(ENABLE_MEMCHECK)
+ dump_allocation_t *allocations; /* list of allocations in this area */
+#endif
+};
+
+
+/* internal includes **********************************************************/
+
+#include "mm/gc-common.h"
+
/*
---------------------------- Interface description -----------------------
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 MEMORY_ALIGN(pos,size) ((((pos) + (size) - 1) / (size)) * (size))
+#define PADDING(pos,size) (MEMORY_ALIGN((pos),(size)) - (pos))
+#define OFFSET(s,el) ((s4) ((ptrint) &(((s*) 0)->el)))
+
+
+#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))
+
+
+#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))
+
+#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))
+
+#define CNEW(type,num) ((type *) memory_cnew(sizeof(type) * (num)))
+#define CFREE(ptr,num) memory_cfree((ptr),(num))
+
+
+/* GC macros ******************************************************************/
+
/* Uncollectable memory which can contain references */
-void *heap_alloc_uncollectable(u4 bytelen);
-#define GCNEW(type,num) heap_alloc_uncollectable(sizeof(type) * (num))
-#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)))
+#define GCNEW_UNCOLLECTABLE(type,num) ((type *) heap_alloc_uncollectable(sizeof(type) * (num)))
+#define GCNEW(type) heap_allocate(sizeof(type), true, NULL)
+#define GCMNEW(type,num) heap_allocate(sizeof(type) * (num), true, NULL)
-#define NEW(type) ((type*) mem_alloc(sizeof(type)))
-#define FREE(ptr,type) mem_free(ptr, sizeof(type))
+#define GCFREE(ptr) heap_free((ptr))
-#define LNEW(type) ((type*) lit_mem_alloc(sizeof(type)))
-#define LFREE(ptr,type) lit_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))
+/* initializes the memory subsystem */
+bool memory_init(void);
-#define MCOPY(dest,src,type,num) memcpy(dest,src, sizeof(type)* (num))
+void *memory_mmap_anon(void *addr, size_t len, int prot, int flags);
-#ifdef USE_CODEMMAP
-#define CNEW(type,num) ((type*) mem_mmap( sizeof(type) * (num)))
-#define CFREE(ptr,num)
-#else
-#define CNEW(type,num) ((type*) mem_alloc(sizeof(type) * (num)))
-#define CFREE(ptr,num) mem_free(ptr, num)
-#endif
+void *memory_cnew(s4 size);
+void memory_cfree(void *p, s4 size);
+void *mem_alloc(s4 size);
+void mem_free(void *m, s4 size);
+void *mem_realloc(void *src, s4 len1, s4 len2);
-void *mem_alloc(int length);
-void *mem_mmap(int length);
-void *lit_mem_alloc(int length);
-void mem_free(void *m, int length);
-void lit_mem_free(void *m, int length);
-void *mem_realloc(void *m, int len1, int len2);
-long int mem_usage();
+#if defined(ENABLE_THREADS)
+bool memory_start_thread(void);
+#endif
-void *dump_alloc(int length);
-void *dump_realloc(void *m, int len1, int len2);
-long int dump_size();
-void dump_release(long int size);
+void *dump_alloc(s4 size);
+void *dump_realloc(void *src, s4 len1, s4 len2);
+s4 dump_size(void);
+void dump_release(s4 size);
-void mem_usagelog(int givewarnings);
-
#endif /* _MEMORY_H */