This commit introduces C++ support.
[cacao.git] / src / mm / memory.h
index 3c4000ad1c4b2a493673cf10a762c5b4843dfc63..8a88321d38480fceaa3ebb1d34759a2b84952dd9 100644 (file)
@@ -1,9 +1,7 @@
 /* src/mm/memory.h - macros for memory management
 
-   Copyright (C) 1996-2005, 2006 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
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Reinhard Grafl
-
-   Changes: Christian Thalinger
-
-   $Id: memory.h 6034 2006-11-21 21:02:30Z twisti $
-
 */
 
 
 #ifndef _MEMORY_H
 #define _MEMORY_H
 
-/* forward typedefs ***********************************************************/
-
-typedef struct dumpblock_t dumpblock_t;
-typedef struct dumpinfo_t  dumpinfo_t;
-
 #include "config.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #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
+#include "mm/codememory.h"
+#include "mm/dumpmemory.h"
 
 
-/* dumpinfo *******************************************************************/
+/* constants for ENABLE_MEMCHECK **********************************************/
 
-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
-};
+#define MEMORY_CANARY_SIZE          16
+#define MEMORY_CANARY_FIRST_BYTE    0xca
+#define MEMORY_CLEAR_BYTE           0xa5
+#endif /* defined(ENABLE_MEMCHECK) */
 
 
 /* internal includes **********************************************************/
@@ -111,15 +66,6 @@ There are two possible choices for allocating memory:
                        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`
@@ -130,11 +76,6 @@ There are some useful macros:
        
        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:
@@ -152,7 +93,7 @@ Some more macros:
 
 #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 OFFSET(s,el)          ((int32_t) ((ptrint) &(((s*) 0)->el)))
 
 
 #define NEW(type)             ((type *) mem_alloc(sizeof(type)))
@@ -165,48 +106,50 @@ Some more macros:
                                                         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 (boehm only) *****************************************************/
 
-/* GC macros ******************************************************************/
+#if defined(ENABLE_GC_BOEHM)
 
 /* Uncollectable memory which can contain references */
 
 #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 GCNEW(type)           heap_alloc(sizeof(type), true, NULL, true)
+#define GCMNEW(type,num)      heap_alloc(sizeof(type) * (num), true, NULL, true)
 
 #define GCFREE(ptr)           heap_free((ptr))
 
+#endif
+
 
 /* function prototypes ********************************************************/
 
-/* initializes the memory subsystem */
-bool memory_init(void);
+bool  memory_init(void);
+
+void  memory_mprotect(void *addr, size_t len, int prot);
 
-void *memory_cnew(s4 size);
-void  memory_cfree(void *p, s4 size);
+void *memory_checked_alloc(size_t size);
 
-void *mem_alloc(s4 size);
-void  mem_free(void *m, s4 size);
-void *mem_realloc(void *src, s4 len1, s4 len2);
+void *memory_cnew(int32_t size);
+void  memory_cfree(void *p, int32_t 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_alloc(int32_t size);
+void  mem_free(void *m, int32_t size);
+void *mem_realloc(void *src, int32_t len1, int32_t len2);
+
+#if defined(ENABLE_THREADS)
+bool  memory_start_thread(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _MEMORY_H */
 
@@ -222,4 +165,5 @@ void  dump_release(s4 size);
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */